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 42b3a766f..5e960ba8b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java @@ -30,6 +30,7 @@ import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder; import com.velocitypowered.proxy.util.except.QuietDecoderException; import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; +import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; @@ -46,6 +47,7 @@ import javax.crypto.spec.SecretKeySpec; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.checkerframework.checker.nullness.qual.Nullable; +import org.jetbrains.annotations.NotNull; /** * A utility class to make working with the pipeline a little less painful and transparently handles @@ -64,6 +66,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { private final VelocityServer server; private ConnectionType connectionType = ConnectionTypes.UNDETERMINED; private boolean knownDisconnect = false; + private boolean disconnected = false; /** * Initializes a new {@link MinecraftConnection} instance. @@ -236,12 +239,18 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { this.setAutoReading(false); channel.eventLoop().schedule(() -> { knownDisconnect = true; - channel.writeAndFlush(msg).addListener(ChannelFutureListener.CLOSE); + channel.writeAndFlush(msg).addListener((ChannelFutureListener) future -> { + future.channel().close(); + this.fireDisconnected(); + }); }, 250, TimeUnit.MILLISECONDS); }); } else { knownDisconnect = true; - channel.writeAndFlush(msg).addListener(ChannelFutureListener.CLOSE); + channel.writeAndFlush(msg).addListener((ChannelFutureListener) future -> { + future.channel().close(); + this.fireDisconnected(); + }); } } } @@ -261,17 +270,28 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { knownDisconnect = true; } channel.close(); + this.fireDisconnected(); } else { channel.eventLoop().execute(() -> { if (markKnown) { knownDisconnect = true; } channel.close(); + this.fireDisconnected(); }); } } } + private void fireDisconnected() { + if (!disconnected) { + disconnected = true; + } + if (sessionHandler != null) { + sessionHandler.disconnected(); + } + } + public Channel getChannel() { return channel; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java index 80e6bd7ce..c199f788a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java @@ -117,8 +117,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { resultFuture.completeExceptionally( new QuietRuntimeException("The connection to the remote server was unexpectedly closed.\n" + "This is usually because the remote server does not have BungeeCord IP forwarding " - + "correctly enabled.\nSee " - + "https://docs.velocitypowered.com/en/latest/users/player-info-forwarding.html " + + "correctly enabled.\nSee https://velocitypowered.com/wiki/users/forwarding/ " + "for instructions on how to configure player info forwarding correctly.") ); } else {