From 840ac01dc5482d7d5e5f3593969973f91ce008cb Mon Sep 17 00:00:00 2001 From: ORelio Date: Wed, 3 Jun 2015 12:00:25 +0200 Subject: [PATCH] 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! :) --- .../Protocol/Handlers/Protocol18.cs | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index 760f398a..362bbd41 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -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)); } ///