Minecraft 1.11: Raise chat message max length to 256

This commit is contained in:
ORelio 2016-11-19 16:06:08 +01:00
parent 8ec2b2e570
commit 609b939159
4 changed files with 30 additions and 6 deletions

View file

@ -538,21 +538,22 @@ namespace MinecraftClient
/// <returns>True if the text was sent with no error</returns> /// <returns>True if the text was sent with no error</returns>
public bool SendText(string text) 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] == '/') if (text[0] == '/')
{ {
//Send the first 100 chars of the command //Send the first 100/256 chars of the command
text = text.Substring(0, 100); text = text.Substring(0, maxLength);
return handler.SendChatMessage(text); return handler.SendChatMessage(text);
} }
else else
{ {
//Send the message splitted into several messages //Send the message splitted into several messages
while (text.Length > 100) while (text.Length > maxLength)
{ {
handler.SendChatMessage(text.Substring(0, 100)); handler.SendChatMessage(text.Substring(0, maxLength));
text = text.Substring(100, text.Length - 100); text = text.Substring(maxLength, text.Length - maxLength);
if (Settings.splitMessageDelay.TotalSeconds > 0) if (Settings.splitMessageDelay.TotalSeconds > 0)
Thread.Sleep(Settings.splitMessageDelay); Thread.Sleep(Settings.splitMessageDelay);
} }

View file

@ -586,6 +586,11 @@ namespace MinecraftClient.Protocol.Handlers
catch (System.IO.IOException) { } catch (System.IO.IOException) { }
} }
public int GetMaxChatMessageLength()
{
return 100;
}
public bool SendChatMessage(string message) public bool SendChatMessage(string message)
{ {
if (String.IsNullOrEmpty(message)) if (String.IsNullOrEmpty(message))

View file

@ -21,6 +21,7 @@ namespace MinecraftClient.Protocol.Handlers
private const int MC19Version = 107; private const int MC19Version = 107;
private const int MC191Version = 108; private const int MC191Version = 108;
private const int MC110Version = 210; private const int MC110Version = 210;
private const int MC111Version = 315;
private int compression_treshold = 0; private int compression_treshold = 0;
private bool autocomplete_received = false; private bool autocomplete_received = false;
@ -1411,6 +1412,17 @@ namespace MinecraftClient.Protocol.Handlers
} }
} }
/// <summary>
/// Get max length for chat messages
/// </summary>
/// <returns>Max length, in characters</returns>
public int GetMaxChatMessageLength()
{
return protocolversion >= MC111Version
? 256
: 100;
}
/// <summary> /// <summary>
/// Send a chat message to the server /// Send a chat message to the server
/// </summary> /// </summary>

View file

@ -28,6 +28,12 @@ namespace MinecraftClient.Protocol
/// <param name="message">Reason</param> /// <param name="message">Reason</param>
void Disconnect(); void Disconnect();
/// <summary>
/// Get max length for chat messages
/// </summary>
/// <returns>Max length, in characters</returns>
int GetMaxChatMessageLength();
/// <summary> /// <summary>
/// Send a chat message or command to the server /// Send a chat message or command to the server
/// </summary> /// </summary>