Skip to content

Commit

Permalink
Merge branch 'release/2.0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
gravit0 committed Oct 15, 2021
2 parents e0c8a44 + d01ba5e commit 52ac04a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -475,7 +490,7 @@ private CompletableFuture<LoginAndPasswordResult> tryLogin(String resentLogin, A
return authFuture;
}

private void start(CompletableFuture<AuthRequestEvent> result, String resentLogin, AuthRequest.AuthPasswordInterface resentPassword) {
private void start(CompletableFuture<SuccessAuth> result, String resentLogin, AuthRequest.AuthPasswordInterface resentPassword) {
CompletableFuture<LoginAndPasswordResult> authFuture = tryLogin(resentLogin, resentPassword);
authFuture.thenAccept(e -> {
login(e.login, e.password, authAvailability, result);
Expand All @@ -490,18 +505,20 @@ private void start(CompletableFuture<AuthRequestEvent> result, String resentLogi
});
}

private CompletableFuture<AuthRequestEvent> start() {
CompletableFuture<AuthRequestEvent> result = new CompletableFuture<>();
private CompletableFuture<SuccessAuth> start() {
CompletableFuture<SuccessAuth> result = new CompletableFuture<>();
start(result, null, null);
return result;
}


private void login(String login, AuthRequest.AuthPasswordInterface password, GetAvailabilityAuthRequestEvent.AuthAvailability authId, CompletableFuture<AuthRequestEvent> result) {
private void login(String login, AuthRequest.AuthPasswordInterface password, GetAvailabilityAuthRequestEvent.AuthAvailability authId, CompletableFuture<SuccessAuth> 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;
Expand Down Expand Up @@ -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;
}
}
}

0 comments on commit 52ac04a

Please sign in to comment.