public function serverToInterface(DesktopPlayer $player, DataPacket $packet) { switch ($packet->pid()) { case Info::DISCONNECT_PACKET: if ($player->bigBrother_getStatus() === 0) { $pk = new LoginDisconnectPacket(); $pk->reason = TextFormat::toJSON($packet->message === "" ? "You have been disconnected." : $packet->message); } else { $pk = new PlayDisconnectPacket(); $pk->reason = TextFormat::toJSON($packet->message === "" ? "You have been disconnected." : $packet->message); } return $pk; case Info::TEXT_PACKET: echo $player->getSetting("Lang") . "\n"; /*if($packet->message === "chat.type.achievement"){ /*$pk = new ScoreboardObjectivePacket(); $pk->ObjectiveName = $packet->parameters[0]; $pk->Mode = 0; $pk->ObjectiveValue = 3; return $pk;*/ /*echo "TextPacket: achievement\n"; return null; }else{ $pk = new STCChatPacket(); $pk->message = TextFormat::toJSON($packet->message, $packet->type, $packet->parameters); }*/ //return $pk; return null; case Info::SET_TIME_PACKET: $pk = new TimeUpdatePacket(); $pk->age = $packet->time; $pk->time = $packet->time; //TODO: calculate offset from MCPE return $pk; case Info::START_GAME_PACKET: $packets = []; $pk = new JoinGamePacket(); $pk->eid = $packet->eid; $pk->gamemode = $packet->gamemode; $pk->dimension = 0; $pk->difficulty = $player->getServer()->getDifficulty(); $pk->maxPlayers = $player->getServer()->getMaxPlayers(); $pk->levelType = "default"; $packets[] = $pk; $pk = new SpawnPositionPacket(); $pk->spawnX = $packet->spawnX; $pk->spawnY = $packet->spawnY; $pk->spawnZ = $packet->spawnZ; $packets[] = $pk; $pk = new PlayerAbilitiesPacket(); $pk->flyingSpeed = 0.05; $pk->walkingSpeed = 0.1; $pk->canFly = ($player->getGamemode() & 0x1) > 0; $pk->damageDisabled = ($player->getGamemode() & 0x1) > 0; $pk->isFlying = false; $pk->isCreative = ($player->getGamemode() & 0x1) > 0; $packets[] = $pk; $pk = new PositionAndLookPacket(); $pk->x = $packet->x; $pk->y = $packet->y; $pk->z = $packet->z; $pk->yaw = $player->yaw; $pk->pitch = $player->pitch; $packets[] = $pk; return $packets; case Info::ADD_PLAYER_PACKET: $packets = []; $packetplayer = $player->getServer()->getPlayerExact($packet->username); $pk = new PlayerListPacket(); $pk->actionID = PlayerListPacket::TYPE_ADD; $pk->players[] = [$packetplayer->getUniqueId()->toBinary(), $packetplayer->getName(), [], $packetplayer->getGamemode(), 0, false]; if ($packetplayer instanceof DesktopPlayer) { $pk->players[0][2] = $packetplayer->bigBrother_getPeroperties(); } $packets[] = $pk; $pk = new SpawnPlayerPacket(); $pk->eid = $packet->eid; $pk->uuid = $packetplayer->getUniqueId()->toBinary(); $pk->x = $packet->x; $pk->z = $packet->z; $pk->y = $packet->y; $pk->yaw = $packet->yaw; $pk->pitch = $packet->pitch; $pk->item = $packetplayer->getInventory()->getItemInHand()->getId(); $pk->metadata = $packet->metadata; $packets[] = $pk; $pk = new EntityTeleportPacket(); $pk->eid = $packet->eid; $pk->x = $packet->x; $pk->y = $packet->y; $pk->z = $packet->z; $pk->yaw = $packet->yaw; $pk->pitch = $packet->pitch; $packets[] = $pk; return $packets; /*case Info::ADD_ENTITY_PACKET: return null;*/ /*case Info::REMOVE_PLAYER_PACKET: $pk = new PlayerListPacket(); $pk->actionID = PlayerListPacket::TYPE_REMOVE; $pk->players[] = [ $packet->clientId->toBinary() ]; $packets[] = $pk; $pk = new DestroyEntitiesPacket(); $pk->ids[] = $packet->eid; $packets[] = $pk; return $packets;*/ /*case Info::ADD_ENTITY_PACKET: return null;*/ /*case Info::REMOVE_PLAYER_PACKET: $pk = new PlayerListPacket(); $pk->actionID = PlayerListPacket::TYPE_REMOVE; $pk->players[] = [ $packet->clientId->toBinary() ]; $packets[] = $pk; $pk = new DestroyEntitiesPacket(); $pk->ids[] = $packet->eid; $packets[] = $pk; return $packets;*/ case Info::REMOVE_ENTITY_PACKET: $pk = new DestroyEntitiesPacket(); $pk->ids[] = $packet->eid; return $pk; case Info::ADD_ITEM_ENTITY_PACKET: $packets = []; $pk = new SpawnObjectPacket(); $pk->eid = $packet->eid; $pk->type = 2; $pk->x = $packet->x; $pk->y = $packet->y; $pk->z = $packet->z; $pk->yaw = $player->yaw; $pk->pitch = $player->pitch; $packets[] = $pk; $pk = new EntityMetadataPacket(); $pk->eid = $packet->eid; $pk->metadata = [0 => [0 => 0, 1 => 0], 10 => [0 => 5, 1 => $packet->item]]; $packets[] = $pk; return $packets; /*case Info::REMOVE_ITEM_ENTITY_PACKET: return null;*/ /*case Info::REMOVE_ITEM_ENTITY_PACKET: return null;*/ case Info::MOVE_ENTITY_PACKET: $packets = []; foreach ($packet->entities as $d) { $pk = new EntityTeleportPacket(); $pk->eid = $d[0]; $pk->x = $d[1]; $pk->y = $d[2] - $player->getEyeHeight(); $pk->z = $d[3]; $pk->yaw = $d[4]; $pk->pitch = $d[6]; $packets[] = $pk; $pk = new EntityHeadLookPacket(); $pk->eid = $d[0]; $pk->yaw = $d[5]; $packets[] = $pk; } return $packets; case Info::MOVE_PLAYER_PACKET: if ($packet->eid === 0) { $pk = new PositionAndLookPacket(); $pk->x = $packet->x; $pk->y = $packet->y - $player->getEyeHeight(); $pk->z = $packet->z; $pk->yaw = $packet->yaw; $pk->pitch = $packet->pitch; $pk->onGround = $player->isOnGround(); return $pk; } else { $packets = []; $pk = new EntityTeleportPacket(); $pk->eid = $packet->eid; $pk->x = $packet->x; $pk->y = $packet->y - $player->getEyeHeight(); $pk->z = $packet->z; $pk->yaw = $packet->yaw; $pk->pitch = $packet->pitch; $packets[] = $pk; $pk = new EntityHeadLookPacket(); $pk->eid = $packet->eid; $pk->yaw = $packet->yaw; $packets[] = $pk; return $packets; } case Info::UPDATE_BLOCK_PACKET: //TODO $pk = new BlockChangePacket(); $pk->x = $packet->x; $pk->y = $packet->y; $pk->z = $packet->z; $pk->blockId = $packet->blockId; $pk->blockMeta = $packet->blockData; return $pk; case Info::MOB_EQUIPMENT_PACKET: $pk = new EntityEquipmentPacket(); $pk->eid = $packet->eid; $pk->slot = $packet->slot; $pk->item = $packet->item; return $pk; case Info::MOB_ARMOR_EQUIPMENT_PACKET: $packets = []; foreach ($packet->slots as $num => $item) { $pk = new EntityEquipmentPacket(); $pk->eid = $packet->eid; $pk->slot = $num + 1; $pk->item = $item; $packets[] = $pk; } return $packets; case Info::SET_ENTITY_DATA_PACKET: /*if(isset($packet->metadata[16])){ if($packet->metadata[16][1] === 2){ $pk = new UseBedPacket(); //Bug $pk->eid = $packet->eid; $bedXYZ = $player->getSetting("BedXYZ"); $pk->bedX = $bedXYZ[0]; $pk->bedY = $bedXYZ[1]; $pk->bedZ = $bedXYZ[2]; $player->removeSetting("BedXYZ"); }else{ $pk = new CAnimatePacket(); $pk->eid = $packet->eid; $pk->actionID = 2; } return $pk; }elseif(isset($packet->metadata[17])){ $player->setSetting(["BedXYZ" => $packet->metadata[17][1]]); }*/ $pk = new EntityMetadataPacket(); $pk->eid = $packet->eid; $pk->metadata = $packet->metadata; return $pk; case Info::SET_ENTITY_MOTION_PACKET: $pk = new EntityVelocityPacket(); $pk->eid = $packet->eid; $pk->velocityX = $packet->motionX; $pk->velocityY = $packet->motionY; $pk->velocityZ = $packet->motionZ; return $pk; case Info::SET_HEALTH_PACKET: $pk = new UpdateHealthPacket(); $pk->health = $packet->health; $pk->food = 20; $pk->saturation = 5; return $pk; case Info::SET_SPAWN_POSITION_PACKET: $pk = new SpawnPositionPacket(); $pk->spawnX = $packet->x; $pk->spawnY = $packet->y; $pk->spawnZ = $packet->z; return $pk; case Info::ANIMATE_PACKET: switch ($packet->action) { case 1: $pk = new CAnimatePacket(); $pk->actionID = 0; $pk->eid = $packet->eid; return $pk; break; case 3: //LeaveBed $pk = new CAnimatePacket(); $pk->actionID = 2; $pk->eid = $packet->eid; return $pk; break; default: echo "AnimatePacket: " . $packet->action . "\n"; break; } return null; case Info::RESPAWN_PACKET: $pk = new CRespawnPacket(); $pk->dimension = 0; $pk->difficulty = $player->getServer()->getDifficulty(); $pk->gamemode = $player->getGamemode(); $pk->levelType = "default"; return $pk; /*case Info::CONTAINER_OPEN_PACKET: $pk = new OpenWindowPacket(); $pk->windowID = $packet->windowid; $pk->inventoryType = $packet->type; $pk->windowTitle = ""; $pk->slots = $packet->slots; return $pk; case Info::CONTAINER_CLOSE_PACKET: $pk = new STCCloseWindowPacket(); $pk->windowID = $packet->windowid; return $pk; case Info::CONTAINER_SET_SLOT_PACKET: echo "ContainerSetSlotPacket: 0x".bin2hex(chr($packet->windowid))."\n"; $pk = new SetSlotPacket(); $pk->windowID = $packet->windowid; if($pk->windowID === 0x00){ $pk->slot = $packet->slot + 36; }elseif($pk->windowID === 0x78){ $pk->windowID = 0; $pk->slot = $packet->slot + 5; }else{ $pk->slot = $packet->slot; } $pk->item = $packet->item; return $pk; case Info::CONTAINER_SET_CONTENT_PACKET://Bug echo "ContainerSetContentPacket: 0x".bin2hex(chr($packet->windowid))."\n"; if($packet->windowid !== 0x79 and $packet->windowid !== 0x78){ $pk = new WindowItemsPacket(); $pk->windowID = 0; for($i = 0; $i < 5; ++$i){ $pk->items[] = Item::get(Item::AIR, 0, 0); } $pk->items[] = $player->getInventory()->getHelmet(); $pk->items[] = $player->getInventory()->getChestplate(); $pk->items[] = $player->getInventory()->getLeggings(); $pk->items[] = $player->getInventory()->getBoots(); if($player->getGamemode() === 0){ for($i = 9; $i < 36; ++$i){ $pk->items[] = $player->getInventory()->getItem($i); } }else{ for($i = 0; $i < 27; ++$i){ $pk->items[] = Item::get(Item::AIR, 0, 0); } } for($i = 0; $i < 9; ++$i){ $pk->items[] = $player->getInventory()->getItem($i); } return $pk; } return null;*/ /*case Info::CONTAINER_OPEN_PACKET: $pk = new OpenWindowPacket(); $pk->windowID = $packet->windowid; $pk->inventoryType = $packet->type; $pk->windowTitle = ""; $pk->slots = $packet->slots; return $pk; case Info::CONTAINER_CLOSE_PACKET: $pk = new STCCloseWindowPacket(); $pk->windowID = $packet->windowid; return $pk; case Info::CONTAINER_SET_SLOT_PACKET: echo "ContainerSetSlotPacket: 0x".bin2hex(chr($packet->windowid))."\n"; $pk = new SetSlotPacket(); $pk->windowID = $packet->windowid; if($pk->windowID === 0x00){ $pk->slot = $packet->slot + 36; }elseif($pk->windowID === 0x78){ $pk->windowID = 0; $pk->slot = $packet->slot + 5; }else{ $pk->slot = $packet->slot; } $pk->item = $packet->item; return $pk; case Info::CONTAINER_SET_CONTENT_PACKET://Bug echo "ContainerSetContentPacket: 0x".bin2hex(chr($packet->windowid))."\n"; if($packet->windowid !== 0x79 and $packet->windowid !== 0x78){ $pk = new WindowItemsPacket(); $pk->windowID = 0; for($i = 0; $i < 5; ++$i){ $pk->items[] = Item::get(Item::AIR, 0, 0); } $pk->items[] = $player->getInventory()->getHelmet(); $pk->items[] = $player->getInventory()->getChestplate(); $pk->items[] = $player->getInventory()->getLeggings(); $pk->items[] = $player->getInventory()->getBoots(); if($player->getGamemode() === 0){ for($i = 9; $i < 36; ++$i){ $pk->items[] = $player->getInventory()->getItem($i); } }else{ for($i = 0; $i < 27; ++$i){ $pk->items[] = Item::get(Item::AIR, 0, 0); } } for($i = 0; $i < 9; ++$i){ $pk->items[] = $player->getInventory()->getItem($i); } return $pk; } return null;*/ case Info::CRAFTING_DATA_PACKET: $player->setSetting(["Recipes" => $packet->entries, "cleanRecipes" => $packet->cleanRecipes]); return null; case Info::BLOCK_ENTITY_DATA_PACKET: $nbt = new NBT(NBT::LITTLE_ENDIAN); $nbt->read($packet->namedtag); $nbt = $nbt->getData(); if ($nbt["id"] !== Tile::SIGN) { return null; } else { $index = Level::chunkHash($packet->x >> 4, $packet->z >> 4); if (isset($player->usedChunks[$index]) and $player->usedChunks[$index]) { $pk = new UpdateSignPacket(); $pk->x = $packet->x; $pk->y = $packet->y; $pk->z = $packet->z; $pk->line1 = TextFormat::toJSON($nbt["Text1"]); $pk->line2 = TextFormat::toJSON($nbt["Text2"]); $pk->line3 = TextFormat::toJSON($nbt["Text3"]); $pk->line4 = TextFormat::toJSON($nbt["Text4"]); return $pk; } } return null; case Info::SET_DIFFICULTY_PACKET: $pk = new ServerDifficultyPacket(); $pk->difficulty = $packet->difficulty; return $pk; case Info::SET_PLAYER_GAMETYPE_PACKET: $packets = []; $pk = new PlayerAbilitiesPacket(); $pk->flyingSpeed = 0.05; $pk->walkingSpeed = 0.1; $pk->canFly = ($player->getGamemode() & 0x1) > 0; $pk->damageDisabled = ($player->getGamemode() & 0x1) > 0; $pk->isFlying = false; $pk->isCreative = ($player->getGamemode() & 0x1) > 0; $packets[] = $pk; $pk = new ChangeGameStatePacket(); $pk->reason = 3; $pk->value = $player->getGamemode(); $packets[] = $pk; return $packets; case Info::PLAY_STATUS_PACKET: case Info::PLAYER_LIST_PACKET: case Info::ADVENTURE_SETTINGS_PACKET: case Info::FULL_CHUNK_DATA_PACKET: case Info::BATCH_PACKET: return null; default: echo "[Send] 0x" . bin2hex(chr($packet->pid())) . "\n"; return null; } }
public function process() { $length = Binary::readVarIntSession($this); if ($length === false or $this->status === -1) { $this->close("Connection closed"); return; } elseif ($length <= 0 or $length > 131070) { $this->close("Invalid length"); return; } $offset = 0; $buffer = $this->read($length); if ($this->threshold !== null) { $dataLength = Binary::readVarInt($buffer, $offset); if ($dataLength !== 0) { if ($dataLength < $this->threshold) { $this->close("Invalid compression threshold"); } else { $buffer = zlib_decode(substr($buffer, $offset)); $offset = 0; } } else { $buffer = substr($buffer, $offset); $offset = 0; } } if ($this->status === 2) { //Login $this->manager->sendPacket($this->identifier, $buffer); } elseif ($this->status === 1) { $pid = Binary::readVarInt($buffer, $offset); if ($pid === 0x0) { $sample = []; foreach ($this->manager->sample as $id => $name) { $sample[] = ["name" => $name, "id" => $id]; } $data = ["version" => ["name" => Info::VERSION, "protocol" => Info::PROTOCOL], "players" => ["max" => $this->manager->getServerData()["MaxPlayers"], "online" => $this->manager->getServerData()["OnlinePlayers"], "sample" => $sample], "description" => json_decode(TextFormat::toJSON($this->manager->description))]; if ($this->manager->favicon !== null) { $data["favicon"] = $this->manager->favicon; } $data = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); $data = Binary::writeVarInt(0x0) . Binary::writeVarInt(strlen($data)) . $data; $this->writeRaw($data); } elseif ($pid === 0x1) { $packet = new PingPacket(); $packet->read($buffer, $offset); $this->writePacket($packet); $this->status = -1; } } elseif ($this->status === 0) { $pid = Binary::readVarInt($buffer, $offset); if ($pid === 0x0) { $protocol = Binary::readVarInt($buffer, $offset); $len = Binary::readVarInt($buffer, $offset); $hostname = substr($buffer, $offset, $len); $offset += $len; $serverPort = Binary::readShort(substr($buffer, $offset, 2)); $offset += 2; $nextState = Binary::readVarInt($buffer, $offset); if ($nextState === 1) { $this->status = 1; } elseif ($nextState === 2) { $this->status = -1; if ($protocol < Info::PROTOCOL) { $packet = new LoginDisconnectPacket(); $packet->reson = TextFormat::toJSON(TextFormat::BOLD . "Outdated client!" . TextFormat::RESET . "\n\nPlease use " . Info::VERSION); $this->writePacket($packet); } elseif ($protocol > Info::PROTOCOL) { $packet = new LoginDisconnectPacket(); $packet->reson = TextFormat::toJSON(TextFormat::BOLD . "Outdated server!" . TextFormat::RESET . "\n\nI'm using " . Info::VERSION); $this->writePacket($packet); } else { $this->manager->openSession($this); $this->status = 2; } } else { $this->close(); } } else { $this->close("Unexpected packet {$pid}"); } } }
public function close($message = "", $reason = "generic reason") { if ($this->bigBrother_status === 0) { $pk = new LoginDisconnectPacket(); $pk->reason = TextFormat::toJSON($reason === "" ? "You have been disconnected." : $reason); $this->putRawPacket($pk); } else { $pk = new PlayDisconnectPacket(); $pk->reason = TextFormat::toJSON($reason === "" ? "You have been disconnected." : $reason); $this->putRawPacket($pk); } parent::close($message, $reason); }
public function serverToInterface(DesktopPlayer $player, DataPacket $packet) { switch ($packet->pid()) { case Info::UPDATE_BLOCK_PACKET: $pk = new BlockChangePacket(); $pk->x = $packet->x; $pk->y = $packet->y; $pk->z = $packet->z; $pk->blockId = $packet->block; $pk->blockMeta = $packet->meta; return $pk; case Info::START_GAME_PACKET: $packets = []; $pk = new JoinGamePacket(); $pk->eid = $packet->eid; $pk->gamemode = $player->getGamemode(); $pk->dimension = 0; $pk->difficulty = $player->getServer()->getDifficulty(); $pk->maxPlayers = $player->getServer()->getMaxPlayers(); $pk->levelType = "default"; $packets[] = $pk; $pk = new PlayerAbilitiesPacket(); $pk->flyingSpeed = 0.05; $pk->walkingSpeed = 0.1; $pk->canFly = ($player->getGamemode() & 0x1) > 0; $pk->damageDisabled = ($player->getGamemode() & 0x1) > 0; $pk->isFlying = false; $pk->isCreative = ($player->getGamemode() & 0x1) > 0; if ($player->spawned === true) { $packets = [$pk]; $pk = new ChangeGameStatePacket(); $pk->reason = 3; $pk->value = $player->getGamemode(); $packets[] = $pk; return $packets; } else { $packets[] = $pk; } $pk = new SpawnPositionPacket(); $pk->spawnX = $packet->spawnX; $pk->spawnY = $packet->spawnY; $pk->spawnZ = $packet->spawnZ; $packets[] = $pk; $pk = new PositionAndLookPacket(); $pk->x = $packet->x; $pk->y = $packet->y; $pk->z = $packet->z; $pk->yaw = $player->yaw; $pk->pitch = $player->pitch; $pk->onGround = $player->isOnGround(); $packets[] = $pk; return $packets; case Info::SET_HEALTH_PACKET: $pk = new UpdateHealthPacket(); $pk->health = $packet->health; $pk->food = 20; $pk->saturation = 5; return $pk; case Info::TEXT_PACKET: $pk = new STCChatPacket(); $pk->message = TextFormat::toJSON($packet->message); return $pk; case Info::SET_TIME_PACKET: $pk = new TimeUpdatePacket(); $pk->age = $packet->time; $pk->time = $packet->time; //TODO: calculate offset from MCPE return $pk; case Info::SET_SPAWN_POSITION_PACKET: $pk = new SpawnPositionPacket(); $pk->spawnX = $packet->x; $pk->spawnY = $packet->y; $pk->spawnZ = $packet->z; return $pk; case Info::REMOVE_ENTITY_PACKET: case Info::REMOVE_PLAYER_PACKET: $pk = new DestroyEntitiesPacket(); $pk->ids[] = $packet->eid; return $pk; case Info::MOVE_PLAYER_PACKET: if ($packet->eid === 0) { $pk = new PositionAndLookPacket(); $pk->x = $packet->x; $pk->y = $packet->y; $pk->z = $packet->z; $pk->yaw = $packet->yaw; $pk->pitch = $packet->pitch; $pk->onGround = $player->isOnGround(); return $pk; } else { $packets = []; $pk = new EntityTeleportPacket(); $pk->eid = $packet->eid; $pk->x = $packet->x; $pk->y = $packet->y; $pk->z = $packet->z; $pk->yaw = $packet->yaw; $pk->pitch = $packet->pitch; $packets[] = $pk; $pk = new EntityHeadLookPacket(); $pk->eid = $packet->eid; $pk->yaw = $packet->yaw; $packets[] = $pk; return $packets; } case Info::MOVE_ENTITY_PACKET: $packets = []; foreach ($packet->entities as $d) { $pk = new EntityTeleportPacket(); $pk->eid = $d[0]; $pk->x = $d[1]; $pk->y = $d[2]; $pk->z = $d[3]; $pk->yaw = $d[4]; $pk->pitch = $d[5]; $packets[] = $pk; $pk = new EntityHeadLookPacket(); $pk->eid = $d[0]; $pk->yaw = $d[4]; $packets[] = $pk; } return $packets; case Info::SET_ENTITY_MOTION_PACKET: $packets = []; foreach ($packet->entities as $d) { $pk = new EntityVelocityPacket(); $pk->eid = $d[0]; $pk->velocityX = $d[1]; $pk->velocityY = $d[2]; $pk->velocityZ = $d[3]; $packets[] = $pk; } return $packets; /* case Info::CONTAINER_CLOSE_PACKET: $pk = new STCCloseWindowPacket(); $pk->windowID = $packet->windowid; return $pk; case Info::CONTAINER_OPEN_PACKET: $pk = new OpenWindowPacket(); $pk->windowID = $packet->windowid; $pk->inventoryType = $packet->type; $pk->windowTitle = ""; $pk->slots = $packet->slots; return $pk; case Info::CONTAINER_SET_SLOT_PACKET: $pk = new SetSlotPacket(); $pk->windowID = $packet->windowid; if($pk->windowID === 0){ $pk->slot = $packet->slot + 9; }elseif($pk->windowID === 0x78){ $pk->windowID = 0; $pk->slot = $packet->slot + 5; }else{ $pk->slot = $packet->slot; } $pk->item = $packet->item; return $pk; case Info::CONTAINER_SET_CONTENT_PACKET: $pk = new WindowItemsPacket(); $pk->windowID = $packet->windowid; if($pk->windowID === 0 or $pk->windowID === 0x78){ $pk->windowID = 0; for($i = 0; $i < 5; ++$i){ $pk->items[] = Item::get(Item::AIR, 0, 0); } $pk->items[] = $player->getInventory()->getHelmet(); $pk->items[] = $player->getInventory()->getChestplate(); $pk->items[] = $player->getInventory()->getLeggings(); $pk->items[] = $player->getInventory()->getBoots(); $slots = $player->getInventory()->getSize(); for($i = 0; $i < $slots; ++$i){ $pk->items[] = $player->getInventory()->getItem($i); } }else{ $pk->items = $packet->slots; } return $pk; */ /* case Info::CONTAINER_CLOSE_PACKET: $pk = new STCCloseWindowPacket(); $pk->windowID = $packet->windowid; return $pk; case Info::CONTAINER_OPEN_PACKET: $pk = new OpenWindowPacket(); $pk->windowID = $packet->windowid; $pk->inventoryType = $packet->type; $pk->windowTitle = ""; $pk->slots = $packet->slots; return $pk; case Info::CONTAINER_SET_SLOT_PACKET: $pk = new SetSlotPacket(); $pk->windowID = $packet->windowid; if($pk->windowID === 0){ $pk->slot = $packet->slot + 9; }elseif($pk->windowID === 0x78){ $pk->windowID = 0; $pk->slot = $packet->slot + 5; }else{ $pk->slot = $packet->slot; } $pk->item = $packet->item; return $pk; case Info::CONTAINER_SET_CONTENT_PACKET: $pk = new WindowItemsPacket(); $pk->windowID = $packet->windowid; if($pk->windowID === 0 or $pk->windowID === 0x78){ $pk->windowID = 0; for($i = 0; $i < 5; ++$i){ $pk->items[] = Item::get(Item::AIR, 0, 0); } $pk->items[] = $player->getInventory()->getHelmet(); $pk->items[] = $player->getInventory()->getChestplate(); $pk->items[] = $player->getInventory()->getLeggings(); $pk->items[] = $player->getInventory()->getBoots(); $slots = $player->getInventory()->getSize(); for($i = 0; $i < $slots; ++$i){ $pk->items[] = $player->getInventory()->getItem($i); } }else{ $pk->items = $packet->slots; } return $pk; */ case Info::ADD_ITEM_ENTITY_PACKET: $packets = []; $pk = new SpawnObjectPacket(); $pk->eid = $packet->eid; $pk->type = 2; $pk->x = $packet->x; $pk->y = $packet->y; $pk->z = $packet->z; $pk->yaw = $packet->yaw; $pk->pitch = $packet->pitch; $packets[] = $pk; $pk = new EntityMetadataPacket(); $pk->eid = $packet->eid; $pk->metadata = $pk->metadata = [0 => ["type" => 0, "value" => 0], 10 => ["type" => 5, "value" => $packet->item]]; $packets[] = $pk; return $packets; case Info::ADD_PLAYER_PACKET: $packets = []; $pk = new SpawnPlayerPacket(); $pk->name = $packet->username; $pk->eid = $packet->eid; $pk->uuid = Binary::UUIDtoString("00000000000030008000000000000000"); $pk->x = $packet->x; $pk->z = $packet->y; $pk->y = $packet->z; $pk->yaw = $packet->yaw; $pk->pitch = $packet->pitch; $pk->item = 0; $pk->metadata = $packet->metadata; $packets[] = $pk; $pk = new EntityTeleportPacket(); $pk->eid = $packet->eid; $pk->x = $packet->x; $pk->y = $packet->y; $pk->z = $packet->z; $pk->yaw = $packet->yaw; $pk->pitch = $packet->pitch; $packets[] = $pk; return $packets; default: return null; } }