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.
This commit is contained in:
ReinforceZwei 2021-05-13 01:34:55 +08:00 committed by GitHub
parent b15c3a8e46
commit 3b5488a7bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View file

@ -735,6 +735,15 @@ namespace MinecraftClient
}
}
/// <summary>
/// Get a list of disallowed characters in chat
/// </summary>
/// <returns></returns>
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
/// <summary>
@ -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?
{