#3190: Improve login protocol state machine

Prevents repetition of packets
This commit is contained in:
Outfluencer 2021-09-17 18:16:01 +10:00 committed by md_5
parent 06bf088d27
commit 1823f86dbb
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11

View File

@ -115,12 +115,12 @@ public class InitialHandler extends PacketHandler implements PendingConnection
private enum State private enum State
{ {
HANDSHAKE, STATUS, PING, USERNAME, ENCRYPT, FINISHED; HANDSHAKE, STATUS, PING, USERNAME, ENCRYPT, FINISHING;
} }
private boolean canSendKickMessage() private boolean canSendKickMessage()
{ {
return thisState == State.USERNAME || thisState == State.ENCRYPT || thisState == State.FINISHED; return thisState == State.USERNAME || thisState == State.ENCRYPT || thisState == State.FINISHING;
} }
@Override @Override
@ -392,12 +392,13 @@ public class InitialHandler extends PacketHandler implements PendingConnection
} }
if ( onlineMode ) if ( onlineMode )
{ {
thisState = State.ENCRYPT;
unsafe().sendPacket( request = EncryptionUtil.encryptRequest() ); unsafe().sendPacket( request = EncryptionUtil.encryptRequest() );
} else } else
{ {
thisState = State.FINISHING;
finish(); finish();
} }
thisState = State.ENCRYPT;
} }
}; };
@ -455,7 +456,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
} }
} }
}; };
thisState = State.FINISHING;
HttpClient.get( authURL, ch.getHandle().eventLoop(), handler ); HttpClient.get( authURL, ch.getHandle().eventLoop(), handler );
} }
@ -542,8 +543,6 @@ public class InitialHandler extends PacketHandler implements PendingConnection
} }
userCon.connect( server, null, true, ServerConnectEvent.Reason.JOIN_PROXY ); userCon.connect( server, null, true, ServerConnectEvent.Reason.JOIN_PROXY );
thisState = State.FINISHED;
} }
} }
} ); } );