Skip to content

Commit

Permalink
early merge of #32940
Browse files Browse the repository at this point in the history
  • Loading branch information
deltanedas committed Oct 24, 2024
1 parent 6a533f2 commit a2281c8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Content.Server/Chat/Managers/ChatSanitizationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
7 changes: 4 additions & 3 deletions Content.Server/Chat/Systems/ChatSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -756,8 +756,9 @@ private bool CanSendInGame(string message, IConsoleShell? shell = null, ICommonS
// 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);
Expand All @@ -769,7 +770,7 @@ private string SanitizeInGameICMessage(EntityUid source, string message, out str
if (punctuate)
newMessage = SanitizeMessagePeriod(newMessage);

return newMessage;
return prefix + newMessage;
}

private string SanitizeInGameOOCMessage(string message)
Expand Down
29 changes: 29 additions & 0 deletions Content.Shared/Chat/SharedChatSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,35 @@ public SpeechVerbPrototype GetSpeechVerb(EntityUid source, string message, Speec
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.
Expand Down

0 comments on commit a2281c8

Please sign in to comment.