From ef7c6732767151d958e2192dc2bd167a3e0d139e Mon Sep 17 00:00:00 2001 From: Redned Date: Wed, 21 Jul 2021 21:39:30 -0500 Subject: [PATCH] Properly use CompleteableFuture for MSA auth --- .../network/session/GeyserSession.java | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index f9ae137bf..df2e3767c 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -609,28 +609,31 @@ public class GeyserSession implements CommandSender { } loggingIn = true; + + // This just looks cool + SetTimePacket packet = new SetTimePacket(); + packet.setTime(16000); + sendUpstreamPacket(packet); + // 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 { - MsaAuthenticationService msaAuthenticationService = new MsaAuthenticationService(GeyserConnector.OAUTH_CLIENT_ID); - - MsaAuthenticationService.MsCodeResponse response = msaAuthenticationService.getAuthCode(); - 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(); + 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); + }); } /**