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:
@@ -46,6 +46,7 @@ namespace Content.Server.Administration.Systems
|
|||||||
private readonly Dictionary<NetUserId, Queue<string>> _messageQueues = new();
|
private readonly Dictionary<NetUserId, Queue<string>> _messageQueues = new();
|
||||||
private readonly HashSet<NetUserId> _processingChannels = new();
|
private readonly HashSet<NetUserId> _processingChannels = new();
|
||||||
private readonly Dictionary<NetUserId, (TimeSpan Timestamp, bool Typing)> _typingUpdateTimestamps = 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
|
// 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
|
// 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.DiscordAHelpFooterIcon, OnFooterIconChanged, true);
|
||||||
_config.OnValueChanged(CCVars.DiscordAHelpAvatar, OnAvatarChanged, true);
|
_config.OnValueChanged(CCVars.DiscordAHelpAvatar, OnAvatarChanged, true);
|
||||||
_config.OnValueChanged(CVars.GameHostName, OnServerNameChanged, true);
|
_config.OnValueChanged(CVars.GameHostName, OnServerNameChanged, true);
|
||||||
|
_config.OnValueChanged(CCVars.AdminAhelpOverrideClientName, OnOverrideChanged, true);
|
||||||
_sawmill = IoCManager.Resolve<ILogManager>().GetSawmill("AHELP");
|
_sawmill = IoCManager.Resolve<ILogManager>().GetSawmill("AHELP");
|
||||||
_maxAdditionalChars = GenerateAHelpMessage("", "", true).Length;
|
_maxAdditionalChars = GenerateAHelpMessage("", "", true).Length;
|
||||||
_playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
|
_playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
|
||||||
@@ -75,6 +77,11 @@ namespace Content.Server.Administration.Systems
|
|||||||
SubscribeNetworkEvent<BwoinkClientTypingUpdated>(OnClientTypingUpdated);
|
SubscribeNetworkEvent<BwoinkClientTypingUpdated>(OnClientTypingUpdated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnOverrideChanged(string obj)
|
||||||
|
{
|
||||||
|
_overrideClientName = obj;
|
||||||
|
}
|
||||||
|
|
||||||
private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e)
|
private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.NewStatus != SessionStatus.InGame)
|
if (e.NewStatus != SessionStatus.InGame)
|
||||||
@@ -144,6 +151,7 @@ namespace Content.Server.Administration.Systems
|
|||||||
_config.UnsubValueChanged(CCVars.DiscordAHelpWebhook, OnWebhookChanged);
|
_config.UnsubValueChanged(CCVars.DiscordAHelpWebhook, OnWebhookChanged);
|
||||||
_config.UnsubValueChanged(CCVars.DiscordAHelpFooterIcon, OnFooterIconChanged);
|
_config.UnsubValueChanged(CCVars.DiscordAHelpFooterIcon, OnFooterIconChanged);
|
||||||
_config.UnsubValueChanged(CVars.GameHostName, OnServerNameChanged);
|
_config.UnsubValueChanged(CVars.GameHostName, OnServerNameChanged);
|
||||||
|
_config.UnsubValueChanged(CCVars.AdminAhelpOverrideClientName, OnOverrideChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void OnWebhookChanged(string url)
|
private async void OnWebhookChanged(string url)
|
||||||
@@ -393,14 +401,20 @@ namespace Content.Server.Administration.Systems
|
|||||||
|
|
||||||
var escapedText = FormattedMessage.EscapeText(message.Text);
|
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 =>
|
bwoinkText = $"[color=purple]{senderSession.Name}[/color]: {escapedText}";
|
||||||
$"[color=purple]{senderSession.Name}[/color]: {escapedText}",
|
}
|
||||||
var x when x is not null && x.HasFlag(AdminFlags.Adminhelp) =>
|
else if (senderAdmin is not null && senderAdmin.HasFlag(AdminFlags.Adminhelp))
|
||||||
$"[color=red]{senderSession.Name}[/color]: {escapedText}",
|
{
|
||||||
_ => $"{senderSession.Name}: {escapedText}",
|
bwoinkText = $"[color=red]{senderSession.Name}[/color]: {escapedText}";
|
||||||
};
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bwoinkText = $"{senderSession.Name}: {escapedText}";
|
||||||
|
}
|
||||||
|
|
||||||
var msg = new BwoinkTextMessage(message.UserId, senderSession.UserId, bwoinkText);
|
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 (_playerManager.TryGetSessionById(message.UserId, out var session))
|
||||||
{
|
{
|
||||||
if (!admins.Contains(session.ConnectedClient))
|
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;
|
var sendsWebhook = _webhookUrl != string.Empty;
|
||||||
|
|||||||
@@ -776,6 +776,11 @@ namespace Content.Shared.CCVar
|
|||||||
public static readonly CVarDef<bool> AdminDeadminOnJoin =
|
public static readonly CVarDef<bool> AdminDeadminOnJoin =
|
||||||
CVarDef.Create("admin.deadmin_on_join", false, CVar.SERVERONLY);
|
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
|
* Explosions
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user