Fix two bugs with 1.7.10 protocol

The first bug is that the list isn't cleared in some cases, meaning new packets get data from the previous packet if it isn't read fully.  Most commonly, this happens with a plugin channel message.  The second bug happens because lists don't throw IndexOutOfRangeExceptions, but instead throw ArgumentOutOfRangeExceptions.  This caused the catch for ignoring message types to not occur, instead causing the client to crash.  This only happens in 1.7.10, where the message type is not included.

Most likely, these changes will fix the bugs seen in #114 and #117, although they may be caused by other bugs.
This commit is contained in:
Pokechu22 2016-02-26 17:57:05 -08:00
parent f55c3f3994
commit 0617629570

View file

@ -104,6 +104,7 @@ namespace MinecraftClient.Protocol.Handlers
private void readNextPacket(ref int packetID, List<byte> packetData) private void readNextPacket(ref int packetID, List<byte> packetData)
{ {
packetData.Clear();
int size = readNextVarIntRAW(); //Packet size int size = readNextVarIntRAW(); //Packet size
packetData.AddRange(readDataRAW(size)); //Packet contents packetData.AddRange(readDataRAW(size)); //Packet contents
@ -165,7 +166,7 @@ namespace MinecraftClient.Protocol.Handlers
|| (messageType == 2 && !Settings.DisplayXPBarMessages)) || (messageType == 2 && !Settings.DisplayXPBarMessages))
break; break;
} }
catch (IndexOutOfRangeException) { /* No message type */ } catch (ArgumentOutOfRangeException) { /* No message type */ }
handler.OnTextReceived(ChatParser.ParseText(message)); handler.OnTextReceived(ChatParser.ParseText(message));
break; break;
case 0x08: //Player Position and Look case 0x08: //Player Position and Look