diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java index 404e60809..c34b6fa7c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java @@ -28,7 +28,6 @@ import com.velocitypowered.api.event.connection.PluginMessageEvent; import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent; import com.velocitypowered.api.event.player.ServerResourcePackSendEvent; import com.velocitypowered.api.event.proxy.ProxyPingEvent; -import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.api.proxy.player.ResourcePackInfo; import com.velocitypowered.proxy.VelocityServer; @@ -367,7 +366,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { if (server.getConfiguration().isFailoverOnUnexpectedServerDisconnect()) { serverConn.getPlayer().handleConnectionException(serverConn.getServer(), Disconnect.create(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR, - ProtocolVersion.MINECRAFT_1_16), true); + serverConn.getPlayer().getProtocolVersion(), false), true); } else { serverConn.getPlayer().disconnect(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index 99f4ba608..5bd49bd9e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -579,7 +579,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, logger.info("{} has disconnected: {}", this, LegacyComponentSerializer.legacySection().serialize(translated)); } - connection.closeWith(Disconnect.create(translated, this.getProtocolVersion())); + connection.closeWith(Disconnect.create(translated, this.getProtocolVersion(), duringLogin)); } public @Nullable VelocityServerConnection getConnectedServer() { @@ -750,7 +750,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, Component reason = status.getReasonComponent() .orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); handleConnectionException(res.getServer(), - Disconnect.create(reason, getProtocolVersion()), ((Impl) status).isSafe()); + Disconnect.create(reason, getProtocolVersion(), false), + ((Impl) status).isSafe()); break; case SUCCESS: Component requestedMessage = res.getMessageComponent(); @@ -1274,8 +1275,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player, case SERVER_DISCONNECTED: Component reason = status.getReasonComponent() .orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); - handleConnectionException(toConnect, Disconnect.create(reason, getProtocolVersion()), - status.isSafe()); + handleConnectionException(toConnect, + Disconnect.create(reason, getProtocolVersion(), false), status.isSafe()); break; default: // The only remaining value is successful (no need to do anything!) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java index e8ac43b0b..2af8c3961 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java @@ -95,9 +95,7 @@ public final class InitialInboundConnection implements VelocityInboundConnection logger.info("{} has disconnected: {}", this, LegacyComponentSerializer.legacySection().serialize(translated)); } - connection.closeWith(Disconnect.create(translated, - getProtocolVersion() == ProtocolVersion.MINECRAFT_1_20_3 // Login disconnects are string - ? ProtocolVersion.MINECRAFT_1_20_2 : getProtocolVersion())); + connection.closeWith(Disconnect.create(translated, getProtocolVersion(), true)); } /** @@ -108,8 +106,6 @@ public final class InitialInboundConnection implements VelocityInboundConnection public void disconnectQuietly(Component reason) { Component translated = GlobalTranslator.render(reason, ClosestLocaleMatcher.INSTANCE .lookupClosest(Locale.getDefault())); - connection.closeWith(Disconnect.create(translated, - getProtocolVersion() == ProtocolVersion.MINECRAFT_1_20_3 // Login disconnects are string - ? ProtocolVersion.MINECRAFT_1_20_2 : getProtocolVersion())); + connection.closeWith(Disconnect.create(translated, getProtocolVersion(), true)); } } \ No newline at end of file diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java index 746fbbd3c..583ba26c2 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java @@ -149,7 +149,8 @@ public enum StateRegistry { clientbound.register( PluginMessage.class, PluginMessage::new, map(0x00, MINECRAFT_1_20_2, false)); - clientbound.register(Disconnect.class, Disconnect::new, map(0x01, MINECRAFT_1_20_2, false)); + clientbound.register( + Disconnect.class, () -> new Disconnect(false), map(0x01, MINECRAFT_1_20_2, false)); clientbound.register( FinishedUpdate.class, FinishedUpdate::new, map(0x02, MINECRAFT_1_20_2, false)); clientbound.register(KeepAlive.class, KeepAlive::new, map(0x03, MINECRAFT_1_20_2, false)); @@ -335,7 +336,7 @@ public enum StateRegistry { map(0x18, MINECRAFT_1_20_2, false)); clientbound.register( Disconnect.class, - Disconnect::new, + () -> new Disconnect(false), map(0x40, MINECRAFT_1_7_2, false), map(0x1A, MINECRAFT_1_9, false), map(0x1B, MINECRAFT_1_13, false), @@ -566,7 +567,8 @@ public enum StateRegistry { serverbound.register( LoginAcknowledged.class, LoginAcknowledged::new, map(0x03, MINECRAFT_1_20_2, false)); - clientbound.register(Disconnect.class, Disconnect::new, map(0x00, MINECRAFT_1_7_2, false)); + clientbound.register( + Disconnect.class, () -> new Disconnect(true), map(0x00, MINECRAFT_1_7_2, false)); clientbound.register( EncryptionRequest.class, EncryptionRequest::new, map(0x01, MINECRAFT_1_7_2, false)); clientbound.register( diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Disconnect.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Disconnect.java index 53b576206..fd24b71b7 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Disconnect.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Disconnect.java @@ -30,11 +30,14 @@ import org.checkerframework.checker.nullness.qual.Nullable; public class Disconnect implements MinecraftPacket { private @Nullable ComponentHolder reason; + private final boolean login; - public Disconnect() { + public Disconnect(boolean login) { + this.login = login; } - public Disconnect(ComponentHolder reason) { + private Disconnect(boolean login, ComponentHolder reason) { + this.login = login; this.reason = Preconditions.checkNotNull(reason, "reason"); } @@ -58,7 +61,7 @@ public class Disconnect implements MinecraftPacket { @Override public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { - reason = ComponentHolder.read(buf, version); + reason = ComponentHolder.read(buf, login ? ProtocolVersion.MINECRAFT_1_20_2 : version); } @Override @@ -71,8 +74,8 @@ public class Disconnect implements MinecraftPacket { return handler.handle(this); } - public static Disconnect create(Component component, ProtocolVersion version) { + public static Disconnect create(Component component, ProtocolVersion version, boolean login) { Preconditions.checkNotNull(component, "component"); - return new Disconnect(new ComponentHolder(version, component)); + return new Disconnect(login, new ComponentHolder(login ? ProtocolVersion.MINECRAFT_1_20_2 : version, component)); } } \ No newline at end of file