From cd35e8f8a92e6769e8aefd8e52cbdf8264a3c9ce Mon Sep 17 00:00:00 2001 From: DEv0on Date: Wed, 15 Feb 2023 07:00:11 +0100 Subject: [PATCH] Fix for edgecase FML|HS packet desynchronization (#948) * Fix for edgecase FML|HS packet desynchronization * Change approach for FML packet desynchronization edge case --- .../connection/client/ClientPlaySessionHandler.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 5bc9362c9..82f6706d7 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 @@ -40,6 +40,7 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler; 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.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.packet.BossBar; @@ -277,7 +278,14 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { @Override public boolean handle(PluginMessage packet) { - VelocityServerConnection serverConn = player.getConnectedServer(); + // 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(); + MinecraftConnection backendConn = serverConn != null ? serverConn.getConnection() : null; if (serverConn != null && backendConn != null) { if (backendConn.getState() != StateRegistry.PLAY) {