]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
CVar for custom name in client-side ahelp menu. (#22069)
authorSimon <63975668+Simyon264@users.noreply.github.com>
Tue, 19 Dec 2023 23:40:37 +0000 (00:40 +0100)
committerGitHub <noreply@github.com>
Tue, 19 Dec 2023 23:40:37 +0000 (17:40 -0600)
* the grinch will ruin christmas

* comments here, comments there, comments should not be a thing :godo:

* Unsubscribe from CVar

* rename cvar to be clearer.

* Change switch to if statement.

Content.Server/Administration/Systems/BwoinkSystem.cs
Content.Shared/CCVar/CCVars.cs

index 31ef285a882165aad829c0ef22a9f87ab6db7f1a..00b771e4488215c9b15f38d1f8f59c530fd98495 100644 (file)
@@ -46,6 +46,7 @@ namespace Content.Server.Administration.Systems
         private readonly Dictionary<NetUserId, Queue<string>> _messageQueues = new();
         private readonly HashSet<NetUserId> _processingChannels = new();
         private readonly Dictionary<NetUserId, (TimeSpan Timestamp, bool Typing)> _typingUpdateTimestamps = new();
+        private string _overrideClientName = string.Empty;
 
         // Max embed description length is 4096, according to https://discord.com/developers/docs/resources/channel#embed-object-embed-limits
         // Keep small margin, just to be safe
@@ -67,6 +68,7 @@ namespace Content.Server.Administration.Systems
             _config.OnValueChanged(CCVars.DiscordAHelpFooterIcon, OnFooterIconChanged, true);
             _config.OnValueChanged(CCVars.DiscordAHelpAvatar, OnAvatarChanged, true);
             _config.OnValueChanged(CVars.GameHostName, OnServerNameChanged, true);
+            _config.OnValueChanged(CCVars.AdminAhelpOverrideClientName, OnOverrideChanged, true);
             _sawmill = IoCManager.Resolve<ILogManager>().GetSawmill("AHELP");
             _maxAdditionalChars = GenerateAHelpMessage("", "", true).Length;
             _playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
@@ -75,6 +77,11 @@ namespace Content.Server.Administration.Systems
             SubscribeNetworkEvent<BwoinkClientTypingUpdated>(OnClientTypingUpdated);
         }
 
+        private void OnOverrideChanged(string obj)
+        {
+            _overrideClientName = obj;
+        }
+
         private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e)
         {
             if (e.NewStatus != SessionStatus.InGame)
@@ -144,6 +151,7 @@ namespace Content.Server.Administration.Systems
             _config.UnsubValueChanged(CCVars.DiscordAHelpWebhook, OnWebhookChanged);
             _config.UnsubValueChanged(CCVars.DiscordAHelpFooterIcon, OnFooterIconChanged);
             _config.UnsubValueChanged(CVars.GameHostName, OnServerNameChanged);
+            _config.UnsubValueChanged(CCVars.AdminAhelpOverrideClientName, OnOverrideChanged);
         }
 
         private async void OnWebhookChanged(string url)
@@ -393,14 +401,20 @@ namespace Content.Server.Administration.Systems
 
             var escapedText = FormattedMessage.EscapeText(message.Text);
 
-            var bwoinkText = senderAdmin switch
+            string bwoinkText;
+
+            if (senderAdmin is not null && senderAdmin.Flags == AdminFlags.Adminhelp) // Mentor. Not full admin. That's why it's colored differently.
             {
-                var x when x is not null && x.Flags == AdminFlags.Adminhelp =>
-                    $"[color=purple]{senderSession.Name}[/color]: {escapedText}",
-                var x when x is not null && x.HasFlag(AdminFlags.Adminhelp) =>
-                    $"[color=red]{senderSession.Name}[/color]: {escapedText}",
-                _ => $"{senderSession.Name}: {escapedText}",
-            };
+                bwoinkText = $"[color=purple]{senderSession.Name}[/color]: {escapedText}";
+            }
+            else if (senderAdmin is not null && senderAdmin.HasFlag(AdminFlags.Adminhelp))
+            {
+                bwoinkText = $"[color=red]{senderSession.Name}[/color]: {escapedText}";
+            }
+            else
+            {
+                bwoinkText = $"{senderSession.Name}: {escapedText}";
+            }
 
             var msg = new BwoinkTextMessage(message.UserId, senderSession.UserId, bwoinkText);
 
@@ -418,7 +432,30 @@ namespace Content.Server.Administration.Systems
             if (_playerManager.TryGetSessionById(message.UserId, out var session))
             {
                 if (!admins.Contains(session.ConnectedClient))
-                    RaiseNetworkEvent(msg, session.ConnectedClient);
+                {
+                    // If _overrideClientName is set, we generate a new message with the override name. The admins name will still be the original name for the webhooks.
+                    if (_overrideClientName != string.Empty)
+                    {
+                        string overrideMsgText;
+                        // Doing the same thing as above, but with the override name. Theres probably a better way to do this.
+                        if (senderAdmin is not null && senderAdmin.Flags == AdminFlags.Adminhelp) // Mentor. Not full admin. That's why it's colored differently.
+                        {
+                            overrideMsgText = $"[color=purple]{_overrideClientName}[/color]: {escapedText}";
+                        }
+                        else if (senderAdmin is not null && senderAdmin.HasFlag(AdminFlags.Adminhelp))
+                        {
+                            overrideMsgText = $"[color=red]{_overrideClientName}[/color]: {escapedText}";
+                        }
+                        else
+                        {
+                            overrideMsgText = $"{senderSession.Name}: {escapedText}"; // Not an admin, name is not overridden.
+                        }
+
+                        RaiseNetworkEvent(new BwoinkTextMessage(message.UserId, senderSession.UserId, overrideMsgText), session.ConnectedClient);
+                    }
+                    else
+                        RaiseNetworkEvent(msg, session.ConnectedClient);
+                }
             }
 
             var sendsWebhook = _webhookUrl != string.Empty;
index 2e1589a7e9c1aea92f8b10dbcf1e4978bb3a665e..fb6626c150c10852d11f5428a24e0844b6a476ee 100644 (file)
@@ -776,6 +776,11 @@ namespace Content.Shared.CCVar
         public static readonly CVarDef<bool> AdminDeadminOnJoin =
             CVarDef.Create("admin.deadmin_on_join", false, CVar.SERVERONLY);
 
+        /// <summary>
+        ///     Overrides the name the client sees in ahelps. Set empty to disable.
+        /// </summary>
+        public static readonly CVarDef<string> AdminAhelpOverrideClientName =
+            CVarDef.Create("admin.override_adminname_in_client_ahelp", string.Empty, CVar.SERVERONLY);
         /*
          * Explosions
          */