From 782a10f36d6fb765f3f2044340d78a7194dcd7f3 Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Tue, 23 Oct 2018 16:07:42 -0300 Subject: [PATCH] Separate protocol version for new proxy <-> server connections --- .../proxy/connection/MinecraftConnection.java | 10 ++++++++++ .../connection/backend/VelocityServerConnection.java | 4 ++-- 2 files changed, 12 insertions(+), 2 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 6fd8aca54..677bdecba 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java @@ -37,6 +37,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { private StateRegistry state; private MinecraftSessionHandler sessionHandler; private int protocolVersion; + private int nextProtocolVersion; private MinecraftConnectionAssociation association; private boolean isLegacyForge; private final VelocityServer server; @@ -185,6 +186,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { public void setProtocolVersion(int protocolVersion) { this.protocolVersion = protocolVersion; + this.nextProtocolVersion = protocolVersion; if (protocolVersion != ProtocolConstants.LEGACY) { this.channel.pipeline().get(MinecraftEncoder.class).setProtocolVersion(protocolVersion); this.channel.pipeline().get(MinecraftDecoder.class).setProtocolVersion(protocolVersion); @@ -264,4 +266,12 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { public void setCanSendLegacyFMLResetPacket(boolean canSendLegacyFMLResetPacket) { this.canSendLegacyFMLResetPacket = isLegacyForge && canSendLegacyFMLResetPacket; } + + public int getNextProtocolVersion() { + return this.nextProtocolVersion; + } + + public void setNextProtocolVersion(int nextProtocolVersion) { + this.nextProtocolVersion = nextProtocolVersion; + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java index 40718cd30..56a275931 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java @@ -98,7 +98,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, // Initiate a handshake. Handshake handshake = new Handshake(); handshake.setNextStatus(StateRegistry.LOGIN_ID); - handshake.setProtocolVersion(proxyPlayer.getConnection().getProtocolVersion()); + handshake.setProtocolVersion(proxyPlayer.getConnection().getNextProtocolVersion()); if (forwardingMode == PlayerInfoForwarding.LEGACY) { handshake.setServerAddress(createBungeeForwardingAddress()); } else if (proxyPlayer.getConnection().isLegacyForge()) { @@ -109,7 +109,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, handshake.setPort(registeredServer.getServerInfo().getAddress().getPort()); connection.write(handshake); - int protocolVersion = proxyPlayer.getConnection().getProtocolVersion(); + int protocolVersion = proxyPlayer.getConnection().getNextProtocolVersion(); connection.setProtocolVersion(protocolVersion); connection.setState(StateRegistry.LOGIN);