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:
@@ -6,6 +6,7 @@ using System.Text.Json.Nodes;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Administration.Managers;
|
||||
using Content.Server.Afk;
|
||||
using Content.Server.Discord;
|
||||
using Content.Server.GameTicking;
|
||||
using Content.Shared.Administration;
|
||||
@@ -33,6 +34,7 @@ namespace Content.Server.Administration.Systems
|
||||
[Dependency] private readonly IPlayerLocator _playerLocator = default!;
|
||||
[Dependency] private readonly GameTicker _gameTicker = default!;
|
||||
[Dependency] private readonly SharedMindSystem _minds = default!;
|
||||
[Dependency] private readonly IAfkManager _afkManager = default!;
|
||||
|
||||
private ISawmill _sawmill = default!;
|
||||
private readonly HttpClient _httpClient = new();
|
||||
@@ -327,7 +329,7 @@ namespace Content.Server.Administration.Systems
|
||||
username += $" ({characterName})";
|
||||
|
||||
// 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
|
||||
var serverName = _serverName[..Math.Min(_serverName.Length, 1500)];
|
||||
@@ -471,7 +473,8 @@ namespace Content.Server.Administration.Systems
|
||||
{
|
||||
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)
|
||||
@@ -483,13 +486,20 @@ namespace Content.Server.Administration.Systems
|
||||
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()
|
||||
{
|
||||
return _adminManager.ActiveAdmins
|
||||
.Where(p => _adminManager.GetAdminData(p)?.HasFlag(AdminFlags.Adminhelp) ?? false)
|
||||
.Select(p => p.Channel)
|
||||
.ToList();
|
||||
.Where(p => _adminManager.GetAdminData(p)?.HasFlag(AdminFlags.Adminhelp) ?? false)
|
||||
.Select(p => p.Channel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private static string GenerateAHelpMessage(string username, string message, bool admin, string roundTime, GameRunLevel roundState, bool noReceivers = false)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Server.Administration.Managers;
|
||||
using Content.Shared.CCVar;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Configuration;
|
||||
@@ -38,6 +39,7 @@ namespace Content.Server.Afk
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||
[Dependency] private readonly IConsoleHost _consoleHost = default!;
|
||||
[Dependency] private readonly IAdminManager _adminManager = default!;
|
||||
|
||||
private readonly Dictionary<ICommonSession, TimeSpan> _lastActionTimes = new();
|
||||
|
||||
@@ -61,10 +63,15 @@ namespace Content.Server.Afk
|
||||
public bool IsAfk(ICommonSession player)
|
||||
{
|
||||
if (!_lastActionTimes.TryGetValue(player, out var time))
|
||||
{
|
||||
// Some weird edge case like disconnected clients. Just say true I guess.
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -833,6 +833,12 @@ namespace Content.Shared.CCVar
|
||||
public static readonly CVarDef<int> NewPlayerThreshold =
|
||||
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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user