Files
tbd-station-14/Content.Server/GameTicking/GameTicker.StatusShell.cs
Myra 40fc4992e5 Add a CCVar to allow from hiding admins in the reported player count. (#34406)
Good for:
- Keeping admins hidden
- Not confuse players seeing 84/80 players

Nicely pairs up with the ``admin.admins_count_for_max_players`` ccvar
2025-01-15 22:10:54 +01:00

63 lines
2.4 KiB
C#

using System.Linq;
using System.Text.Json.Nodes;
using Content.Shared.CCVar;
using Content.Shared.GameTicking;
using Robust.Server.ServerStatus;
using Robust.Shared.Configuration;
namespace Content.Server.GameTicking
{
public sealed partial class GameTicker
{
/// <summary>
/// Used for thread safety, given <see cref="IStatusHost.OnStatusRequest"/> is called from another thread.
/// </summary>
private readonly object _statusShellLock = new();
/// <summary>
/// Round start time in UTC, for status shell purposes.
/// </summary>
[ViewVariables]
private DateTime _roundStartDateTime;
/// <summary>
/// For access to CVars in status responses.
/// </summary>
[Dependency] private readonly IConfigurationManager _cfg = default!;
/// <summary>
/// For access to the round ID in status responses.
/// </summary>
[Dependency] private readonly SharedGameTicker _gameTicker = default!;
private void InitializeStatusShell()
{
IoCManager.Resolve<IStatusHost>().OnStatusRequest += GetStatusResponse;
}
private void GetStatusResponse(JsonNode jObject)
{
var preset = CurrentPreset ?? Preset;
// This method is raised from another thread, so this better be thread safe!
lock (_statusShellLock)
{
jObject["name"] = _baseServer.ServerName;
jObject["map"] = _gameMapManager.GetSelectedMap()?.MapName;
jObject["round_id"] = _gameTicker.RoundId;
jObject["players"] = _cfg.GetCVar(CCVars.AdminsCountInReportedPlayerCount)
? _playerManager.PlayerCount
: _playerManager.PlayerCount - _adminManager.ActiveAdmins.Count();
jObject["soft_max_players"] = _cfg.GetCVar(CCVars.SoftMaxPlayers);
jObject["panic_bunker"] = _cfg.GetCVar(CCVars.PanicBunkerEnabled);
jObject["run_level"] = (int) _runLevel;
if (preset != null)
jObject["preset"] = Loc.GetString(preset.ModeTitle);
if (_runLevel >= GameRunLevel.InRound)
{
jObject["round_start_time"] = _roundStartDateTime.ToString("o");
}
}
}
}
}