Skip to content

Commit

Permalink
Fix race conditions with login plugin messages
Browse files Browse the repository at this point in the history
  • Loading branch information
aromaa committed Nov 22, 2023
1 parent df736b8 commit dfe4de5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ public CompletableFuture<ChannelBuf> sendTo(final EngineConnection connection, f

final Packet<?> mcPacket = PacketUtil.createLoginPayloadRequest(this.parent.key(), buf, transactionId);

transactionStore.put(transactionId, this.parent, resultConsumer);

PacketSender.sendTo(connection, mcPacket, throwable -> {
if (throwable == null) {
transactionStore.put(transactionId, this.parent, resultConsumer);
} else {
if (throwable != null && transactionStore.remove(transactionId) != null) {
// The packet already failed before it could reach the client
future.completeExceptionally(throwable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public abstract class ServerLoginPacketListenerImplMixin_Vanilla implements Serv
private static final int HANDSHAKE_NOT_STARTED = 0;
private static final int HANDSHAKE_CLIENT_TYPE = 1;
private static final int HANDSHAKE_SYNC_CHANNEL_REGISTRATIONS = 2;
private static final int HANDSHAKE_SYNC_PLUGIN_DATA = 3;
private static final int HANDSHAKE_CHANNEL_REGISTRATION = 3;
private static final int HANDSHAKE_SYNC_PLUGIN_DATA = 4;

private int impl$handshakeState = ServerLoginPacketListenerImplMixin_Vanilla.HANDSHAKE_NOT_STARTED;

Expand All @@ -85,6 +86,8 @@ private void onResponsePayload(final ServerboundCustomQueryPacket packet, final
});

} else if (this.impl$handshakeState == ServerLoginPacketListenerImplMixin_Vanilla.HANDSHAKE_SYNC_CHANNEL_REGISTRATIONS) {
this.impl$handshakeState = ServerLoginPacketListenerImplMixin_Vanilla.HANDSHAKE_CHANNEL_REGISTRATION;

((SpongeChannelManager) Sponge.channelManager()).sendLoginChannelRegistry(connection).thenAccept(result -> {
final Cause cause = Cause.of(EventContext.empty(), this);
final ServerSideConnectionEvent.Handshake event =
Expand Down

0 comments on commit dfe4de5

Please sign in to comment.