From 8da8f6044f2237a282f0450de2d4e53020f3a5fd Mon Sep 17 00:00:00 2001 From: ReinforceZwei <39955851+ReinforceZwei@users.noreply.github.com> Date: Sat, 25 Mar 2023 16:42:28 +0800 Subject: [PATCH] Fix message marker mixed with actual message body Should fix regex not working for autorespond and other chatbots that relied on matching message --- MinecraftClient/McClient.cs | 32 ++++++++++++++++++- .../Protocol/Message/ChatMessage.cs | 10 ++++-- .../Protocol/Message/ChatParser.cs | 29 +---------------- 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/MinecraftClient/McClient.cs b/MinecraftClient/McClient.cs index fa94d196..df2f9cf4 100644 --- a/MinecraftClient/McClient.cs +++ b/MinecraftClient/McClient.cs @@ -2634,11 +2634,41 @@ namespace MinecraftClient List links = new(); string messageText; + // Used for 1.19+ to mark: system message, legal / illegal signature + string color = string.Empty; + if (message.isSignedChat) { if (!Config.Signature.ShowIllegalSignedChat && !message.isSystemChat && !(bool)message.isSignatureLegal!) return; messageText = ChatParser.ParseSignedChat(message, links); + + if (message.isSystemChat) + { + if (Config.Signature.MarkSystemMessage) + color = "§7▌§r"; // Background Gray + } + else + { + if ((bool)message.isSignatureLegal!) + { + if (Config.Signature.ShowModifiedChat && message.unsignedContent != null) + { + if (Config.Signature.MarkModifiedMsg) + color = "§6▌§r"; // Background Yellow + } + else + { + if (Config.Signature.MarkLegallySignedMsg) + color = "§2▌§r"; // Background Green + } + } + else + { + if (Config.Signature.MarkIllegallySignedMsg) + color = "§4▌§r"; // Background Red + } + } } else { @@ -2648,7 +2678,7 @@ namespace MinecraftClient messageText = message.content; } - Log.Chat(messageText); + Log.Chat(color + messageText); if (Config.Main.Advanced.ShowChatLinks) foreach (string link in links) diff --git a/MinecraftClient/Protocol/Message/ChatMessage.cs b/MinecraftClient/Protocol/Message/ChatMessage.cs index 09048f3f..3088d85e 100644 --- a/MinecraftClient/Protocol/Message/ChatMessage.cs +++ b/MinecraftClient/Protocol/Message/ChatMessage.cs @@ -4,15 +4,19 @@ namespace MinecraftClient.Protocol.Message { public class ChatMessage { - // in 1.19 and above, isSignedChat = true + /// + /// In 1.19 and above, isSignedChat = true + /// public bool isSignedChat; public string content; public bool isJson, isSenderJson; - // 0: chat (chat box), 1: system message (chat box), 2: game info (above hotbar), 3: say command, - // 4: msg command, 5: team msg command, 6: emote command, 7: tellraw command + /// + /// 0: chat (chat box), 1: system message (chat box), 2: game info (above hotbar), 3: say command, + /// 4: msg command, 5: team msg command, 6: emote command, 7: tellraw command + /// public int chatTypeId; public Guid senderUUID; diff --git a/MinecraftClient/Protocol/Message/ChatParser.cs b/MinecraftClient/Protocol/Message/ChatParser.cs index a1db8862..fb1a28fc 100644 --- a/MinecraftClient/Protocol/Message/ChatParser.cs +++ b/MinecraftClient/Protocol/Message/ChatParser.cs @@ -142,34 +142,7 @@ namespace MinecraftClient.Protocol.Message default: goto case MessageType.CHAT; } - string color = string.Empty; - if (message.isSystemChat) - { - if (Config.Signature.MarkSystemMessage) - color = "§7▌§r"; // Background Gray - } - else - { - if ((bool)message.isSignatureLegal!) - { - if (Config.Signature.ShowModifiedChat && message.unsignedContent != null) - { - if (Config.Signature.MarkModifiedMsg) - color = "§6▌§r"; // Background Yellow - } - else - { - if (Config.Signature.MarkLegallySignedMsg) - color = "§2▌§r"; // Background Green - } - } - else - { - if (Config.Signature.MarkIllegallySignedMsg) - color = "§4▌§r"; // Background Red - } - } - return color + text; + return text; } ///