Skip to content

Commit

Permalink
Merge branch 'master' into Psionic-Power-Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
VMSolidus authored May 28, 2024
2 parents c591bc3 + 4123236 commit 4567016
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-docfx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup .NET Core
uses: actions/[email protected]
with:
dotnet-version: 8.0.x
dotnet-version: 8.0.100

- name: Install dependencies
run: dotnet restore
Expand Down
98 changes: 98 additions & 0 deletions Content.Server/Administration/Managers/AdminManager.Metrics.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System.Diagnostics.Metrics;
using System.Runtime.InteropServices;
using Content.Server.Afk;
using Robust.Server.DataMetrics;

namespace Content.Server.Administration.Managers;

// Handles metrics reporting for active admin count and such.

public sealed partial class AdminManager
{
private Dictionary<int, (int active, int afk, int deadminned)>? _adminOnlineCounts;

private const int SentinelRankId = -1;

[Dependency] private readonly IMetricsManager _metrics = default!;
[Dependency] private readonly IAfkManager _afkManager = default!;
[Dependency] private readonly IMeterFactory _meterFactory = default!;

private void InitializeMetrics()
{
_metrics.UpdateMetrics += MetricsOnUpdateMetrics;

var meter = _meterFactory.Create("SS14.AdminManager");

meter.CreateObservableGauge(
"admins_online_count",
MeasureAdminCount,
null,
"The count of online admins");
}

private void MetricsOnUpdateMetrics()
{
_sawmill.Verbose("Updating metrics");

var dict = new Dictionary<int, (int active, int afk, int deadminned)>();

foreach (var (session, reg) in _admins)
{
var rankId = reg.RankId ?? SentinelRankId;

ref var counts = ref CollectionsMarshal.GetValueRefOrAddDefault(dict, rankId, out _);

if (reg.Data.Active)
{
if (_afkManager.IsAfk(session))
counts.afk += 1;
else
counts.active += 1;
}
else
{
counts.deadminned += 1;
}
}

// Neither prometheus-net nor dotnet-counters seem to handle stuff well if we STOP returning measurements.
// i.e. if the last admin with a rank disconnects.
// So if we have EVER reported a rank, always keep reporting it.
if (_adminOnlineCounts != null)
{
foreach (var rank in _adminOnlineCounts.Keys)
{
CollectionsMarshal.GetValueRefOrAddDefault(dict, rank, out _);
}
}

// Make sure "no rank" is always available. Avoid "no data".
CollectionsMarshal.GetValueRefOrAddDefault(dict, SentinelRankId, out _);

_adminOnlineCounts = dict;
}

private IEnumerable<Measurement<int>> MeasureAdminCount()
{
if (_adminOnlineCounts == null)
yield break;

foreach (var (rank, (active, afk, deadminned)) in _adminOnlineCounts)
{
yield return new Measurement<int>(
active,
new KeyValuePair<string, object?>("state", "active"),
new KeyValuePair<string, object?>("rank", rank == SentinelRankId ? "none" : rank.ToString()));

yield return new Measurement<int>(
afk,
new KeyValuePair<string, object?>("state", "afk"),
new KeyValuePair<string, object?>("rank", rank == SentinelRankId ? "none" : rank.ToString()));

yield return new Measurement<int>(
deadminned,
new KeyValuePair<string, object?>("state", "deadminned"),
new KeyValuePair<string, object?>("rank", rank == SentinelRankId ? "none" : rank.ToString()));
}
}
}
9 changes: 8 additions & 1 deletion Content.Server/Administration/Managers/AdminManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace Content.Server.Administration.Managers
{
public sealed class AdminManager : IAdminManager, IPostInjectInit, IConGroupControllerImplementation
public sealed partial class AdminManager : IAdminManager, IPostInjectInit, IConGroupControllerImplementation
{
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IServerDbManager _dbManager = default!;
Expand All @@ -34,6 +34,7 @@ public sealed class AdminManager : IAdminManager, IPostInjectInit, IConGroupCont
[Dependency] private readonly IServerConsoleHost _consoleHost = default!;
[Dependency] private readonly IChatManager _chat = default!;
[Dependency] private readonly ToolshedManager _toolshed = default!;
[Dependency] private readonly ILogManager _logManager = default!;

private readonly Dictionary<ICommonSession, AdminReg> _admins = new();
private readonly HashSet<NetUserId> _promotedPlayers = new();
Expand All @@ -49,6 +50,8 @@ public sealed class AdminManager : IAdminManager, IPostInjectInit, IConGroupCont
private readonly AdminCommandPermissions _commandPermissions = new();
private readonly AdminCommandPermissions _toolshedCommandPermissions = new();

private ISawmill _sawmill = default!;

public bool IsAdmin(ICommonSession session, bool includeDeAdmin = false)
{
return GetAdminData(session, includeDeAdmin) != null;
Expand Down Expand Up @@ -181,6 +184,8 @@ public void ReloadAdminsWithRank(int rankId)

public void Initialize()
{
_sawmill = _logManager.GetSawmill("admin");

_netMgr.RegisterNetMessage<MsgUpdateAdminStatus>();

// Cache permissions for loaded console commands with the requisite attributes.
Expand Down Expand Up @@ -234,6 +239,8 @@ public void Initialize()
}

_toolshed.ActivePermissionController = this;

InitializeMetrics();
}

public void PromoteHost(ICommonSession player)
Expand Down
8 changes: 8 additions & 0 deletions Resources/Changelog/Changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4086,3 +4086,11 @@ Entries:
message: Added a number of new corporate coats to the Clothesmate.
id: 6111
time: '2024-05-22T03:35:11.0000000+00:00'
- author: VMSolidus
changes:
- type: Tweak
message: >-
Syndicate Listening Posts can now appear any time in a round, and can
appear on low-pop servers.
id: 6112
time: '2024-05-28T23:44:39.0000000+00:00'
5 changes: 2 additions & 3 deletions Resources/Prototypes/DeltaV/GameRules/events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@
noSpawn: true
components:
- type: StationEvent
earliestStart: 15
weight: 5
minimumPlayers: 25
weight: 7.5
minimumPlayers: 10
maxOccurrences: 1
duration: 1
- type: PirateRadioSpawnRule
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.100",
"rollForward": "latestFeature"
"rollForward": "disable"
}
}

0 comments on commit 4567016

Please sign in to comment.