diff --git a/build.gradle b/build.gradle index f2b2ded0..072d9178 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ javafx { sourceCompatibility = '1.8' targetCompatibility = '1.8' group 'pro.gravit.launcher' -version '2.0.3' +version '2.0.4' def mainClassName = "pro.gravit.launcher.client.JavaRuntimeModule" task sourcesJar(type: Jar) { diff --git a/src/main/java/pro/gravit/launcher/client/JavaRuntimeModule.java b/src/main/java/pro/gravit/launcher/client/JavaRuntimeModule.java index 7c3f13ee..bef8ba80 100644 --- a/src/main/java/pro/gravit/launcher/client/JavaRuntimeModule.java +++ b/src/main/java/pro/gravit/launcher/client/JavaRuntimeModule.java @@ -22,7 +22,7 @@ public class JavaRuntimeModule extends LauncherModule { private RuntimeProvider provider; public JavaRuntimeModule() { - super(new LauncherModuleInfo("StdJavaRuntime", new Version(2, 0, 3, 1, Version.Type.STABLE), + super(new LauncherModuleInfo("StdJavaRuntime", new Version(2, 0, 4, 1, Version.Type.STABLE), 0, new String[]{}, new String[]{"runtime"})); } diff --git a/src/main/java/pro/gravit/launcher/client/gui/scenes/login/LoginScene.java b/src/main/java/pro/gravit/launcher/client/gui/scenes/login/LoginScene.java index d74ea8c0..c053c578 100644 --- a/src/main/java/pro/gravit/launcher/client/gui/scenes/login/LoginScene.java +++ b/src/main/java/pro/gravit/launcher/client/gui/scenes/login/LoginScene.java @@ -273,7 +273,7 @@ private void loginWithOAuth(AuthOAuthPassword password, GetAvailabilityAuthReque AuthRequest authRequest = authService.makeAuthRequest(null, password, authAvailability.name); processing(authRequest, application.getTranslation("runtime.overlay.processing.text.auth"), (result) -> { contextHelper.runInFxThread(() -> { - onSuccessLogin(result); + onSuccessLogin(new SuccessAuth(result, null, null)); }); }, (error) -> { if (error.equals(AuthRequestEvent.OAUTH_TOKEN_INVALID)) { @@ -301,13 +301,28 @@ private void loginWithGui() { }); } - private void onSuccessLogin(AuthRequestEvent result) { + private boolean checkSavePasswordAvailable(AuthRequest.AuthPasswordInterface password) { + if(password instanceof Auth2FAPassword) + return false; + if(password instanceof AuthMultiPassword) + return false; + if(authAvailability == null || authAvailability.details == null || authAvailability.details.size() == 0 || !( authAvailability.details.get(0) instanceof AuthPasswordDetails ) ) + return false; + return true; + } + + private void onSuccessLogin(SuccessAuth successAuth) { + AuthRequestEvent result = successAuth.requestEvent; application.stateService.setAuthResult(authAvailability.name, result); boolean savePassword = savePasswordCheckBox.isSelected(); if (savePassword) { - application.runtimeSettings.login = result.playerProfile.username; // TODO + application.runtimeSettings.login = successAuth.recentLogin; if (result.oauth == null) { - application.runtimeSettings.password = null; + if(successAuth.recentPassword != null && checkSavePasswordAvailable(successAuth.recentPassword)) { + application.runtimeSettings.password = successAuth.recentPassword; + } else { + LogHelper.warning("2FA/MFA Password not saved"); + } } else { application.runtimeSettings.oauthAccessToken = result.oauth.accessToken; application.runtimeSettings.oauthRefreshToken = result.oauth.refreshToken; @@ -475,7 +490,7 @@ private CompletableFuture tryLogin(String resentLogin, A return authFuture; } - private void start(CompletableFuture result, String resentLogin, AuthRequest.AuthPasswordInterface resentPassword) { + private void start(CompletableFuture result, String resentLogin, AuthRequest.AuthPasswordInterface resentPassword) { CompletableFuture authFuture = tryLogin(resentLogin, resentPassword); authFuture.thenAccept(e -> { login(e.login, e.password, authAvailability, result); @@ -490,18 +505,20 @@ private void start(CompletableFuture result, String resentLogi }); } - private CompletableFuture start() { - CompletableFuture result = new CompletableFuture<>(); + private CompletableFuture start() { + CompletableFuture result = new CompletableFuture<>(); start(result, null, null); return result; } - private void login(String login, AuthRequest.AuthPasswordInterface password, GetAvailabilityAuthRequestEvent.AuthAvailability authId, CompletableFuture result) { + private void login(String login, AuthRequest.AuthPasswordInterface password, GetAvailabilityAuthRequestEvent.AuthAvailability authId, CompletableFuture result) { isLoginStarted = true; LogHelper.dev("Auth with %s password ***** authId %s", login, authId); AuthRequest authRequest = authService.makeAuthRequest(login, password, authId.name); - processing(authRequest, application.getTranslation("runtime.overlay.processing.text.auth"), result::complete, (error) -> { + processing(authRequest, application.getTranslation("runtime.overlay.processing.text.auth"), (event) -> { + result.complete(new SuccessAuth(event, login, password)); + }, (error) -> { if (error.equals(AuthRequestEvent.OAUTH_TOKEN_INVALID)) { application.runtimeSettings.oauthAccessToken = null; application.runtimeSettings.oauthRefreshToken = null; @@ -546,4 +563,16 @@ private void login(String login, AuthRequest.AuthPasswordInterface password, Get return authService.getPasswordFromList(result); }*/ } + + public static class SuccessAuth { + public AuthRequestEvent requestEvent; + public String recentLogin; + public AuthRequest.AuthPasswordInterface recentPassword; + + public SuccessAuth(AuthRequestEvent requestEvent, String recentLogin, AuthRequest.AuthPasswordInterface recentPassword) { + this.requestEvent = requestEvent; + this.recentLogin = recentLogin; + this.recentPassword = recentPassword; + } + } }