From 352f339eaaed554e221221e171be7160feaed316 Mon Sep 17 00:00:00 2001 From: deathride58 Date: Tue, 19 Nov 2024 21:07:43 -0500 Subject: [PATCH 1/3] Makes admins not count towards the playercount cap --- Content.Server/Connection/ConnectionManager.cs | 13 +++++++++++-- Content.Shared/CCVar/CCVars.Admin.cs | 9 +++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Content.Server/Connection/ConnectionManager.cs b/Content.Server/Connection/ConnectionManager.cs index 2c1f9fb36f1163..68924c7be24521 100644 --- a/Content.Server/Connection/ConnectionManager.cs +++ b/Content.Server/Connection/ConnectionManager.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Threading.Tasks; using System.Runtime.InteropServices; +using Content.Server.Administration.Managers; using Content.Server.Chat.Managers; using Content.Server.Database; using Content.Server.GameTicking; @@ -56,6 +57,7 @@ public sealed partial class ConnectionManager : IConnectionManager [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly ILogManager _logManager = default!; [Dependency] private readonly IChatManager _chatManager = default!; + [Dependency] private readonly IAdminManager _adminManager = default!; private ISawmill _sawmill = default!; private readonly Dictionary _temporaryBypasses = []; @@ -265,7 +267,14 @@ session.Status is SessionStatus.Connected or SessionStatus.InGame ticker.PlayerGameStatuses.TryGetValue(userId, out var status) && status == PlayerGameStatus.JoinedGame; var adminBypass = _cfg.GetCVar(CCVars.AdminBypassMaxPlayers) && adminData != null; - if ((_plyMgr.PlayerCount >= _cfg.GetCVar(CCVars.SoftMaxPlayers) && !adminBypass) && !wasInGame) + var softPlayerCount = _plyMgr.PlayerCount; + + if (!_cfg.GetCVar(CCVars.AdminsCountForMaxPlayers)) + { + softPlayerCount -= _adminManager.ActiveAdmins.Count(); + } + + if ((softPlayerCount >= _cfg.GetCVar(CCVars.SoftMaxPlayers) && !adminBypass) && !wasInGame) { return (ConnectionDenyReason.Full, Loc.GetString("soft-player-cap-full"), null); } @@ -282,7 +291,7 @@ session.Status is SessionStatus.Connected or SessionStatus.InGame foreach (var whitelist in _whitelists) { - if (!IsValid(whitelist, _plyMgr.PlayerCount)) + if (!IsValid(whitelist, softPlayerCount)) { // Not valid for current player count. continue; diff --git a/Content.Shared/CCVar/CCVars.Admin.cs b/Content.Shared/CCVar/CCVars.Admin.cs index 28bebfbe8a6521..c5d4b0b5818719 100644 --- a/Content.Shared/CCVar/CCVars.Admin.cs +++ b/Content.Shared/CCVar/CCVars.Admin.cs @@ -149,6 +149,15 @@ public sealed partial class CCVars public static readonly CVarDef AdminBypassMaxPlayers = CVarDef.Create("admin.bypass_max_players", true, CVar.SERVERONLY); + /// + /// Determines whether admins count towards the total playercount when determining whether the server is over + /// Ideally this should be used in conjuction with . + /// /// This also applies to playercount limits in whitelist conditions + /// If false, then admins will not be considered when checking whether the playercount is already above the soft player cap + /// + public static readonly CVarDef AdminsCountForMaxPlayers = + CVarDef.Create("admin.admins_count_for_max_players", false, CVar.SERVERONLY); + /// /// Determine if custom rank names are used. /// If it is false, it'd use the actual rank name regardless of the individual's title. From aece14a97d5188b51eb2b23b3c4617988bdae404 Mon Sep 17 00:00:00 2001 From: deathride58 Date: Tue, 19 Nov 2024 22:26:06 -0500 Subject: [PATCH 2/3] Update Content.Shared/CCVar/CCVars.Admin.cs (thx Aeshus Co-authored-by: Thomas <87614336+Aeshus@users.noreply.github.com> --- Content.Shared/CCVar/CCVars.Admin.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Shared/CCVar/CCVars.Admin.cs b/Content.Shared/CCVar/CCVars.Admin.cs index c5d4b0b5818719..969a3e75fe13d9 100644 --- a/Content.Shared/CCVar/CCVars.Admin.cs +++ b/Content.Shared/CCVar/CCVars.Admin.cs @@ -152,7 +152,7 @@ public sealed partial class CCVars /// /// Determines whether admins count towards the total playercount when determining whether the server is over /// Ideally this should be used in conjuction with . - /// /// This also applies to playercount limits in whitelist conditions + /// This also applies to playercount limits in whitelist conditions /// If false, then admins will not be considered when checking whether the playercount is already above the soft player cap /// public static readonly CVarDef AdminsCountForMaxPlayers = From 322e1d35141649efda7bd2dd3d7ee3fba78e04cb Mon Sep 17 00:00:00 2001 From: deathride58 Date: Wed, 20 Nov 2024 01:26:39 -0500 Subject: [PATCH 3/3] Actually fixes whitespace on the comments Thanks VScode very good IDE --- Content.Shared/CCVar/CCVars.Admin.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Content.Shared/CCVar/CCVars.Admin.cs b/Content.Shared/CCVar/CCVars.Admin.cs index 969a3e75fe13d9..c422a5a02a1d73 100644 --- a/Content.Shared/CCVar/CCVars.Admin.cs +++ b/Content.Shared/CCVar/CCVars.Admin.cs @@ -152,8 +152,8 @@ public sealed partial class CCVars /// /// Determines whether admins count towards the total playercount when determining whether the server is over /// Ideally this should be used in conjuction with . - /// This also applies to playercount limits in whitelist conditions - /// If false, then admins will not be considered when checking whether the playercount is already above the soft player cap + /// This also applies to playercount limits in whitelist conditions + /// If false, then admins will not be considered when checking whether the playercount is already above the soft player cap /// public static readonly CVarDef AdminsCountForMaxPlayers = CVarDef.Create("admin.admins_count_for_max_players", false, CVar.SERVERONLY);