forked from SerbiaStrong-220/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add prohibited characters filter (SerbiaStrong-220#2538)
* Add prohibited characters filter * change message comparation
- Loading branch information
Showing
6 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Content.Shared.Database; | ||
using Content.Shared.Mind; | ||
using Robust.Shared.Player; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace Content.Server.Chat.Managers; | ||
|
||
internal sealed partial class ChatManager | ||
{ | ||
[GeneratedRegex(@"[\u0fd5-\u0fd8\u2500-\u25ff\u2800-\u28ff]+")] | ||
private static partial Regex ProhibitedCharactersRegex(); | ||
|
||
public string DeleteProhibitedCharacters(string message, EntityUid player) | ||
{ | ||
var mindSystem = _entityManager.System<SharedMindSystem>(); | ||
mindSystem.TryGetMind(player, out _, out var mind); | ||
|
||
return DeleteProhibitedCharacters(message, mind?.Session); | ||
} | ||
|
||
public string DeleteProhibitedCharacters(string message, ICommonSession? player = null) | ||
{ | ||
string censoredMessage = ProhibitedCharactersRegex().Replace(message, string.Empty); | ||
if (message.Length != censoredMessage.Length && player != null) | ||
{ | ||
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"{player.Name} tried to send a message with forbidden characters:\n{message}"); | ||
SendAdminAlert(Loc.GetString("chat-manager-founded-prohibited-characters", ("player", player.Name), ("message", message))); | ||
} | ||
|
||
return censoredMessage; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
chat-manager-founded-prohibited-characters = { $player } попытался отправить сообщение с запрещенными символами: | ||
{ $message } |