From 107806775e22019bd2ab92539e07d699a1cb02d1 Mon Sep 17 00:00:00 2001 From: Clyybber Date: Tue, 25 Jan 2022 10:38:52 +0100 Subject: [PATCH] Apply smiley filter on me-command (#6153) --- Content.Server/Chat/Commands/MeCommand.cs | 34 +++++++------------- Content.Server/Chat/Managers/ChatManager.cs | 27 ++++++++++++++-- Content.Server/Chat/Managers/IChatManager.cs | 2 ++ 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/Content.Server/Chat/Commands/MeCommand.cs b/Content.Server/Chat/Commands/MeCommand.cs index 3103ffe83a..a07fa09e54 100644 --- a/Content.Server/Chat/Commands/MeCommand.cs +++ b/Content.Server/Chat/Commands/MeCommand.cs @@ -18,39 +18,29 @@ namespace Content.Server.Chat.Commands public void Execute(IConsoleShell shell, string argStr, string[] args) { - var player = shell.Player as IPlayerSession; - if (player == null) + if (shell.Player is not IPlayerSession player) { - shell.WriteLine("This command cannot be run from the server."); + shell.WriteError("This command cannot be run from the server."); return; } - if (player.Status != SessionStatus.InGame || player.AttachedEntity == null) + if (player.Status != SessionStatus.InGame) return; - if (args.Length < 1) - return; - - var action = string.Join(" ", args).Trim(); - if (string.IsNullOrEmpty(action)) - return; - - var chat = IoCManager.Resolve(); - var mindComponent = player.ContentData()?.Mind; - - if (mindComponent == null) - { - shell.WriteError("You don't have a mind!"); - return; - } - - if (mindComponent.OwnedEntity == null) + if (player.AttachedEntity is not {} playerEntity) { shell.WriteError("You don't have an entity!"); return; } - chat.EntityMe(mindComponent.OwnedEntity.Value, action); + if (args.Length < 1) + return; + + var message = string.Join(" ", args).Trim(); + if (string.IsNullOrEmpty(message)) + return; + + IoCManager.Resolve().TryEmote(playerEntity, message, shell, player); } } } diff --git a/Content.Server/Chat/Managers/ChatManager.cs b/Content.Server/Chat/Managers/ChatManager.cs index 0424d519c6..ac03a3a3a1 100644 --- a/Content.Server/Chat/Managers/ChatManager.cs +++ b/Content.Server/Chat/Managers/ChatManager.cs @@ -169,15 +169,38 @@ namespace Content.Server.Chat.Managers var isEmote = _sanitizer.TrySanitizeOutSmilies(message, owned, out var sanitized, out var emoteStr); if (sanitized.Length != 0) - { SendEntityChatType(owned, sanitized, isWhisper); - } if (isEmote) EntityMe(owned, emoteStr!); } } + public void TryEmote(EntityUid source, string message, IConsoleShell? shell = null, IPlayerSession? player = null) + { + var mindComponent = player?.ContentData()?.Mind; + + if (mindComponent == null) + { + shell?.WriteError("You don't have a mind!"); + return; + } + + if (mindComponent.OwnedEntity is not {Valid: true} owned) + { + shell?.WriteError("You don't have an entity!"); + return; + } + + var isEmote = _sanitizer.TrySanitizeOutSmilies(message, mindComponent.OwnedEntity.Value, out var sanitized, out var emoteStr); + + if (sanitized.Length != 0) + EntityMe(mindComponent.OwnedEntity.Value, sanitized); + + if (isEmote) + EntityMe(mindComponent.OwnedEntity.Value, emoteStr!); + } + public void EntitySay(EntityUid source, string message, bool hideChat=false) { if (!EntitySystem.Get().CanSpeak(source)) diff --git a/Content.Server/Chat/Managers/IChatManager.cs b/Content.Server/Chat/Managers/IChatManager.cs index 1793f3a7c1..d14e7dd253 100644 --- a/Content.Server/Chat/Managers/IChatManager.cs +++ b/Content.Server/Chat/Managers/IChatManager.cs @@ -29,6 +29,8 @@ namespace Content.Server.Chat.Managers /// void TrySpeak(EntityUid source, string message, bool whisper = false, IConsoleShell? shell = null, IPlayerSession? player = null); + void TryEmote(EntityUid source, string message, IConsoleShell? shell = null, IPlayerSession? player = null); + /// If true, message will not be logged to chat boxes but will still produce a speech bubble. void EntitySay(EntityUid source, string message, bool hideChat=false); void EntityWhisper(EntityUid source, string message, bool hideChat = false);