3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 16:12:46 +01:00

Properly use CompleteableFuture for MSA auth

Dieser Commit ist enthalten in:
Redned 2021-07-21 21:39:30 -05:00 committet von RednedEpic
Ursprung 1a0ac26398
Commit ef7c673276

Datei anzeigen

@ -609,28 +609,31 @@ public class GeyserSession implements CommandSender {
} }
loggingIn = true; loggingIn = true;
// new thread so clients don't timeout
new Thread(() -> {
try {
MsaAuthenticationService msaAuthenticationService = new MsaAuthenticationService(GeyserConnector.OAUTH_CLIENT_ID);
MsaAuthenticationService.MsCodeResponse response = msaAuthenticationService.getAuthCode();
LoginEncryptionUtils.buildAndShowMicrosoftCodeWindow(this, response);
// This just looks cool // This just looks cool
SetTimePacket packet = new SetTimePacket(); SetTimePacket packet = new SetTimePacket();
packet.setTime(16000); packet.setTime(16000);
sendUpstreamPacket(packet); sendUpstreamPacket(packet);
// Wait for the code to validate // new thread so clients don't timeout
attemptCodeAuthentication(msaAuthenticationService); MsaAuthenticationService msaAuthenticationService = new MsaAuthenticationService(GeyserConnector.OAUTH_CLIENT_ID);
} catch (InvalidCredentialsException | IllegalArgumentException e) {
connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.auth.login.invalid", getAuthData().getName())); // Use a future to prevent timeouts as all the authentication is handled sync
disconnect(LanguageUtils.getPlayerLocaleString("geyser.auth.login.invalid.kick", getClientData().getLanguageCode())); // This will be changed with the new protocol library.
} catch (RequestException ex) { CompletableFuture.supplyAsync(() -> {
ex.printStackTrace(); try {
return msaAuthenticationService.getAuthCode();
} catch (RequestException e) {
throw new CompletionException(e);
} }
}).start(); }).whenComplete((response, ex) -> {
if (ex != null) {
ex.printStackTrace();
return;
}
LoginEncryptionUtils.buildAndShowMicrosoftCodeWindow(this, response);
attemptCodeAuthentication(msaAuthenticationService);
});
} }
/** /**