Simplify UpstreamBridge packet handling code

This commit is contained in:
md_5 2023-09-28 06:55:00 +10:00
parent 86e079a4b1
commit b34cfcde5a
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11

View File

@ -10,6 +10,7 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import net.md_5.bungee.BungeeCord; import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.ServerConnection;
import net.md_5.bungee.ServerConnection.KeepAliveData; import net.md_5.bungee.ServerConnection.KeepAliveData;
import net.md_5.bungee.UserConnection; import net.md_5.bungee.UserConnection;
import net.md_5.bungee.Util; import net.md_5.bungee.Util;
@ -134,14 +135,10 @@ public class UpstreamBridge extends PacketHandler
@Override @Override
public void handle(PacketWrapper packet) throws Exception public void handle(PacketWrapper packet) throws Exception
{ {
if ( con.getServer() != null ) ServerConnection server = con.getServer();
if ( server != null && server.isConnected() )
{ {
if ( con.getServer().getCh().isClosed() ) Protocol serverEncode = server.getCh().getEncodeProtocol();
{
return;
}
Protocol serverEncode = con.getServer().getCh().getEncodeProtocol();
// #3527: May still have old packets from client in game state when switching server to configuration state - discard those // #3527: May still have old packets from client in game state when switching server to configuration state - discard those
if ( packet.protocol != serverEncode ) if ( packet.protocol != serverEncode )
{ {
@ -153,7 +150,7 @@ public class UpstreamBridge extends PacketHandler
{ {
rewrite.rewriteServerbound( packet.buf, con.getClientEntityId(), con.getServerEntityId(), con.getPendingConnection().getVersion() ); rewrite.rewriteServerbound( packet.buf, con.getClientEntityId(), con.getServerEntityId(), con.getPendingConnection().getVersion() );
} }
con.getServer().getCh().write( packet ); server.getCh().write( packet );
} }
} }