Search in sources :

Example 1 with AuthenticationException

use of com.mojang.authlib.exceptions.AuthenticationException in project Krothium-Launcher by DarkLBP.

the class YggdrasilGameProfileRepository method findProfilesByNames.

public void findProfilesByNames(String[] names, Agent agent, ProfileLookupCallback callback) {
    HashSet criteria = Sets.newHashSet();
    String[] page = names;
    int i$ = names.length;
    for (int var19 = 0; var19 < i$; ++var19) {
        String var20 = page[var19];
        if (!Strings.isNullOrEmpty(var20)) {
            criteria.add(var20.toLowerCase());
        }
    }
    byte var211 = 0;
    Iterator var221 = Iterables.partition(criteria, ENTRIES_PER_PAGE).iterator();
    while (var221.hasNext()) {
        List var21 = (List) var221.next();
        int var22 = 0;
        while (true) {
            boolean failed = false;
            try {
                ProfileSearchResultsResponse var18 = (ProfileSearchResultsResponse) this.authenticationService.makeRequest(GET_PROFILESID, var21, ProfileSearchResultsResponse.class);
                var22 = 0;
                LOGGER.debug("Page {} returned {} results, parsing", new Object[] { Integer.valueOf(var211), Integer.valueOf(var18.getProfiles().length) });
                HashSet var23 = Sets.newHashSet(var21);
                GameProfile[] var24 = var18.getProfiles();
                int var25 = var24.length;
                for (int var26 = 0; var26 < var25; ++var26) {
                    GameProfile var27 = var24[var26];
                    System.out.println("Profile data from " + var27.getName() + " got from the Krothium API");
                    LOGGER.debug("Successfully looked up profile {}", new Object[] { var27 });
                    var23.remove(var27.getName().toLowerCase());
                    callback.onProfileLookupSucceeded(var27);
                }
                Iterator var261 = Iterables.partition(var23, ENTRIES_PER_PAGE).iterator();
                while (var261.hasNext()) {
                    List var30 = (List) var261.next();
                    var18 = (ProfileSearchResultsResponse) this.authenticationService.makeRequest(GET_PROFILESID_MOJANG, var30, ProfileSearchResultsResponse.class);
                    var22 = 0;
                    LOGGER.debug("Page {} returned {} results, parsing", new Object[] { Integer.valueOf(var211), Integer.valueOf(var18.getProfiles().length) });
                    var23 = Sets.newHashSet(var21);
                    var24 = var18.getProfiles();
                    var25 = var24.length;
                    for (int var26 = 0; var26 < var25; ++var26) {
                        GameProfile var27 = var24[var26];
                        System.out.println("Profile data from " + var27.getName() + " got from the Mojang API");
                        LOGGER.debug("Successfully looked up profile {}", new Object[] { var27 });
                        var23.remove(var27.getName().toLowerCase());
                        callback.onProfileLookupSucceeded(var27);
                    }
                    var261 = var23.iterator();
                    while (var261.hasNext()) {
                        String var271 = (String) var261.next();
                        LOGGER.debug("Couldn\'t find profile {}", new Object[] { var271 });
                        callback.onProfileLookupFailed(new GameProfile(null, var271), new ProfileNotFoundException("Server did not find the requested profile"));
                    }
                    try {
                        Thread.sleep(DELAY_BETWEEN_PAGES);
                    } catch (InterruptedException var191) {
                        ;
                    }
                }
                try {
                    Thread.sleep(DELAY_BETWEEN_PAGES);
                } catch (InterruptedException var191) {
                    ;
                }
            } catch (AuthenticationException var201) {
                AuthenticationException e = var201;
                ++var22;
                if (var22 == MAX_FAIL_COUNT) {
                    Iterator ignored = var21.iterator();
                    while (ignored.hasNext()) {
                        String name = (String) ignored.next();
                        LOGGER.debug("Couldn\'t find profile {} because of a server error", new Object[] { name });
                        callback.onProfileLookupFailed(new GameProfile(null, name), e);
                    }
                } else {
                    try {
                        Thread.sleep(DELAY_BETWEEN_FAILURES);
                    } catch (InterruptedException var181) {
                        ;
                    }
                    failed = true;
                }
            }
            if (!failed) {
                break;
            }
        }
    }
}
Also used : AuthenticationException(com.mojang.authlib.exceptions.AuthenticationException) ProfileSearchResultsResponse(com.mojang.authlib.yggdrasil.response.ProfileSearchResultsResponse) GameProfile(com.mojang.authlib.GameProfile) Iterator(java.util.Iterator) List(java.util.List) HashSet(java.util.HashSet)

Example 2 with AuthenticationException

use of com.mojang.authlib.exceptions.AuthenticationException in project Krothium-Launcher by DarkLBP.

the class YggdrasilMinecraftSessionService method hasJoinedServer.

public GameProfile hasJoinedServer(GameProfile user, String serverId, InetAddress address) throws AuthenticationUnavailableException {
    Map<String, Object> arguments = new HashMap();
    arguments.put("username", user.getName());
    arguments.put("serverId", serverId);
    if (address != null) {
        arguments.put("ip", address.getHostAddress());
    }
    URL url = HttpAuthenticationService.concatenateURL(CHECK_URL, HttpAuthenticationService.buildQuery(arguments));
    try {
        HasJoinedMinecraftServerResponse response = (HasJoinedMinecraftServerResponse) this.getAuthenticationService().makeRequest(url, (Object) null, HasJoinedMinecraftServerResponse.class);
        if (response != null && response.getId() != null) {
            GameProfile result = new GameProfile(response.getId(), user.getName());
            if (response.getProperties() != null) {
                result.getProperties().putAll(response.getProperties());
            }
            return result;
        } else {
            return null;
        }
    } catch (AuthenticationUnavailableException var8) {
        throw var8;
    } catch (AuthenticationException var9) {
        return null;
    }
}
Also used : AuthenticationUnavailableException(com.mojang.authlib.exceptions.AuthenticationUnavailableException) HashMap(java.util.HashMap) HasJoinedMinecraftServerResponse(com.mojang.authlib.yggdrasil.response.HasJoinedMinecraftServerResponse) GameProfile(com.mojang.authlib.GameProfile) AuthenticationException(com.mojang.authlib.exceptions.AuthenticationException) JSONObject(org.json.JSONObject)

