#3742: Add more checks to InitialHandler

This commit is contained in:
Outfluencer 2024-09-21 01:05:50 +02:00 committed by GitHub
parent 9437cedc48
commit acb85e30fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -196,6 +196,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
@Override @Override
public void handle(LegacyHandshake legacyHandshake) throws Exception public void handle(LegacyHandshake legacyHandshake) throws Exception
{ {
Preconditions.checkState( !this.legacy, "Not expecting LegacyHandshake" );
this.legacy = true; this.legacy = true;
ch.close( bungee.getTranslation( "outdated_client", bungee.getGameVersion() ) ); ch.close( bungee.getTranslation( "outdated_client", bungee.getGameVersion() ) );
} }
@ -203,6 +204,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
@Override @Override
public void handle(LegacyPing ping) throws Exception public void handle(LegacyPing ping) throws Exception
{ {
Preconditions.checkState( !this.legacy, "Not expecting LegacyPing" );
this.legacy = true; this.legacy = true;
final boolean v1_5 = ping.isV1_5(); final boolean v1_5 = ping.isV1_5();
@ -342,7 +344,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
@Override @Override
public void handle(Handshake handshake) throws Exception public void handle(Handshake handshake) throws Exception
{ {
Preconditions.checkState( thisState == State.HANDSHAKE, "Not expecting HANDSHAKE" ); Preconditions.checkState( thisState == State.HANDSHAKE && !this.legacy, "Not expecting HANDSHAKE" );
this.handshake = handshake; this.handshake = handshake;
ch.setVersion( handshake.getProtocolVersion() ); ch.setVersion( handshake.getProtocolVersion() );
ch.getHandle().pipeline().remove( PipelineUtils.LEGACY_KICKER ); ch.getHandle().pipeline().remove( PipelineUtils.LEGACY_KICKER );
@ -420,7 +422,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
@Override @Override
public void handle(LoginRequest loginRequest) throws Exception public void handle(LoginRequest loginRequest) throws Exception
{ {
Preconditions.checkState( thisState == State.USERNAME, "Not expecting USERNAME" ); Preconditions.checkState( thisState == State.USERNAME && this.loginRequest == null, "Not expecting USERNAME" );
if ( !AllowedCharacters.isValidName( loginRequest.getData(), onlineMode ) ) if ( !AllowedCharacters.isValidName( loginRequest.getData(), onlineMode ) )
{ {