Skip to content

Commit

Permalink
Fix rare race condition in login
Browse files Browse the repository at this point in the history
  • Loading branch information
aromaa committed Dec 9, 2023
1 parent 1fdc9ef commit 492297b
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerLoginPacketListenerImpl;
import net.minecraft.server.players.PlayerList;
import net.minecraft.util.RandomSource;
import org.objectweb.asm.Opcodes;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.event.Cause;
Expand All @@ -43,6 +44,7 @@
import org.spongepowered.api.network.ServerSideConnection;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -64,6 +66,11 @@
@Mixin(ServerLoginPacketListenerImpl.class)
public abstract class ServerLoginPacketListenerImplMixin implements ServerLoginPacketListenerImplBridge, ConnectionHolderBridge {

// @formatter:off

//Vanilla is creating a non-thread safe one while a thread safe one should be used instead
@Shadow @Final @Mutable private static RandomSource RANDOM = RandomSource.createThreadSafe();

@Shadow @Final public Connection connection;
@Shadow com.mojang.authlib.GameProfile gameProfile;
@Shadow @Final MinecraftServer server;
Expand All @@ -73,6 +80,7 @@ public abstract class ServerLoginPacketListenerImplMixin implements ServerLoginP
@Shadow protected abstract com.mojang.authlib.GameProfile shadow$createFakeProfile(com.mojang.authlib.GameProfile profile);
@Shadow public abstract void shadow$disconnect(Component reason);
@Shadow protected abstract void shadow$placeNewPlayer(final ServerPlayer param0);
// @formatter:on

private boolean impl$accepted = false;

Expand Down

0 comments on commit 492297b

Please sign in to comment.