mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Properly use CompleteableFuture for MSA auth
This commit is contained in:
parent
1a0ac26398
commit
ef7c673276
1 changed files with 22 additions and 19 deletions
|
@ -609,28 +609,31 @@ public class GeyserSession implements CommandSender {
|
||||||
}
|
}
|
||||||
|
|
||||||
loggingIn = true;
|
loggingIn = true;
|
||||||
|
|
||||||
|
// This just looks cool
|
||||||
|
SetTimePacket packet = new SetTimePacket();
|
||||||
|
packet.setTime(16000);
|
||||||
|
sendUpstreamPacket(packet);
|
||||||
|
|
||||||
// new thread so clients don't timeout
|
// new thread so clients don't timeout
|
||||||
new Thread(() -> {
|
MsaAuthenticationService msaAuthenticationService = new MsaAuthenticationService(GeyserConnector.OAUTH_CLIENT_ID);
|
||||||
|
|
||||||
|
// Use a future to prevent timeouts as all the authentication is handled sync
|
||||||
|
// This will be changed with the new protocol library.
|
||||||
|
CompletableFuture.supplyAsync(() -> {
|
||||||
try {
|
try {
|
||||||
MsaAuthenticationService msaAuthenticationService = new MsaAuthenticationService(GeyserConnector.OAUTH_CLIENT_ID);
|
return msaAuthenticationService.getAuthCode();
|
||||||
|
} catch (RequestException e) {
|
||||||
MsaAuthenticationService.MsCodeResponse response = msaAuthenticationService.getAuthCode();
|
throw new CompletionException(e);
|
||||||
LoginEncryptionUtils.buildAndShowMicrosoftCodeWindow(this, response);
|
|
||||||
|
|
||||||
// This just looks cool
|
|
||||||
SetTimePacket packet = new SetTimePacket();
|
|
||||||
packet.setTime(16000);
|
|
||||||
sendUpstreamPacket(packet);
|
|
||||||
|
|
||||||
// Wait for the code to validate
|
|
||||||
attemptCodeAuthentication(msaAuthenticationService);
|
|
||||||
} catch (InvalidCredentialsException | IllegalArgumentException e) {
|
|
||||||
connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.auth.login.invalid", getAuthData().getName()));
|
|
||||||
disconnect(LanguageUtils.getPlayerLocaleString("geyser.auth.login.invalid.kick", getClientData().getLanguageCode()));
|
|
||||||
} catch (RequestException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}).start();
|
}).whenComplete((response, ex) -> {
|
||||||
|
if (ex != null) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LoginEncryptionUtils.buildAndShowMicrosoftCodeWindow(this, response);
|
||||||
|
attemptCodeAuthentication(msaAuthenticationService);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue