[feat] SlangSatinization
# Conflicts: # Content.Server/Chat/Systems/ChatSystem.cs
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Content.Server.Administration.Logs;
|
||||
@@ -19,6 +18,7 @@ using Content.Shared.Interaction;
|
||||
using Content.Shared.Mobs.Systems;
|
||||
using Content.Shared.Players;
|
||||
using Content.Shared.Radio;
|
||||
using Content.Shared.White;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
@@ -64,7 +64,7 @@ public sealed partial class ChatSystem : SharedChatSystem
|
||||
private bool _loocEnabled = true;
|
||||
private bool _deadLoocEnabled;
|
||||
private bool _critLoocEnabled;
|
||||
private readonly bool _adminLoocEnabled = true;
|
||||
private const bool AdminLoocEnabled = true;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -217,13 +217,11 @@ public sealed partial class ChatSystem : SharedChatSystem
|
||||
message = message[1..];
|
||||
}
|
||||
|
||||
bool shouldCapitalize = (desiredType != InGameICChatType.Emote);
|
||||
bool shouldPunctuate = _configurationManager.GetCVar(CCVars.ChatPunctuation);
|
||||
// Capitalizing the word I only happens in English, so we check language here
|
||||
bool shouldCapitalizeTheWordI = (!CultureInfo.CurrentCulture.IsNeutralCulture && CultureInfo.CurrentCulture.Parent.Name == "en")
|
||||
|| (CultureInfo.CurrentCulture.IsNeutralCulture && CultureInfo.CurrentCulture.Name == "en");
|
||||
var shouldCapitalize = (desiredType != InGameICChatType.Emote);
|
||||
var shouldPunctuate = _configurationManager.GetCVar(CCVars.ChatPunctuation);
|
||||
var sanitizeSlang = _configurationManager.GetCVar(WhiteCVars.ChatSlangFilter);
|
||||
|
||||
message = SanitizeInGameICMessage(source, message, out var emoteStr, shouldCapitalize, shouldPunctuate, shouldCapitalizeTheWordI);
|
||||
message = SanitizeInGameICMessage(source, message, out var emoteStr, shouldCapitalize, shouldPunctuate, sanitizeSlang);
|
||||
|
||||
// Was there an emote in the message? If so, send it.
|
||||
if (player != null && emoteStr != message && emoteStr != null)
|
||||
@@ -418,7 +416,7 @@ public sealed partial class ChatSystem : SharedChatSystem
|
||||
|
||||
// To avoid logging any messages sent by entities that are not players, like vendors, cloning, etc.
|
||||
// Also doesn't log if hideLog is true.
|
||||
if (!HasComp<ActorComponent>(source) || hideLog == true)
|
||||
if (!HasComp<ActorComponent>(source) || hideLog)
|
||||
return;
|
||||
|
||||
if (originalMessage == message)
|
||||
@@ -431,11 +429,15 @@ public sealed partial class ChatSystem : SharedChatSystem
|
||||
else
|
||||
{
|
||||
if (name != Name(source))
|
||||
{
|
||||
_adminLogger.Add(LogType.Chat, LogImpact.Low,
|
||||
$"Say from {ToPrettyString(source):user} as {name}, original: {originalMessage}, transformed: {message}.");
|
||||
}
|
||||
else
|
||||
{
|
||||
_adminLogger.Add(LogType.Chat, LogImpact.Low,
|
||||
$"Say from {ToPrettyString(source):user}, original: {originalMessage}, transformed: {message}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -459,7 +461,7 @@ public sealed partial class ChatSystem : SharedChatSystem
|
||||
var obfuscatedMessage = ObfuscateMessageReadability(message, 0.2f);
|
||||
|
||||
// get the entity's name by visual identity (if no override provided).
|
||||
string nameIdentity = FormattedMessage.EscapeText(nameOverride ?? Identity.Name(source, EntityManager));
|
||||
var nameIdentity = FormattedMessage.EscapeText(nameOverride ?? Identity.Name(source, EntityManager));
|
||||
// get the entity's name by voice (if no override provided).
|
||||
string name;
|
||||
if (nameOverride != null)
|
||||
@@ -486,47 +488,51 @@ public sealed partial class ChatSystem : SharedChatSystem
|
||||
|
||||
foreach (var (session, data) in GetRecipients(source, WhisperMuffledRange))
|
||||
{
|
||||
EntityUid listener;
|
||||
|
||||
if (session.AttachedEntity is not { Valid: true } playerEntity)
|
||||
if (session.AttachedEntity is not { Valid: true })
|
||||
continue;
|
||||
listener = session.AttachedEntity.Value;
|
||||
var listener = session.AttachedEntity.Value;
|
||||
|
||||
if (MessageRangeCheck(session, data, range) != MessageRangeCheckResult.Full)
|
||||
continue; // Won't get logged to chat, and ghosts are too far away to see the pop-up, so we just won't send it to them.
|
||||
|
||||
if (data.Range <= WhisperClearRange)
|
||||
_chatManager.ChatMessageToOne(ChatChannel.Whisper, message, wrappedMessage, source, false, session.ConnectedClient);
|
||||
_chatManager.ChatMessageToOne(ChatChannel.Whisper, message, wrappedMessage, source, false, session.Channel);
|
||||
//If listener is too far, they only hear fragments of the message
|
||||
//Collisiongroup.Opaque is not ideal for this use. Preferably, there should be a check specifically with "Can Ent1 see Ent2" in mind
|
||||
else if (_interactionSystem.InRangeUnobstructed(source, listener, WhisperMuffledRange, Shared.Physics.CollisionGroup.Opaque)) //Shared.Physics.CollisionGroup.Opaque
|
||||
_chatManager.ChatMessageToOne(ChatChannel.Whisper, obfuscatedMessage, wrappedobfuscatedMessage, source, false, session.ConnectedClient);
|
||||
_chatManager.ChatMessageToOne(ChatChannel.Whisper, obfuscatedMessage, wrappedobfuscatedMessage, source, false, session.Channel);
|
||||
//If listener is too far and has no line of sight, they can't identify the whisperer's identity
|
||||
else
|
||||
_chatManager.ChatMessageToOne(ChatChannel.Whisper, obfuscatedMessage, wrappedUnknownMessage, source, false, session.ConnectedClient);
|
||||
_chatManager.ChatMessageToOne(ChatChannel.Whisper, obfuscatedMessage, wrappedUnknownMessage, source, false, session.Channel);
|
||||
}
|
||||
|
||||
_replay.RecordServerMessage(new ChatMessage(ChatChannel.Whisper, message, wrappedMessage, GetNetEntity(source), null, MessageRangeHideChatForReplay(range)));
|
||||
|
||||
var ev = new EntitySpokeEvent(source, message, channel, obfuscatedMessage);
|
||||
RaiseLocalEvent(source, ev, true);
|
||||
if (!hideLog)
|
||||
if (originalMessage == message)
|
||||
if (hideLog)
|
||||
return;
|
||||
|
||||
if (originalMessage == message)
|
||||
{
|
||||
if (name != Name(source))
|
||||
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Whisper from {ToPrettyString(source):user} as {name}: {originalMessage}.");
|
||||
else
|
||||
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Whisper from {ToPrettyString(source):user}: {originalMessage}.");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (name != Name(source))
|
||||
{
|
||||
if (name != Name(source))
|
||||
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Whisper from {ToPrettyString(source):user} as {name}: {originalMessage}.");
|
||||
else
|
||||
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Whisper from {ToPrettyString(source):user}: {originalMessage}.");
|
||||
_adminLogger.Add(LogType.Chat, LogImpact.Low,
|
||||
$"Whisper from {ToPrettyString(source):user} as {name}, original: {originalMessage}, transformed: {message}.");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (name != Name(source))
|
||||
_adminLogger.Add(LogType.Chat, LogImpact.Low,
|
||||
$"Whisper from {ToPrettyString(source):user} as {name}, original: {originalMessage}, transformed: {message}.");
|
||||
else
|
||||
_adminLogger.Add(LogType.Chat, LogImpact.Low,
|
||||
_adminLogger.Add(LogType.Chat, LogImpact.Low,
|
||||
$"Whisper from {ToPrettyString(source):user}, original: {originalMessage}, transformed: {message}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SendEntityEmote(
|
||||
@@ -545,7 +551,7 @@ public sealed partial class ChatSystem : SharedChatSystem
|
||||
|
||||
// get the entity's apparent name (if no override provided).
|
||||
var ent = Identity.Entity(source, EntityManager);
|
||||
string name = FormattedMessage.EscapeText(nameOverride ?? Name(ent));
|
||||
var name = FormattedMessage.EscapeText(nameOverride ?? Name(ent));
|
||||
|
||||
// Emotes use Identity.Name, since it doesn't actually involve your voice at all.
|
||||
var wrappedMessage = Loc.GetString("chat-manager-entity-me-wrap-message",
|
||||
@@ -556,11 +562,13 @@ public sealed partial class ChatSystem : SharedChatSystem
|
||||
if (checkEmote)
|
||||
TryEmoteChatInput(source, action);
|
||||
SendInVoiceRange(ChatChannel.Emotes, action, wrappedMessage, source, range, author);
|
||||
if (!hideLog)
|
||||
if (name != Name(source))
|
||||
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Emote from {ToPrettyString(source):user} as {name}: {action}");
|
||||
else
|
||||
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Emote from {ToPrettyString(source):user}: {action}");
|
||||
if (hideLog)
|
||||
return;
|
||||
|
||||
if (name != Name(source))
|
||||
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Emote from {ToPrettyString(source):user} as {name}: {action}");
|
||||
else
|
||||
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Emote from {ToPrettyString(source):user}: {action}");
|
||||
}
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
@@ -570,9 +578,13 @@ public sealed partial class ChatSystem : SharedChatSystem
|
||||
|
||||
if (_adminManager.IsAdmin(player))
|
||||
{
|
||||
if (!_adminLoocEnabled) return;
|
||||
if (!AdminLoocEnabled)
|
||||
return;
|
||||
}
|
||||
else if (!_loocEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (!_loocEnabled) return;
|
||||
|
||||
// If crit player LOOC is disabled, don't send the message at all.
|
||||
if (!_critLoocEnabled && _mobStateSystem.IsCritical(source))
|
||||
@@ -595,7 +607,7 @@ public sealed partial class ChatSystem : SharedChatSystem
|
||||
{
|
||||
wrappedMessage = Loc.GetString("chat-manager-send-admin-dead-chat-wrap-message",
|
||||
("adminChannelName", Loc.GetString("chat-manager-admin-channel-name")),
|
||||
("userName", player.ConnectedClient.UserName),
|
||||
("userName", player.Channel.UserName),
|
||||
("message", FormattedMessage.EscapeText(message)));
|
||||
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Admin dead chat from {player:Player}: {message}");
|
||||
}
|
||||
@@ -704,15 +716,13 @@ 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)
|
||||
private string SanitizeInGameICMessage(EntityUid source, string message, out string? emoteStr, bool capitalize = true, bool punctuate = false, bool sanitizeSlang = true)
|
||||
{
|
||||
var newMessage = message.Trim();
|
||||
newMessage = SanitizeMessageReplaceWords(newMessage);
|
||||
|
||||
if(sanitizeSlang)
|
||||
newMessage = _sanitizer.SanitizeOutSlang(newMessage);
|
||||
if (capitalize)
|
||||
newMessage = SanitizeMessageCapital(newMessage);
|
||||
if (capitalizeTheWordI)
|
||||
newMessage = SanitizeMessageCapitalizeTheWordI(newMessage, "i");
|
||||
if (punctuate)
|
||||
newMessage = SanitizeMessagePeriod(newMessage);
|
||||
|
||||
@@ -768,15 +778,16 @@ public sealed partial class ChatSystem : SharedChatSystem
|
||||
}
|
||||
|
||||
[ValidatePrototypeId<ReplacementAccentPrototype>]
|
||||
public const string ChatSanitize_Accent = "chatsanitize";
|
||||
public const string ChatSanitizeAccent = "chatsanitize";
|
||||
|
||||
public string SanitizeMessageReplaceWords(string message)
|
||||
{
|
||||
if (string.IsNullOrEmpty(message)) return message;
|
||||
if (string.IsNullOrEmpty(message))
|
||||
return message;
|
||||
|
||||
var msg = message;
|
||||
|
||||
msg = _wordreplacement.ApplyReplacements(msg, ChatSanitize_Accent);
|
||||
msg = _wordreplacement.ApplyReplacements(msg, ChatSanitizeAccent);
|
||||
|
||||
return msg;
|
||||
}
|
||||
@@ -823,9 +834,7 @@ public sealed partial class ChatSystem : SharedChatSystem
|
||||
return recipients;
|
||||
}
|
||||
|
||||
public readonly record struct ICChatRecipientData(float Range, bool Observer, bool? HideChatOverride = null)
|
||||
{
|
||||
}
|
||||
public readonly record struct ICChatRecipientData(float Range, bool Observer, bool? HideChatOverride = null);
|
||||
|
||||
private string ObfuscateMessageReadability(string message, float chance)
|
||||
{
|
||||
@@ -854,9 +863,7 @@ public sealed partial class ChatSystem : SharedChatSystem
|
||||
/// This event is raised before chat messages are sent out to clients. This enables some systems to send the chat
|
||||
/// messages to otherwise out-of view entities (e.g. for multiple viewports from cameras).
|
||||
/// </summary>
|
||||
public record ExpandICChatRecipientstEvent(EntityUid Source, float VoiceRange, Dictionary<ICommonSession, ChatSystem.ICChatRecipientData> Recipients)
|
||||
{
|
||||
}
|
||||
public record ExpandICChatRecipientstEvent(EntityUid Source, float VoiceRange, Dictionary<ICommonSession, ChatSystem.ICChatRecipientData> Recipients);
|
||||
|
||||
public sealed class TransformSpeakerNameEvent : EntityEventArgs
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user