Fix aHelp relay to detect AFK Admins (#24482)

* Add AFK detection for aHelp relay and admin specific afk time.

* Correct query to new refactor

* Change AFK timeout to 10min or else Pancake closes my PR 😭

* It wasnt a bug it was a feature, way less aHelps that way.

* aHelp Colors arn't real!

* Update Content.Shared/CCVar/CCVars.cs

---------

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
Repo
2024-02-02 02:03:49 +13:00
committed by GitHub
parent 45dff4b47d
commit 0084121706
3 changed files with 32 additions and 9 deletions

View File

@@ -6,6 +6,7 @@ using System.Text.Json.Nodes;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Server.Administration.Managers; using Content.Server.Administration.Managers;
using Content.Server.Afk;
using Content.Server.Discord; using Content.Server.Discord;
using Content.Server.GameTicking; using Content.Server.GameTicking;
using Content.Shared.Administration; using Content.Shared.Administration;
@@ -33,6 +34,7 @@ namespace Content.Server.Administration.Systems
[Dependency] private readonly IPlayerLocator _playerLocator = default!; [Dependency] private readonly IPlayerLocator _playerLocator = default!;
[Dependency] private readonly GameTicker _gameTicker = default!; [Dependency] private readonly GameTicker _gameTicker = default!;
[Dependency] private readonly SharedMindSystem _minds = default!; [Dependency] private readonly SharedMindSystem _minds = default!;
[Dependency] private readonly IAfkManager _afkManager = default!;
private ISawmill _sawmill = default!; private ISawmill _sawmill = default!;
private readonly HttpClient _httpClient = new(); private readonly HttpClient _httpClient = new();
@@ -327,7 +329,7 @@ namespace Content.Server.Administration.Systems
username += $" ({characterName})"; username += $" ({characterName})";
// If no admins are online, set embed color to red. Otherwise green // If no admins are online, set embed color to red. Otherwise green
var color = GetTargetAdmins().Count > 0 ? 0x41F097 : 0xFF0000; var color = GetNonAfkAdmins().Count > 0 ? 0x41F097 : 0xFF0000;
// Limit server name to 1500 characters, in case someone tries to be a little funny // Limit server name to 1500 characters, in case someone tries to be a little funny
var serverName = _serverName[..Math.Min(_serverName.Length, 1500)]; var serverName = _serverName[..Math.Min(_serverName.Length, 1500)];
@@ -471,7 +473,8 @@ namespace Content.Server.Administration.Systems
{ {
str = str[..(DescriptionMax - _maxAdditionalChars - unameLength)]; str = str[..(DescriptionMax - _maxAdditionalChars - unameLength)];
} }
_messageQueues[msg.UserId].Enqueue(GenerateAHelpMessage(senderSession.Name, str, !personalChannel, _gameTicker.RoundDuration().ToString("hh\\:mm\\:ss"), _gameTicker.RunLevel, admins.Count == 0)); var nonAfkAdmins = GetNonAfkAdmins();
_messageQueues[msg.UserId].Enqueue(GenerateAHelpMessage(senderSession.Name, str, !personalChannel, _gameTicker.RoundDuration().ToString("hh\\:mm\\:ss"), _gameTicker.RunLevel, nonAfkAdmins.Count == 0));
} }
if (admins.Count != 0 || sendsWebhook) if (admins.Count != 0 || sendsWebhook)
@@ -483,7 +486,14 @@ namespace Content.Server.Administration.Systems
RaiseNetworkEvent(starMuteMsg, senderSession.Channel); RaiseNetworkEvent(starMuteMsg, senderSession.Channel);
} }
// Returns all online admins with AHelp access private IList<INetChannel> GetNonAfkAdmins()
{
return _adminManager.ActiveAdmins
.Where(p => (_adminManager.GetAdminData(p)?.HasFlag(AdminFlags.Adminhelp) ?? false) && !_afkManager.IsAfk(p))
.Select(p => p.Channel)
.ToList();
}
private IList<INetChannel> GetTargetAdmins() private IList<INetChannel> GetTargetAdmins()
{ {
return _adminManager.ActiveAdmins return _adminManager.ActiveAdmins

View File

@@ -1,4 +1,5 @@
using Content.Shared.CCVar; using Content.Server.Administration.Managers;
using Content.Shared.CCVar;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Server.Player; using Robust.Server.Player;
using Robust.Shared.Configuration; using Robust.Shared.Configuration;
@@ -38,6 +39,7 @@ namespace Content.Server.Afk
[Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IConsoleHost _consoleHost = default!; [Dependency] private readonly IConsoleHost _consoleHost = default!;
[Dependency] private readonly IAdminManager _adminManager = default!;
private readonly Dictionary<ICommonSession, TimeSpan> _lastActionTimes = new(); private readonly Dictionary<ICommonSession, TimeSpan> _lastActionTimes = new();
@@ -61,10 +63,15 @@ namespace Content.Server.Afk
public bool IsAfk(ICommonSession player) public bool IsAfk(ICommonSession player)
{ {
if (!_lastActionTimes.TryGetValue(player, out var time)) if (!_lastActionTimes.TryGetValue(player, out var time))
{
// Some weird edge case like disconnected clients. Just say true I guess. // Some weird edge case like disconnected clients. Just say true I guess.
return true; return true;
}
var timeOut = _adminManager.IsAdmin(player)
? TimeSpan.FromSeconds(_cfg.GetCVar(CCVars.AdminAfkTime))
: TimeSpan.FromSeconds(_cfg.GetCVar(CCVars.AfkTime));
var timeOut = TimeSpan.FromSeconds(_cfg.GetCVar(CCVars.AfkTime));
return _gameTiming.RealTime - time > timeOut; return _gameTiming.RealTime - time > timeOut;
} }

View File

@@ -833,6 +833,12 @@ namespace Content.Shared.CCVar
public static readonly CVarDef<int> NewPlayerThreshold = public static readonly CVarDef<int> NewPlayerThreshold =
CVarDef.Create("admin.new_player_threshold", 0, CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER); CVarDef.Create("admin.new_player_threshold", 0, CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER);
/// <summary>
/// How long an admin client can go without any input before being considered AFK.
/// </summary>
public static readonly CVarDef<float> AdminAfkTime =
CVarDef.Create("admin.afk_time", 600f, CVar.SERVERONLY);
/* /*
* Explosions * Explosions
*/ */