From 9450e6600cd823f7cdb207fe0c6bfb392af3e862 Mon Sep 17 00:00:00 2001 From: Gero Date: Sat, 23 Dec 2023 10:58:32 +0100 Subject: [PATCH] Fix race condition when switching from config to play state --- .../connection/client/ClientConfigSessionHandler.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientConfigSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientConfigSessionHandler.java index 8281b40e9..d14e3b823 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientConfigSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientConfigSessionHandler.java @@ -25,6 +25,7 @@ import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.StateRegistry; +import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder; import com.velocitypowered.proxy.protocol.packet.ClientSettings; import com.velocitypowered.proxy.protocol.packet.KeepAlive; import com.velocitypowered.proxy.protocol.packet.PingIdentify; @@ -186,16 +187,21 @@ public class ClientConfigSessionHandler implements MinecraftSessionHandler { * @return a future that completes when the config stage is finished */ public CompletableFuture handleBackendFinishUpdate(VelocityServerConnection serverConn) { + MinecraftConnection smc = serverConn.ensureConnected(); + String brand = serverConn.getPlayer().getClientBrand(); if (brand != null && brandChannel != null) { ByteBuf buf = Unpooled.buffer(); ProtocolUtils.writeString(buf, brand); PluginMessage brandPacket = new PluginMessage(brandChannel, buf); - serverConn.ensureConnected().write(brandPacket); + smc.write(brandPacket); } player.getConnection().write(new FinishedUpdate()); - serverConn.ensureConnected().write(new FinishedUpdate()); + + smc.write(new FinishedUpdate()); + smc.getChannel().pipeline().get(MinecraftEncoder.class).setState(StateRegistry.PLAY); + return configSwitchFuture; } }