#3527: Switching between servers causes a decoding error

This commit is contained in:
md_5 2023-09-26 06:35:48 +10:00
parent f3397b3003
commit 3cb7a12738
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
4 changed files with 12 additions and 4 deletions

View File

@ -31,12 +31,12 @@ public class LegacyDecoder extends ByteToMessageDecoder
if ( packetID == 0xFE ) if ( packetID == 0xFE )
{ {
out.add( new PacketWrapper( new LegacyPing( in.isReadable() && in.readUnsignedByte() == 0x01 ), Unpooled.EMPTY_BUFFER ) ); out.add( new PacketWrapper( new LegacyPing( in.isReadable() && in.readUnsignedByte() == 0x01 ), Unpooled.EMPTY_BUFFER, Protocol.STATUS ) );
return; return;
} else if ( packetID == 0x02 && in.isReadable() ) } else if ( packetID == 0x02 && in.isReadable() )
{ {
in.skipBytes( in.readableBytes() ); in.skipBytes( in.readableBytes() );
out.add( new PacketWrapper( new LegacyHandshake(), Unpooled.EMPTY_BUFFER ) ); out.add( new PacketWrapper( new LegacyHandshake(), Unpooled.EMPTY_BUFFER, Protocol.STATUS ) );
return; return;
} }

View File

@ -50,7 +50,7 @@ public class MinecraftDecoder extends MessageToMessageDecoder<ByteBuf>
in.skipBytes( in.readableBytes() ); in.skipBytes( in.readableBytes() );
} }
out.add( new PacketWrapper( packet, slice ) ); out.add( new PacketWrapper( packet, slice, protocol ) );
slice = null; slice = null;
} finally } finally
{ {

View File

@ -10,6 +10,7 @@ public class PacketWrapper
public final DefinedPacket packet; public final DefinedPacket packet;
public final ByteBuf buf; public final ByteBuf buf;
public final Protocol protocol;
@Setter @Setter
private boolean released; private boolean released;

View File

@ -136,8 +136,15 @@ public class UpstreamBridge extends PacketHandler
{ {
if ( con.getServer() != null ) if ( con.getServer() != null )
{ {
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
if ( packet.protocol != serverEncode )
{
return;
}
EntityMap rewrite = con.getEntityRewrite(); EntityMap rewrite = con.getEntityRewrite();
if ( rewrite != null && con.getServer().getCh().getEncodeProtocol() == Protocol.GAME ) if ( rewrite != null && serverEncode == Protocol.GAME )
{ {
rewrite.rewriteServerbound( packet.buf, con.getClientEntityId(), con.getServerEntityId(), con.getPendingConnection().getVersion() ); rewrite.rewriteServerbound( packet.buf, con.getClientEntityId(), con.getServerEntityId(), con.getPendingConnection().getVersion() );
} }