diff --git a/Content.Server/Administration/Systems/BwoinkSystem.cs b/Content.Server/Administration/Systems/BwoinkSystem.cs index b08bdd4bc2..c1ec0dff7e 100644 --- a/Content.Server/Administration/Systems/BwoinkSystem.cs +++ b/Content.Server/Administration/Systems/BwoinkSystem.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Content.Server.Administration.Managers; using Content.Server.Afk; +using Content.Server.Database; using Content.Server.Discord; using Content.Server.GameTicking; using Content.Shared.Administration; @@ -35,6 +36,8 @@ public sealed class BwoinkSystem : SharedBwoinkSystem [Dependency] private readonly GameTicker _gameTicker = default!; [Dependency] private readonly SharedMindSystem _minds = default!; [Dependency] private readonly IAfkManager _afkManager = default!; + [Dependency] private readonly IPlayerLocator _locator = default!; + [Dependency] private readonly IServerDbManager _db = default!; private ISawmill _sawmill = default!; private readonly HttpClient _httpClient = new(); @@ -517,11 +520,16 @@ private static string GenerateAHelpMessage(string username, string message, bool stringbuilder.Append(message); return stringbuilder.ToString(); } - public void DiscordAhelpSendMessage(BwoinkTextMessage message, EntitySessionEventArgs eventArgs) + public async void DiscordAhelpSendMessage(BwoinkTextMessage message, EntitySessionEventArgs eventArgs) { var senderSession = eventArgs.SenderSession; // Confirm that this person is actually allowed to send a message here. - var adminNickname = _playerManager.GetSessionById(message.TrueSender).Name; + var data = await _locator.LookupIdByNameOrIdAsync($"{message.TrueSender}"); + if (data != null) + { + var adminNickname = data.Username; + + //var adminNickname = _playerManager.GetSessionById(message.TrueSender).Name; var personalChannel = senderSession.UserId == message.UserId; var senderAdmin = _adminManager.GetAdminData(senderSession); var senderAHelpAdmin = senderAdmin?.HasFlag(AdminFlags.Adminhelp) ?? false; @@ -531,8 +539,11 @@ public void DiscordAhelpSendMessage(BwoinkTextMessage message, EntitySessionEven // Unauthorized bwoink (log?) return; } + var escapedText = FormattedMessage.EscapeText(message.Text); + string bwoinkText; + if (senderAdmin is not null && senderAdmin.Flags == AdminFlags.Adminhelp) // Mentor. Not full admin. That's why it's colored differently. { bwoinkText = $"[color=purple]{adminNickname}[/color]"; @@ -543,39 +554,81 @@ public void DiscordAhelpSendMessage(BwoinkTextMessage message, EntitySessionEven } else { - bwoinkText = $"{adminNickname}"; + bwoinkText = $"[color=blue]{adminNickname}[/color]"; } - bwoinkText = $"{"(Discord) "}{bwoinkText}: {escapedText}"; + + bwoinkText = $"{(message.PlaySound ? "" : "(S) ")}(Discord) {bwoinkText}: {escapedText}"; + // If it's not an admin / admin chooses to keep the sound then play it. var playSound = !senderAHelpAdmin || message.PlaySound; - var msg = new BwoinkTextMessage(message.UserId, message.TrueSender, bwoinkText, playSound: playSound); + var msg = new BwoinkTextMessage(message.UserId, senderSession.UserId, bwoinkText, playSound: playSound); + LogBwoink(msg); + var admins = GetTargetAdmins(); + // Notify all admins foreach (var channel in admins) { RaiseNetworkEvent(msg, channel); } + + // Notify player + if (_playerManager.TryGetSessionById(message.UserId, out var session)) + { + if (!admins.Contains(session.Channel)) + { + // 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 (adminNickname != 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]{adminNickname}[/color]"; + } + else if (senderAdmin is not null && senderAdmin.HasFlag(AdminFlags.Adminhelp)) + { + overrideMsgText = $"[color=red]{adminNickname}[/color]"; + } + else + { + overrideMsgText = $"[color=blue]{adminNickname}[/color]"; // Not an admin, name is not overridden. + } + + overrideMsgText = $"{(message.PlaySound ? "" : "(S) ")}(Discord){overrideMsgText}: {escapedText}"; + + RaiseNetworkEvent(new BwoinkTextMessage(message.UserId, senderSession.UserId, overrideMsgText, playSound: playSound), session.Channel); + } + else + RaiseNetworkEvent(msg, session.Channel); + } + } var sendsWebhook = _webhookUrl != string.Empty; if (sendsWebhook) { if (!_messageQueues.ContainsKey(msg.UserId)) _messageQueues[msg.UserId] = new Queue(); + var str = message.Text; var unameLength = senderSession.Name.Length; + if (unameLength + str.Length + _maxAdditionalChars > DescriptionMax) { str = str[..(DescriptionMax - _maxAdditionalChars - unameLength)]; } var nonAfkAdmins = GetNonAfkAdmins(); - _messageQueues[msg.UserId].Enqueue(GenerateAHelpMessage(senderSession.Name, str, !personalChannel, _gameTicker.RoundDuration().ToString("hh\\:mm\\:ss"), _gameTicker.RunLevel, playedSound: playSound, noReceivers: nonAfkAdmins.Count == 0)); + _messageQueues[msg.UserId].Enqueue(GenerateAHelpMessage(adminNickname, str, !personalChannel, _gameTicker.RoundDuration().ToString("hh\\:mm\\:ss"), _gameTicker.RunLevel, playedSound: false, noReceivers: nonAfkAdmins.Count == 0)); } + if (admins.Count != 0 || sendsWebhook) return; + // No admin online, let the player know var systemText = Loc.GetString("bwoink-system-starmute-message-no-other-users"); var starMuteMsg = new BwoinkTextMessage(message.UserId, SystemUserId, systemText); RaiseNetworkEvent(starMuteMsg, senderSession.Channel); + } } } }