Clean out tags when attempting to speak/whisper/emote (#23055)

A few bugs have popped up where (legal) string formatting tags
have been duplicated out into whisper and local.

Using the RemoveMarkup static we can sanitize attempted
speech to remove markup.
This commit is contained in:
Hannah Giovanna Dawson
2023-12-30 00:38:11 +00:00
committed by GitHub
parent 530e3c4add
commit 84f544ff10

View File

@@ -384,7 +384,8 @@ public sealed partial class ChatSystem : SharedChatSystem
if (!_actionBlocker.CanSpeak(source) && !ignoreActionBlocker) if (!_actionBlocker.CanSpeak(source) && !ignoreActionBlocker)
return; return;
var message = TransformSpeech(source, originalMessage); var message = TransformSpeech(source, FormattedMessage.RemoveMarkup(originalMessage));
if (message.Length == 0) if (message.Length == 0)
return; return;
@@ -416,7 +417,7 @@ public sealed partial class ChatSystem : SharedChatSystem
RaiseLocalEvent(source, ev, true); RaiseLocalEvent(source, ev, true);
// To avoid logging any messages sent by entities that are not players, like vendors, cloning, etc. // To avoid logging any messages sent by entities that are not players, like vendors, cloning, etc.
// Also doesn't log if hideLog is true. // Also doesn't log if hideLog is true.
if (!HasComp<ActorComponent>(source) || hideLog == true) if (!HasComp<ActorComponent>(source) || hideLog == true)
return; return;
@@ -451,7 +452,7 @@ public sealed partial class ChatSystem : SharedChatSystem
if (!_actionBlocker.CanSpeak(source) && !ignoreActionBlocker) if (!_actionBlocker.CanSpeak(source) && !ignoreActionBlocker)
return; return;
var message = TransformSpeech(source, originalMessage); var message = TransformSpeech(source, FormattedMessage.RemoveMarkup(originalMessage));
if (message.Length == 0) if (message.Length == 0)
return; return;
@@ -473,7 +474,6 @@ public sealed partial class ChatSystem : SharedChatSystem
} }
name = FormattedMessage.EscapeText(name); name = FormattedMessage.EscapeText(name);
var wrappedMessage = Loc.GetString("chat-manager-entity-whisper-wrap-message", var wrappedMessage = Loc.GetString("chat-manager-entity-whisper-wrap-message",
("entityName", name), ("message", FormattedMessage.EscapeText(message))); ("entityName", name), ("message", FormattedMessage.EscapeText(message)));
@@ -551,7 +551,7 @@ public sealed partial class ChatSystem : SharedChatSystem
var wrappedMessage = Loc.GetString("chat-manager-entity-me-wrap-message", var wrappedMessage = Loc.GetString("chat-manager-entity-me-wrap-message",
("entityName", name), ("entityName", name),
("entity", ent), ("entity", ent),
("message", FormattedMessage.EscapeText(action))); ("message", FormattedMessage.RemoveMarkup(action)));
if (checkEmote) if (checkEmote)
TryEmoteChatInput(source, action); TryEmoteChatInput(source, action);
@@ -614,7 +614,8 @@ public sealed partial class ChatSystem : SharedChatSystem
#region Utility #region Utility
private enum MessageRangeCheckResult { private enum MessageRangeCheckResult
{
Disallowed, Disallowed,
HideChat, HideChat,
Full Full
@@ -797,7 +798,7 @@ public sealed partial class ChatSystem : SharedChatSystem
foreach (var player in _playerManager.Sessions) foreach (var player in _playerManager.Sessions)
{ {
if (player.AttachedEntity is not {Valid: true} playerEntity) if (player.AttachedEntity is not { Valid: true } playerEntity)
continue; continue;
var transformEntity = xforms.GetComponent(playerEntity); var transformEntity = xforms.GetComponent(playerEntity);