#3438: Fix possible race condition in duplicate player check

This commit is contained in:
BoomEaro 2023-11-01 21:32:31 +11:00 committed by md_5
parent df20effacc
commit f5157f12a4
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
4 changed files with 14 additions and 4 deletions

View File

@ -753,7 +753,7 @@ public class BungeeCord extends ProxyServer
} }
} }
public void addConnection(UserConnection con) public boolean addConnection(UserConnection con)
{ {
UUID offlineId = con.getPendingConnection().getOfflineId(); UUID offlineId = con.getPendingConnection().getOfflineId();
if ( offlineId != null && offlineId.version() != 3 ) if ( offlineId != null && offlineId.version() != 3 )
@ -763,6 +763,10 @@ public class BungeeCord extends ProxyServer
connectionLock.writeLock().lock(); connectionLock.writeLock().lock();
try try
{ {
if ( connections.containsKey( con.getName() ) || connectionsByUUID.containsKey( con.getUniqueId() ) || connectionsByOfflineUUID.containsKey( offlineId ) )
{
return false;
}
connections.put( con.getName(), con ); connections.put( con.getName(), con );
connectionsByUUID.put( con.getUniqueId(), con ); connectionsByUUID.put( con.getUniqueId(), con );
connectionsByOfflineUUID.put( offlineId, con ); connectionsByOfflineUUID.put( offlineId, con );
@ -770,6 +774,7 @@ public class BungeeCord extends ProxyServer
{ {
connectionLock.writeLock().unlock(); connectionLock.writeLock().unlock();
} }
return true;
} }
public void removeConnection(UserConnection con) public void removeConnection(UserConnection con)

View File

@ -153,7 +153,7 @@ public final class UserConnection implements ProxiedPlayer
} }
}; };
public void init() public boolean init()
{ {
this.entityRewrite = EntityMap.getEntityMap( getPendingConnection().getVersion() ); this.entityRewrite = EntityMap.getEntityMap( getPendingConnection().getVersion() );
@ -172,6 +172,8 @@ public final class UserConnection implements ProxiedPlayer
// Set whether the connection has a 1.8 FML marker in the handshake. // Set whether the connection has a 1.8 FML marker in the handshake.
forgeClientHandler.setFmlTokenInHandshake( this.getPendingConnection().getExtraDataInHandshake().contains( ForgeConstants.FML_HANDSHAKE_TOKEN ) ); forgeClientHandler.setFmlTokenInHandshake( this.getPendingConnection().getExtraDataInHandshake().contains( ForgeConstants.FML_HANDSHAKE_TOKEN ) );
return BungeeCord.getInstance().addConnection( this );
} }
public void sendPacket(PacketWrapper packet) public void sendPacket(PacketWrapper packet)

View File

@ -613,7 +613,11 @@ public class InitialHandler extends PacketHandler implements PendingConnection
private void finish2() private void finish2()
{ {
userCon.init(); if ( !userCon.init() )
{
disconnect( bungee.getTranslation( "already_connected_proxy" ) );
return;
}
ch.getHandle().pipeline().get( HandlerBoss.class ).setHandler( new UpstreamBridge( bungee, userCon ) ); ch.getHandle().pipeline().get( HandlerBoss.class ).setHandler( new UpstreamBridge( bungee, userCon ) );
bungee.getPluginManager().callEvent( new PostLoginEvent( userCon ) ); bungee.getPluginManager().callEvent( new PostLoginEvent( userCon ) );

View File

@ -54,7 +54,6 @@ public class UpstreamBridge extends PacketHandler
this.bungee = bungee; this.bungee = bungee;
this.con = con; this.con = con;
BungeeCord.getInstance().addConnection( con );
con.getTabListHandler().onConnect(); con.getTabListHandler().onConnect();
} }