Fix crash on empty player list updates

Player list updates on MC 1.8 handler did not take into account the
amount of items in the list and were only processing the first item,
including when there wasn't any item to process. Unfortunately some
weird servers were sending useless empty tab-list updates, causing a
crash. Should fix issue #78 and forum posts 1267, 1269, 1284. Thanks
dbear20, link3321, gerik43, Darkaegis, k3ldon and Ryan6578 for their bug
reports! :)
This commit is contained in:
ORelio 2015-06-03 12:00:25 +02:00
parent 80b468b301
commit 840ac01dc5

View file

@ -146,19 +146,22 @@ namespace MinecraftClient.Protocol.Handlers
case 0x38: //Player List update case 0x38: //Player List update
int action = readNextVarInt(ref packetData); int action = readNextVarInt(ref packetData);
int numActions = readNextVarInt(ref packetData); int numActions = readNextVarInt(ref packetData);
Guid uuid = readNextUUID(ref packetData); for (int i = 0; i < numActions; i++)
switch (action)
{ {
case 0x00: //Player Join Guid uuid = readNextUUID(ref packetData);
string name = readNextString(ref packetData); switch (action)
handler.OnPlayerJoin(uuid, name); {
break; case 0x00: //Player Join
case 0x04: //Player Leave string name = readNextString(ref packetData);
handler.OnPlayerLeave(uuid); handler.OnPlayerJoin(uuid, name);
break; break;
default: case 0x04: //Player Leave
//Unknown player list item type handler.OnPlayerLeave(uuid);
break; break;
default:
//Unknown player list item type
break;
}
} }
break; break;
case 0x3A: //Tab-Complete Result case 0x3A: //Tab-Complete Result
@ -282,14 +285,7 @@ namespace MinecraftClient.Protocol.Handlers
private Guid readNextUUID(ref byte[] cache) private Guid readNextUUID(ref byte[] cache)
{ {
try return new Guid(readData(16, ref cache));
{
return new Guid(readData(16, ref cache));
}
catch (ArgumentException)
{
return Guid.Empty;
}
} }
/// <summary> /// <summary>