Search in sources :

Example 1 with AuthenticationUnavailableException

use of com.mojang.authlib.exceptions.AuthenticationUnavailableException 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 2 with AuthenticationUnavailableException

use of com.mojang.authlib.exceptions.AuthenticationUnavailableException 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)2 AuthenticationUnavailableException (com.mojang.authlib.exceptions.AuthenticationUnavailableException)2 GameProfile (com.mojang.authlib.GameProfile)1 YggdrasilAuthenticationService (com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService)1 YggdrasilUserAuthentication (com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication)1 HasJoinedMinecraftServerResponse (com.mojang.authlib.yggdrasil.response.HasJoinedMinecraftServerResponse)1 HashMap (java.util.HashMap)1 Session (net.minecraft.util.Session)1 JSONObject (org.json.JSONObject)1