Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes admins not count towards the playercount cap #33424

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Content.Server/Connection/ConnectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<NetUserId, TimeSpan> _temporaryBypasses = [];
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions Content.Shared/CCVar/CCVars.Admin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ public sealed partial class CCVars
public static readonly CVarDef<bool> AdminBypassMaxPlayers =
CVarDef.Create("admin.bypass_max_players", true, CVar.SERVERONLY);

/// <summary>
/// Determines whether admins count towards the total playercount when determining whether the server is over <see cref="SoftMaxPlayers"/>
/// Ideally this should be used in conjuction with <see cref="AdminBypassPlayers"/>.
/// /// This also applies to playercount limits in whitelist conditions
deathride58 marked this conversation as resolved.
Show resolved Hide resolved
/// If false, then admins will not be considered when checking whether the playercount is already above the soft player cap
/// </summary>
public static readonly CVarDef<bool> AdminsCountForMaxPlayers =
CVarDef.Create("admin.admins_count_for_max_players", false, CVar.SERVERONLY);

/// <summary>
/// Determine if custom rank names are used.
/// If it is false, it'd use the actual rank name regardless of the individual's title.
Expand Down
Loading