From 86e1754b2512ea2c153178a4cdb4df80ef75b81f Mon Sep 17 00:00:00 2001 From: zaop <11255568+enteryournamehere@users.noreply.github.com> Date: Tue, 12 Sep 2023 14:38:49 +0200 Subject: [PATCH] Improve user feedback for chat filter (#347) * Fix highlighting of prohibited words in chat * Also highlight subsequent instances of a word --- Uchu.World/Packets/Server/ChatModerationResponsePacket.cs | 4 ++-- Uchu.World/Social/Whitelist.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Uchu.World/Packets/Server/ChatModerationResponsePacket.cs b/Uchu.World/Packets/Server/ChatModerationResponsePacket.cs index a535bbfd..dc15ada1 100644 --- a/Uchu.World/Packets/Server/ChatModerationResponsePacket.cs +++ b/Uchu.World/Packets/Server/ChatModerationResponsePacket.cs @@ -28,7 +28,7 @@ public override void SerializePacket(BitWriter writer) writer.Write(ChatChannel); writer.Write(ChatMode); - writer.WriteString(PlayerName, 33, true); + writer.WriteString(PlayerName, 42, true); foreach (var (start, length) in UnacceptedRanges) { @@ -36,7 +36,7 @@ public override void SerializePacket(BitWriter writer) writer.Write(length); } - for (var i = 0; i < 32 - UnacceptedRanges.Length; i++) + for (var i = 0; i < 64 - UnacceptedRanges.Length; i++) { writer.Write(0); writer.Write(0); diff --git a/Uchu.World/Social/Whitelist.cs b/Uchu.World/Social/Whitelist.cs index f0454f02..cea22be9 100644 --- a/Uchu.World/Social/Whitelist.cs +++ b/Uchu.World/Social/Whitelist.cs @@ -115,7 +115,7 @@ public void AddWord(string word) if (allowed) continue; // Add the bad word's position and length. - var position = (byte) phrase.IndexOf(word, StringComparison.Ordinal); + var position = (byte) (phrase.Substring(match.Index).IndexOf(word, StringComparison.Ordinal) + match.Index); redact.Add((position, (byte) word.Length)); }