Throttle people trying to connect to a full server. (#20972)

* Throttle people trying to connect to a full server.

To reduce spam/load on the server and connection logs table.

Players are forced to wait 30 seconds after getting denied for "server full", before they can try connecting again.

This code is an absolute nightmare mess. I tried to re-use the existing code for the redial timer but god everything here sucks so much.

Requires https://github.com/space-wizards/RobustToolbox/pull/4487

* Use new NetDisconnectMessage API instead.

* Add admin.bypass_max_players CVar.

Just something to help with debugging the player cap on dev, I don't expect this to ever be disabled on real servers.
This commit is contained in:
Pieter-Jan Briers
2024-03-14 09:00:47 +01:00
committed by GitHub
parent 3cb1c585c5
commit 0ecc5e8c96
5 changed files with 86 additions and 26 deletions

View File

@@ -1,4 +1,5 @@
using System.Collections.Immutable;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Content.Server.Database;
using Content.Server.GameTicking;
@@ -77,7 +78,11 @@ namespace Content.Server.Connection
if (banHits is { Count: > 0 })
await _db.AddServerBanHitsAsync(id, banHits);
e.Deny(msg);
var properties = new Dictionary<string, object>();
if (reason == ConnectionDenyReason.Full)
properties["delay"] = _cfg.GetCVar(CCVars.GameServerFullReconnectDelay);
e.Deny(new NetDenyReason(msg, properties));
}
else
{
@@ -156,7 +161,8 @@ namespace Content.Server.Connection
var wasInGame = EntitySystem.TryGet<GameTicker>(out var ticker) &&
ticker.PlayerGameStatuses.TryGetValue(userId, out var status) &&
status == PlayerGameStatus.JoinedGame;
if ((_plyMgr.PlayerCount >= _cfg.GetCVar(CCVars.SoftMaxPlayers) && adminData is null) && !wasInGame)
var adminBypass = _cfg.GetCVar(CCVars.AdminBypassMaxPlayers) && adminData != null;
if ((_plyMgr.PlayerCount >= _cfg.GetCVar(CCVars.SoftMaxPlayers) && !adminBypass) && !wasInGame)
{
return (ConnectionDenyReason.Full, Loc.GetString("soft-player-cap-full"), null);
}