Untitled
unknown
java
3 years ago
2.7 kB
15
Indexable
public void login(String username, String password)
{
if (!checkConnection())
{
this.aFrame.getError("Can't connect to minecraft.net");
this.aFrame.offline();
} else
{
try
{
JSONObject agentParameters = new JSONObject();
agentParameters.put("name", "Minecraft");
agentParameters.put("version", 1);
JSONObject jsonParameters = new JSONObject();
jsonParameters.put("agent", agentParameters);
jsonParameters.put("username", username);
jsonParameters.put("password", password);
jsonParameters.put("requestUser", true);
JSONObject jsonResponse = Util.excuteAuth("https://authserver.mojang.com/authenticate", String.valueOf(jsonParameters));
if (!jsonResponse.has("errorMessage"))
{
if (jsonResponse.getJSONArray("availableProfiles").length() == 0)
{
this.launcher = new Launcher();
this.launcher.customParameters.put("username", "Player");
//this.launcher.customParameters.put("sessionid", sessionId);
this.launcher.init();
this.removeAll();
this.add(this.launcher, "Center");
this.validate();
this.launcher.start();
} else
{
username = jsonResponse.getJSONObject("selectedProfile").getString("name");
System.out.println("Username is '" + username + "'");
this.launcher = new Launcher();
this.launcher.customParameters.put("username", username);
//this.launcher.customParameters.put("sessionid", sessionId);
this.launcher.init();
this.removeAll();
this.add(this.launcher, "Center");
this.validate();
this.launcher.start();
this.aFrame.getLastLogin();
}
this.aFrame = null;
this.setTitle("Minecraft");
} else
{
switch (jsonResponse.getString("errorMessage"))
{
case "Forbidden":
if (username.matches("^\\w+$")
&& username.length() > 2 && username.length() < 17)
{
this.playOffline(username);
} else if (username.isEmpty())
{
this.aFrame.getError("Can't connect to minecraft.net");
this.aFrame.offline();
return;
} else
{
this.aFrame.getError("Login failed");
return;
}
break;
case "Invalid credentials.":
this.aFrame.getError("Login failed");
break;
case "Migrated":
this.aFrame.getError("Migrated");
break;
default:
this.aFrame.getError(jsonResponse.getString(String.valueOf(jsonResponse)));
break;
}
}
} catch (Exception e)
{
e.printStackTrace();
this.aFrame.getError(e.toString());
this.aFrame.offline();
}
}
}Editor is loading...