public function ReceiveDataPacket($buffer)
 {
     $id = ord($buffer[0]);
     switch ($id) {
         case 0:
             $packet = new PingPacket($buffer);
             break;
         case 3:
             $packet = new PongPacket($buffer);
             break;
         case 9:
             $packet = new ClientConnectionPacket($buffer);
             break;
         case 16:
             $packet = new ServerHandShakePacket($buffer);
             break;
         case 19:
             $packet = new ClientHandShakePacket($buffer);
             break;
         case 21:
             $packet = new DisconnectionConnectionPacket($buffer);
             break;
         case 143:
             $packet = new LoginPacket($buffer);
             break;
         case 144:
             $packet = new PlayStatusPacket($buffer);
             break;
         case 145:
             $packet = new DisconnectPacket($buffer);
             break;
         case 146:
             $packet = new BatchPacket($buffer);
             $packet->decode();
             foreach ($packet->buffers as $buffer) {
                 $this->ReceiveDataPacket($buffer);
             }
             break;
         case 147:
             $packet = new TextPacket($buffer);
             break;
         case 148:
             $packet = new SetTimePacket($buffer);
             break;
         case 149:
             $packet = new StartGamePacket($buffer);
             break;
         case 150:
             $packet = new AddPlayerPacket($buffer);
             break;
         case 151:
             $packet = new RemovePlayerPacket($buffer);
             break;
         case 152:
             $packet = new AddEntityPacket($buffer);
             break;
         case 153:
             $packet = new RemoveEntityPacket($buffer);
             break;
         case 154:
             $packet = new AddItemEntityPacket($buffer);
             break;
         case 155:
             $packet = new TakeItemEntityPacket($buffer);
             break;
         case 156:
             $packet = new MoveEntityPacket($buffer);
             break;
         case 157:
             $packet = new MovePlayerPacket($buffer);
             break;
         case 158:
             $packet = new RemoveBlockPacket($buffer);
             break;
         case 159:
             $packet = new UpdateBlockPacket($buffer);
             break;
         case 160:
             $packet = new AddPaintingPacket($buffer);
             break;
         case 161:
             $packet = new ExplodePacket($buffer);
             break;
         case 162:
             $packet = new LevelEventPacket($buffer);
             break;
         case 163:
             $packet = new BlockEventPacket($buffer);
             break;
         case 164:
             $packet = new EntityEventPacket($buffer);
             break;
         case 165:
             $packet = new MobEffectPacket($buffer);
             break;
         case 166:
             $packet = new UpdateAttributesPacket($buffer);
             break;
         case 167:
             $packet = new MobEquipmentPacket($buffer);
             break;
         case 168:
             $packet = new MobArmorEquipmentPacket($buffer);
             break;
         case 169:
             $packet = new InteractPacket($buffer);
             break;
         case 170:
             $packet = new UseItemPacket($buffer);
             break;
         case 171:
             $packet = new PlayerActionPacket($buffer);
             break;
         case 172:
             $packet = new HurtArmorPacket($buffer);
             break;
         case 173:
             $packet = new SetEntityDataPacket($buffer);
             break;
         case 174:
             $packet = new SetEntityMotionPacket($buffer);
             break;
         case 175:
             $packet = new SetEntityLinkPacket($buffer);
             break;
         case 176:
             $packet = new SetHealthPacket($buffer);
             break;
         case 177:
             $packet = new SetSpawnPositionPacket($buffer);
             break;
         case 178:
             $packet = new AnimatePacket($buffer);
             break;
         case 179:
             $packet = new RespawnPacket($buffer);
             break;
         case 180:
             $packet = new DropItemPacket($buffer);
             break;
         case 181:
             $packet = new ContainerOpenPacket($buffer);
             break;
         case 182:
             $packet = new ContainerClosePacket($buffer);
             break;
         case 183:
             $packet = new ContainerSetSlotPacket($buffer);
             break;
         case 184:
             $packet = new ContainerSetDataPacket($buffer);
             break;
         case 185:
             $packet = new ContainerSetContentPacket($buffer);
             break;
         case 186:
             $packet = new CraftingDataPacket($buffer);
             break;
         case 187:
             $packet = new CraftingEventPacket($buffer);
             break;
         case 188:
             $packet = new AdventureSettingsPacket($buffer);
             break;
         case 189:
             $packet = new BlockEntityDataPacket($buffer);
             break;
         case 190:
             $packet = new PlayerInputPacket($buffer);
             break;
         case 191:
             $packet = new FullChunkDataPacket($buffer);
             break;
         case 192:
             $packet = new SetDifficultyPacket($buffer);
             break;
         case 193:
             $packet = new ChangeDimensionPacket($buffer);
             break;
         case 194:
             $packet = new SetPlayerGameTypePacket($buffer);
             break;
         case 195:
             $packet = new PlayerListPacket($buffer);
             break;
         case 196:
             $packet = new TelemetryEventPacket($buffer);
             break;
         case 197:
             $packet = new SpawnExperienceOrbPacket($buffer);
             break;
         default:
             $name = "Unknown";
             break;
     }
     if (debug_backtrace()[2]["function"] === "receivesocket" or debug_backtrace()[3]["function"] === "receivesocket") {
         $callname = "Server";
     } else {
         $callname = "Client";
     }
     if (!isset($packet)) {
         $packet = new UnknownDataPacket($buffer);
     }
     if (!$packet->decoded) {
         $packet->decode();
     }
     $packet->check();
     if ($id >= 143 and $id !== 146 and $id !== 156 and $id !== 174 and $id !== 173) {
         if (!isset($size)) {
             $size = strlen($buffer) - 1;
         }
         if (!isset($name)) {
             //
             $name = $packet->getName();
         }
         $this->logger->debug("DataPacket(" . $callname . "): " . $id . " (0x" . bin2hex(chr($id)) . ") : " . $name . " " . $size . "");
     }
     unset($packet);
 }
 public function ReceiveDataPacket($buffer, $callname, &$status)
 {
     $id = ord($buffer[0]);
     if ($id === 254) {
         $id = ord($buffer[1]);
         $buffer = substr($buffer, 1);
     }
     echo $status;
     if ($status === 0) {
         switch ($id) {
             case 0:
                 $packet = new PingPacket($buffer);
                 break;
             case 3:
                 $packet = new PongPacket($buffer);
                 break;
             case 9:
                 $packet = new ClientConnectionPacket($buffer);
                 break;
             case 16:
                 $packet = new ServerHandShakePacket($buffer);
                 break;
             case 19:
                 $packet = new ClientHandShakePacket($buffer);
                 $status = 1;
                 break;
             case 21:
                 $packet = new DisconnectionConnectionPacket($buffer);
                 break;
             default:
                 $packet = new UnknownDataPacket($buffer);
                 break;
         }
     } else {
         switch ($id) {
             case 0:
                 if (strlen($buffer) === 9) {
                     $packet = new PingPacket($buffer);
                 } else {
                     $packet = new UnknownDataPacket($buffer);
                 }
                 break;
             case 1:
                 $packet = new LoginPacket($buffer);
                 break;
             case 2:
                 $packet = new PlayStatusPacket($buffer);
                 break;
             case 3:
                 if (strlen($buffer) === 9) {
                     $packet = new PongPacket($buffer);
                 } else {
                     $packet = new UnknownDataPacket($buffer);
                 }
                 break;
             case 5:
                 $packet = new DisconnectPacket($buffer);
                 break;
             case 6:
                 $packet = new BatchPacket($buffer);
                 $packet->decode();
                 foreach ($packet->buffers as $buffer) {
                     $this->ReceiveDataPacket($buffer, $callname, $status);
                 }
                 break;
             case 7:
                 $packet = new TextPacket($buffer);
                 break;
             case 8:
                 $packet = new SetTimePacket($buffer);
                 break;
             case 9:
                 $packet = new StartGamePacket($buffer);
                 break;
             case 10:
                 $packet = new AddPlayerPacket($buffer);
                 break;
             case 11:
                 $packet = new AddEntityPacket($buffer);
                 break;
             case 12:
                 $packet = new RemoveEntityPacket($buffer);
                 break;
             case 13:
                 $packet = new AddItemEntityPacket($buffer);
                 break;
             case 14:
                 $packet = new TakeItemEntityPacket($buffer);
                 break;
             case 15:
                 $packet = new MoveEntityPacket($buffer);
                 break;
             case 16:
                 $packet = new MovePlayerPacket($buffer);
                 break;
                 /*case 17:
                 
                 				break;*/
             /*case 17:
             
             				break;*/
             case 18:
                 $packet = new RemoveBlockPacket($buffer);
                 break;
             case 19:
                 $packet = new UpdateBlockPacket($buffer);
                 break;
             case 20:
                 $packet = new AddPaintingPacket($buffer);
                 break;
             case 21:
                 if (strlen($buffer) === 1) {
                     $status = 0;
                     $this->ReceiveDataPacket($buffer, $callname, $status);
                     return;
                 }
                 $packet = new ExplodePacket($buffer);
                 break;
             case 22:
                 $packet = new LevelEventPacket($buffer);
                 break;
             case 23:
                 $packet = new BlockEventPacket($buffer);
                 break;
             case 24:
                 $packet = new EntityEventPacket($buffer);
                 break;
             case 25:
                 $packet = new MobEffectPacket($buffer);
                 break;
             case 26:
                 $packet = new UpdateAttributesPacket($buffer);
                 break;
             case 27:
                 $packet = new MobEquipmentPacket($buffer);
                 break;
             case 28:
                 $packet = new MobArmorEquipmentPacket($buffer);
                 break;
                 /*case 29:
                 
                 				break;*/
             /*case 29:
             
             				break;*/
             case 30:
                 $packet = new InteractPacket($buffer);
                 break;
             case 31:
                 $packet = new UseItemPacket($buffer);
                 break;
             case 32:
                 $packet = new PlayerActionPacket($buffer);
                 break;
             case 33:
                 $packet = new HurtArmorPacket($buffer);
                 break;
             case 34:
                 $packet = new SetEntityDataPacket($buffer);
                 break;
             case 35:
                 $packet = new SetEntityMotionPacket($buffer);
                 break;
             case 36:
                 $packet = new SetEntityLinkPacket($buffer);
                 break;
             case 37:
                 $packet = new SetHealthPacket($buffer);
                 break;
             case 38:
                 $packet = new SetSpawnPositionPacket($buffer);
                 break;
             case 39:
                 $packet = new AnimatePacket($buffer);
                 break;
             case 40:
                 $packet = new RespawnPacket($buffer);
                 break;
             case 41:
                 $packet = new DropItemPacket($buffer);
                 break;
             case 42:
                 $packet = new ContainerOpenPacket($buffer);
                 break;
             case 43:
                 $packet = new ContainerClosePacket($buffer);
                 break;
             case 44:
                 $packet = new ContainerSetSlotPacket($buffer);
                 break;
             case 45:
                 $packet = new ContainerSetDataPacket($buffer);
                 break;
             case 46:
                 $packet = new ContainerSetContentPacket($buffer);
                 break;
             case 47:
                 $packet = new CraftingDataPacket($buffer);
                 break;
             case 48:
                 $packet = new CraftingEventPacket($buffer);
                 break;
             case 49:
                 $packet = new AdventureSettingsPacket($buffer);
                 break;
             case 50:
                 $packet = new BlockEntityDataPacket($buffer);
                 break;
             case 51:
                 $packet = new PlayerInputPacket($buffer);
                 break;
             case 52:
                 $packet = new FullChunkDataPacket($buffer);
                 break;
             case 53:
                 $packet = new SetDifficultyPacket($buffer);
                 break;
             case 54:
                 $packet = new ChangeDimensionPacket($buffer);
                 break;
             case 55:
                 $packet = new SetPlayerGameTypePacket($buffer);
                 break;
             case 56:
                 $packet = new PlayerListPacket($buffer);
                 break;
             case 57:
                 $packet = new TelemetryEventPacket($buffer);
                 break;
             case 58:
                 $packet = new SpawnExperienceOrbPacket($buffer);
                 break;
             case 59:
                 $packet = new UpdateMapInfoPacket($buffer);
                 break;
             case 60:
                 $packet = new RequestMapInfoPacket($buffer);
                 break;
             case 61:
                 $packet = new RequestChunkRadiusPacket($buffer);
                 break;
             case 62:
                 $packet = new UpdateChunkRadiusPacket($buffer);
                 break;
             case 63:
                 $packet = new ItemFrameDropItemPacket($buffer);
                 break;
             default:
                 $packet = new UnknownDataPacket($buffer);
                 break;
         }
     }
     //if($packet->echo){
     $size = strlen($packet->buffer) - 1;
     $this->logger->debug("DataPacket(" . $callname . "): " . $id . " (0x" . bin2hex(chr($id)) . ") : " . $packet->getName() . " " . $size . "", 1);
     //}
     if (!$packet->decoded) {
         $packet->decode();
     }
     $packet->check();
     unset($packet);
 }