Example 3 with AuthenticationException

use of com.mojang.authlib.exceptions.AuthenticationException in project Krothium-Launcher by DarkLBP.

the class YggdrasilMinecraftSessionService method fillGameProfile.

protected GameProfile fillGameProfile(GameProfile profile, boolean requireSecure) {
    try {
        URL url = HttpAuthenticationService.constantURL("https://sessionserver.mojang.com/session/minecraft/profile/" + UUIDTypeAdapter.fromUUID(profile.getId()));
        url = HttpAuthenticationService.concatenateURL(url, "unsigned=" + !requireSecure);
        MinecraftProfilePropertiesResponse response = (MinecraftProfilePropertiesResponse) this.getAuthenticationService().makeRequest(url, (Object) null, MinecraftProfilePropertiesResponse.class);
        if (response == null) {
            LOGGER.debug("Couldn't fetch profile properties for " + profile + " as the profile does not exist");
            return profile;
        } else {
            GameProfile result = new GameProfile(response.getId(), response.getName());
            result.getProperties().putAll(response.getProperties());
            profile.getProperties().putAll(response.getProperties());
            LOGGER.debug("Successfully fetched profile properties for " + profile);
            return result;
        }
    } catch (AuthenticationException var6) {
        LOGGER.warn("Couldn't look up profile properties for " + profile, var6);
        return profile;
    }
}
Also used : GameProfile(com.mojang.authlib.GameProfile) AuthenticationException(com.mojang.authlib.exceptions.AuthenticationException) MinecraftProfilePropertiesResponse(com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse) JSONObject(org.json.JSONObject)

Example 4 with AuthenticationException

use of com.mojang.authlib.exceptions.AuthenticationException in project MinecraftForge by MinecraftForge.

the class Yggdrasil method login.

public static void login(Map<String, String> args) {
    if (!args.containsKey("--username") || !args.containsKey("--password"))
        return;
    YggdrasilUserAuthentication auth = (YggdrasilUserAuthentication) new YggdrasilAuthenticationService(Proxy.NO_PROXY, "1").createUserAuthentication(Agent.MINECRAFT);
    auth.setUsername(args.get("--username"));
    auth.setPassword(args.remove("--password"));
    try {
        auth.logIn();
    } catch (AuthenticationException e) {
        LogManager.getLogger("FMLTWEAK").error("-- Login failed!  " + e.getMessage());
        Throwables.propagate(e);
        // don't set other variables
        return;
    }
    args.put("--username", auth.getSelectedProfile().getName());
    args.put("--uuid", auth.getSelectedProfile().getId().toString().replace("-", ""));
    args.put("--accessToken", auth.getAuthenticatedToken());
    args.put("--userProperties", auth.getUserProperties().toString());
}
Also used : AuthenticationException(com.mojang.authlib.exceptions.AuthenticationException) YggdrasilAuthenticationService(com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService) YggdrasilUserAuthentication(com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication)

Example 5 with AuthenticationException

use of com.mojang.authlib.exceptions.AuthenticationException in project Wurst-MC-1.12 by Wurst-Imperium.

the class LoginManager method login.

public static String login(String email, String password) {
    YggdrasilUserAuthentication auth = (YggdrasilUserAuthentication) new YggdrasilAuthenticationService(Proxy.NO_PROXY, "").createUserAuthentication(Agent.MINECRAFT);
    auth.setUsername(email);
    auth.setPassword(password);
    try {
        auth.logIn();
        Minecraft.getMinecraft().session = new Session(auth.getSelectedProfile().getName(), auth.getSelectedProfile().getId().toString(), auth.getAuthenticatedToken(), "mojang");
        return "";
    } catch (AuthenticationUnavailableException e) {
        return "�4�lCannot contact authentication server!";
    } catch (AuthenticationException e) {
        e.printStackTrace();
        if (e.getMessage().contains("Invalid username or password.") || e.getMessage().toLowerCase().contains("account migrated"))
            return "�4�lWrong password!";
        else
            return "�4�lCannot contact authentication server!";
    } catch (NullPointerException e) {
        return "�4�lWrong password!";
    }
}
Also used : AuthenticationUnavailableException(com.mojang.authlib.exceptions.AuthenticationUnavailableException) AuthenticationException(com.mojang.authlib.exceptions.AuthenticationException) YggdrasilAuthenticationService(com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService) YggdrasilUserAuthentication(com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication) Session(net.minecraft.util.Session)

Aggregations

AuthenticationException (com.mojang.authlib.exceptions.AuthenticationException)5 GameProfile (com.mojang.authlib.GameProfile)3 AuthenticationUnavailableException (com.mojang.authlib.exceptions.AuthenticationUnavailableException)2 YggdrasilAuthenticationService (com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService)2 YggdrasilUserAuthentication (com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication)2 JSONObject (org.json.JSONObject)2 HasJoinedMinecraftServerResponse (com.mojang.authlib.yggdrasil.response.HasJoinedMinecraftServerResponse)1 MinecraftProfilePropertiesResponse (com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse)1 ProfileSearchResultsResponse (com.mojang.authlib.yggdrasil.response.ProfileSearchResultsResponse)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Session (net.minecraft.util.Session)1