From 9a0affbca9ae60afeab3e4b19eef8f708995ab74 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Fri, 30 Oct 2020 06:34:28 -0400 Subject: [PATCH] Fix disconnect issues in 1.7-specific logic. --- .../proxy/connection/MinecraftConnection.java | 25 ++++++++++--------- .../client/LoginSessionHandler.java | 4 +-- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java index b2381f51f..cb161b38d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java @@ -223,20 +223,21 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { */ public void closeWith(Object msg) { if (channel.isActive()) { - boolean is1Point8 = this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0; - boolean isLegacyOrPing = this.getState() == StateRegistry.HANDSHAKE - || this.getState() == StateRegistry.STATUS; - if (channel.eventLoop().inEventLoop() && (is1Point8 || isLegacyOrPing)) { + boolean is1_7 = this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) < 0 + && this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_7_2) >= 0; + if (is1_7) { + channel.eventLoop().execute(() -> { + // 1.7.x versions have a race condition with switching protocol states, so just explicitly + // close the connection after a short while. + this.setAutoReading(false); + channel.eventLoop().schedule(() -> { + knownDisconnect = true; + channel.writeAndFlush(msg).addListener(ChannelFutureListener.CLOSE); + }, 250, TimeUnit.MILLISECONDS); + }); + } else { knownDisconnect = true; channel.writeAndFlush(msg).addListener(ChannelFutureListener.CLOSE); - } else { - // 1.7.x versions have a race condition with switching protocol states, so just explicitly - // close the connection after a short while. - this.setAutoReading(false); - channel.eventLoop().schedule(() -> { - knownDisconnect = true; - channel.writeAndFlush(msg).addListener(ChannelFutureListener.CLOSE); - }, 250, TimeUnit.MILLISECONDS); } } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java index fbfca874f..2874ba137 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java @@ -208,7 +208,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { onlineMode); final GameProfile finalProfile = profile; - server.getEventManager().fire(profileRequestEvent).thenCompose(profileEvent -> { + server.getEventManager().fire(profileRequestEvent).thenComposeAsync(profileEvent -> { if (mcConnection.isClosed()) { // The player disconnected after we authenticated them. return CompletableFuture.completedFuture(null); @@ -234,7 +234,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { completeLoginProtocolPhaseAndInitialize(player); } }, mcConnection.eventLoop()); - }).exceptionally((ex) -> { + }, mcConnection.eventLoop()).exceptionally((ex) -> { logger.error("Exception during connection of {}", finalProfile, ex); return null; });