diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs index 765c866d..be830dfc 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -538,21 +538,22 @@ namespace MinecraftClient /// True if the text was sent with no error public bool SendText(string text) { - if (text.Length > 100) //Message is too long? + int maxLength = handler.GetMaxChatMessageLength(); + if (text.Length > maxLength) //Message is too long? { if (text[0] == '/') { - //Send the first 100 chars of the command - text = text.Substring(0, 100); + //Send the first 100/256 chars of the command + text = text.Substring(0, maxLength); return handler.SendChatMessage(text); } else { //Send the message splitted into several messages - while (text.Length > 100) + while (text.Length > maxLength) { - handler.SendChatMessage(text.Substring(0, 100)); - text = text.Substring(100, text.Length - 100); + handler.SendChatMessage(text.Substring(0, maxLength)); + text = text.Substring(maxLength, text.Length - maxLength); if (Settings.splitMessageDelay.TotalSeconds > 0) Thread.Sleep(Settings.splitMessageDelay); } diff --git a/MinecraftClient/Protocol/Handlers/Protocol16.cs b/MinecraftClient/Protocol/Handlers/Protocol16.cs index 6710a60d..d79a271e 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol16.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol16.cs @@ -586,6 +586,11 @@ namespace MinecraftClient.Protocol.Handlers catch (System.IO.IOException) { } } + public int GetMaxChatMessageLength() + { + return 100; + } + public bool SendChatMessage(string message) { if (String.IsNullOrEmpty(message)) diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index 8acc2810..1b7a0eb6 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -21,6 +21,7 @@ namespace MinecraftClient.Protocol.Handlers private const int MC19Version = 107; private const int MC191Version = 108; private const int MC110Version = 210; + private const int MC111Version = 315; private int compression_treshold = 0; private bool autocomplete_received = false; @@ -1411,6 +1412,17 @@ namespace MinecraftClient.Protocol.Handlers } } + /// + /// Get max length for chat messages + /// + /// Max length, in characters + public int GetMaxChatMessageLength() + { + return protocolversion >= MC111Version + ? 256 + : 100; + } + /// /// Send a chat message to the server /// diff --git a/MinecraftClient/Protocol/IMinecraftCom.cs b/MinecraftClient/Protocol/IMinecraftCom.cs index 1c305eae..d8fa3f61 100644 --- a/MinecraftClient/Protocol/IMinecraftCom.cs +++ b/MinecraftClient/Protocol/IMinecraftCom.cs @@ -28,6 +28,12 @@ namespace MinecraftClient.Protocol /// Reason void Disconnect(); + /// + /// Get max length for chat messages + /// + /// Max length, in characters + int GetMaxChatMessageLength(); + /// /// Send a chat message or command to the server ///