Skip to content

Commit

Permalink
Fix rejoining clients kicked for maxclient limit
Browse files Browse the repository at this point in the history
  • Loading branch information
NikoCat233 committed Apr 26, 2024
1 parent c73a339 commit 1bd836f
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/Impostor.Server/Net/State/Game.Incoming.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,24 +174,6 @@ private async ValueTask<GameJoinResult> AddClientSafeAsync(ClientBase client)
return GameJoinResult.FromError(GameJoinError.Banned);
}

if (Client._antiCheatConfig!.MaxOnlineFromSameIp != 0)
{
if (ClientManager._onlineCount.TryGetValue(client.Connection.EndPoint.Address.ToString(), out var count))
{
if (count >= Client._antiCheatConfig.MaxOnlineFromSameIp)
{
return GameJoinResult.CreateCustomError(string.Format("[Impostor Anticheat+]\nToo many clients from a same ip.\n({0}) x {1}", client.Connection.EndPoint.Address.ToString(), count));
}

ClientManager._onlineCount[client.Connection.EndPoint.Address.ToString()] = count + 1;
}
else
{
ClientManager._onlineCount.TryAdd(client.Connection.EndPoint.Address.ToString(), 1);
ClientManager._onlineCount[client.Connection.EndPoint.Address.ToString()] = 1;
}
}

var player = client.Player;

// Check if the player is running the same version as the host
Expand Down Expand Up @@ -239,6 +221,26 @@ private async ValueTask<GameJoinResult> AddClientSafeAsync(ClientBase client)
client.Player = clientPlayer;
}

// Rejoining clients need to bypass this limit with isNew
if (Client._antiCheatConfig!.MaxOnlineFromSameIp != 0 && isNew)
{
if (ClientManager._onlineCount.TryGetValue(client.Connection.EndPoint.Address.ToString(), out var count))
{
if (count >= Client._antiCheatConfig.MaxOnlineFromSameIp)
{
_logger.LogInformation("Client {0} ({1}) x {2} reached max clients online limit. Kicked.", client.Name, client.Connection.EndPoint.Address.ToString(), count);
return GameJoinResult.CreateCustomError(string.Format("[Impostor Anticheat+]\nToo many clients from a same ip.\n({0}) x {1}", client.Connection.EndPoint.Address.ToString(), count));
}

ClientManager._onlineCount[client.Connection.EndPoint.Address.ToString()] = count + 1;
}
else
{
ClientManager._onlineCount.TryAdd(client.Connection.EndPoint.Address.ToString(), 1);
ClientManager._onlineCount[client.Connection.EndPoint.Address.ToString()] = 1;
}
}

if (ClientManager._puids.TryGetValue(client.Connection.EndPoint.Address.ToString(), out var puid))
{
client.Puid = puid;
Expand Down

0 comments on commit 1bd836f

Please sign in to comment.