From 5ece9bd9e8d67d9a10003f7cba44d4c01223219d Mon Sep 17 00:00:00 2001 From: Chief-Engineer <119664036+Chief-Engineer@users.noreply.github.com> Date: Mon, 19 Dec 2022 21:39:01 -0600 Subject: [PATCH] Modify admin chat (#13050) * split admin chat into new channel * add ability to play audio when a chat message is received and add audio to admin chat * give client control of AdminChat sound and volume + suppress sound for senders --- .../Systems/Chat/ChatUIController.cs | 1 + .../Chat/Controls/ChannelFilterPopup.xaml.cs | 1 + .../Chat/Controls/ChannelSelectorButton.cs | 2 +- .../Systems/Chat/Widgets/ChatBox.xaml.cs | 5 +++ Content.Server/Chat/Managers/ChatManager.cs | 34 +++++++++++++------ Content.Server/Chat/Managers/IChatManager.cs | 8 ++--- Content.Shared/CCVar/CCVars.cs | 4 +++ Content.Shared/Chat/ChatChannel.cs | 9 +++-- Content.Shared/Chat/ChatChannelExtensions.cs | 1 + Content.Shared/Chat/ChatSelectChannel.cs | 2 +- Content.Shared/Chat/MsgChatMessage.cs | 6 +++- Resources/Locale/en-US/chat/ui/chat-box.ftl | 3 +- 12 files changed, 55 insertions(+), 21 deletions(-) diff --git a/Content.Client/UserInterface/Systems/Chat/ChatUIController.cs b/Content.Client/UserInterface/Systems/Chat/ChatUIController.cs index 585a55e063..4ecde7deb3 100644 --- a/Content.Client/UserInterface/Systems/Chat/ChatUIController.cs +++ b/Content.Client/UserInterface/Systems/Chat/ChatUIController.cs @@ -420,6 +420,7 @@ public sealed class ChatUIController : UIController if (_admin.HasFlag(AdminFlags.Admin)) { FilterableChannels |= ChatChannel.Admin; + FilterableChannels |= ChatChannel.AdminChat; CanSendChannels |= ChatSelectChannel.Admin; } diff --git a/Content.Client/UserInterface/Systems/Chat/Controls/ChannelFilterPopup.xaml.cs b/Content.Client/UserInterface/Systems/Chat/Controls/ChannelFilterPopup.xaml.cs index 5a3c88c85c..92149bfb80 100644 --- a/Content.Client/UserInterface/Systems/Chat/Controls/ChannelFilterPopup.xaml.cs +++ b/Content.Client/UserInterface/Systems/Chat/Controls/ChannelFilterPopup.xaml.cs @@ -20,6 +20,7 @@ public sealed partial class ChannelFilterPopup : Popup ChatChannel.OOC, ChatChannel.Dead, ChatChannel.Admin, + ChatChannel.AdminChat, ChatChannel.Server }; diff --git a/Content.Client/UserInterface/Systems/Chat/Controls/ChannelSelectorButton.cs b/Content.Client/UserInterface/Systems/Chat/Controls/ChannelSelectorButton.cs index 1279f8f481..daf0d95ec4 100644 --- a/Content.Client/UserInterface/Systems/Chat/Controls/ChannelSelectorButton.cs +++ b/Content.Client/UserInterface/Systems/Chat/Controls/ChannelSelectorButton.cs @@ -82,7 +82,7 @@ public sealed class ChannelSelectorButton : Button ChatSelectChannel.LOOC => Color.MediumTurquoise, ChatSelectChannel.OOC => Color.LightSkyBlue, ChatSelectChannel.Dead => Color.MediumPurple, - ChatSelectChannel.Admin => Color.Red, + ChatSelectChannel.Admin => Color.HotPink, _ => Color.DarkGray }; } diff --git a/Content.Client/UserInterface/Systems/Chat/Widgets/ChatBox.xaml.cs b/Content.Client/UserInterface/Systems/Chat/Widgets/ChatBox.xaml.cs index 1f00af0fe1..04d7e42ad1 100644 --- a/Content.Client/UserInterface/Systems/Chat/Widgets/ChatBox.xaml.cs +++ b/Content.Client/UserInterface/Systems/Chat/Widgets/ChatBox.xaml.cs @@ -7,7 +7,9 @@ using Robust.Client.AutoGenerated; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.XAML; +using Robust.Shared.Audio; using Robust.Shared.Input; +using Robust.Shared.Player; using Robust.Shared.Utility; using static Robust.Client.UserInterface.Controls.LineEdit; @@ -52,6 +54,9 @@ public partial class ChatBox : UIWidget return; } + if (msg is { Read: false, AudioPath: { } }) + SoundSystem.Play(msg.AudioPath, Filter.Local(), new AudioParams().WithVolume(msg.AudioVolume)); + msg.Read = true; var color = msg.MessageColorOverride != null diff --git a/Content.Server/Chat/Managers/ChatManager.cs b/Content.Server/Chat/Managers/ChatManager.cs index d2bf9874dc..77c8464af0 100644 --- a/Content.Server/Chat/Managers/ChatManager.cs +++ b/Content.Server/Chat/Managers/ChatManager.cs @@ -38,6 +38,7 @@ namespace Content.Server.Chat.Managers [Dependency] private readonly IAdminLogManager _adminLogger = default!; [Dependency] private readonly IServerPreferencesManager _preferencesManager = default!; [Dependency] private readonly IConfigurationManager _configurationManager = default!; + [Dependency] private readonly INetConfigurationManager _netConfigManager = default!; /// /// The maximum length a player-sent message can be sent @@ -191,7 +192,18 @@ namespace Content.Server.Chat.Managers var wrappedMessage = Loc.GetString("chat-manager-send-admin-chat-wrap-message", ("adminChannelName", Loc.GetString("chat-manager-admin-channel-name")), ("playerName", player.Name), ("message", FormattedMessage.EscapeText(message))); - ChatMessageToMany(ChatChannel.Admin, message, wrappedMessage, default, false, true, clients.ToList()); + foreach (var client in clients) + { + var isSource = client != player.ConnectedClient; + ChatMessageToOne(ChatChannel.AdminChat, + message, + wrappedMessage, + default, + false, + client, + audioPath: isSource ? _netConfigManager.GetClientCVar(client, CCVars.AdminChatSoundPath) : default, + audioVolume: isSource ? _netConfigManager.GetClientCVar(client, CCVars.AdminChatSoundVolume) : default); + } _adminLogger.Add(LogType.Chat, $"Admin chat from {player:Player}: {message}"); } @@ -200,21 +212,21 @@ namespace Content.Server.Chat.Managers #region Utility - public void ChatMessageToOne(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, INetChannel client, Color? colorOverride = null, bool recordReplay = false) + public void ChatMessageToOne(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, INetChannel client, Color? colorOverride = null, bool recordReplay = false, string? audioPath = null, float audioVolume = 0) { - var msg = new ChatMessage(channel, message, wrappedMessage, source, hideChat, colorOverride); + var msg = new ChatMessage(channel, message, wrappedMessage, source, hideChat, colorOverride, audioPath, audioVolume); _netManager.ServerSendMessage(new MsgChatMessage() { Message = msg }, client); if (recordReplay) _replay.QueueReplayMessage(msg); } - public void ChatMessageToMany(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, IEnumerable clients, Color? colorOverride = null) - => ChatMessageToMany(channel, message, wrappedMessage, source, hideChat, recordReplay, clients.ToList(), colorOverride); + public void ChatMessageToMany(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, IEnumerable clients, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0) + => ChatMessageToMany(channel, message, wrappedMessage, source, hideChat, recordReplay, clients.ToList(), colorOverride, audioPath, audioVolume); - public void ChatMessageToMany(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, List clients, Color? colorOverride = null) + public void ChatMessageToMany(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, List clients, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0) { - var msg = new ChatMessage(channel, message, wrappedMessage, source, hideChat, colorOverride); + var msg = new ChatMessage(channel, message, wrappedMessage, source, hideChat, colorOverride, audioPath, audioVolume); _netManager.ServerSendToMany(new MsgChatMessage() { Message = msg }, clients); if (recordReplay) @@ -222,7 +234,7 @@ namespace Content.Server.Chat.Managers } public void ChatMessageToManyFiltered(Filter filter, ChatChannel channel, string message, string wrappedMessage, EntityUid source, - bool hideChat, bool recordReplay, Color? colorOverride = null) + bool hideChat, bool recordReplay, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0) { if (!recordReplay && !filter.Recipients.Any()) return; @@ -233,12 +245,12 @@ namespace Content.Server.Chat.Managers clients.Add(recipient.ConnectedClient); } - ChatMessageToMany(channel, message, wrappedMessage, source, hideChat, recordReplay, clients, colorOverride); + ChatMessageToMany(channel, message, wrappedMessage, source, hideChat, recordReplay, clients, colorOverride, audioPath, audioVolume); } - public void ChatMessageToAll(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, Color? colorOverride = null) + public void ChatMessageToAll(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0) { - var msg = new ChatMessage(channel, message, wrappedMessage, source, hideChat, colorOverride); + var msg = new ChatMessage(channel, message, wrappedMessage, source, hideChat, colorOverride, audioPath, audioVolume); _netManager.ServerSendToAll(new MsgChatMessage() { Message = msg }); if (recordReplay) diff --git a/Content.Server/Chat/Managers/IChatManager.cs b/Content.Server/Chat/Managers/IChatManager.cs index cbf5814c36..3fedeb0d35 100644 --- a/Content.Server/Chat/Managers/IChatManager.cs +++ b/Content.Server/Chat/Managers/IChatManager.cs @@ -24,14 +24,14 @@ namespace Content.Server.Chat.Managers void SendAdminAnnouncement(string message); void ChatMessageToOne(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, - INetChannel client, Color? colorOverride = null, bool recordReplay = false); + INetChannel client, Color? colorOverride = null, bool recordReplay = false, string? audioPath = null, float audioVolume = 0); void ChatMessageToMany(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, - IEnumerable clients, Color? colorOverride = null); + IEnumerable clients, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0); - void ChatMessageToManyFiltered(Filter filter, ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, Color? colorOverride); + void ChatMessageToManyFiltered(Filter filter, ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, Color? colorOverride, string? audioPath = null, float audioVolume = 0); - void ChatMessageToAll(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, Color? colorOverride = null); + void ChatMessageToAll(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0); bool MessageCharacterLimit(IPlayerSession player, string message); } diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index dc6fefcb56..584f947051 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -511,6 +511,10 @@ namespace Content.Shared.CCVar public static readonly CVarDef AdminSoundsEnabled = CVarDef.Create("audio.admin_sounds_enabled", true, CVar.ARCHIVE | CVar.CLIENTONLY); + public static readonly CVarDef AdminChatSoundPath = + CVarDef.Create("audio.admin_chat_sound_path", "/Audio/Items/pop.ogg", CVar.ARCHIVE | CVar.CLIENT | CVar.REPLICATED); + public static readonly CVarDef AdminChatSoundVolume = + CVarDef.Create("audio.admin_chat_sound_volume", -5f, CVar.ARCHIVE | CVar.CLIENT | CVar.REPLICATED); /* * HUD diff --git a/Content.Shared/Chat/ChatChannel.cs b/Content.Shared/Chat/ChatChannel.cs index a2f5e99180..3ea6435908 100644 --- a/Content.Shared/Chat/ChatChannel.cs +++ b/Content.Shared/Chat/ChatChannel.cs @@ -60,14 +60,19 @@ namespace Content.Shared.Chat Dead = 1 << 9, /// - /// Admin chat + /// Misc admin messages /// Admin = 1 << 10, + /// + /// Admin chat + /// + AdminChat = 1 << 11, + /// /// Unspecified. /// - Unspecified = 1 << 11, + Unspecified = 1 << 12, /// /// Channels considered to be IC. diff --git a/Content.Shared/Chat/ChatChannelExtensions.cs b/Content.Shared/Chat/ChatChannelExtensions.cs index 883f2977d2..505f032331 100644 --- a/Content.Shared/Chat/ChatChannelExtensions.cs +++ b/Content.Shared/Chat/ChatChannelExtensions.cs @@ -12,6 +12,7 @@ public static class ChatChannelExtensions ChatChannel.OOC => Color.LightSkyBlue, ChatChannel.Dead => Color.MediumPurple, ChatChannel.Admin => Color.Red, + ChatChannel.AdminChat => Color.HotPink, ChatChannel.Whisper => Color.DarkGray, _ => Color.LightGray }; diff --git a/Content.Shared/Chat/ChatSelectChannel.cs b/Content.Shared/Chat/ChatSelectChannel.cs index f612b1d081..c18bb9b8ee 100644 --- a/Content.Shared/Chat/ChatSelectChannel.cs +++ b/Content.Shared/Chat/ChatSelectChannel.cs @@ -49,7 +49,7 @@ /// /// Admin chat /// - Admin = ChatChannel.Admin, + Admin = ChatChannel.AdminChat, Console = ChatChannel.Unspecified } diff --git a/Content.Shared/Chat/MsgChatMessage.cs b/Content.Shared/Chat/MsgChatMessage.cs index 4497ef8f7f..fee886b023 100644 --- a/Content.Shared/Chat/MsgChatMessage.cs +++ b/Content.Shared/Chat/MsgChatMessage.cs @@ -16,11 +16,13 @@ namespace Content.Shared.Chat public EntityUid SenderEntity; public bool HideChat; public Color? MessageColorOverride; + public string? AudioPath; + public float AudioVolume; [NonSerialized] public bool Read; - public ChatMessage(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat = false, Color? colorOverride = null) + public ChatMessage(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat = false, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0) { Channel = channel; Message = message; @@ -28,6 +30,8 @@ namespace Content.Shared.Chat SenderEntity = source; HideChat = hideChat; MessageColorOverride = colorOverride; + AudioPath = audioPath; + AudioVolume = audioVolume; } } diff --git a/Resources/Locale/en-US/chat/ui/chat-box.ftl b/Resources/Locale/en-US/chat/ui/chat-box.ftl index dd10bf3289..29b3403aa3 100644 --- a/Resources/Locale/en-US/chat/ui/chat-box.ftl +++ b/Resources/Locale/en-US/chat/ui/chat-box.ftl @@ -13,7 +13,8 @@ hud-chatbox-select-channel-Damage = Damage hud-chatbox-select-channel-Visual = Actions hud-chatbox-select-channel-Radio = Radio -hud-chatbox-channel-Admin = Admin +hud-chatbox-channel-Admin = Admin Misc +hud-chatbox-channel-AdminChat = Admin Chat hud-chatbox-channel-Dead = Dead hud-chatbox-channel-Emotes = Emotes hud-chatbox-channel-Local = Local