From 3b5488a7bfb85b3b634493d27d6ad24e8b60cb46 Mon Sep 17 00:00:00 2001 From: ReinforceZwei <39955851+ReinforceZwei@users.noreply.github.com> Date: Thu, 13 May 2021 01:34:55 +0800 Subject: [PATCH] Remove illegal characters in chat messages before sending (#1587) Sending illegal character will cause server to kick the client. This happens when using remote control to execute some command that contains color output. Message checking applies to remote control only. --- MinecraftClient/ChatBots/RemoteControl.cs | 5 +++++ MinecraftClient/McClient.cs | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/MinecraftClient/ChatBots/RemoteControl.cs b/MinecraftClient/ChatBots/RemoteControl.cs index 300beb02..9bf038df 100644 --- a/MinecraftClient/ChatBots/RemoteControl.cs +++ b/MinecraftClient/ChatBots/RemoteControl.cs @@ -19,6 +19,11 @@ namespace MinecraftClient.ChatBots { string response = ""; PerformInternalCommand(command, ref response); + response = GetVerbatim(response); + foreach (char disallowedChar in McClient.GetDisallowedChatCharacters()) + { + response = response.Replace(disallowedChar.ToString(), String.Empty); + } if (response.Length > 0) { SendPrivateMessage(sender, response); diff --git a/MinecraftClient/McClient.cs b/MinecraftClient/McClient.cs index 27ed6346..1ba43f6e 100644 --- a/MinecraftClient/McClient.cs +++ b/MinecraftClient/McClient.cs @@ -735,6 +735,15 @@ namespace MinecraftClient } } + /// + /// Get a list of disallowed characters in chat + /// + /// + public static char[] GetDisallowedChatCharacters() + { + return new char[] { (char)167, (char)127 }; // Minecraft color code and ASCII code DEL + } + #region Management: Load/Unload ChatBots and Enable/Disable settings /// @@ -1021,6 +1030,8 @@ namespace MinecraftClient { lock (chatQueue) { + if (String.IsNullOrEmpty(text)) + return; int maxLength = handler.GetMaxChatMessageLength(); if (text.Length > maxLength) //Message is too long? {