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.
This commit is contained in:
Simon
2023-12-20 00:40:37 +01:00
committed by GitHub
parent 3293892941
commit dc017dd6fa
2 changed files with 50 additions and 8 deletions

View 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;