Commit f692ae95 authored by superblaubeere27's avatar superblaubeere27

Improved Remember Me

parent c232f572
......@@ -87,7 +87,7 @@ public class LiquidLauncher {
public File launcherDirectory;
public List<ClientBuild> clientBuilds;
public AssetManager assetManager;
public String[] account = AuthenticationUtils.login("CrackedUser");
public AuthenticationUtils.AuthenticationResponse account = AuthenticationUtils.login("CrackedUser");
private URL versionsUrl;
public LiquidLauncher() throws MalformedURLException {
......@@ -202,7 +202,6 @@ public class LiquidLauncher {
}
fatalError("Failed to load LiquidBounce versions: " + e);
}
assetManager = new AssetManager(launcherDirectory);
statusLabel.setText("Checking for updates...");
checkForUpdate();
Runtime.getRuntime().addShutdownHook(new Thread(LiquidLauncher::stop));
......@@ -313,25 +312,11 @@ public class LiquidLauncher {
final String mainClass = obj.get("mainClass").getAsString();
final String minecraftArguments = obj.get("minecraftArguments").getAsString();
if (account[1] != null && !account[1].isEmpty() && account.length <= 2) {
menuInterface.progress.setString("Logging in...");
final String[] loginAccount = AuthenticationUtils.login(account[0], account[1]);
if (loginAccount != null) {
account = loginAccount;
menuInterface.progress.setString("Login successful.");
} else {
menuInterface.progress.setString("Login failed.");
JOptionPane.showMessageDialog(menuInterface, "The currently selected account don't work.\nChange the account!", "Login failed.", JOptionPane.ERROR_MESSAGE);
return;
}
menuInterface.progress.setString("Preparing launch...");
}
final String username = account[2];
final String uuid = account[3];
final String accessToken = account[4];
final String userType = account[1] == null || account[1].isEmpty() ? "legacy" : "mojang";
final String username = account.getName();
final String uuid = account.getUUID();
final String accessToken = account.getAccessToken();
final String userType = !account.isLegacy() ? "legacy" : "mojang";
// GameProcess building
final GameProcessBuilder gameProcessBuilder = new GameProcessBuilder(menuInterface.jvmPath.getText());
......
......@@ -59,8 +59,11 @@ public class Settings {
// TODO Only save session
final JsonObject accountObject = new JsonObject();
accountObject.addProperty("USERNAME", LiquidLauncher.liquidLauncher.account[0]);
accountObject.addProperty("PASSWORD", LiquidLauncher.liquidLauncher.account[1]);
accountObject.addProperty("clientToken", LiquidLauncher.liquidLauncher.account.getClientToken());
accountObject.addProperty("accessToken", LiquidLauncher.liquidLauncher.account.getAccessToken());
accountObject.addProperty("uuid", LiquidLauncher.liquidLauncher.account.getUUID());
accountObject.addProperty("name", LiquidLauncher.liquidLauncher.account.getName());
accountObject.addProperty("legacy", LiquidLauncher.liquidLauncher.account.isLegacy());
jsonObject.add(ACCOUNT, accountObject);
}
......@@ -139,13 +142,13 @@ public class Settings {
if (jsonObject.has(ACCOUNT)) {
// TODO: LOAD SESSION
final JsonObject accountObject = jsonObject.get(ACCOUNT).getAsJsonObject();
final String username = accountObject.get("USERNAME").getAsString();
final JsonElement passwordObject = accountObject.get("PASSWORD");
final String name = accountObject.get("name").getAsString();
final String uuid = accountObject.get("uuid").getAsString();
final String accessToken = accountObject.get("accessToken").getAsString();
final String clientToken = accountObject.get("clientToken").getAsString();
final boolean legacy = accountObject.get("legacy").getAsBoolean();
if (passwordObject.isJsonNull() || passwordObject.getAsString().isEmpty())
LiquidLauncher.liquidLauncher.account = AuthenticationUtils.login(username);
else
LiquidLauncher.liquidLauncher.account = new String[]{username, passwordObject.getAsString()};
LiquidLauncher.liquidLauncher.account = new AuthenticationUtils.AuthenticationResponse(clientToken, accessToken, uuid, name, legacy);
}
} catch (Exception e) {
LiquidLauncher.liquidLauncher.LOGGER.severe("Failed to load settings: ");
......
......@@ -82,6 +82,7 @@
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<selected value="true"/>
<text value="Remember me"/>
</properties>
</component>
......
......@@ -155,7 +155,7 @@ public class MenuInterface extends JFrame {
try {
emailPassword.setText("");
statusLabel.setText("Logging in...");
String[] account = AuthenticationUtils.login(username.getText(), password.getText());
AuthenticationUtils.AuthenticationResponse account = AuthenticationUtils.login(username.getText(), password.getText());
if (account == null) {
statusLabel.setText("Login failed.");
......@@ -360,6 +360,7 @@ public class MenuInterface extends JFrame {
password = new JPasswordField();
panel1.add(password, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
rememberMeCheckBox = new JCheckBox();
rememberMeCheckBox.setSelected(true);
rememberMeCheckBox.setText("Remember me");
panel1.add(rememberMeCheckBox, new GridConstraints(6, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
loginButton = new JButton();
......
......@@ -23,12 +23,13 @@ public class AuthenticationUtils {
private static final String AUTHSERVER_URL = "https://authserver.mojang.com/%s";
private static final String AUTHENTICATION = "authenticate";
private static final String VALIDATE = "validate";
public static String[] login(final String username) {
return new String[]{username, null, username, UUID.randomUUID().toString(), "0"};
public static AuthenticationResponse login(final String username) {
return new AuthenticationResponse(UUID.randomUUID().toString(), "0", username, username, false);
}
public static String[] login(final String username, final String password) throws IOException {
public static AuthenticationResponse login(final String username, final String password) throws IOException {
if (password == null || password.isEmpty())
return login(username);
......@@ -78,10 +79,57 @@ public class AuthenticationUtils {
final JsonObject outputObject = (JsonObject) outputElement;
LiquidLauncher.LOGGER.info("Got response: " + outputElement);
final JsonObject profileObject = outputObject.get("selectedProfile").getAsJsonObject();
return new String[]{username, password, profileObject.get("name").getAsString(), profileObject.get("id").getAsString(), outputObject.get("accessToken").getAsString()};
AuthenticationResponse response = new AuthenticationResponse(outputObject.get("clientToken").getAsString(), outputObject.get("accessToken").getAsString(), profileObject.get("id").getAsString(), profileObject.get("name").getAsString(), profileObject.has("legacy") ? profileObject.get("legacy").getAsBoolean() : true);
return response;
}
return null;
}
public static class AuthenticationResponse {
private final String clientToken;
private final String accessToken;
private final String uuid;
private final String name;
private final boolean legacy;
public AuthenticationResponse(String clientToken, String accessToken, String uuid, String name, boolean legacy) {
this.clientToken = clientToken;
this.accessToken = accessToken;
this.uuid = uuid;
this.name = name;
this.legacy = legacy;
}
@Override
public String toString() {
return "AuthenticationResponse{" +
"clientToken='" + clientToken + '\'' +
", accessToken='" + accessToken + '\'' +
", uuid='" + uuid + '\'' +
", name='" + name + '\'' +
", legacy=" + legacy +
'}';
}
public String getClientToken() {
return clientToken;
}
public String getAccessToken() {
return accessToken;
}
public String getUUID() {
return uuid;
}
public String getName() {
return name;
}
public boolean isLegacy() {
return legacy;
}
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment