]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix Emote Chat Sanitizer (#32940)
authorThomas <87614336+Aeshus@users.noreply.github.com>
Thu, 24 Oct 2024 05:10:13 +0000 (00:10 -0500)
committerGitHub <noreply@github.com>
Thu, 24 Oct 2024 05:10:13 +0000 (16:10 +1100)
* Fix bug?

* Fix :)

* aaaa

* AAAA!!!

* comment

* Nicer code

* What's a pull requestWhat's a pull request?

Content.Server/Chat/Managers/ChatSanitizationManager.cs
Content.Server/Chat/Systems/ChatSystem.cs
Content.Shared/Chat/SharedChatSystem.cs

index b0d28eae75ca2898c490f64b0ad2f3259bbc207e..0c78e45f86eda146235ffbd714b534f9ec1b512d 100644 (file)
@@ -35,7 +35,7 @@ public sealed class ChatSanitizationManager : IChatSanitizationManager
         { ":D", "chatsan-smiles-widely" },
         { "D:", "chatsan-frowns-deeply" },
         { ":O", "chatsan-surprised" },
-        { ":3", "chatsan-smiles" }, //nope
+        { ":3", "chatsan-smiles" },
         { ":S", "chatsan-uncertain" },
         { ":>", "chatsan-grins" },
         { ":<", "chatsan-pouts" },
index 41646bee2e46b7f4b01613714a6d6a69dedbdb8a..d834d8304a8bfc141fd9fd48a88594d403e41adc 100644 (file)
@@ -746,8 +746,9 @@ public sealed partial class ChatSystem : SharedChatSystem
     // ReSharper disable once InconsistentNaming
     private string SanitizeInGameICMessage(EntityUid source, string message, out string? emoteStr, bool capitalize = true, bool punctuate = false, bool capitalizeTheWordI = true)
     {
-        var newMessage = message.Trim();
-        newMessage = SanitizeMessageReplaceWords(newMessage);
+        var newMessage = SanitizeMessageReplaceWords(message.Trim());
+
+        GetRadioKeycodePrefix(source, newMessage, out newMessage, out var prefix);
 
         // Sanitize it first as it might change the word order
         _sanitizer.TrySanitizeEmoteShorthands(newMessage, source, out newMessage, out emoteStr);
@@ -759,7 +760,7 @@ public sealed partial class ChatSystem : SharedChatSystem
         if (punctuate)
             newMessage = SanitizeMessagePeriod(newMessage);
 
-        return newMessage;
+        return prefix + newMessage;
     }
 
     private string SanitizeInGameOOCMessage(string message)
index bd9ca4fa28cf70dac1c7ea5d9e091ad19104f4b5..84b0e2266ec8424733513d6e95b56a9a0802e817 100644 (file)
@@ -84,6 +84,35 @@ public abstract class SharedChatSystem : EntitySystem
         return current ?? _prototypeManager.Index<SpeechVerbPrototype>(speech.SpeechVerb);
     }
 
+    /// <summary>
+    /// Splits the input message into a radio prefix part and the rest to preserve it during sanitization.
+    /// </summary>
+    /// <remarks>
+    /// This is primarily for the chat emote sanitizer, which can match against ":b" as an emote, which is a valid radio keycode.
+    /// </remarks>
+    public void GetRadioKeycodePrefix(EntityUid source,
+        string input,
+        out string output,
+        out string prefix)
+    {
+        prefix = string.Empty;
+        output = input;
+
+        // If the string is less than 2, then it's probably supposed to be an emote.
+        // No one is sending empty radio messages!
+        if (input.Length <= 2)
+            return;
+
+        if (!(input.StartsWith(RadioChannelPrefix) || input.StartsWith(RadioChannelAltPrefix)))
+            return;
+
+        if (!_keyCodes.TryGetValue(input[1], out _))
+            return;
+
+        prefix = input[..2];
+        output = input[2..];
+    }
+
     /// <summary>
     ///     Attempts to resolve radio prefixes in chat messages (e.g., remove a leading ":e" and resolve the requested
     ///     channel. Returns true if a radio message was attempted, even if the channel is invalid.