From: Simon <63975668+Simyon264@users.noreply.github.com> Date: Tue, 19 Dec 2023 23:40:37 +0000 (+0100) Subject: CVar for custom name in client-side ahelp menu. (#22069) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=dc017dd6fa45da1387a726de2b4756d4391467c8;p=space-station-14.git CVar for custom name in client-side ahelp menu. (#22069) * 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. --- diff --git a/Content.Server/Administration/Systems/BwoinkSystem.cs b/Content.Server/Administration/Systems/BwoinkSystem.cs index 31ef285a88..00b771e448 100644 --- a/Content.Server/Administration/Systems/BwoinkSystem.cs +++ b/Content.Server/Administration/Systems/BwoinkSystem.cs @@ -46,6 +46,7 @@ namespace Content.Server.Administration.Systems private readonly Dictionary> _messageQueues = new(); private readonly HashSet _processingChannels = new(); private readonly Dictionary _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().GetSawmill("AHELP"); _maxAdditionalChars = GenerateAHelpMessage("", "", true).Length; _playerManager.PlayerStatusChanged += OnPlayerStatusChanged; @@ -75,6 +77,11 @@ namespace Content.Server.Administration.Systems SubscribeNetworkEvent(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; diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index 2e1589a7e9..fb6626c150 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -776,6 +776,11 @@ namespace Content.Shared.CCVar public static readonly CVarDef AdminDeadminOnJoin = CVarDef.Create("admin.deadmin_on_join", false, CVar.SERVERONLY); + /// + /// Overrides the name the client sees in ahelps. Set empty to disable. + /// + public static readonly CVarDef AdminAhelpOverrideClientName = + CVarDef.Create("admin.override_adminname_in_client_ahelp", string.Empty, CVar.SERVERONLY); /* * Explosions */