]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix aHelp relay to detect AFK Admins (#24482)
authorRepo <47093363+Titian3@users.noreply.github.com>
Thu, 1 Feb 2024 13:03:49 +0000 (02:03 +1300)
committerGitHub <noreply@github.com>
Thu, 1 Feb 2024 13:03:49 +0000 (00:03 +1100)
* 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>
Content.Server/Administration/Systems/BwoinkSystem.cs
Content.Server/Afk/AfkManager.cs
Content.Shared/CCVar/CCVars.cs

index 87c200e08b82821e03c6c96eb6ffb1cb71b7355d..5439b27f42495cd80266b942f9d5bda54f34239e 100644 (file)
@@ -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,19 +486,26 @@ 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)
         {
             var stringbuilder = new StringBuilder();
-            
+
             if (admin)
                 stringbuilder.Append(":outbox_tray:");
             else if (noReceivers)
index 8f7090431710fb5e72afe99ddf06c1b171fd2060..96dcb475cd80ef5ee91eaa17f688fc73ebf8f9e1 100644 (file)
@@ -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;
         }
 
index f0b6c2f9232ed7ebabeb47ca69f2e91a1534add1..08c80abdc89fe7a7858c89ee3a450c533e202dbd 100644 (file)
@@ -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
          */