diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java index 8880233bb3..ad5ba0684d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java @@ -37,7 +37,6 @@ import com.velocitypowered.proxy.connection.backend.BackendConnectionPhases; import com.velocitypowered.proxy.connection.backend.BungeeCordMessageResponder; import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; -import com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeConstants; import com.velocitypowered.proxy.connection.player.resourcepack.ResourcePackResponseBundle; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.StateRegistry; @@ -341,13 +340,9 @@ public boolean handle(TabCompleteRequestPacket packet) { @Override public boolean handle(PluginMessagePacket packet) { - // Handling edge case when packet with FML client handshake (state COMPLETE) - // arrives after JoinGame packet from destination server - VelocityServerConnection serverConn = - (player.getConnectedServer() == null - && packet.getChannel().equals( - LegacyForgeConstants.FORGE_LEGACY_HANDSHAKE_CHANNEL)) - ? player.getConnectionInFlight() : player.getConnectedServer(); + final VelocityServerConnection connected = player.getConnectedServer(); + final VelocityServerConnection serverConn = + connected != null ? connected : player.getConnectionInFlight(); MinecraftConnection backendConn = serverConn != null ? serverConn.getConnection() : null; if (serverConn != null && backendConn != null) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/LegacyPingDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/LegacyPingDecoder.java index a6c2c065f5..061d2cb229 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/LegacyPingDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/LegacyPingDecoder.java @@ -57,13 +57,20 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) t } short next = in.readUnsignedByte(); - if (next == 1 && !in.isReadable()) { - out.add(new LegacyPingPacket(LegacyMinecraftPingVersion.MINECRAFT_1_4)); - return; + if (next == 1) { + if (!in.isReadable()) { + out.add(new LegacyPingPacket(LegacyMinecraftPingVersion.MINECRAFT_1_4)); + return; + } + if (in.getUnsignedByte(in.readerIndex()) == 0xFA) { + out.add(readExtended16Data(in)); + return; + } } - // We got a 1.6.x ping. Let's chomp off the stuff we don't need. - out.add(readExtended16Data(in)); + // Not a legacy ping. Reset and let the modern decoder handle it. + in.readerIndex(originalReaderIndex); + ctx.pipeline().remove(this); } else if (first == 0x02 && in.isReadable()) { in.skipBytes(in.readableBytes()); out.add(new LegacyHandshakePacket()); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HandshakePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HandshakePacket.java index 88cb3688bd..3f65f3c0ab 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HandshakePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/HandshakePacket.java @@ -17,8 +17,6 @@ package com.velocitypowered.proxy.protocol.packet; -import static com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeConstants.HANDSHAKE_HOSTNAME_TOKEN; - import com.velocitypowered.api.network.HandshakeIntent; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; @@ -29,9 +27,6 @@ public class HandshakePacket implements MinecraftPacket { - // This size was chosen to ensure Forge clients can still connect even with very long hostnames. - // While DNS technically allows any character to be used, in practice ASCII is used. - private static final int MAXIMUM_HOSTNAME_LENGTH = 255 + HANDSHAKE_HOSTNAME_TOKEN.length() + 1; private ProtocolVersion protocolVersion; private String serverAddress = ""; private int port; @@ -89,7 +84,7 @@ public String toString() { public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion ignored) { int realProtocolVersion = ProtocolUtils.readVarInt(buf); this.protocolVersion = ProtocolVersion.getProtocolVersion(realProtocolVersion); - this.serverAddress = ProtocolUtils.readString(buf, MAXIMUM_HOSTNAME_LENGTH); + this.serverAddress = ProtocolUtils.readString(buf, Short.MAX_VALUE); this.port = buf.readUnsignedShort(); this.nextStatus = ProtocolUtils.readVarInt(buf); this.intent = HandshakeIntent.getById(nextStatus); @@ -117,7 +112,7 @@ public int decodeExpectedMinLength(ByteBuf buf, ProtocolUtils.Direction directio @Override public int decodeExpectedMaxLength(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { - return 9 + (MAXIMUM_HOSTNAME_LENGTH * 3); + return 9 + (Short.MAX_VALUE * 3); } @Override