Skip to content

Commit

Permalink
#3438: Fix possible race condition in duplicate player check
Browse files Browse the repository at this point in the history
  • Loading branch information
BoomEaro authored and md-5 committed Nov 1, 2023
1 parent df20eff commit f5157f1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
7 changes: 6 additions & 1 deletion proxy/src/main/java/net/md_5/bungee/BungeeCord.java
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ public void broadcast(BaseComponent message)
}
}

public void addConnection(UserConnection con)
public boolean addConnection(UserConnection con)
{
UUID offlineId = con.getPendingConnection().getOfflineId();
if ( offlineId != null && offlineId.version() != 3 )
Expand All @@ -763,13 +763,18 @@ public void addConnection(UserConnection con)
connectionLock.writeLock().lock();
try
{
if ( connections.containsKey( con.getName() ) || connectionsByUUID.containsKey( con.getUniqueId() ) || connectionsByOfflineUUID.containsKey( offlineId ) )
{
return false;
}
connections.put( con.getName(), con );
connectionsByUUID.put( con.getUniqueId(), con );
connectionsByOfflineUUID.put( offlineId, con );
} finally
{
connectionLock.writeLock().unlock();
}
return true;
}

public void removeConnection(UserConnection con)
Expand Down
4 changes: 3 additions & 1 deletion proxy/src/main/java/net/md_5/bungee/UserConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void sendPacket(DefinedPacket packet)
}
};

public void init()
public boolean init()
{
this.entityRewrite = EntityMap.getEntityMap( getPendingConnection().getVersion() );

Expand All @@ -172,6 +172,8 @@ public void init()

// Set whether the connection has a 1.8 FML marker in the handshake.
forgeClientHandler.setFmlTokenInHandshake( this.getPendingConnection().getExtraDataInHandshake().contains( ForgeConstants.FML_HANDSHAKE_TOKEN ) );

return BungeeCord.getInstance().addConnection( this );
}

public void sendPacket(PacketWrapper packet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,11 @@ public void run()

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 ) );
bungee.getPluginManager().callEvent( new PostLoginEvent( userCon ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public UpstreamBridge(ProxyServer bungee, UserConnection con)
this.bungee = bungee;
this.con = con;

BungeeCord.getInstance().addConnection( con );
con.getTabListHandler().onConnect();
}

Expand Down

0 comments on commit f5157f1

Please sign in to comment.