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