From 78aef86a8f6a52eebc6511447b63cc4076021ad2 Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 29 Sep 2023 06:50:28 +1000 Subject: [PATCH] #3533: Don't put initial client in configure phase until server is ready --- .../java/net/md_5/bungee/ServerConnector.java | 7 +++--- .../bungee/connection/InitialHandler.java | 23 ++++--------------- .../bungee/connection/UpstreamBridge.java | 11 +++++++++ 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index 7ef4ee91..409464d2 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -43,7 +43,6 @@ import net.md_5.bungee.protocol.packet.GameState; import net.md_5.bungee.protocol.packet.Handshake; import net.md_5.bungee.protocol.packet.Kick; import net.md_5.bungee.protocol.packet.Login; -import net.md_5.bungee.protocol.packet.LoginAcknowledged; import net.md_5.bungee.protocol.packet.LoginPayloadRequest; import net.md_5.bungee.protocol.packet.LoginPayloadResponse; import net.md_5.bungee.protocol.packet.LoginRequest; @@ -334,9 +333,9 @@ public class ServerConnector extends PacketHandler user.unsafe().sendPacket( new StartConfiguration() ); } else { - ch.setDecodeProtocol( Protocol.CONFIGURATION ); - ch.write( new LoginAcknowledged() ); - ch.setEncodeProtocol( Protocol.CONFIGURATION ); + LoginResult loginProfile = user.getPendingConnection().getLoginProfile(); + user.unsafe().sendPacket( new LoginSuccess( user.getUniqueId(), user.getName(), ( loginProfile == null ) ? null : loginProfile.getProperties() ) ); + user.getCh().setEncodeProtocol( Protocol.CONFIGURATION ); } } diff --git a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java index 7ea9bcef..09080f36 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java @@ -59,7 +59,6 @@ import net.md_5.bungee.protocol.packet.Handshake; import net.md_5.bungee.protocol.packet.Kick; import net.md_5.bungee.protocol.packet.LegacyHandshake; import net.md_5.bungee.protocol.packet.LegacyPing; -import net.md_5.bungee.protocol.packet.LoginAcknowledged; import net.md_5.bungee.protocol.packet.LoginPayloadResponse; import net.md_5.bungee.protocol.packet.LoginRequest; import net.md_5.bungee.protocol.packet.LoginSuccess; @@ -123,12 +122,12 @@ public class InitialHandler extends PacketHandler implements PendingConnection private enum State { - HANDSHAKE, STATUS, PING, USERNAME, ENCRYPT, FINISHING, CONFIGURING; + HANDSHAKE, STATUS, PING, USERNAME, ENCRYPT, FINISHING; } private boolean canSendKickMessage() { - return thisState == State.USERNAME || thisState == State.ENCRYPT || thisState == State.FINISHING || thisState == State.CONFIGURING; + return thisState == State.USERNAME || thisState == State.ENCRYPT || thisState == State.FINISHING; } @Override @@ -598,15 +597,12 @@ public class InitialHandler extends PacketHandler implements PendingConnection userCon = new UserConnection( bungee, ch, getName(), InitialHandler.this ); userCon.setCompressionThreshold( BungeeCord.getInstance().config.getCompressionThreshold() ); - unsafe.sendPacket( new LoginSuccess( getUniqueId(), getName(), ( loginProfile == null ) ? null : loginProfile.getProperties() ) ); - if ( getVersion() >= ProtocolConstants.MINECRAFT_1_20_2 ) - { - thisState = State.CONFIGURING; - } else + if ( getVersion() < ProtocolConstants.MINECRAFT_1_20_2 ) { + unsafe.sendPacket( new LoginSuccess( getUniqueId(), getName(), ( loginProfile == null ) ? null : loginProfile.getProperties() ) ); ch.setProtocol( Protocol.GAME ); - finish2(); } + finish2(); } } } ); @@ -617,15 +613,6 @@ public class InitialHandler extends PacketHandler implements PendingConnection bungee.getPluginManager().callEvent( new LoginEvent( InitialHandler.this, complete ) ); } - @Override - public void handle(LoginAcknowledged loginAcknowledged) throws Exception - { - Preconditions.checkState( thisState == State.CONFIGURING, "Not expecting CONFIGURING" ); - - ch.setEncodeProtocol( Protocol.CONFIGURATION ); - finish2(); - } - private void finish2() { userCon.init(); diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java index 3c312589..8a8877d4 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java @@ -331,8 +331,19 @@ public class UpstreamBridge extends PacketHandler con.getPendingConnection().relayMessage( pluginMessage ); } + @Override + public void handle(LoginAcknowledged loginAcknowledged) throws Exception + { + configureServer(); + } + @Override public void handle(StartConfiguration startConfiguration) throws Exception + { + configureServer(); + } + + private void configureServer() { ChannelWrapper ch = con.getServer().getCh(); if ( ch.getDecodeProtocol() == Protocol.LOGIN )