diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 8a8e5732c..1fd99d08e 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -55,6 +55,7 @@ use pocketmine\event\player\PlayerExhaustEvent; use pocketmine\event\player\PlayerGameModeChangeEvent; use pocketmine\event\player\PlayerInteractEvent; use pocketmine\event\player\PlayerItemConsumeEvent; +use pocketmine\event\player\PlayerItemHeldEvent; use pocketmine\event\player\PlayerJoinEvent; use pocketmine\event\player\PlayerJumpEvent; use pocketmine\event\player\PlayerKickEvent; @@ -88,7 +89,6 @@ use pocketmine\level\format\Chunk; use pocketmine\level\Level; use pocketmine\level\Location; use pocketmine\level\Position; -use pocketmine\math\AxisAlignedBB; use pocketmine\math\Vector3; use pocketmine\metadata\MetadataValue; use pocketmine\nbt\NetworkLittleEndianNBTStream; @@ -96,48 +96,31 @@ use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\DoubleTag; use pocketmine\nbt\tag\ListTag; -use pocketmine\network\mcpe\PlayerNetworkSessionAdapter; +use pocketmine\network\mcpe\NetworkSession; use pocketmine\network\mcpe\protocol\AdventureSettingsPacket; use pocketmine\network\mcpe\protocol\AnimatePacket; use pocketmine\network\mcpe\protocol\AvailableCommandsPacket; -use pocketmine\network\mcpe\protocol\BatchPacket; use pocketmine\network\mcpe\protocol\BlockEntityDataPacket; -use pocketmine\network\mcpe\protocol\BlockPickRequestPacket; use pocketmine\network\mcpe\protocol\BookEditPacket; use pocketmine\network\mcpe\protocol\ChunkRadiusUpdatedPacket; -use pocketmine\network\mcpe\protocol\ContainerClosePacket; use pocketmine\network\mcpe\protocol\DataPacket; use pocketmine\network\mcpe\protocol\EntityEventPacket; -use pocketmine\network\mcpe\protocol\InteractPacket; use pocketmine\network\mcpe\protocol\InventoryTransactionPacket; use pocketmine\network\mcpe\protocol\ItemFrameDropItemPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; use pocketmine\network\mcpe\protocol\LoginPacket; use pocketmine\network\mcpe\protocol\MobEffectPacket; -use pocketmine\network\mcpe\protocol\MobEquipmentPacket; use pocketmine\network\mcpe\protocol\MovePlayerPacket; -use pocketmine\network\mcpe\protocol\PlayerActionPacket; -use pocketmine\network\mcpe\protocol\PlayStatusPacket; -use pocketmine\network\mcpe\protocol\ProtocolInfo; -use pocketmine\network\mcpe\protocol\ResourcePackChunkDataPacket; -use pocketmine\network\mcpe\protocol\ResourcePackChunkRequestPacket; -use pocketmine\network\mcpe\protocol\ResourcePackClientResponsePacket; -use pocketmine\network\mcpe\protocol\ResourcePackDataInfoPacket; -use pocketmine\network\mcpe\protocol\ResourcePacksInfoPacket; -use pocketmine\network\mcpe\protocol\ResourcePackStackPacket; -use pocketmine\network\mcpe\protocol\RespawnPacket; use pocketmine\network\mcpe\protocol\SetPlayerGameTypePacket; use pocketmine\network\mcpe\protocol\SetSpawnPositionPacket; use pocketmine\network\mcpe\protocol\SetTitlePacket; -use pocketmine\network\mcpe\protocol\StartGamePacket; use pocketmine\network\mcpe\protocol\TextPacket; use pocketmine\network\mcpe\protocol\TransferPacket; use pocketmine\network\mcpe\protocol\types\CommandData; use pocketmine\network\mcpe\protocol\types\CommandEnum; use pocketmine\network\mcpe\protocol\types\CommandParameter; use pocketmine\network\mcpe\protocol\types\ContainerIds; -use pocketmine\network\mcpe\protocol\types\DimensionIds; use pocketmine\network\mcpe\protocol\types\PlayerPermissions; use pocketmine\network\mcpe\protocol\UpdateAttributesPacket; use pocketmine\network\mcpe\protocol\UpdateBlockPacket; @@ -147,7 +130,6 @@ use pocketmine\permission\PermissibleBase; use pocketmine\permission\PermissionAttachment; use pocketmine\permission\PermissionAttachmentInfo; use pocketmine\plugin\Plugin; -use pocketmine\resourcepacks\ResourcePack; use pocketmine\tile\ItemFrame; use pocketmine\tile\Spawnable; use pocketmine\tile\Tile; @@ -183,19 +165,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return $lname !== "rcon" and $lname !== "console" and $len >= 1 and $len <= 16 and preg_match("/[^A-Za-z0-9_ ]/", $name) === 0; } - /** - * @var PlayerNetworkSessionAdapter - * TODO: remove this once player and network are divorced properly - */ - protected $sessionAdapter; - - /** @var int */ - protected $protocol = -1; - - /** @var string */ - protected $ip; - /** @var int */ - protected $port; + /** @var NetworkSession */ + protected $networkSession; /** * @var int @@ -699,29 +670,30 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ */ public function __construct(NetworkInterface $interface, string $ip, int $port){ $this->perm = new PermissibleBase($this); - $this->namedtag = new CompoundTag(); $this->server = Server::getInstance(); - $this->ip = $ip; - $this->port = $port; $this->loaderId = Level::generateChunkLoaderId($this); $this->chunksPerTick = (int) $this->server->getProperty("chunk-sending.per-tick", 4); $this->spawnThreshold = (int) (($this->server->getProperty("chunk-sending.spawn-radius", 4) ** 2) * M_PI); - $this->gamemode = $this->server->getGamemode(); - $this->setLevel($this->server->getDefaultLevel()); - $this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0); $this->creationTime = microtime(true); $this->allowMovementCheats = (bool) $this->server->getProperty("player.anti-cheat.allow-movement-cheats", false); - $this->sessionAdapter = new PlayerNetworkSessionAdapter($this->server, $this, $interface); + $this->networkSession = new NetworkSession($this->server, $this, $interface, $ip, $port); } /** * @return bool */ public function isConnected() : bool{ - return $this->sessionAdapter !== null; + return $this->networkSession !== null; + } + + /** + * @return NetworkSession + */ + public function getNetworkSession() : NetworkSession{ + return $this->networkSession; } /** @@ -809,14 +781,14 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * @return string */ public function getAddress() : string{ - return $this->ip; + return $this->networkSession->getIp(); } /** * @return int */ public function getPort() : int{ - return $this->port; + return $this->networkSession->getPort(); } /** @@ -944,7 +916,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ unset($this->loadQueue[$index]); } - public function sendChunk(int $x, int $z, BatchPacket $payload){ + public function sendChunk(int $x, int $z, string $payload){ if(!$this->isConnected()){ return; } @@ -952,7 +924,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->usedChunks[Level::chunkHash($x, $z)] = true; $this->chunkLoadCount++; - $this->dataPacket($payload); + $this->networkSession->getInterface()->putPacket($this, $payload); if($this->spawned){ foreach($this->level->getChunkEntities($x, $z) as $entity){ @@ -1004,7 +976,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ protected function doFirstSpawn(){ $this->spawned = true; - $this->sendPlayStatus(PlayStatusPacket::PLAYER_SPAWN); + $this->networkSession->onSpawn(); if($this->hasPermission(Server::BROADCAST_CHANNEL_USERS)){ $this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_USERS, $this); @@ -1044,13 +1016,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } - protected function sendRespawnPacket(Vector3 $pos){ - $pk = new RespawnPacket(); - $pk->position = $pos->add(0, $this->baseOffset, 0); - - $this->dataPacket($pk); - } - protected function orderChunks() : void{ if(!$this->isConnected() or $this->viewDistance === -1){ return; @@ -1514,7 +1479,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } protected function processMovement(int $tickDiff){ - if(!$this->isAlive() or !$this->spawned or $this->newPosition === null or $this->isSleeping()){ + if($this->newPosition === null or $this->isSleeping()){ return; } @@ -1809,73 +1774,18 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return ($targetDot - $eyeDot) >= -$maxDiff; } - protected function initHumanData() : void{ - $this->setNameTag($this->username); - } - - protected function initEntity() : void{ - parent::initEntity(); - $this->addDefaultWindows(); - } - public function handleLogin(LoginPacket $packet) : bool{ - if($this->loggedIn){ - return false; - } - - $this->protocol = $packet->protocol; - - if($packet->protocol !== ProtocolInfo::CURRENT_PROTOCOL){ - if($packet->protocol < ProtocolInfo::CURRENT_PROTOCOL){ - $this->sendPlayStatus(PlayStatusPacket::LOGIN_FAILED_CLIENT, true); - }else{ - $this->sendPlayStatus(PlayStatusPacket::LOGIN_FAILED_SERVER, true); - } - - //This pocketmine disconnect message will only be seen by the console (PlayStatusPacket causes the messages to be shown for the client) - $this->close("", $this->server->getLanguage()->translateString("pocketmine.disconnect.incompatibleProtocol", [$packet->protocol ?? "unknown"]), false); - - return true; - } - - if(!self::isValidUserName($packet->username)){ - $this->close("", "disconnectionScreen.invalidName"); - - return true; - } - $this->username = TextFormat::clean($packet->username); $this->displayName = $this->username; $this->iusername = strtolower($this->username); - - if($packet->locale !== null){ - $this->locale = $packet->locale; - } - - if(count($this->server->getOnlinePlayers()) >= $this->server->getMaxPlayers() and $this->kick("disconnectionScreen.serverFull", false)){ - return true; - } - + $this->locale = $packet->locale; $this->randomClientId = $packet->clientId; $this->uuid = UUID::fromString($packet->clientUUID); $this->rawUUID = $this->uuid->toBinary(); - $skin = new Skin( - $packet->clientData["SkinId"], - base64_decode($packet->clientData["SkinData"] ?? ""), - base64_decode($packet->clientData["CapeData"] ?? ""), - $packet->clientData["SkinGeometryName"] ?? "", - base64_decode($packet->clientData["SkinGeometry"] ?? "") - ); + $this->setSkin($packet->skin); - if(!$skin->isValid()){ - $this->close("", "disconnectionScreen.invalidSkin"); - - return true; - } - - $this->setSkin($skin); $this->server->getPluginManager()->callEvent($ev = new PlayerPreLoginEvent($this, "Plugin reason")); if($ev->isCancelled()){ @@ -1884,6 +1794,10 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return true; } + if(count($this->server->getOnlinePlayers()) >= $this->server->getMaxPlayers() and $this->kick("disconnectionScreen.serverFull", false)){ + return true; + } + if(!$this->server->isWhitelisted($this->iusername) and $this->kick("Server is white-listed", false)){ return true; } @@ -1904,13 +1818,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return true; } - public function sendPlayStatus(int $status, bool $immediate = false){ - $pk = new PlayStatusPacket(); - $pk->status = $status; - $pk->protocol = $this->protocol; - $this->sendDataPacket($pk, false, $immediate); - } - public function onVerifyCompleted(LoginPacket $packet, ?string $error, bool $signedByMojang) : void{ if($this->closed){ return; @@ -1945,10 +1852,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ //TODO: encryption - $this->processLogin(); - } - - protected function processLogin(){ foreach($this->server->getLoggedInPlayers() as $p){ if($p !== $this and ($p->iusername === $this->iusername or $this->getUniqueId()->equals($p->getUniqueId()))){ if(!$p->kick("logged in from another location")){ @@ -1959,10 +1862,63 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } - $this->namedtag = $this->server->getOfflinePlayerData($this->username); + $this->loggedIn = true; + $this->server->onPlayerLogin($this); + $this->networkSession->onLoginSuccess(); + } + + public function _actuallyConstruct(){ + $namedtag = $this->server->getOfflinePlayerData($this->username); //TODO: make this async + + if(($level = $this->server->getLevelByName($namedtag->getString("Level", "", true))) === null){ + /** @var Level $level */ + $level = $this->server->getDefaultLevel(); //TODO: default level may be null + + $namedtag->setString("Level", $level->getFolderName()); + $spawnLocation = $level->getSafeSpawn(); + $namedtag->setTag(new ListTag("Pos", [ + new DoubleTag("", $spawnLocation->x), + new DoubleTag("", $spawnLocation->y), + new DoubleTag("", $spawnLocation->z) + ])); + } + + /** @var float[] $pos */ + $pos = $namedtag->getListTag("Pos")->getAllValues(); + $level->registerChunkLoader($this, ((int) floor($pos[0])) >> 4, ((int) floor($pos[2])) >> 4, true); + + parent::__construct($level, $namedtag); + + $this->server->getPluginManager()->callEvent($ev = new PlayerLoginEvent($this, "Plugin reason")); + if($ev->isCancelled()){ + $this->close($this->getLeaveMessage(), $ev->getKickMessage()); + + return; + } + + $this->server->getLogger()->info($this->getServer()->getLanguage()->translateString("pocketmine.player.logIn", [ + TextFormat::AQUA . $this->username . TextFormat::WHITE, + $this->networkSession->getIp(), + $this->networkSession->getPort(), + $this->id, + $this->level->getName(), + round($this->x, 4), + round($this->y, 4), + round($this->z, 4) + ])); + + $this->server->addOnlinePlayer($this); + } + + protected function initHumanData() : void{ + $this->setNameTag($this->username); + } + + protected function initEntity() : void{ + parent::initEntity(); + $this->addDefaultWindows(); $this->playedBefore = ($this->getLastPlayed() - $this->getFirstPlayed()) > 1; // microtime(true) - microtime(true) may have less than one millisecond difference - $this->namedtag->setString("NameTag", $this->username); $this->gamemode = $this->namedtag->getInt("playerGameType", self::SURVIVAL) & 0x03; if($this->server->getForceGamemode()){ @@ -1970,100 +1926,23 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->namedtag->setInt("playerGameType", $this->gamemode); } - $this->allowFlight = $this->isCreative(); + $this->setAllowFlight($this->isCreative()); $this->keepMovement = $this->isSpectator() || $this->allowMovementCheats(); - - if(($level = $this->server->getLevelByName($this->namedtag->getString("Level", "", true))) === null){ - $this->setLevel($this->server->getDefaultLevel()); - $this->namedtag->setString("Level", $this->level->getFolderName()); - $spawnLocation = $this->level->getSafeSpawn(); - $this->namedtag->setTag(new ListTag("Pos", [ - new DoubleTag("", $spawnLocation->x), - new DoubleTag("", $spawnLocation->y), - new DoubleTag("", $spawnLocation->z) - ])); - }else{ - $this->setLevel($level); + if($this->isOp()){ + $this->setRemoveFormat(false); } - $this->achievements = []; + $this->setNameTagVisible(); + $this->setNameTagAlwaysVisible(); + $this->setCanClimb(); + $this->achievements = []; $achievements = $this->namedtag->getCompoundTag("Achievements") ?? []; /** @var ByteTag $achievement */ foreach($achievements as $achievement){ $this->achievements[$achievement->getName()] = $achievement->getValue() !== 0; } - $this->sendPlayStatus(PlayStatusPacket::LOGIN_SUCCESS); - - $this->loggedIn = true; - $this->server->onPlayerLogin($this); - - $pk = new ResourcePacksInfoPacket(); - $manager = $this->server->getResourcePackManager(); - $pk->resourcePackEntries = $manager->getResourceStack(); - $pk->mustAccept = $manager->resourcePacksRequired(); - $this->dataPacket($pk); - } - - public function handleResourcePackClientResponse(ResourcePackClientResponsePacket $packet) : bool{ - switch($packet->status){ - case ResourcePackClientResponsePacket::STATUS_REFUSED: - //TODO: add lang strings for this - $this->close("", "You must accept resource packs to join this server.", true); - break; - case ResourcePackClientResponsePacket::STATUS_SEND_PACKS: - $manager = $this->server->getResourcePackManager(); - foreach($packet->packIds as $uuid){ - $pack = $manager->getPackById($uuid); - if(!($pack instanceof ResourcePack)){ - //Client requested a resource pack but we don't have it available on the server - $this->close("", "disconnectionScreen.resourcePack", true); - $this->server->getLogger()->debug("Got a resource pack request for unknown pack with UUID " . $uuid . ", available packs: " . implode(", ", $manager->getPackIdList())); - - return false; - } - - $pk = new ResourcePackDataInfoPacket(); - $pk->packId = $pack->getPackId(); - $pk->maxChunkSize = 1048576; //1MB - $pk->chunkCount = (int) ceil($pack->getPackSize() / $pk->maxChunkSize); - $pk->compressedPackSize = $pack->getPackSize(); - $pk->sha256 = $pack->getSha256(); - $this->dataPacket($pk); - } - - break; - case ResourcePackClientResponsePacket::STATUS_HAVE_ALL_PACKS: - $pk = new ResourcePackStackPacket(); - $manager = $this->server->getResourcePackManager(); - $pk->resourcePackStack = $manager->getResourceStack(); - $pk->mustAccept = $manager->resourcePacksRequired(); - $this->dataPacket($pk); - break; - case ResourcePackClientResponsePacket::STATUS_COMPLETED: - $this->completeLoginSequence(); - break; - default: - return false; - } - - return true; - } - - protected function completeLoginSequence(){ - /** @var float[] $pos */ - $pos = $this->namedtag->getListTag("Pos")->getAllValues(); - $this->level->registerChunkLoader($this, ((int) floor($pos[0])) >> 4, ((int) floor($pos[2])) >> 4, true); - - parent::__construct($this->level, $this->namedtag); - $this->server->getPluginManager()->callEvent($ev = new PlayerLoginEvent($this, "Plugin reason")); - if($ev->isCancelled()){ - $this->close($this->getLeaveMessage(), $ev->getKickMessage()); - - return; - } - if(!$this->hasValidSpawnPosition()){ if(($level = $this->server->getLevelByName($this->namedtag->getString("SpawnLevel", ""))) instanceof Level){ $this->spawnPosition = new Position($this->namedtag->getInt("SpawnX"), $this->namedtag->getInt("SpawnY"), $this->namedtag->getInt("SpawnZ"), $level); @@ -2071,69 +1950,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->spawnPosition = $this->level->getSafeSpawn(); } } - - $spawnPosition = $this->getSpawn(); - - $pk = new StartGamePacket(); - $pk->entityUniqueId = $this->id; - $pk->entityRuntimeId = $this->id; - $pk->playerGamemode = Player::getClientFriendlyGamemode($this->gamemode); - - $pk->playerPosition = $this->getOffsetPosition($this); - - $pk->pitch = $this->pitch; - $pk->yaw = $this->yaw; - $pk->seed = -1; - $pk->dimension = DimensionIds::OVERWORLD; //TODO: implement this properly - $pk->worldGamemode = Player::getClientFriendlyGamemode($this->server->getGamemode()); - $pk->difficulty = $this->level->getDifficulty(); - $pk->spawnX = $spawnPosition->getFloorX(); - $pk->spawnY = $spawnPosition->getFloorY(); - $pk->spawnZ = $spawnPosition->getFloorZ(); - $pk->hasAchievementsDisabled = true; - $pk->time = $this->level->getTime(); - $pk->eduMode = false; - $pk->rainLevel = 0; //TODO: implement these properly - $pk->lightningLevel = 0; - $pk->commandsEnabled = true; - $pk->levelId = ""; - $pk->worldName = $this->server->getMotd(); - $this->dataPacket($pk); - - $this->level->sendTime($this); - - $this->sendAttributes(true); - $this->setNameTagVisible(); - $this->setNameTagAlwaysVisible(); - $this->setCanClimb(); - - $this->server->getLogger()->info($this->getServer()->getLanguage()->translateString("pocketmine.player.logIn", [ - TextFormat::AQUA . $this->username . TextFormat::WHITE, - $this->ip, - $this->port, - $this->id, - $this->level->getName(), - round($this->x, 4), - round($this->y, 4), - round($this->z, 4) - ])); - - if($this->isOp()){ - $this->setRemoveFormat(false); - } - - $this->sendCommandData(); - $this->sendSettings(); - $this->sendPotionEffects($this); - $this->sendData($this); - - $this->sendAllInventories(); - $this->inventory->sendCreativeContents(); - $this->inventory->sendHeldItem($this); - $this->dataPacket($this->server->getCraftingManager()->getCraftingDataPacket()); - - $this->server->addOnlinePlayer($this); - $this->server->sendFullPlayerListData($this); } /** @@ -2145,10 +1961,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * @return bool */ public function chat(string $message) : bool{ - if(!$this->spawned or !$this->isAlive()){ - return false; - } - $this->doCloseInventory(); $message = TextFormat::clean($message, $this->removeFormat); @@ -2189,9 +2001,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->sendPosition($this, null, null, MovePlayerPacket::MODE_RESET); $this->server->getLogger()->debug("Got outdated pre-teleport movement from " . $this->getName() . ", received " . $newPos . ", expected " . $this->asVector3()); //Still getting movements from before teleport, ignore them - }elseif((!$this->isAlive() or !$this->spawned) and $newPos->distanceSquared($this) > 0.01){ - $this->sendPosition($this, null, null, MovePlayerPacket::MODE_RESET); - $this->server->getLogger()->debug("Reverted movement of " . $this->getName() . " due to not alive or not spawned, received " . $newPos . ", locked at " . $this->asVector3()); }else{ // Once we get a movement within a reasonable distance, treat it as a teleport ACK and remove position lock if($this->isTeleporting){ @@ -2221,9 +2030,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } public function handleEntityEvent(EntityEventPacket $packet) : bool{ - if(!$this->spawned or !$this->isAlive()){ - return true; - } $this->doCloseInventory(); switch($packet->event){ @@ -2249,10 +2055,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * @return bool */ public function handleInventoryTransaction(InventoryTransactionPacket $packet) : bool{ - if(!$this->spawned or !$this->isAlive()){ - return false; - } - if($this->isSpectator()){ $this->sendAllInventories(); return true; @@ -2610,56 +2412,29 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return false; //TODO } - public function handleMobEquipment(MobEquipmentPacket $packet) : bool{ - if(!$this->spawned or !$this->isAlive()){ - return true; - } - - $item = $this->inventory->getItem($packet->hotbarSlot); - - if(!$item->equals($packet->item)){ - $this->server->getLogger()->debug("Tried to equip " . $packet->item . " but have " . $item . " in target slot"); + public function equipItem(int $hotbarSlot) : bool{ + if(!$this->inventory->isHotbarSlot($hotbarSlot)){ $this->inventory->sendContents($this); return false; } - $this->inventory->equipItem($packet->hotbarSlot); + $this->server->getPluginManager()->callEvent($ev = new PlayerItemHeldEvent($this, $this->inventory->getItem($hotbarSlot), $hotbarSlot)); + if($ev->isCancelled()){ + $this->inventory->sendHeldItem($this); + return false; + } + $this->inventory->setHeldItemIndex($hotbarSlot, false); $this->setUsingItem(false); return true; } - public function handleInteract(InteractPacket $packet) : bool{ - if(!$this->spawned or !$this->isAlive()){ - return true; - } - - $this->doCloseInventory(); - - $target = $this->level->getEntity($packet->target); - if($target === null){ - return false; - } - - switch($packet->action){ - case InteractPacket::ACTION_LEAVE_VEHICLE: - case InteractPacket::ACTION_MOUSEOVER: - break; //TODO: handle these - default: - $this->server->getLogger()->debug("Unhandled/unknown interaction type " . $packet->action . "received from " . $this->getName()); - - return false; - } - - return true; - } - - public function handleBlockPickRequest(BlockPickRequestPacket $packet) : bool{ - $block = $this->level->getBlockAt($packet->blockX, $packet->blockY, $packet->blockZ); + public function pickBlock(Vector3 $pos, bool $addTileNBT) : bool{ + $block = $this->level->getBlock($pos); $item = $block->getPickedItem(); - if($packet->addUserData){ + if($addTileNBT){ $tile = $this->getLevel()->getTile($block); if($tile instanceof Tile){ $nbt = $tile->getCleanedNBT(); @@ -2682,107 +2457,58 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } return true; - } - public function handlePlayerAction(PlayerActionPacket $packet) : bool{ - if(!$this->spawned or (!$this->isAlive() and $packet->action !== PlayerActionPacket::ACTION_RESPAWN and $packet->action !== PlayerActionPacket::ACTION_DIMENSION_CHANGE_REQUEST)){ + public function startBreakBlock(Vector3 $pos, int $face) : bool{ + if($pos->distanceSquared($this) > 10000){ + return false; //TODO: maybe this should throw an exception instead? + } + + $target = $this->level->getBlock($pos); + + $ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $target, null, $face, $target->getId() === 0 ? PlayerInteractEvent::LEFT_CLICK_AIR : PlayerInteractEvent::LEFT_CLICK_BLOCK); + if($this->level->checkSpawnProtection($this, $target)){ + $ev->setCancelled(); + } + + $this->getServer()->getPluginManager()->callEvent($ev); + if($ev->isCancelled()){ + $this->inventory->sendHeldItem($this); return true; } - $packet->entityRuntimeId = $this->id; - $pos = new Vector3($packet->x, $packet->y, $packet->z); - - switch($packet->action){ - case PlayerActionPacket::ACTION_START_BREAK: - if($pos->distanceSquared($this) > 10000){ - break; - } - - $target = $this->level->getBlock($pos); - - $ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $target, null, $packet->face, $target->getId() === 0 ? PlayerInteractEvent::LEFT_CLICK_AIR : PlayerInteractEvent::LEFT_CLICK_BLOCK); - if($this->level->checkSpawnProtection($this, $target)){ - $ev->setCancelled(); - } - - $this->getServer()->getPluginManager()->callEvent($ev); - if($ev->isCancelled()){ - $this->inventory->sendHeldItem($this); - break; - } - - $block = $target->getSide($packet->face); - if($block->getId() === Block::FIRE){ - $this->level->setBlock($block, BlockFactory::get(Block::AIR)); - break; - } - - if(!$this->isCreative()){ - //TODO: improve this to take stuff like swimming, ladders, enchanted tools into account, fix wrong tool break time calculations for bad tools (pmmp/PocketMine-MP#211) - $breakTime = ceil($target->getBreakTime($this->inventory->getItemInHand()) * 20); - if($breakTime > 0){ - $this->level->broadcastLevelEvent($pos, LevelEventPacket::EVENT_BLOCK_START_BREAK, (int) (65535 / $breakTime)); - } - } - - break; - - case PlayerActionPacket::ACTION_ABORT_BREAK: - case PlayerActionPacket::ACTION_STOP_BREAK: - $this->level->broadcastLevelEvent($pos, LevelEventPacket::EVENT_BLOCK_STOP_BREAK); - break; - case PlayerActionPacket::ACTION_START_SLEEPING: - //unused - break; - case PlayerActionPacket::ACTION_STOP_SLEEPING: - $this->stopSleep(); - break; - case PlayerActionPacket::ACTION_RESPAWN: - if(!$this->spawned or $this->isAlive() or !$this->isOnline()){ - break; - } - - $this->respawn(); - break; - case PlayerActionPacket::ACTION_JUMP: - $this->jump(); - return true; - case PlayerActionPacket::ACTION_START_SPRINT: - $this->toggleSprint(true); - return true; - case PlayerActionPacket::ACTION_STOP_SPRINT: - $this->toggleSprint(false); - return true; - case PlayerActionPacket::ACTION_START_SNEAK: - $this->toggleSneak(true); - return true; - case PlayerActionPacket::ACTION_STOP_SNEAK: - $this->toggleSneak(false); - return true; - case PlayerActionPacket::ACTION_START_GLIDE: - case PlayerActionPacket::ACTION_STOP_GLIDE: - break; //TODO - case PlayerActionPacket::ACTION_CONTINUE_BREAK: - $block = $this->level->getBlock($pos); - $this->level->broadcastLevelEvent($pos, LevelEventPacket::EVENT_PARTICLE_PUNCH_BLOCK, BlockFactory::toStaticRuntimeId($block->getId(), $block->getDamage()) | ($packet->face << 24)); - //TODO: destroy-progress level event - break; - case PlayerActionPacket::ACTION_START_SWIMMING: - break; //TODO - case PlayerActionPacket::ACTION_STOP_SWIMMING: - //TODO: handle this when it doesn't spam every damn tick (yet another spam bug!!) - break; - default: - $this->server->getLogger()->debug("Unhandled/unknown player action type " . $packet->action . " from " . $this->getName()); - return false; + $block = $target->getSide($face); + if($block->getId() === Block::FIRE){ + $this->level->setBlock($block, BlockFactory::get(Block::AIR)); + return true; } - $this->setUsingItem(false); + if(!$this->isCreative()){ + //TODO: improve this to take stuff like swimming, ladders, enchanted tools into account, fix wrong tool break time calculations for bad tools (pmmp/PocketMine-MP#211) + $breakTime = ceil($target->getBreakTime($this->inventory->getItemInHand()) * 20); + if($breakTime > 0){ + $this->level->broadcastLevelEvent($pos, LevelEventPacket::EVENT_BLOCK_START_BREAK, (int) (65535 / $breakTime)); + } + } return true; } + public function continueBreakBlock(Vector3 $pos, int $face) : void{ + $block = $this->level->getBlock($pos); + $this->level->broadcastLevelEvent( + $pos, + LevelEventPacket::EVENT_PARTICLE_PUNCH_BLOCK, + BlockFactory::toStaticRuntimeId($block->getId(), $block->getDamage()) | ($face << 24) + ); + + //TODO: destroy-progress level event + } + + public function stopBreakBlock(Vector3 $pos) : void{ + $this->level->broadcastLevelEvent($pos, LevelEventPacket::EVENT_BLOCK_STOP_BREAK); + } + public function toggleSprint(bool $sprint) : void{ $ev = new PlayerToggleSprintEvent($this, $sprint); $this->server->getPluginManager()->callEvent($ev); @@ -2803,12 +2529,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } - public function handleAnimate(AnimatePacket $packet) : bool{ - if(!$this->spawned or !$this->isAlive()){ - return true; - } - - $this->server->getPluginManager()->callEvent($ev = new PlayerAnimationEvent($this, $packet->action)); + public function animate(int $action) : bool{ + $this->server->getPluginManager()->callEvent($ev = new PlayerAnimationEvent($this, $action)); if($ev->isCancelled()){ return true; } @@ -2828,10 +2550,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * @return bool if the item was dropped or if the item was null */ public function dropItem(Item $item) : bool{ - if(!$this->spawned or !$this->isAlive()){ - return false; - } - if($item->isNull()){ $this->server->getLogger()->debug($this->getName() . " attempted to drop a null item (" . $item . ")"); return true; @@ -2844,25 +2562,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return true; } - public function handleContainerClose(ContainerClosePacket $packet) : bool{ - if(!$this->spawned or $packet->windowId === 0){ - return true; - } - - $this->doCloseInventory(); - - if(isset($this->windowIndex[$packet->windowId])){ - $this->server->getPluginManager()->callEvent(new InventoryCloseEvent($this->windowIndex[$packet->windowId], $this)); - $this->removeWindow($this->windowIndex[$packet->windowId]); - return true; - }elseif($packet->windowId === 255){ - //Closed a fake window - return true; - } - - return false; - } - public function handleAdventureSettings(AdventureSettingsPacket $packet) : bool{ if($packet->entityUniqueId !== $this->getId()){ return false; //TODO @@ -2896,9 +2595,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } public function handleBlockEntityData(BlockEntityDataPacket $packet) : bool{ - if(!$this->spawned or !$this->isAlive()){ - return true; - } $this->doCloseInventory(); $pos = new Vector3($packet->x, $packet->y, $packet->z); @@ -2922,20 +2618,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return true; } - public function handleSetPlayerGameType(SetPlayerGameTypePacket $packet) : bool{ - if($packet->gamemode !== $this->gamemode){ - //Set this back to default. TODO: handle this properly - $this->sendGamemode(); - $this->sendSettings(); - } - return true; - } - public function handleItemFrameDropItem(ItemFrameDropItemPacket $packet) : bool{ - if(!$this->spawned or !$this->isAlive()){ - return true; - } - $tile = $this->level->getTileAt($packet->x, $packet->y, $packet->z); if($tile instanceof ItemFrame){ $ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $tile->getBlock(), null, 5 - $tile->getBlock()->getDamage(), PlayerInteractEvent::LEFT_CLICK_BLOCK); @@ -2959,25 +2642,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return true; } - public function handleResourcePackChunkRequest(ResourcePackChunkRequestPacket $packet) : bool{ - $manager = $this->server->getResourcePackManager(); - $pack = $manager->getPackById($packet->packId); - if(!($pack instanceof ResourcePack)){ - $this->close("", "disconnectionScreen.resourcePack", true); - $this->server->getLogger()->debug("Got a resource pack chunk request for unknown pack with UUID " . $packet->packId . ", available packs: " . implode(", ", $manager->getPackIdList())); - - return false; - } - - $pk = new ResourcePackChunkDataPacket(); - $pk->packId = $pack->getPackId(); - $pk->chunkIndex = $packet->chunkIndex; - $pk->data = $pack->getPackChunk(1048576 * $packet->chunkIndex, 1048576); - $pk->progress = (1048576 * $packet->chunkIndex); - $this->dataPacket($pk); - return true; - } - public function handleBookEdit(BookEditPacket $packet) : bool{ /** @var WritableBook $oldBook */ $oldBook = $this->inventory->getItem($packet->inventorySlot); @@ -3027,24 +2691,12 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } /** - * Called when a packet is received from the client. This method will call DataPacketReceiveEvent. - * * @param DataPacket $packet - */ - public function handleDataPacket(DataPacket $packet){ - if($this->sessionAdapter !== null){ - $this->sessionAdapter->handleDataPacket($packet); - } - } - - /** - * @param DataPacket $packet - * @param bool $needACK * @param bool $immediate * - * @return bool|int + * @return bool */ - public function sendDataPacket(DataPacket $packet, bool $needACK = false, bool $immediate = false){ + public function sendDataPacket(DataPacket $packet, bool $immediate = false) : bool{ if(!$this->isConnected()){ return false; } @@ -3054,27 +2706,25 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ throw new \InvalidArgumentException("Attempted to send " . get_class($packet) . " to " . $this->getName() . " too early"); } - return $this->sessionAdapter->sendDataPacket($packet, $immediate); + return $this->networkSession->sendDataPacket($packet, $immediate); } /** * @param DataPacket $packet - * @param bool $needACK * - * @return bool|int + * @return bool */ - public function dataPacket(DataPacket $packet, bool $needACK = false){ - return $this->sendDataPacket($packet, $needACK, false); + public function dataPacket(DataPacket $packet) : bool{ + return $this->sendDataPacket($packet, false); } /** * @param DataPacket $packet - * @param bool $needACK * - * @return bool|int + * @return bool */ - public function directDataPacket(DataPacket $packet, bool $needACK = false){ - return $this->sendDataPacket($packet, $needACK, true); + public function directDataPacket(DataPacket $packet) : bool{ + return $this->sendDataPacket($packet, true); } /** @@ -3304,8 +2954,10 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ if($this->isConnected() and !$this->closed){ try{ - $this->sessionAdapter->serverDisconnect($reason, $notify); - $this->sessionAdapter = null; + $ip = $this->networkSession->getIp(); + $port = $this->networkSession->getPort(); + $this->networkSession->serverDisconnect($reason, $notify); + $this->networkSession = null; $this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_USERS, $this); $this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this); @@ -3367,8 +3019,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->server->getLogger()->info($this->getServer()->getLanguage()->translateString("pocketmine.player.logOut", [ TextFormat::AQUA . $this->getName() . TextFormat::WHITE, - $this->ip, - $this->port, + $ip, + $port, $this->getServer()->getLanguage()->translateString($reason) ])); @@ -3453,7 +3105,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ parent::kill(); - $this->sendRespawnPacket($this->getSpawn()); + $this->networkSession->onDeath(); } protected function onDeath() : void{ @@ -3602,7 +3254,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return false; //never flag players for despawn } - protected function respawn() : void{ + public function respawn() : void{ if($this->server->isHardcore()){ $this->setBanned(true); return; @@ -3636,6 +3288,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->spawnToAll(); $this->scheduleUpdate(); + + $this->networkSession->onRespawn(); } protected function applyPostDamageEffects(EntityDamageEvent $source) : void{ @@ -3754,6 +3408,10 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->craftingGrid = $grid; } + /** + * @internal Called to clean up crafting grid and cursor inventory when it is detected that the player closed their + * inventory. + */ public function doCloseInventory() : void{ /** @var Inventory[] $inventories */ $inventories = [$this->craftingGrid, $this->cursorInventory]; @@ -3774,6 +3432,33 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } + /** + * @internal Called by the network session when a player closes a window. + * + * @param int $windowId + * + * @return bool + */ + public function doCloseWindow(int $windowId) : bool{ + if($windowId === 0){ + return false; + } + + $this->doCloseInventory(); + + if(isset($this->windowIndex[$windowId])){ + $this->server->getPluginManager()->callEvent(new InventoryCloseEvent($this->windowIndex[$windowId], $this)); + $this->removeWindow($this->windowIndex[$windowId]); + return true; + } + if($windowId === 255){ + //Closed a fake window + return true; + } + + return false; + } + /** * Returns the window ID which the inventory has for this player, or -1 if the window is not open to the player. * @@ -3867,7 +3552,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } - protected function sendAllInventories(){ + public function sendAllInventories(){ foreach($this->windowIndex as $id => $inventory){ $inventory->sendContents($this); } diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index e0b920ad1..0d4a6f1df 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -70,7 +70,8 @@ use pocketmine\nbt\tag\ShortTag; use pocketmine\nbt\tag\StringTag; use pocketmine\network\AdvancedNetworkInterface; use pocketmine\network\mcpe\CompressBatchedTask; -use pocketmine\network\mcpe\protocol\BatchPacket; +use pocketmine\network\mcpe\NetworkCompression; +use pocketmine\network\mcpe\PacketStream; use pocketmine\network\mcpe\protocol\DataPacket; use pocketmine\network\mcpe\protocol\PlayerListPacket; use pocketmine\network\mcpe\protocol\ProtocolInfo; @@ -223,8 +224,6 @@ class Server{ private $network; /** @var bool */ private $networkCompressionAsync = true; - /** @var int */ - public $networkCompressionLevel = 7; /** @var bool */ private $autoTickRate = true; @@ -1517,15 +1516,15 @@ class Server{ $this->asyncPool = new AsyncPool($this, $poolSize, (int) max(-1, (int) $this->getProperty("memory.async-worker-hard-limit", 256)), $this->autoloader, $this->logger); if($this->getProperty("network.batch-threshold", 256) >= 0){ - Network::$BATCH_THRESHOLD = (int) $this->getProperty("network.batch-threshold", 256); + NetworkCompression::$THRESHOLD = (int) $this->getProperty("network.batch-threshold", 256); }else{ - Network::$BATCH_THRESHOLD = -1; + NetworkCompression::$THRESHOLD = -1; } - $this->networkCompressionLevel = $this->getProperty("network.compression-level", 7); - if($this->networkCompressionLevel < 1 or $this->networkCompressionLevel > 9){ - $this->logger->warning("Invalid network compression level $this->networkCompressionLevel set, setting to default 7"); - $this->networkCompressionLevel = 7; + NetworkCompression::$LEVEL = $this->getProperty("network.compression-level", 7); + if(NetworkCompression::$LEVEL < 1 or NetworkCompression::$LEVEL > 9){ + $this->logger->warning("Invalid network compression level " . NetworkCompression::$LEVEL . " set, setting to default 7"); + NetworkCompression::$LEVEL = 7; } $this->networkCompressionAsync = (bool) $this->getProperty("network.async-compression", true); @@ -1864,24 +1863,23 @@ class Server{ $targets = array_filter($players, function(Player $player) : bool{ return $player->isConnected(); }); if(!empty($targets)){ - $pk = new BatchPacket(); + $stream = new PacketStream(); foreach($packets as $p){ - $pk->addPacket($p); + $stream->putPacket($p); } - if(Network::$BATCH_THRESHOLD >= 0 and strlen($pk->payload) >= Network::$BATCH_THRESHOLD){ - $pk->setCompressionLevel($this->networkCompressionLevel); - }else{ - $pk->setCompressionLevel(0); //Do not compress packets under the threshold + $compressionLevel = NetworkCompression::$LEVEL; + if(NetworkCompression::$THRESHOLD < 0 or strlen($stream->buffer) < NetworkCompression::$THRESHOLD){ + $compressionLevel = 0; //Do not compress packets under the threshold $forceSync = true; } if(!$forceSync and !$immediate and $this->networkCompressionAsync){ - $task = new CompressBatchedTask($pk, $targets); + $task = new CompressBatchedTask($stream, $targets, $compressionLevel); $this->asyncPool->submitTask($task); }else{ - $this->broadcastPacketsCallback($pk, $targets, $immediate); + $this->broadcastPacketsCallback(NetworkCompression::compress($stream->buffer), $targets, $immediate); } } @@ -1889,17 +1887,13 @@ class Server{ } /** - * @param BatchPacket $pk - * @param Player[] $players - * @param bool $immediate + * @param string $payload + * @param Player[] $players + * @param bool $immediate */ - public function broadcastPacketsCallback(BatchPacket $pk, array $players, bool $immediate = false){ - if(!$pk->isEncoded){ - $pk->encode(); - } - + public function broadcastPacketsCallback(string $payload, array $players, bool $immediate = false){ foreach($players as $i){ - $i->sendDataPacket($pk, false, $immediate); + $i->getNetworkSession()->getInterface()->putPacket($i, $payload, $immediate); } } diff --git a/src/pocketmine/inventory/CraftingManager.php b/src/pocketmine/inventory/CraftingManager.php index 567e3e1b0..414294d91 100644 --- a/src/pocketmine/inventory/CraftingManager.php +++ b/src/pocketmine/inventory/CraftingManager.php @@ -25,9 +25,9 @@ namespace pocketmine\inventory; use pocketmine\item\Item; use pocketmine\item\ItemFactory; -use pocketmine\network\mcpe\protocol\BatchPacket; +use pocketmine\network\mcpe\NetworkCompression; +use pocketmine\network\mcpe\PacketStream; use pocketmine\network\mcpe\protocol\CraftingDataPacket; -use pocketmine\Server; use pocketmine\timings\Timings; class CraftingManager{ @@ -38,7 +38,7 @@ class CraftingManager{ /** @var FurnaceRecipe[] */ protected $furnaceRecipes = []; - /** @var BatchPacket */ + /** @var string */ private $craftingDataCache; public function __construct(){ @@ -102,21 +102,19 @@ class CraftingManager{ $pk->encode(); - $batch = new BatchPacket(); - $batch->addPacket($pk); - $batch->setCompressionLevel(Server::getInstance()->networkCompressionLevel); - $batch->encode(); + $batch = new PacketStream(); + $batch->putPacket($pk); - $this->craftingDataCache = $batch; + $this->craftingDataCache = NetworkCompression::compress($batch->buffer); Timings::$craftingDataCacheRebuildTimer->stopTiming(); } /** * Returns a pre-compressed CraftingDataPacket for sending to players. Rebuilds the cache if it is not found. * - * @return BatchPacket + * @return string */ - public function getCraftingDataPacket() : BatchPacket{ + public function getCraftingDataPacket() : string{ if($this->craftingDataCache === null){ $this->buildCraftingDataCache(); } diff --git a/src/pocketmine/inventory/PlayerInventory.php b/src/pocketmine/inventory/PlayerInventory.php index 97ed33c42..b701afca0 100644 --- a/src/pocketmine/inventory/PlayerInventory.php +++ b/src/pocketmine/inventory/PlayerInventory.php @@ -24,7 +24,6 @@ declare(strict_types=1); namespace pocketmine\inventory; use pocketmine\entity\Human; -use pocketmine\event\player\PlayerItemHeldEvent; use pocketmine\item\Item; use pocketmine\network\mcpe\protocol\InventoryContentPacket; use pocketmine\network\mcpe\protocol\MobEquipmentPacket; @@ -55,33 +54,7 @@ class PlayerInventory extends BaseInventory{ return 36; } - /** - * Called when a client equips a hotbar slot. This method should not be used by plugins. - * This method will call PlayerItemHeldEvent. - * - * @param int $hotbarSlot Number of the hotbar slot to equip. - * - * @return bool if the equipment change was successful, false if not. - */ - public function equipItem(int $hotbarSlot) : bool{ - if(!$this->isHotbarSlot($hotbarSlot)){ - $this->sendContents($this->getHolder()); - return false; - } - - $this->getHolder()->getLevel()->getServer()->getPluginManager()->callEvent($ev = new PlayerItemHeldEvent($this->getHolder(), $this->getItem($hotbarSlot), $hotbarSlot)); - - if($ev->isCancelled()){ - $this->sendHeldItem($this->getHolder()); - return false; - } - - $this->setHeldItemIndex($hotbarSlot, false); - - return true; - } - - private function isHotbarSlot(int $slot) : bool{ + public function isHotbarSlot(int $slot) : bool{ return $slot >= 0 and $slot <= $this->getHotbarSize(); } diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 4cd1281ce..e6011ef63 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -69,7 +69,6 @@ use pocketmine\metadata\MetadataValue; use pocketmine\nbt\tag\ListTag; use pocketmine\nbt\tag\StringTag; use pocketmine\network\mcpe\ChunkRequestTask; -use pocketmine\network\mcpe\protocol\BatchPacket; use pocketmine\network\mcpe\protocol\DataPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; @@ -123,7 +122,7 @@ class Level implements ChunkManager, Metadatable{ /** @var Block[][] */ private $blockCache = []; - /** @var BatchPacket[] */ + /** @var string[] */ private $chunkCache = []; /** @var int */ @@ -2498,7 +2497,7 @@ class Level implements ChunkManager, Metadatable{ } } - public function chunkRequestCallback(int $x, int $z, BatchPacket $payload){ + public function chunkRequestCallback(int $x, int $z, string $payload){ $this->timings->syncChunkSendTimer->startTiming(); $index = Level::chunkHash($x, $z); diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index 0b315faab..48252a03d 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -33,9 +33,6 @@ use pocketmine\network\mcpe\protocol\PacketPool; use pocketmine\Server; class Network{ - - public static $BATCH_THRESHOLD = 512; - /** @var Server */ private $server; diff --git a/src/pocketmine/network/NetworkInterface.php b/src/pocketmine/network/NetworkInterface.php index 0818234fc..f06526873 100644 --- a/src/pocketmine/network/NetworkInterface.php +++ b/src/pocketmine/network/NetworkInterface.php @@ -26,7 +26,6 @@ declare(strict_types=1); */ namespace pocketmine\network; -use pocketmine\network\mcpe\protocol\DataPacket; use pocketmine\Player; /** @@ -42,14 +41,11 @@ interface NetworkInterface{ /** * Sends a DataPacket to the interface, returns an unique identifier for the packet if $needACK is true * - * @param Player $player - * @param DataPacket $packet - * @param bool $needACK - * @param bool $immediate - * - * @return int|null + * @param Player $player + * @param string $payload + * @param bool $immediate */ - public function putPacket(Player $player, DataPacket $packet, bool $needACK = false, bool $immediate = true) : ?int; + public function putPacket(Player $player, string $payload, bool $immediate = true) : void; /** * Terminates the connection diff --git a/src/pocketmine/network/mcpe/ChunkRequestTask.php b/src/pocketmine/network/mcpe/ChunkRequestTask.php index f28dc22f9..c904f517a 100644 --- a/src/pocketmine/network/mcpe/ChunkRequestTask.php +++ b/src/pocketmine/network/mcpe/ChunkRequestTask.php @@ -25,7 +25,6 @@ namespace pocketmine\network\mcpe; use pocketmine\level\format\Chunk; use pocketmine\level\Level; -use pocketmine\network\mcpe\protocol\BatchPacket; use pocketmine\network\mcpe\protocol\FullChunkDataPacket; use pocketmine\scheduler\AsyncTask; use pocketmine\Server; @@ -47,7 +46,7 @@ class ChunkRequestTask extends AsyncTask{ public function __construct(Level $level, int $chunkX, int $chunkZ, Chunk $chunk){ $this->levelId = $level->getId(); - $this->compressionLevel = $level->getServer()->networkCompressionLevel; + $this->compressionLevel = NetworkCompression::$LEVEL; $this->chunk = $chunk->fastSerialize(); $this->chunkX = $chunkX; @@ -72,22 +71,17 @@ class ChunkRequestTask extends AsyncTask{ $pk->chunkZ = $this->chunkZ; $pk->data = $chunk->networkSerialize() . $this->tiles; - $batch = new BatchPacket(); - $batch->addPacket($pk); - $batch->setCompressionLevel($this->compressionLevel); - $batch->encode(); + $stream = new PacketStream(); + $stream->putPacket($pk); - $this->setResult($batch->buffer, false); + $this->setResult(NetworkCompression::compress($stream->buffer, $this->compressionLevel), false); } public function onCompletion(Server $server) : void{ $level = $server->getLevel($this->levelId); if($level instanceof Level){ if($this->hasResult()){ - $batch = new BatchPacket($this->getResult()); - assert(strlen($batch->buffer) > 0); - $batch->isEncoded = true; - $level->chunkRequestCallback($this->chunkX, $this->chunkZ, $batch); + $level->chunkRequestCallback($this->chunkX, $this->chunkZ, $this->getResult()); }else{ $server->getLogger()->error("Chunk request for level #" . $this->levelId . ", x=" . $this->chunkX . ", z=" . $this->chunkZ . " doesn't have any result data"); } diff --git a/src/pocketmine/network/mcpe/CompressBatchedTask.php b/src/pocketmine/network/mcpe/CompressBatchedTask.php index 420b3fc67..77e4a089f 100644 --- a/src/pocketmine/network/mcpe/CompressBatchedTask.php +++ b/src/pocketmine/network/mcpe/CompressBatchedTask.php @@ -23,44 +23,34 @@ declare(strict_types=1); namespace pocketmine\network\mcpe; -use pocketmine\network\mcpe\protocol\BatchPacket; use pocketmine\Player; use pocketmine\scheduler\AsyncTask; use pocketmine\Server; class CompressBatchedTask extends AsyncTask{ - public $level = 7; - public $data; + private $level; + private $data; /** - * @param BatchPacket $batch - * @param string[] $targets + * @param PacketStream $stream + * @param string[] $targets + * @param int $compressionLevel */ - public function __construct(BatchPacket $batch, array $targets){ - $this->data = $batch->payload; - $this->level = $batch->getCompressionLevel(); + public function __construct(PacketStream $stream, array $targets, int $compressionLevel){ + $this->data = $stream->buffer; + $this->level = $compressionLevel; $this->storeLocal($targets); } public function onRun() : void{ - $batch = new BatchPacket(); - $batch->payload = $this->data; - $this->data = null; - - $batch->setCompressionLevel($this->level); - $batch->encode(); - - $this->setResult($batch->buffer, false); + $this->setResult(NetworkCompression::compress($this->data, $this->level), false); } public function onCompletion(Server $server) : void{ - $pk = new BatchPacket($this->getResult()); - $pk->isEncoded = true; - /** @var Player[] $targets */ $targets = $this->fetchLocal(); - $server->broadcastPacketsCallback($pk, $targets); + $server->broadcastPacketsCallback($this->getResult(), $targets); } } diff --git a/src/pocketmine/network/mcpe/NetworkCompression.php b/src/pocketmine/network/mcpe/NetworkCompression.php new file mode 100644 index 000000000..b7c608f6a --- /dev/null +++ b/src/pocketmine/network/mcpe/NetworkCompression.php @@ -0,0 +1,47 @@ +server = $server; + $this->player = $player; + $this->interface = $interface; - public function handleItemFrameDropItem(ItemFrameDropItemPacket $packet) : bool{ - return false; - } + $this->ip = $ip; + $this->port = $port; - public function handleGameRulesChanged(GameRulesChangedPacket $packet) : bool{ - return false; + $this->setHandler(new LoginSessionHandler($player, $this)); } - public function handleCamera(CameraPacket $packet) : bool{ - return false; + public function getInterface() : NetworkInterface{ + return $this->interface; } - public function handleBossEvent(BossEventPacket $packet) : bool{ - return false; + /** + * @return string + */ + public function getIp() : string{ + return $this->ip; } - public function handleShowCredits(ShowCreditsPacket $packet) : bool{ - return false; + /** + * @return int + */ + public function getPort() : int{ + return $this->port; } - public function handleAvailableCommands(AvailableCommandsPacket $packet) : bool{ - return false; + public function getHandler() : SessionHandler{ + return $this->handler; } - public function handleCommandRequest(CommandRequestPacket $packet) : bool{ - return false; + public function setHandler(SessionHandler $handler) : void{ + $this->handler = $handler; + $this->handler->setUp(); } - public function handleCommandBlockUpdate(CommandBlockUpdatePacket $packet) : bool{ - return false; - } + public function handleEncoded(string $payload) : void{ + //TODO: decryption if enabled - public function handleCommandOutput(CommandOutputPacket $packet) : bool{ - return false; + $stream = new PacketStream(NetworkCompression::decompress($payload)); + while(!$stream->feof()){ + $this->handleDataPacket(PacketPool::getPacket($stream->getString())); + } } - public function handleUpdateTrade(UpdateTradePacket $packet) : bool{ - return false; - } + public function handleDataPacket(DataPacket $packet) : void{ + $timings = Timings::getReceiveDataPacketTimings($packet); + $timings->startTiming(); - public function handleUpdateEquip(UpdateEquipPacket $packet) : bool{ - return false; - } + $packet->decode(); + if(!$packet->feof() and !$packet->mayHaveUnreadBytes()){ + $remains = substr($packet->buffer, $packet->offset); + $this->server->getLogger()->debug("Still " . strlen($remains) . " bytes unread in " . $packet->getName() . ": 0x" . bin2hex($remains)); + } - public function handleResourcePackDataInfo(ResourcePackDataInfoPacket $packet) : bool{ - return false; - } + $this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this->player, $packet)); + if(!$ev->isCancelled() and !$packet->handle($this->handler)){ + $this->server->getLogger()->debug("Unhandled " . $packet->getName() . " received from " . $this->player->getName() . ": 0x" . bin2hex($packet->buffer)); + } - public function handleResourcePackChunkData(ResourcePackChunkDataPacket $packet) : bool{ - return false; + $timings->stopTiming(); } - public function handleResourcePackChunkRequest(ResourcePackChunkRequestPacket $packet) : bool{ - return false; - } + public function sendDataPacket(DataPacket $packet, bool $immediate = false) : bool{ + $timings = Timings::getSendDataPacketTimings($packet); + $timings->startTiming(); + try{ + $this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this->player, $packet)); + if($ev->isCancelled()){ + return false; + } - public function handleTransfer(TransferPacket $packet) : bool{ - return false; - } + //TODO: implement buffering (this is just a quick fix) + $this->server->batchPackets([$this->player], [$packet], true, $immediate); - public function handlePlaySound(PlaySoundPacket $packet) : bool{ - return false; + return true; + }finally{ + $timings->stopTiming(); + } } - public function handleStopSound(StopSoundPacket $packet) : bool{ - return false; + public function serverDisconnect(string $reason, bool $notify = true) : void{ + if($notify){ + $pk = new DisconnectPacket(); + $pk->message = $reason; + $pk->hideDisconnectionScreen = $reason === ""; + $this->sendDataPacket($pk, true); + } + $this->interface->close($this->player, $notify ? $reason : ""); } - public function handleSetTitle(SetTitlePacket $packet) : bool{ - return false; - } + //TODO: onEnableEncryption() step - public function handleAddBehaviorTree(AddBehaviorTreePacket $packet) : bool{ - return false; - } + public function onLoginSuccess() : void{ + $pk = new PlayStatusPacket(); + $pk->status = PlayStatusPacket::LOGIN_SUCCESS; + $this->sendDataPacket($pk); - public function handleStructureBlockUpdate(StructureBlockUpdatePacket $packet) : bool{ - return false; + $this->setHandler(new ResourcePacksSessionHandler($this->player, $this, $this->server->getResourcePackManager())); } - public function handleShowStoreOffer(ShowStoreOfferPacket $packet) : bool{ - return false; - } + public function onResourcePacksDone() : void{ + $this->player->_actuallyConstruct(); - public function handlePurchaseReceipt(PurchaseReceiptPacket $packet) : bool{ - return false; + $this->setHandler(new PreSpawnSessionHandler($this->server, $this->player, $this)); } - public function handlePlayerSkin(PlayerSkinPacket $packet) : bool{ - return false; - } - - public function handleSubClientLogin(SubClientLoginPacket $packet) : bool{ - return false; - } - - public function handleWSConnect(WSConnectPacket $packet) : bool{ - return false; - } - - public function handleSetLastHurtBy(SetLastHurtByPacket $packet) : bool{ - return false; - } - - public function handleBookEdit(BookEditPacket $packet) : bool{ - return false; - } - - public function handleNpcRequest(NpcRequestPacket $packet) : bool{ - return false; - } - - public function handlePhotoTransfer(PhotoTransferPacket $packet) : bool{ - return false; - } - - public function handleModalFormRequest(ModalFormRequestPacket $packet) : bool{ - return false; - } - - public function handleModalFormResponse(ModalFormResponsePacket $packet) : bool{ - return false; - } - - public function handleServerSettingsRequest(ServerSettingsRequestPacket $packet) : bool{ - return false; - } - - public function handleServerSettingsResponse(ServerSettingsResponsePacket $packet) : bool{ - return false; - } - - public function handleShowProfile(ShowProfilePacket $packet) : bool{ - return false; - } - - public function handleSetDefaultGameType(SetDefaultGameTypePacket $packet) : bool{ - return false; - } - - public function handleRemoveObjective(RemoveObjectivePacket $packet) : bool{ - return false; - } - - public function handleSetDisplayObjective(SetDisplayObjectivePacket $packet) : bool{ - return false; - } - - public function handleSetScore(SetScorePacket $packet) : bool{ - return false; - } - - public function handleLabTable(LabTablePacket $packet) : bool{ - return false; - } + public function onSpawn() : void{ + $pk = new PlayStatusPacket(); + $pk->status = PlayStatusPacket::PLAYER_SPAWN; + $this->sendDataPacket($pk); - public function handleUpdateBlockSynced(UpdateBlockSyncedPacket $packet) : bool{ - return false; + //TODO: split this up even further + $this->setHandler(new SimpleSessionHandler($this->player)); } - public function handleMoveEntityDelta(MoveEntityDeltaPacket $packet) : bool{ - return false; + public function onDeath() : void{ + $this->setHandler(new DeathSessionHandler($this->player, $this)); } - public function handleSetLocalPlayerAsInitialized(SetLocalPlayerAsInitializedPacket $packet) : bool{ - return false; + public function onRespawn() : void{ + $this->setHandler(new SimpleSessionHandler($this->player)); } } diff --git a/src/pocketmine/network/mcpe/PacketStream.php b/src/pocketmine/network/mcpe/PacketStream.php new file mode 100644 index 000000000..9a0f4e977 --- /dev/null +++ b/src/pocketmine/network/mcpe/PacketStream.php @@ -0,0 +1,41 @@ +isEncoded){ + $packet->encode(); + } + $this->putString($packet->buffer); + } + + public function getPacket() : DataPacket{ + return PacketPool::getPacket($this->getString()); + } +} diff --git a/src/pocketmine/network/mcpe/RakLibInterface.php b/src/pocketmine/network/mcpe/RakLibInterface.php index 08c46ee85..9aaeeda9f 100644 --- a/src/pocketmine/network/mcpe/RakLibInterface.php +++ b/src/pocketmine/network/mcpe/RakLibInterface.php @@ -25,9 +25,6 @@ namespace pocketmine\network\mcpe; use pocketmine\event\player\PlayerCreationEvent; use pocketmine\network\AdvancedNetworkInterface; -use pocketmine\network\mcpe\protocol\BatchPacket; -use pocketmine\network\mcpe\protocol\DataPacket; -use pocketmine\network\mcpe\protocol\PacketPool; use pocketmine\network\mcpe\protocol\ProtocolInfo; use pocketmine\network\Network; use pocketmine\Player; @@ -48,6 +45,8 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{ */ private const MCPE_RAKNET_PROTOCOL_VERSION = 8; + private const MCPE_RAKNET_PACKET_ID = "\xfe"; + /** @var Server */ private $server; @@ -63,9 +62,6 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{ /** @var string[] */ private $identifiers = []; - /** @var int[] */ - private $identifiersACK = []; - /** @var ServerHandler */ private $interface; @@ -112,7 +108,6 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{ $player = $this->players[$identifier]; unset($this->identifiers[spl_object_hash($player)]); unset($this->players[$identifier]); - unset($this->identifiersACK[$identifier]); $player->close($player->getLeaveMessage(), $reason); } } @@ -120,7 +115,6 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{ public function close(Player $player, string $reason = "unknown reason") : void{ if(isset($this->identifiers[$h = spl_object_hash($player)])){ unset($this->players[$this->identifiers[$h]]); - unset($this->identifiersACK[$this->identifiers[$h]]); $this->interface->closeSession($this->identifiers[$h], $reason); unset($this->identifiers[$h]); } @@ -143,7 +137,6 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{ $player = new $class($this, $ev->getAddress(), $ev->getPort()); $this->players[$identifier] = $player; - $this->identifiersACK[$identifier] = 0; $this->identifiers[spl_object_hash($player)] = $identifier; $this->server->addPlayer($player); } @@ -153,13 +146,12 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{ //get this now for blocking in case the player was closed before the exception was raised $address = $this->players[$identifier]->getAddress(); try{ - if($packet->buffer !== ""){ - $pk = PacketPool::getPacket($packet->buffer); - $this->players[$identifier]->handleDataPacket($pk); + if($packet->buffer !== "" and $packet->buffer{0} === self::MCPE_RAKNET_PACKET_ID){ //Batch + $this->players[$identifier]->getNetworkSession()->handleEncoded(substr($packet->buffer, 1)); } }catch(\Throwable $e){ $logger = $this->server->getLogger(); - $logger->debug("Packet " . (isset($pk) ? get_class($pk) : "unknown") . " 0x" . bin2hex($packet->buffer)); + $logger->debug("EncapsulatedPacket 0x" . bin2hex($packet->buffer)); $logger->logException($e); $this->interface->blockAddress($address, 5); @@ -216,40 +208,17 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{ } } - public function putPacket(Player $player, DataPacket $packet, bool $needACK = false, bool $immediate = true) : ?int{ + public function putPacket(Player $player, string $payload, bool $immediate = true) : void{ if(isset($this->identifiers[$h = spl_object_hash($player)])){ $identifier = $this->identifiers[$h]; - if(!$packet->isEncoded){ - $packet->encode(); - } - if($packet instanceof BatchPacket){ - if($needACK){ - $pk = new EncapsulatedPacket(); - $pk->identifierACK = $this->identifiersACK[$identifier]++; - $pk->buffer = $packet->buffer; - $pk->reliability = PacketReliability::RELIABLE_ORDERED; - $pk->orderChannel = 0; - }else{ - if(!isset($packet->__encapsulatedPacket)){ - $packet->__encapsulatedPacket = new CachedEncapsulatedPacket; - $packet->__encapsulatedPacket->identifierACK = null; - $packet->__encapsulatedPacket->buffer = $packet->buffer; - $packet->__encapsulatedPacket->reliability = PacketReliability::RELIABLE_ORDERED; - $packet->__encapsulatedPacket->orderChannel = 0; - } - $pk = $packet->__encapsulatedPacket; - } + $pk = new EncapsulatedPacket(); + $pk->buffer = self::MCPE_RAKNET_PACKET_ID . $payload; + $pk->reliability = PacketReliability::RELIABLE_ORDERED; + $pk->orderChannel = 0; - $this->interface->sendEncapsulated($identifier, $pk, ($needACK ? RakLib::FLAG_NEED_ACK : 0) | ($immediate ? RakLib::PRIORITY_IMMEDIATE : RakLib::PRIORITY_NORMAL)); - return $pk->identifierACK; - }else{ - $this->server->batchPackets([$player], [$packet], true, $immediate); - return null; - } + $this->interface->sendEncapsulated($identifier, $pk, ($immediate ? RakLib::PRIORITY_IMMEDIATE : RakLib::PRIORITY_NORMAL)); } - - return null; } public function updatePing(string $identifier, int $pingMS) : void{ diff --git a/src/pocketmine/network/mcpe/handler/DeathSessionHandler.php b/src/pocketmine/network/mcpe/handler/DeathSessionHandler.php new file mode 100644 index 000000000..0333fb7f1 --- /dev/null +++ b/src/pocketmine/network/mcpe/handler/DeathSessionHandler.php @@ -0,0 +1,61 @@ +player = $player; + $this->session = $session; + } + + public function setUp() : void{ + $pk = new RespawnPacket(); + $pk->position = $this->player->getOffsetPosition($this->player->getSpawn()); + $this->session->sendDataPacket($pk); + } + + public function handlePlayerAction(PlayerActionPacket $packet) : bool{ + switch($packet->action){ + case PlayerActionPacket::ACTION_RESPAWN: + $this->player->respawn(); + return true; + case PlayerActionPacket::ACTION_DIMENSION_CHANGE_REQUEST: + //TODO: players send this when they die in another dimension + break; + } + + return false; + } +} diff --git a/src/pocketmine/network/mcpe/handler/LoginSessionHandler.php b/src/pocketmine/network/mcpe/handler/LoginSessionHandler.php new file mode 100644 index 000000000..a65854f49 --- /dev/null +++ b/src/pocketmine/network/mcpe/handler/LoginSessionHandler.php @@ -0,0 +1,89 @@ +player = $player; + $this->session = $session; + } + + public function handleLogin(LoginPacket $packet) : bool{ + if(!$this->isCompatibleProtocol($packet->protocol)){ + $pk = new PlayStatusPacket(); + $pk->status = $packet->protocol < ProtocolInfo::CURRENT_PROTOCOL ? + PlayStatusPacket::LOGIN_FAILED_CLIENT : PlayStatusPacket::LOGIN_FAILED_SERVER; + $pk->protocol = $packet->protocol; + $this->session->sendDataPacket($pk, true); + + //This pocketmine disconnect message will only be seen by the console (PlayStatusPacket causes the messages to be shown for the client) + $this->player->close( + "", + $this->player->getServer()->getLanguage()->translateString("pocketmine.disconnect.incompatibleProtocol", [$packet->protocol]), + false + ); + + return true; + } + + if(!Player::isValidUserName($packet->username)){ + $this->player->close("", "disconnectionScreen.invalidName"); + + return true; + } + + if($packet->skin === null or !$packet->skin->isValid()){ + $this->player->close("", "disconnectionScreen.invalidSkin"); + + return true; + } + + if($this->player->handleLogin($packet)){ + if($this->session->getHandler() === $this){ //when login verification is disabled, the handler will already have been replaced + $this->session->setHandler(new NullSessionHandler()); //drop packets received during login verification + } + return true; + } + return false; + } + + protected function isCompatibleProtocol(int $protocolVersion) : bool{ + return $protocolVersion === ProtocolInfo::CURRENT_PROTOCOL; + } +} diff --git a/src/pocketmine/network/mcpe/CachedEncapsulatedPacket.php b/src/pocketmine/network/mcpe/handler/NullSessionHandler.php similarity index 69% rename from src/pocketmine/network/mcpe/CachedEncapsulatedPacket.php rename to src/pocketmine/network/mcpe/handler/NullSessionHandler.php index 74bf3d464..a36a3989d 100644 --- a/src/pocketmine/network/mcpe/CachedEncapsulatedPacket.php +++ b/src/pocketmine/network/mcpe/handler/NullSessionHandler.php @@ -21,15 +21,11 @@ declare(strict_types=1); -namespace pocketmine\network\mcpe; +namespace pocketmine\network\mcpe\handler; -use raklib\protocol\EncapsulatedPacket; +/** + * Handler which simply ignores all packets received. + */ +class NullSessionHandler extends SessionHandler{ -class CachedEncapsulatedPacket extends EncapsulatedPacket{ - /** @var string|null */ - private $internalData = null; - - public function toInternalBinary() : string{ - return $this->internalData ?? ($this->internalData = parent::toInternalBinary()); - } } diff --git a/src/pocketmine/network/mcpe/handler/PreSpawnSessionHandler.php b/src/pocketmine/network/mcpe/handler/PreSpawnSessionHandler.php new file mode 100644 index 000000000..555362538 --- /dev/null +++ b/src/pocketmine/network/mcpe/handler/PreSpawnSessionHandler.php @@ -0,0 +1,99 @@ +player = $player; + $this->server = $server; + $this->session = $session; + } + + public function setUp() : void{ + $spawnPosition = $this->player->getSpawn(); + + $pk = new StartGamePacket(); + $pk->entityUniqueId = $this->player->getId(); + $pk->entityRuntimeId = $this->player->getId(); + $pk->playerGamemode = Player::getClientFriendlyGamemode($this->player->getGamemode()); + $pk->playerPosition = $this->player->getOffsetPosition($this->player); + $pk->pitch = $this->player->pitch; + $pk->yaw = $this->player->yaw; + $pk->seed = -1; + $pk->dimension = DimensionIds::OVERWORLD; //TODO: implement this properly + $pk->worldGamemode = Player::getClientFriendlyGamemode($this->server->getGamemode()); + $pk->difficulty = $this->player->getLevel()->getDifficulty(); + $pk->spawnX = $spawnPosition->getFloorX(); + $pk->spawnY = $spawnPosition->getFloorY(); + $pk->spawnZ = $spawnPosition->getFloorZ(); + $pk->hasAchievementsDisabled = true; + $pk->time = $this->player->getLevel()->getTime(); + $pk->eduMode = false; + $pk->rainLevel = 0; //TODO: implement these properly + $pk->lightningLevel = 0; + $pk->commandsEnabled = true; + $pk->levelId = ""; + $pk->worldName = $this->server->getMotd(); + $this->session->sendDataPacket($pk); + + $this->player->getLevel()->sendTime($this->player); + + $this->player->sendAttributes(true); + $this->player->sendCommandData(); + $this->player->sendSettings(); + $this->player->sendPotionEffects($this->player); + $this->player->sendData($this->player); + + $this->player->sendAllInventories(); + $this->player->getInventory()->sendCreativeContents(); + $this->player->getInventory()->sendHeldItem($this->player); + $this->session->getInterface()->putPacket($this->player, $this->server->getCraftingManager()->getCraftingDataPacket()); + + $this->server->sendFullPlayerListData($this->player); + } + + public function handleRequestChunkRadius(RequestChunkRadiusPacket $packet) : bool{ + $this->player->setViewDistance($packet->radius); + + return true; + } +} diff --git a/src/pocketmine/network/mcpe/handler/ResourcePacksSessionHandler.php b/src/pocketmine/network/mcpe/handler/ResourcePacksSessionHandler.php new file mode 100644 index 000000000..da51a41ca --- /dev/null +++ b/src/pocketmine/network/mcpe/handler/ResourcePacksSessionHandler.php @@ -0,0 +1,125 @@ +player = $player; + $this->session = $session; + $this->resourcePackManager = $resourcePackManager; + } + + public function setUp() : void{ + $pk = new ResourcePacksInfoPacket(); + $pk->resourcePackEntries = $this->resourcePackManager->getResourceStack(); + $pk->mustAccept = $this->resourcePackManager->resourcePacksRequired(); + $this->session->sendDataPacket($pk); + } + + public function handleResourcePackClientResponse(ResourcePackClientResponsePacket $packet) : bool{ + switch($packet->status){ + case ResourcePackClientResponsePacket::STATUS_REFUSED: + //TODO: add lang strings for this + $this->player->close("", "You must accept resource packs to join this server.", true); + break; + case ResourcePackClientResponsePacket::STATUS_SEND_PACKS: + foreach($packet->packIds as $uuid){ + $pack = $this->resourcePackManager->getPackById($uuid); + if(!($pack instanceof ResourcePack)){ + //Client requested a resource pack but we don't have it available on the server + $this->player->close("", "disconnectionScreen.resourcePack", true); + $this->player->getServer()->getLogger()->debug("Got a resource pack request for unknown pack with UUID " . $uuid . ", available packs: " . implode(", ", $this->resourcePackManager->getPackIdList())); + + return false; + } + + $pk = new ResourcePackDataInfoPacket(); + $pk->packId = $pack->getPackId(); + $pk->maxChunkSize = self::PACK_CHUNK_SIZE; //1MB + $pk->chunkCount = (int) ceil($pack->getPackSize() / self::PACK_CHUNK_SIZE); + $pk->compressedPackSize = $pack->getPackSize(); + $pk->sha256 = $pack->getSha256(); + $this->session->sendDataPacket($pk); + } + + break; + case ResourcePackClientResponsePacket::STATUS_HAVE_ALL_PACKS: + $pk = new ResourcePackStackPacket(); + $pk->resourcePackStack = $this->resourcePackManager->getResourceStack(); + $pk->mustAccept = $this->resourcePackManager->resourcePacksRequired(); + $this->session->sendDataPacket($pk); + break; + case ResourcePackClientResponsePacket::STATUS_COMPLETED: + $this->session->onResourcePacksDone(); + break; + default: + return false; + } + + return true; + } + + public function handleResourcePackChunkRequest(ResourcePackChunkRequestPacket $packet) : bool{ + $pack = $this->resourcePackManager->getPackById($packet->packId); + if(!($pack instanceof ResourcePack)){ + $this->player->close("", "disconnectionScreen.resourcePack", true); + $this->player->getServer()->getLogger()->debug("Got a resource pack chunk request for unknown pack with UUID " . $packet->packId . ", available packs: " . implode(", ", $this->resourcePackManager->getPackIdList())); + + return false; + } + + $pk = new ResourcePackChunkDataPacket(); + $pk->packId = $pack->getPackId(); + $pk->chunkIndex = $packet->chunkIndex; + $pk->data = $pack->getPackChunk(self::PACK_CHUNK_SIZE * $packet->chunkIndex, self::PACK_CHUNK_SIZE); + $pk->progress = (self::PACK_CHUNK_SIZE * $packet->chunkIndex); + $this->session->sendDataPacket($pk); + + return true; + } +} diff --git a/src/pocketmine/network/mcpe/handler/SessionHandler.php b/src/pocketmine/network/mcpe/handler/SessionHandler.php new file mode 100644 index 000000000..5ebc11b43 --- /dev/null +++ b/src/pocketmine/network/mcpe/handler/SessionHandler.php @@ -0,0 +1,598 @@ +server = $server; + public function __construct(Player $player){ $this->player = $player; - $this->interface = $interface; - } - - public function handleDataPacket(DataPacket $packet) : void{ - $timings = Timings::getReceiveDataPacketTimings($packet); - $timings->startTiming(); - - $packet->decode(); - if(!$packet->feof() and !$packet->mayHaveUnreadBytes()){ - $remains = substr($packet->buffer, $packet->offset); - $this->server->getLogger()->debug("Still " . strlen($remains) . " bytes unread in " . $packet->getName() . ": 0x" . bin2hex($remains)); - } - - $this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this->player, $packet)); - if(!$ev->isCancelled() and !$packet->handle($this)){ - $this->server->getLogger()->debug("Unhandled " . $packet->getName() . " received from " . $this->player->getName() . ": 0x" . bin2hex($packet->buffer)); - } - - $timings->stopTiming(); - } - - public function sendDataPacket(DataPacket $packet, bool $immediate = false) : bool{ - $timings = Timings::getSendDataPacketTimings($packet); - $timings->startTiming(); - try{ - $this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this->player, $packet)); - if($ev->isCancelled()){ - return false; - } - - $this->interface->putPacket($this->player, $packet, false, $immediate); - - return true; - }finally{ - $timings->stopTiming(); - } - } - - public function serverDisconnect(string $reason, bool $notify = true) : void{ - if($notify){ - $pk = new DisconnectPacket(); - $pk->message = $reason; - $pk->hideDisconnectionScreen = $reason === ""; - $this->sendDataPacket($pk, true); - } - $this->interface->close($this->player, $notify ? $reason : ""); - } - - public function handleLogin(LoginPacket $packet) : bool{ - return $this->player->handleLogin($packet); } public function handleClientToServerHandshake(ClientToServerHandshakePacket $packet) : bool{ return false; //TODO } - public function handleResourcePackClientResponse(ResourcePackClientResponsePacket $packet) : bool{ - return $this->player->handleResourcePackClientResponse($packet); - } - public function handleText(TextPacket $packet) : bool{ if($packet->type === TextPacket::TYPE_CHAT){ return $this->player->chat($packet->message); @@ -166,7 +104,7 @@ class PlayerNetworkSessionAdapter extends NetworkSession{ } public function handleMobEquipment(MobEquipmentPacket $packet) : bool{ - return $this->player->handleMobEquipment($packet); + return $this->player->equipItem($packet->hotbarSlot); } public function handleMobArmorEquipment(MobArmorEquipmentPacket $packet) : bool{ @@ -174,11 +112,11 @@ class PlayerNetworkSessionAdapter extends NetworkSession{ } public function handleInteract(InteractPacket $packet) : bool{ - return $this->player->handleInteract($packet); + return false; //TODO } public function handleBlockPickRequest(BlockPickRequestPacket $packet) : bool{ - return $this->player->handleBlockPickRequest($packet); + return $this->player->pickBlock(new Vector3($packet->blockX, $packet->blockY, $packet->blockZ), $packet->addUserData); } public function handleEntityPickRequest(EntityPickRequestPacket $packet) : bool{ @@ -186,7 +124,58 @@ class PlayerNetworkSessionAdapter extends NetworkSession{ } public function handlePlayerAction(PlayerActionPacket $packet) : bool{ - return $this->player->handlePlayerAction($packet); + $pos = new Vector3($packet->x, $packet->y, $packet->z); + + switch($packet->action){ + case PlayerActionPacket::ACTION_START_BREAK: + $this->player->startBreakBlock($pos, $packet->face); + + break; + + case PlayerActionPacket::ACTION_ABORT_BREAK: + case PlayerActionPacket::ACTION_STOP_BREAK: + $this->player->stopBreakBlock($pos); + break; + case PlayerActionPacket::ACTION_START_SLEEPING: + //unused + break; + case PlayerActionPacket::ACTION_STOP_SLEEPING: + $this->player->stopSleep(); + break; + case PlayerActionPacket::ACTION_JUMP: + $this->player->jump(); + return true; + case PlayerActionPacket::ACTION_START_SPRINT: + $this->player->toggleSprint(true); + return true; + case PlayerActionPacket::ACTION_STOP_SPRINT: + $this->player->toggleSprint(false); + return true; + case PlayerActionPacket::ACTION_START_SNEAK: + $this->player->toggleSneak(true); + return true; + case PlayerActionPacket::ACTION_STOP_SNEAK: + $this->player->toggleSneak(false); + return true; + case PlayerActionPacket::ACTION_START_GLIDE: + case PlayerActionPacket::ACTION_STOP_GLIDE: + break; //TODO + case PlayerActionPacket::ACTION_CONTINUE_BREAK: + $this->player->continueBreakBlock($pos, $packet->face); + break; + case PlayerActionPacket::ACTION_START_SWIMMING: + break; //TODO + case PlayerActionPacket::ACTION_STOP_SWIMMING: + //TODO: handle this when it doesn't spam every damn tick (yet another spam bug!!) + break; + default: + $this->player->getServer()->getLogger()->debug("Unhandled/unknown player action type " . $packet->action . " from " . $this->player->getName()); + return false; + } + + $this->player->setUsingItem(false); + + return true; } public function handleEntityFall(EntityFallPacket $packet) : bool{ @@ -194,11 +183,11 @@ class PlayerNetworkSessionAdapter extends NetworkSession{ } public function handleAnimate(AnimatePacket $packet) : bool{ - return $this->player->handleAnimate($packet); + return $this->player->animate($packet->action); } public function handleContainerClose(ContainerClosePacket $packet) : bool{ - return $this->player->handleContainerClose($packet); + return $this->player->doCloseWindow($packet->windowId); } public function handlePlayerHotbar(PlayerHotbarPacket $packet) : bool{ @@ -222,7 +211,12 @@ class PlayerNetworkSessionAdapter extends NetworkSession{ } public function handleSetPlayerGameType(SetPlayerGameTypePacket $packet) : bool{ - return $this->player->handleSetPlayerGameType($packet); + if($packet->gamemode !== $this->player->getGamemode()){ + //Set this back to default. TODO: handle this properly + $this->player->sendGamemode(); + $this->player->sendSettings(); + } + return true; } public function handleSpawnExperienceOrb(SpawnExperienceOrbPacket $packet) : bool{ @@ -259,14 +253,14 @@ class PlayerNetworkSessionAdapter extends NetworkSession{ return false; //TODO } - public function handleResourcePackChunkRequest(ResourcePackChunkRequestPacket $packet) : bool{ - return $this->player->handleResourcePackChunkRequest($packet); - } - public function handlePlayerSkin(PlayerSkinPacket $packet) : bool{ return $this->player->changeSkin($packet->skin, $packet->newSkinName, $packet->oldSkinName); } + public function handleSubClientLogin(SubClientLoginPacket $packet) : bool{ + return false; //TODO + } + public function handleBookEdit(BookEditPacket $packet) : bool{ return $this->player->handleBookEdit($packet); } @@ -278,4 +272,12 @@ class PlayerNetworkSessionAdapter extends NetworkSession{ public function handleServerSettingsRequest(ServerSettingsRequestPacket $packet) : bool{ return false; //TODO: GUI stuff } + + public function handleLabTable(LabTablePacket $packet) : bool{ + return false; //TODO + } + + public function handleSetLocalPlayerAsInitialized(SetLocalPlayerAsInitializedPacket $packet) : bool{ + return false; //TODO + } } diff --git a/src/pocketmine/network/mcpe/protocol/AddBehaviorTreePacket.php b/src/pocketmine/network/mcpe/protocol/AddBehaviorTreePacket.php index 545e7988d..8472b1b45 100644 --- a/src/pocketmine/network/mcpe/protocol/AddBehaviorTreePacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddBehaviorTreePacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class AddBehaviorTreePacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::ADD_BEHAVIOR_TREE_PACKET; @@ -41,7 +41,7 @@ class AddBehaviorTreePacket extends DataPacket{ $this->putString($this->behaviorTreeJson); } - public function handle(NetworkSession $session) : bool{ - return $session->handleAddBehaviorTree($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleAddBehaviorTree($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/AddEntityPacket.php b/src/pocketmine/network/mcpe/protocol/AddEntityPacket.php index 3c8398364..5ea109c7f 100644 --- a/src/pocketmine/network/mcpe/protocol/AddEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddEntityPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\entity\Attribute; use pocketmine\math\Vector3; -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\network\mcpe\protocol\types\EntityLink; class AddEntityPacket extends DataPacket{ @@ -117,7 +117,7 @@ class AddEntityPacket extends DataPacket{ } } - public function handle(NetworkSession $session) : bool{ - return $session->handleAddEntity($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleAddEntity($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/AddHangingEntityPacket.php b/src/pocketmine/network/mcpe/protocol/AddHangingEntityPacket.php index 871dd6a79..032de9f55 100644 --- a/src/pocketmine/network/mcpe/protocol/AddHangingEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddHangingEntityPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class AddHangingEntityPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::ADD_HANGING_ENTITY_PACKET; @@ -57,7 +57,7 @@ class AddHangingEntityPacket extends DataPacket{ $this->putVarInt($this->direction); } - public function handle(NetworkSession $session) : bool{ - return $session->handleAddHangingEntity($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleAddHangingEntity($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/AddItemEntityPacket.php b/src/pocketmine/network/mcpe/protocol/AddItemEntityPacket.php index f3d24b052..ff1a32dbd 100644 --- a/src/pocketmine/network/mcpe/protocol/AddItemEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddItemEntityPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\item\Item; use pocketmine\math\Vector3; -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class AddItemEntityPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::ADD_ITEM_ENTITY_PACKET; @@ -67,7 +67,7 @@ class AddItemEntityPacket extends DataPacket{ $this->putBool($this->isFromFishing); } - public function handle(NetworkSession $session) : bool{ - return $session->handleAddItemEntity($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleAddItemEntity($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/AddPaintingPacket.php b/src/pocketmine/network/mcpe/protocol/AddPaintingPacket.php index a69560ce6..a1997e338 100644 --- a/src/pocketmine/network/mcpe/protocol/AddPaintingPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddPaintingPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class AddPaintingPacket extends AddHangingEntityPacket{ public const NETWORK_ID = ProtocolInfo::ADD_PAINTING_PACKET; @@ -44,7 +44,7 @@ class AddPaintingPacket extends AddHangingEntityPacket{ $this->putString($this->title); } - public function handle(NetworkSession $session) : bool{ - return $session->handleAddPainting($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleAddPainting($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php b/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php index 675f6c3cd..155011992 100644 --- a/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\item\Item; use pocketmine\math\Vector3; -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\network\mcpe\protocol\types\EntityLink; use pocketmine\utils\UUID; @@ -135,7 +135,7 @@ class AddPlayerPacket extends DataPacket{ } } - public function handle(NetworkSession $session) : bool{ - return $session->handleAddPlayer($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleAddPlayer($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/AdventureSettingsPacket.php b/src/pocketmine/network/mcpe/protocol/AdventureSettingsPacket.php index ff084a018..b98739fde 100644 --- a/src/pocketmine/network/mcpe/protocol/AdventureSettingsPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AdventureSettingsPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\network\mcpe\protocol\types\PlayerPermissions; class AdventureSettingsPacket extends DataPacket{ @@ -116,7 +116,7 @@ class AdventureSettingsPacket extends DataPacket{ } } - public function handle(NetworkSession $session) : bool{ - return $session->handleAdventureSettings($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleAdventureSettings($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/AnimatePacket.php b/src/pocketmine/network/mcpe/protocol/AnimatePacket.php index cabc2889c..22ec0ccd0 100644 --- a/src/pocketmine/network/mcpe/protocol/AnimatePacket.php +++ b/src/pocketmine/network/mcpe/protocol/AnimatePacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class AnimatePacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::ANIMATE_PACKET; @@ -59,7 +59,7 @@ class AnimatePacket extends DataPacket{ } } - public function handle(NetworkSession $session) : bool{ - return $session->handleAnimate($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleAnimate($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/AvailableCommandsPacket.php b/src/pocketmine/network/mcpe/protocol/AvailableCommandsPacket.php index 8806360b1..b0ccbae04 100644 --- a/src/pocketmine/network/mcpe/protocol/AvailableCommandsPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AvailableCommandsPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\network\mcpe\protocol\types\CommandData; use pocketmine\network\mcpe\protocol\types\CommandEnum; use pocketmine\network\mcpe\protocol\types\CommandParameter; @@ -336,7 +336,7 @@ class AvailableCommandsPacket extends DataPacket{ } } - public function handle(NetworkSession $session) : bool{ - return $session->handleAvailableCommands($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleAvailableCommands($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/BatchPacket.php b/src/pocketmine/network/mcpe/protocol/BatchPacket.php deleted file mode 100644 index 657ecb0c2..000000000 --- a/src/pocketmine/network/mcpe/protocol/BatchPacket.php +++ /dev/null @@ -1,122 +0,0 @@ - - - -use pocketmine\network\mcpe\NetworkBinaryStream; -use pocketmine\network\mcpe\NetworkSession; -#ifndef COMPILE -use pocketmine\utils\Binary; -#endif - -class BatchPacket extends DataPacket{ - public const NETWORK_ID = 0xfe; - - /** @var string */ - public $payload = ""; - /** @var int */ - protected $compressionLevel = 7; - - public function canBeBatched() : bool{ - return false; - } - - public function canBeSentBeforeLogin() : bool{ - return true; - } - - protected function decodeHeader() : void{ - $pid = $this->getByte(); - assert($pid === static::NETWORK_ID); - } - - protected function decodePayload() : void{ - $data = $this->getRemaining(); - try{ - $this->payload = zlib_decode($data, 1024 * 1024 * 64); //Max 64MB - }catch(\ErrorException $e){ //zlib decode error - $this->payload = ""; - } - } - - protected function encodeHeader() : void{ - $this->putByte(static::NETWORK_ID); - } - - protected function encodePayload() : void{ - $this->put(zlib_encode($this->payload, ZLIB_ENCODING_DEFLATE, $this->compressionLevel)); - } - - /** - * @param DataPacket $packet - */ - public function addPacket(DataPacket $packet) : void{ - if(!$packet->canBeBatched()){ - throw new \InvalidArgumentException(get_class($packet) . " cannot be put inside a BatchPacket"); - } - if(!$packet->isEncoded){ - $packet->encode(); - } - - $this->payload .= Binary::writeUnsignedVarInt(strlen($packet->buffer)) . $packet->buffer; - } - - /** - * @return \Generator - */ - public function getPackets() : \Generator{ - $stream = new NetworkBinaryStream($this->payload); - while(!$stream->feof()){ - yield $stream->getString(); - } - } - - public function getCompressionLevel() : int{ - return $this->compressionLevel; - } - - public function setCompressionLevel(int $level) : void{ - $this->compressionLevel = $level; - } - - public function handle(NetworkSession $session) : bool{ - if($this->payload === ""){ - return false; - } - - foreach($this->getPackets() as $buf){ - $pk = PacketPool::getPacket($buf); - - if(!$pk->canBeBatched()){ - throw new \InvalidArgumentException("Received invalid " . get_class($pk) . " inside BatchPacket"); - } - - $session->handleDataPacket($pk); - } - - return true; - } -} diff --git a/src/pocketmine/network/mcpe/protocol/BlockEntityDataPacket.php b/src/pocketmine/network/mcpe/protocol/BlockEntityDataPacket.php index e5938f94c..6e06e38b2 100644 --- a/src/pocketmine/network/mcpe/protocol/BlockEntityDataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/BlockEntityDataPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class BlockEntityDataPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::BLOCK_ENTITY_DATA_PACKET; @@ -50,7 +50,7 @@ class BlockEntityDataPacket extends DataPacket{ $this->put($this->namedtag); } - public function handle(NetworkSession $session) : bool{ - return $session->handleBlockEntityData($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleBlockEntityData($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/BlockEventPacket.php b/src/pocketmine/network/mcpe/protocol/BlockEventPacket.php index 1ec8f6b4c..462e4d9e5 100644 --- a/src/pocketmine/network/mcpe/protocol/BlockEventPacket.php +++ b/src/pocketmine/network/mcpe/protocol/BlockEventPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class BlockEventPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::BLOCK_EVENT_PACKET; @@ -54,7 +54,7 @@ class BlockEventPacket extends DataPacket{ $this->putVarInt($this->eventData); } - public function handle(NetworkSession $session) : bool{ - return $session->handleBlockEvent($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleBlockEvent($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/BlockPickRequestPacket.php b/src/pocketmine/network/mcpe/protocol/BlockPickRequestPacket.php index b3a7da89a..1bc27cef1 100644 --- a/src/pocketmine/network/mcpe/protocol/BlockPickRequestPacket.php +++ b/src/pocketmine/network/mcpe/protocol/BlockPickRequestPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class BlockPickRequestPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::BLOCK_PICK_REQUEST_PACKET; @@ -55,7 +55,7 @@ class BlockPickRequestPacket extends DataPacket{ $this->putByte($this->hotbarSlot); } - public function handle(NetworkSession $session) : bool{ - return $session->handleBlockPickRequest($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleBlockPickRequest($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/BookEditPacket.php b/src/pocketmine/network/mcpe/protocol/BookEditPacket.php index 0163b181a..961ee1a81 100644 --- a/src/pocketmine/network/mcpe/protocol/BookEditPacket.php +++ b/src/pocketmine/network/mcpe/protocol/BookEditPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class BookEditPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::BOOK_EDIT_PACKET; @@ -113,7 +113,7 @@ class BookEditPacket extends DataPacket{ } } - public function handle(NetworkSession $session) : bool{ - return $session->handleBookEdit($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleBookEdit($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/BossEventPacket.php b/src/pocketmine/network/mcpe/protocol/BossEventPacket.php index 49739532c..89a9be354 100644 --- a/src/pocketmine/network/mcpe/protocol/BossEventPacket.php +++ b/src/pocketmine/network/mcpe/protocol/BossEventPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class BossEventPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::BOSS_EVENT_PACKET; @@ -126,7 +126,7 @@ class BossEventPacket extends DataPacket{ } } - public function handle(NetworkSession $session) : bool{ - return $session->handleBossEvent($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleBossEvent($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/CameraPacket.php b/src/pocketmine/network/mcpe/protocol/CameraPacket.php index e022fb1da..6e211d516 100644 --- a/src/pocketmine/network/mcpe/protocol/CameraPacket.php +++ b/src/pocketmine/network/mcpe/protocol/CameraPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class CameraPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::CAMERA_PACKET; @@ -45,7 +45,7 @@ class CameraPacket extends DataPacket{ $this->putEntityUniqueId($this->playerUniqueId); } - public function handle(NetworkSession $session) : bool{ - return $session->handleCamera($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleCamera($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/ChangeDimensionPacket.php b/src/pocketmine/network/mcpe/protocol/ChangeDimensionPacket.php index 2177bf6c1..90f487000 100644 --- a/src/pocketmine/network/mcpe/protocol/ChangeDimensionPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ChangeDimensionPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\math\Vector3; -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class ChangeDimensionPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::CHANGE_DIMENSION_PACKET; @@ -51,7 +51,7 @@ class ChangeDimensionPacket extends DataPacket{ $this->putBool($this->respawn); } - public function handle(NetworkSession $session) : bool{ - return $session->handleChangeDimension($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleChangeDimension($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/ChunkRadiusUpdatedPacket.php b/src/pocketmine/network/mcpe/protocol/ChunkRadiusUpdatedPacket.php index 231028525..cf6ec6ef8 100644 --- a/src/pocketmine/network/mcpe/protocol/ChunkRadiusUpdatedPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ChunkRadiusUpdatedPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class ChunkRadiusUpdatedPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::CHUNK_RADIUS_UPDATED_PACKET; @@ -42,7 +42,7 @@ class ChunkRadiusUpdatedPacket extends DataPacket{ $this->putVarInt($this->radius); } - public function handle(NetworkSession $session) : bool{ - return $session->handleChunkRadiusUpdated($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleChunkRadiusUpdated($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/ClientToServerHandshakePacket.php b/src/pocketmine/network/mcpe/protocol/ClientToServerHandshakePacket.php index c6a386ae1..0e42af7bb 100644 --- a/src/pocketmine/network/mcpe/protocol/ClientToServerHandshakePacket.php +++ b/src/pocketmine/network/mcpe/protocol/ClientToServerHandshakePacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class ClientToServerHandshakePacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::CLIENT_TO_SERVER_HANDSHAKE_PACKET; @@ -43,7 +43,7 @@ class ClientToServerHandshakePacket extends DataPacket{ //No payload } - public function handle(NetworkSession $session) : bool{ - return $session->handleClientToServerHandshake($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleClientToServerHandshake($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/ClientboundMapItemDataPacket.php b/src/pocketmine/network/mcpe/protocol/ClientboundMapItemDataPacket.php index fb20e9dea..48b1695dd 100644 --- a/src/pocketmine/network/mcpe/protocol/ClientboundMapItemDataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ClientboundMapItemDataPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\network\mcpe\protocol\types\DimensionIds; use pocketmine\network\mcpe\protocol\types\MapTrackedObject; use pocketmine\utils\Color; @@ -194,7 +194,7 @@ class ClientboundMapItemDataPacket extends DataPacket{ } } - public function handle(NetworkSession $session) : bool{ - return $session->handleClientboundMapItemData($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleClientboundMapItemData($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/CommandBlockUpdatePacket.php b/src/pocketmine/network/mcpe/protocol/CommandBlockUpdatePacket.php index a0d8de69b..d3c5a607d 100644 --- a/src/pocketmine/network/mcpe/protocol/CommandBlockUpdatePacket.php +++ b/src/pocketmine/network/mcpe/protocol/CommandBlockUpdatePacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class CommandBlockUpdatePacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::COMMAND_BLOCK_UPDATE_PACKET; @@ -99,7 +99,7 @@ class CommandBlockUpdatePacket extends DataPacket{ $this->putBool($this->shouldTrackOutput); } - public function handle(NetworkSession $session) : bool{ - return $session->handleCommandBlockUpdate($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleCommandBlockUpdate($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/CommandOutputPacket.php b/src/pocketmine/network/mcpe/protocol/CommandOutputPacket.php index 5d4cbb99a..e60914b13 100644 --- a/src/pocketmine/network/mcpe/protocol/CommandOutputPacket.php +++ b/src/pocketmine/network/mcpe/protocol/CommandOutputPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\network\mcpe\protocol\types\CommandOriginData; use pocketmine\network\mcpe\protocol\types\CommandOutputMessage; @@ -95,7 +95,7 @@ class CommandOutputPacket extends DataPacket{ } } - public function handle(NetworkSession $session) : bool{ - return $session->handleCommandOutput($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleCommandOutput($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/CommandRequestPacket.php b/src/pocketmine/network/mcpe/protocol/CommandRequestPacket.php index f15414f12..11312d815 100644 --- a/src/pocketmine/network/mcpe/protocol/CommandRequestPacket.php +++ b/src/pocketmine/network/mcpe/protocol/CommandRequestPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\network\mcpe\protocol\types\CommandOriginData; class CommandRequestPacket extends DataPacket{ @@ -50,7 +50,7 @@ class CommandRequestPacket extends DataPacket{ $this->putBool($this->isInternal); } - public function handle(NetworkSession $session) : bool{ - return $session->handleCommandRequest($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleCommandRequest($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/ContainerClosePacket.php b/src/pocketmine/network/mcpe/protocol/ContainerClosePacket.php index f50e0a29f..679b9f92f 100644 --- a/src/pocketmine/network/mcpe/protocol/ContainerClosePacket.php +++ b/src/pocketmine/network/mcpe/protocol/ContainerClosePacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class ContainerClosePacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::CONTAINER_CLOSE_PACKET; @@ -42,7 +42,7 @@ class ContainerClosePacket extends DataPacket{ $this->putByte($this->windowId); } - public function handle(NetworkSession $session) : bool{ - return $session->handleContainerClose($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleContainerClose($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/ContainerOpenPacket.php b/src/pocketmine/network/mcpe/protocol/ContainerOpenPacket.php index 0b9f8da0c..82fd3a18f 100644 --- a/src/pocketmine/network/mcpe/protocol/ContainerOpenPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ContainerOpenPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class ContainerOpenPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::CONTAINER_OPEN_PACKET; @@ -58,7 +58,7 @@ class ContainerOpenPacket extends DataPacket{ $this->putEntityUniqueId($this->entityUniqueId); } - public function handle(NetworkSession $session) : bool{ - return $session->handleContainerOpen($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleContainerOpen($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/ContainerSetDataPacket.php b/src/pocketmine/network/mcpe/protocol/ContainerSetDataPacket.php index 1242de2d5..08a83861f 100644 --- a/src/pocketmine/network/mcpe/protocol/ContainerSetDataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ContainerSetDataPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class ContainerSetDataPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::CONTAINER_SET_DATA_PACKET; @@ -60,7 +60,7 @@ class ContainerSetDataPacket extends DataPacket{ $this->putVarInt($this->value); } - public function handle(NetworkSession $session) : bool{ - return $session->handleContainerSetData($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleContainerSetData($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/CraftingDataPacket.php b/src/pocketmine/network/mcpe/protocol/CraftingDataPacket.php index 94dc2e12b..08fac729f 100644 --- a/src/pocketmine/network/mcpe/protocol/CraftingDataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/CraftingDataPacket.php @@ -30,8 +30,8 @@ use pocketmine\inventory\FurnaceRecipe; use pocketmine\inventory\ShapedRecipe; use pocketmine\inventory\ShapelessRecipe; use pocketmine\item\Item; +use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\network\mcpe\NetworkBinaryStream; -use pocketmine\network\mcpe\NetworkSession; class CraftingDataPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::CRAFTING_DATA_PACKET; @@ -215,7 +215,7 @@ class CraftingDataPacket extends DataPacket{ $this->putBool($this->cleanRecipes); } - public function handle(NetworkSession $session) : bool{ - return $session->handleCraftingData($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleCraftingData($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/CraftingEventPacket.php b/src/pocketmine/network/mcpe/protocol/CraftingEventPacket.php index cc48a21fd..7b6332f15 100644 --- a/src/pocketmine/network/mcpe/protocol/CraftingEventPacket.php +++ b/src/pocketmine/network/mcpe/protocol/CraftingEventPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\item\Item; -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\utils\UUID; class CraftingEventPacket extends DataPacket{ @@ -81,7 +81,7 @@ class CraftingEventPacket extends DataPacket{ } } - public function handle(NetworkSession $session) : bool{ - return $session->handleCraftingEvent($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleCraftingEvent($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/DataPacket.php b/src/pocketmine/network/mcpe/protocol/DataPacket.php index 1201971d1..b30e066af 100644 --- a/src/pocketmine/network/mcpe/protocol/DataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/DataPacket.php @@ -25,8 +25,8 @@ namespace pocketmine\network\mcpe\protocol; #include +use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\network\mcpe\NetworkBinaryStream; -use pocketmine\network\mcpe\NetworkSession; use pocketmine\utils\Utils; abstract class DataPacket extends NetworkBinaryStream{ @@ -49,10 +49,6 @@ abstract class DataPacket extends NetworkBinaryStream{ return (new \ReflectionClass($this))->getShortName(); } - public function canBeBatched() : bool{ - return true; - } - public function canBeSentBeforeLogin() : bool{ return false; } @@ -109,16 +105,20 @@ abstract class DataPacket extends NetworkBinaryStream{ } /** - * Performs handling for this packet. Usually you'll want an appropriately named method in the NetworkSession for this. + * Performs handling for this packet. Usually you'll want an appropriately named method in the session handler for + * this. * - * This method returns a bool to indicate whether the packet was handled or not. If the packet was unhandled, a debug message will be logged with a hexdump of the packet. - * Typically this method returns the return value of the handler in the supplied NetworkSession. See other packets for examples how to implement this. + * This method returns a bool to indicate whether the packet was handled or not. If the packet was unhandled, a + * debug message will be logged with a hexdump of the packet. * - * @param NetworkSession $session + * Typically this method returns the return value of the handler in the supplied SessionHandler. See other packets + * for examples how to implement this. + * + * @param SessionHandler $handler * * @return bool true if the packet was handled successfully, false if not. */ - abstract public function handle(NetworkSession $session) : bool; + abstract public function handle(SessionHandler $handler) : bool; public function clean(){ $this->buffer = null; diff --git a/src/pocketmine/network/mcpe/protocol/DisconnectPacket.php b/src/pocketmine/network/mcpe/protocol/DisconnectPacket.php index e8207306f..722efbe2d 100644 --- a/src/pocketmine/network/mcpe/protocol/DisconnectPacket.php +++ b/src/pocketmine/network/mcpe/protocol/DisconnectPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class DisconnectPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::DISCONNECT_PACKET; @@ -54,7 +54,7 @@ class DisconnectPacket extends DataPacket{ } } - public function handle(NetworkSession $session) : bool{ - return $session->handleDisconnect($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleDisconnect($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/EntityEventPacket.php b/src/pocketmine/network/mcpe/protocol/EntityEventPacket.php index 5d6344b4b..b6ff4173a 100644 --- a/src/pocketmine/network/mcpe/protocol/EntityEventPacket.php +++ b/src/pocketmine/network/mcpe/protocol/EntityEventPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class EntityEventPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::ENTITY_EVENT_PACKET; @@ -102,7 +102,7 @@ class EntityEventPacket extends DataPacket{ $this->putVarInt($this->data); } - public function handle(NetworkSession $session) : bool{ - return $session->handleEntityEvent($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleEntityEvent($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/EntityFallPacket.php b/src/pocketmine/network/mcpe/protocol/EntityFallPacket.php index 490d6fd6d..4c0001df8 100644 --- a/src/pocketmine/network/mcpe/protocol/EntityFallPacket.php +++ b/src/pocketmine/network/mcpe/protocol/EntityFallPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class EntityFallPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::ENTITY_FALL_PACKET; @@ -50,7 +50,7 @@ class EntityFallPacket extends DataPacket{ $this->putBool($this->isInVoid); } - public function handle(NetworkSession $session) : bool{ - return $session->handleEntityFall($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleEntityFall($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/EntityPickRequestPacket.php b/src/pocketmine/network/mcpe/protocol/EntityPickRequestPacket.php index 8bb6b156d..f2d1a89aa 100644 --- a/src/pocketmine/network/mcpe/protocol/EntityPickRequestPacket.php +++ b/src/pocketmine/network/mcpe/protocol/EntityPickRequestPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class EntityPickRequestPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::ENTITY_PICK_REQUEST_PACKET; @@ -45,7 +45,7 @@ class EntityPickRequestPacket extends DataPacket{ $this->putByte($this->hotbarSlot); } - public function handle(NetworkSession $session) : bool{ - return $session->handleEntityPickRequest($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleEntityPickRequest($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/EventPacket.php b/src/pocketmine/network/mcpe/protocol/EventPacket.php index d5ce93c83..bcf4f71e5 100644 --- a/src/pocketmine/network/mcpe/protocol/EventPacket.php +++ b/src/pocketmine/network/mcpe/protocol/EventPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class EventPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::EVENT_PACKET; @@ -64,7 +64,7 @@ class EventPacket extends DataPacket{ //TODO: also nice confusing mess } - public function handle(NetworkSession $session) : bool{ - return $session->handleEvent($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleEvent($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/ExplodePacket.php b/src/pocketmine/network/mcpe/protocol/ExplodePacket.php index 8740d2896..3ac3cbbd7 100644 --- a/src/pocketmine/network/mcpe/protocol/ExplodePacket.php +++ b/src/pocketmine/network/mcpe/protocol/ExplodePacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\math\Vector3; -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class ExplodePacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::EXPLODE_PACKET; @@ -66,7 +66,7 @@ class ExplodePacket extends DataPacket{ } } - public function handle(NetworkSession $session) : bool{ - return $session->handleExplode($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleExplode($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/FullChunkDataPacket.php b/src/pocketmine/network/mcpe/protocol/FullChunkDataPacket.php index 549726794..f1528d161 100644 --- a/src/pocketmine/network/mcpe/protocol/FullChunkDataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/FullChunkDataPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class FullChunkDataPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::FULL_CHUNK_DATA_PACKET; @@ -50,7 +50,7 @@ class FullChunkDataPacket extends DataPacket{ $this->putString($this->data); } - public function handle(NetworkSession $session) : bool{ - return $session->handleFullChunkData($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleFullChunkData($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/GameRulesChangedPacket.php b/src/pocketmine/network/mcpe/protocol/GameRulesChangedPacket.php index c7865588e..a807e5cae 100644 --- a/src/pocketmine/network/mcpe/protocol/GameRulesChangedPacket.php +++ b/src/pocketmine/network/mcpe/protocol/GameRulesChangedPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class GameRulesChangedPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::GAME_RULES_CHANGED_PACKET; @@ -41,7 +41,7 @@ class GameRulesChangedPacket extends DataPacket{ $this->putGameRules($this->gameRules); } - public function handle(NetworkSession $session) : bool{ - return $session->handleGameRulesChanged($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleGameRulesChanged($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/GuiDataPickItemPacket.php b/src/pocketmine/network/mcpe/protocol/GuiDataPickItemPacket.php index 834159552..4b2034bd4 100644 --- a/src/pocketmine/network/mcpe/protocol/GuiDataPickItemPacket.php +++ b/src/pocketmine/network/mcpe/protocol/GuiDataPickItemPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class GuiDataPickItemPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::GUI_DATA_PICK_ITEM_PACKET; @@ -41,7 +41,7 @@ class GuiDataPickItemPacket extends DataPacket{ $this->putLInt($this->hotbarSlot); } - public function handle(NetworkSession $session) : bool{ - return $session->handleGuiDataPickItem($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleGuiDataPickItem($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/HurtArmorPacket.php b/src/pocketmine/network/mcpe/protocol/HurtArmorPacket.php index ba557a2b2..e55a7638d 100644 --- a/src/pocketmine/network/mcpe/protocol/HurtArmorPacket.php +++ b/src/pocketmine/network/mcpe/protocol/HurtArmorPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class HurtArmorPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::HURT_ARMOR_PACKET; @@ -42,7 +42,7 @@ class HurtArmorPacket extends DataPacket{ $this->putVarInt($this->health); } - public function handle(NetworkSession $session) : bool{ - return $session->handleHurtArmor($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleHurtArmor($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/InteractPacket.php b/src/pocketmine/network/mcpe/protocol/InteractPacket.php index eea2d30f1..184b583b8 100644 --- a/src/pocketmine/network/mcpe/protocol/InteractPacket.php +++ b/src/pocketmine/network/mcpe/protocol/InteractPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class InteractPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::INTERACT_PACKET; @@ -71,7 +71,7 @@ class InteractPacket extends DataPacket{ } } - public function handle(NetworkSession $session) : bool{ - return $session->handleInteract($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleInteract($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/InventoryContentPacket.php b/src/pocketmine/network/mcpe/protocol/InventoryContentPacket.php index bb6e6eebc..bf37bf964 100644 --- a/src/pocketmine/network/mcpe/protocol/InventoryContentPacket.php +++ b/src/pocketmine/network/mcpe/protocol/InventoryContentPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\item\Item; -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class InventoryContentPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::INVENTORY_CONTENT_PACKET; @@ -52,7 +52,7 @@ class InventoryContentPacket extends DataPacket{ } } - public function handle(NetworkSession $session) : bool{ - return $session->handleInventoryContent($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleInventoryContent($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/InventorySlotPacket.php b/src/pocketmine/network/mcpe/protocol/InventorySlotPacket.php index 2eff470d4..f6bf66435 100644 --- a/src/pocketmine/network/mcpe/protocol/InventorySlotPacket.php +++ b/src/pocketmine/network/mcpe/protocol/InventorySlotPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\item\Item; -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class InventorySlotPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::INVENTORY_SLOT_PACKET; @@ -50,7 +50,7 @@ class InventorySlotPacket extends DataPacket{ $this->putSlot($this->item); } - public function handle(NetworkSession $session) : bool{ - return $session->handleInventorySlot($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleInventorySlot($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/InventoryTransactionPacket.php b/src/pocketmine/network/mcpe/protocol/InventoryTransactionPacket.php index 90d09bc32..e6f57ac27 100644 --- a/src/pocketmine/network/mcpe/protocol/InventoryTransactionPacket.php +++ b/src/pocketmine/network/mcpe/protocol/InventoryTransactionPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\network\mcpe\protocol\types\NetworkInventoryAction; class InventoryTransactionPacket extends DataPacket{ @@ -151,7 +151,7 @@ class InventoryTransactionPacket extends DataPacket{ } } - public function handle(NetworkSession $session) : bool{ - return $session->handleInventoryTransaction($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleInventoryTransaction($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/ItemFrameDropItemPacket.php b/src/pocketmine/network/mcpe/protocol/ItemFrameDropItemPacket.php index 989c49080..2b16febee 100644 --- a/src/pocketmine/network/mcpe/protocol/ItemFrameDropItemPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ItemFrameDropItemPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class ItemFrameDropItemPacket extends DataPacket{ @@ -46,7 +46,7 @@ class ItemFrameDropItemPacket extends DataPacket{ $this->putBlockPosition($this->x, $this->y, $this->z); } - public function handle(NetworkSession $session) : bool{ - return $session->handleItemFrameDropItem($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleItemFrameDropItem($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/LabTablePacket.php b/src/pocketmine/network/mcpe/protocol/LabTablePacket.php index f5d6f4f93..3291a7dae 100644 --- a/src/pocketmine/network/mcpe/protocol/LabTablePacket.php +++ b/src/pocketmine/network/mcpe/protocol/LabTablePacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class LabTablePacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::LAB_TABLE_PACKET; @@ -55,7 +55,7 @@ class LabTablePacket extends DataPacket{ $this->putByte($this->reactionType); } - public function handle(NetworkSession $session) : bool{ - return $session->handleLabTable($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleLabTable($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/LevelEventPacket.php b/src/pocketmine/network/mcpe/protocol/LevelEventPacket.php index a0f9fd92e..01f422f81 100644 --- a/src/pocketmine/network/mcpe/protocol/LevelEventPacket.php +++ b/src/pocketmine/network/mcpe/protocol/LevelEventPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\math\Vector3; -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class LevelEventPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::LEVEL_EVENT_PACKET; @@ -130,7 +130,7 @@ class LevelEventPacket extends DataPacket{ $this->putVarInt($this->data); } - public function handle(NetworkSession $session) : bool{ - return $session->handleLevelEvent($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleLevelEvent($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/LevelSoundEventPacket.php b/src/pocketmine/network/mcpe/protocol/LevelSoundEventPacket.php index f9e330dd0..c98dbf2d0 100644 --- a/src/pocketmine/network/mcpe/protocol/LevelSoundEventPacket.php +++ b/src/pocketmine/network/mcpe/protocol/LevelSoundEventPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\math\Vector3; -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class LevelSoundEventPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::LEVEL_SOUND_EVENT_PACKET; @@ -275,7 +275,7 @@ class LevelSoundEventPacket extends DataPacket{ $this->putBool($this->disableRelativeVolume); } - public function handle(NetworkSession $session) : bool{ - return $session->handleLevelSoundEvent($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleLevelSoundEvent($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/LoginPacket.php b/src/pocketmine/network/mcpe/protocol/LoginPacket.php index 60d28dbac..d6aaff9eb 100644 --- a/src/pocketmine/network/mcpe/protocol/LoginPacket.php +++ b/src/pocketmine/network/mcpe/protocol/LoginPacket.php @@ -26,7 +26,8 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\entity\Skin; +use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\utils\BinaryStream; use pocketmine\utils\MainLogger; use pocketmine\utils\Utils; @@ -52,6 +53,8 @@ class LoginPacket extends DataPacket{ public $serverAddress; /** @var string */ public $locale; + /** @var Skin|null */ + public $skin; /** @var array (the "chain" index contains one or more JWTs) */ public $chainData = []; @@ -136,14 +139,22 @@ class LoginPacket extends DataPacket{ $this->clientId = $this->clientData["ClientRandomId"] ?? null; $this->serverAddress = $this->clientData["ServerAddress"] ?? null; - $this->locale = $this->clientData["LanguageCode"] ?? null; + $this->locale = $this->clientData["LanguageCode"] ?? "en_US"; + + $this->skin = new Skin( + $this->clientData["SkinId"] ?? "", + base64_decode($this->clientData["SkinData"] ?? ""), + base64_decode($this->clientData["CapeData"] ?? ""), + $this->clientData["SkinGeometryName"] ?? "", + base64_decode($this->clientData["SkinGeometry"] ?? "") + ); } protected function encodePayload() : void{ //TODO } - public function handle(NetworkSession $session) : bool{ - return $session->handleLogin($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleLogin($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/MapInfoRequestPacket.php b/src/pocketmine/network/mcpe/protocol/MapInfoRequestPacket.php index 68b2a5d64..04199d698 100644 --- a/src/pocketmine/network/mcpe/protocol/MapInfoRequestPacket.php +++ b/src/pocketmine/network/mcpe/protocol/MapInfoRequestPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class MapInfoRequestPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::MAP_INFO_REQUEST_PACKET; @@ -43,7 +43,7 @@ class MapInfoRequestPacket extends DataPacket{ $this->putEntityUniqueId($this->mapId); } - public function handle(NetworkSession $session) : bool{ - return $session->handleMapInfoRequest($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleMapInfoRequest($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/MobArmorEquipmentPacket.php b/src/pocketmine/network/mcpe/protocol/MobArmorEquipmentPacket.php index 53131172d..214b73f83 100644 --- a/src/pocketmine/network/mcpe/protocol/MobArmorEquipmentPacket.php +++ b/src/pocketmine/network/mcpe/protocol/MobArmorEquipmentPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\item\Item; -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class MobArmorEquipmentPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::MOB_ARMOR_EQUIPMENT_PACKET; @@ -51,7 +51,7 @@ class MobArmorEquipmentPacket extends DataPacket{ } } - public function handle(NetworkSession $session) : bool{ - return $session->handleMobArmorEquipment($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleMobArmorEquipment($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/MobEffectPacket.php b/src/pocketmine/network/mcpe/protocol/MobEffectPacket.php index ccb43c535..f95c5a098 100644 --- a/src/pocketmine/network/mcpe/protocol/MobEffectPacket.php +++ b/src/pocketmine/network/mcpe/protocol/MobEffectPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class MobEffectPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::MOB_EFFECT_PACKET; @@ -66,7 +66,7 @@ class MobEffectPacket extends DataPacket{ $this->putVarInt($this->duration); } - public function handle(NetworkSession $session) : bool{ - return $session->handleMobEffect($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleMobEffect($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/MobEquipmentPacket.php b/src/pocketmine/network/mcpe/protocol/MobEquipmentPacket.php index 428f25b4b..21661c6c4 100644 --- a/src/pocketmine/network/mcpe/protocol/MobEquipmentPacket.php +++ b/src/pocketmine/network/mcpe/protocol/MobEquipmentPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\item\Item; -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class MobEquipmentPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::MOB_EQUIPMENT_PACKET; @@ -59,7 +59,7 @@ class MobEquipmentPacket extends DataPacket{ $this->putByte($this->windowId); } - public function handle(NetworkSession $session) : bool{ - return $session->handleMobEquipment($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleMobEquipment($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/ModalFormRequestPacket.php b/src/pocketmine/network/mcpe/protocol/ModalFormRequestPacket.php index bc6fc0b24..92cc5d871 100644 --- a/src/pocketmine/network/mcpe/protocol/ModalFormRequestPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ModalFormRequestPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class ModalFormRequestPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::MODAL_FORM_REQUEST_PACKET; @@ -45,7 +45,7 @@ class ModalFormRequestPacket extends DataPacket{ $this->putString($this->formData); } - public function handle(NetworkSession $session) : bool{ - return $session->handleModalFormRequest($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleModalFormRequest($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/ModalFormResponsePacket.php b/src/pocketmine/network/mcpe/protocol/ModalFormResponsePacket.php index ca888ee96..9300507c6 100644 --- a/src/pocketmine/network/mcpe/protocol/ModalFormResponsePacket.php +++ b/src/pocketmine/network/mcpe/protocol/ModalFormResponsePacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class ModalFormResponsePacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::MODAL_FORM_RESPONSE_PACKET; @@ -45,7 +45,7 @@ class ModalFormResponsePacket extends DataPacket{ $this->putString($this->formData); } - public function handle(NetworkSession $session) : bool{ - return $session->handleModalFormResponse($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleModalFormResponse($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/MoveEntityAbsolutePacket.php b/src/pocketmine/network/mcpe/protocol/MoveEntityAbsolutePacket.php index 0d02d2dc2..34c1d1eab 100644 --- a/src/pocketmine/network/mcpe/protocol/MoveEntityAbsolutePacket.php +++ b/src/pocketmine/network/mcpe/protocol/MoveEntityAbsolutePacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\math\Vector3; -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class MoveEntityAbsolutePacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::MOVE_ENTITY_ABSOLUTE_PACKET; @@ -66,7 +66,7 @@ class MoveEntityAbsolutePacket extends DataPacket{ $this->putByteRotation($this->zRot); } - public function handle(NetworkSession $session) : bool{ - return $session->handleMoveEntityAbsolute($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleMoveEntityAbsolute($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/MoveEntityDeltaPacket.php b/src/pocketmine/network/mcpe/protocol/MoveEntityDeltaPacket.php index 134fb82c5..906cd6669 100644 --- a/src/pocketmine/network/mcpe/protocol/MoveEntityDeltaPacket.php +++ b/src/pocketmine/network/mcpe/protocol/MoveEntityDeltaPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class MoveEntityDeltaPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::MOVE_ENTITY_DELTA_PACKET; @@ -98,7 +98,7 @@ class MoveEntityDeltaPacket extends DataPacket{ $this->maybeWriteRotation(self::FLAG_HAS_ROT_Z, $this->zRot); } - public function handle(NetworkSession $session) : bool{ - return $session->handleMoveEntityDelta($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleMoveEntityDelta($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/MovePlayerPacket.php b/src/pocketmine/network/mcpe/protocol/MovePlayerPacket.php index cf1447011..24e998390 100644 --- a/src/pocketmine/network/mcpe/protocol/MovePlayerPacket.php +++ b/src/pocketmine/network/mcpe/protocol/MovePlayerPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\math\Vector3; -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class MovePlayerPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::MOVE_PLAYER_PACKET; @@ -88,7 +88,7 @@ class MovePlayerPacket extends DataPacket{ } } - public function handle(NetworkSession $session) : bool{ - return $session->handleMovePlayer($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleMovePlayer($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/NpcRequestPacket.php b/src/pocketmine/network/mcpe/protocol/NpcRequestPacket.php index 3a61b5541..babe74f6d 100644 --- a/src/pocketmine/network/mcpe/protocol/NpcRequestPacket.php +++ b/src/pocketmine/network/mcpe/protocol/NpcRequestPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class NpcRequestPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::NPC_REQUEST_PACKET; @@ -53,7 +53,7 @@ class NpcRequestPacket extends DataPacket{ $this->putByte($this->actionType); } - public function handle(NetworkSession $session) : bool{ - return $session->handleNpcRequest($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleNpcRequest($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/PacketPool.php b/src/pocketmine/network/mcpe/protocol/PacketPool.php index 962932f1a..88f6b0c0a 100644 --- a/src/pocketmine/network/mcpe/protocol/PacketPool.php +++ b/src/pocketmine/network/mcpe/protocol/PacketPool.php @@ -23,6 +23,8 @@ declare(strict_types=1); namespace pocketmine\network\mcpe\protocol; +use pocketmine\utils\Binary; + class PacketPool{ /** @var \SplFixedArray */ protected static $pool = null; @@ -30,7 +32,6 @@ class PacketPool{ public static function init() : void{ static::$pool = new \SplFixedArray(256); - //Normal packets static::registerPacket(new LoginPacket()); static::registerPacket(new PlayStatusPacket()); static::registerPacket(new ServerToClientHandshakePacket()); @@ -143,8 +144,6 @@ class PacketPool{ static::registerPacket(new UpdateBlockSyncedPacket()); static::registerPacket(new MoveEntityDeltaPacket()); static::registerPacket(new SetLocalPlayerAsInitializedPacket()); - - static::registerPacket(new BatchPacket()); } /** @@ -167,8 +166,9 @@ class PacketPool{ * @return DataPacket */ public static function getPacket(string $buffer) : DataPacket{ - $pk = static::getPacketById(ord($buffer{0})); - $pk->setBuffer($buffer); + $offset = 0; + $pk = static::getPacketById(Binary::readUnsignedVarInt($buffer, $offset)); + $pk->setBuffer($buffer, $offset); return $pk; } diff --git a/src/pocketmine/network/mcpe/protocol/PhotoTransferPacket.php b/src/pocketmine/network/mcpe/protocol/PhotoTransferPacket.php index 75b6f89f7..ce4f0d7c5 100644 --- a/src/pocketmine/network/mcpe/protocol/PhotoTransferPacket.php +++ b/src/pocketmine/network/mcpe/protocol/PhotoTransferPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class PhotoTransferPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::PHOTO_TRANSFER_PACKET; @@ -49,7 +49,7 @@ class PhotoTransferPacket extends DataPacket{ $this->putString($this->bookId); } - public function handle(NetworkSession $session) : bool{ - return $session->handlePhotoTransfer($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handlePhotoTransfer($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/PlaySoundPacket.php b/src/pocketmine/network/mcpe/protocol/PlaySoundPacket.php index 0460a3efc..27aa677b2 100644 --- a/src/pocketmine/network/mcpe/protocol/PlaySoundPacket.php +++ b/src/pocketmine/network/mcpe/protocol/PlaySoundPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class PlaySoundPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::PLAY_SOUND_PACKET; @@ -62,7 +62,7 @@ class PlaySoundPacket extends DataPacket{ $this->putLFloat($this->pitch); } - public function handle(NetworkSession $session) : bool{ - return $session->handlePlaySound($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handlePlaySound($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/PlayStatusPacket.php b/src/pocketmine/network/mcpe/protocol/PlayStatusPacket.php index 7a89018c0..839e66b3a 100644 --- a/src/pocketmine/network/mcpe/protocol/PlayStatusPacket.php +++ b/src/pocketmine/network/mcpe/protocol/PlayStatusPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class PlayStatusPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::PLAY_STATUS_PACKET; @@ -69,7 +69,7 @@ class PlayStatusPacket extends DataPacket{ $this->putInt($this->status); } - public function handle(NetworkSession $session) : bool{ - return $session->handlePlayStatus($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handlePlayStatus($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/PlayerActionPacket.php b/src/pocketmine/network/mcpe/protocol/PlayerActionPacket.php index 3a16a783b..92254d75b 100644 --- a/src/pocketmine/network/mcpe/protocol/PlayerActionPacket.php +++ b/src/pocketmine/network/mcpe/protocol/PlayerActionPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class PlayerActionPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::PLAYER_ACTION_PACKET; @@ -84,7 +84,7 @@ class PlayerActionPacket extends DataPacket{ $this->putVarInt($this->face); } - public function handle(NetworkSession $session) : bool{ - return $session->handlePlayerAction($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handlePlayerAction($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/PlayerHotbarPacket.php b/src/pocketmine/network/mcpe/protocol/PlayerHotbarPacket.php index b541128be..ffcacbb66 100644 --- a/src/pocketmine/network/mcpe/protocol/PlayerHotbarPacket.php +++ b/src/pocketmine/network/mcpe/protocol/PlayerHotbarPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\network\mcpe\protocol\types\ContainerIds; /** @@ -53,7 +53,7 @@ class PlayerHotbarPacket extends DataPacket{ $this->putBool($this->selectHotbarSlot); } - public function handle(NetworkSession $session) : bool{ - return $session->handlePlayerHotbar($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handlePlayerHotbar($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/PlayerInputPacket.php b/src/pocketmine/network/mcpe/protocol/PlayerInputPacket.php index 8664e92eb..a08eae9b8 100644 --- a/src/pocketmine/network/mcpe/protocol/PlayerInputPacket.php +++ b/src/pocketmine/network/mcpe/protocol/PlayerInputPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class PlayerInputPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::PLAYER_INPUT_PACKET; @@ -54,7 +54,7 @@ class PlayerInputPacket extends DataPacket{ $this->putBool($this->sneaking); } - public function handle(NetworkSession $session) : bool{ - return $session->handlePlayerInput($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handlePlayerInput($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/PlayerListPacket.php b/src/pocketmine/network/mcpe/protocol/PlayerListPacket.php index ba854d8b9..2027068fa 100644 --- a/src/pocketmine/network/mcpe/protocol/PlayerListPacket.php +++ b/src/pocketmine/network/mcpe/protocol/PlayerListPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\entity\Skin; -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\network\mcpe\protocol\types\PlayerListEntry; class PlayerListPacket extends DataPacket{ @@ -105,7 +105,7 @@ class PlayerListPacket extends DataPacket{ } } - public function handle(NetworkSession $session) : bool{ - return $session->handlePlayerList($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handlePlayerList($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/PlayerSkinPacket.php b/src/pocketmine/network/mcpe/protocol/PlayerSkinPacket.php index 64a9b67c5..7a2fb964f 100644 --- a/src/pocketmine/network/mcpe/protocol/PlayerSkinPacket.php +++ b/src/pocketmine/network/mcpe/protocol/PlayerSkinPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\entity\Skin; -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\utils\UUID; class PlayerSkinPacket extends DataPacket{ @@ -68,7 +68,7 @@ class PlayerSkinPacket extends DataPacket{ $this->putString($this->skin->getGeometryData()); } - public function handle(NetworkSession $session) : bool{ - return $session->handlePlayerSkin($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handlePlayerSkin($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/PurchaseReceiptPacket.php b/src/pocketmine/network/mcpe/protocol/PurchaseReceiptPacket.php index e841fed93..071468a37 100644 --- a/src/pocketmine/network/mcpe/protocol/PurchaseReceiptPacket.php +++ b/src/pocketmine/network/mcpe/protocol/PurchaseReceiptPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class PurchaseReceiptPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::PURCHASE_RECEIPT_PACKET; @@ -47,7 +47,7 @@ class PurchaseReceiptPacket extends DataPacket{ } } - public function handle(NetworkSession $session) : bool{ - return $session->handlePurchaseReceipt($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handlePurchaseReceipt($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/RemoveEntityPacket.php b/src/pocketmine/network/mcpe/protocol/RemoveEntityPacket.php index 856b9b211..9925679e5 100644 --- a/src/pocketmine/network/mcpe/protocol/RemoveEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/RemoveEntityPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class RemoveEntityPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::REMOVE_ENTITY_PACKET; @@ -42,7 +42,7 @@ class RemoveEntityPacket extends DataPacket{ $this->putEntityUniqueId($this->entityUniqueId); } - public function handle(NetworkSession $session) : bool{ - return $session->handleRemoveEntity($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleRemoveEntity($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/RemoveObjectivePacket.php b/src/pocketmine/network/mcpe/protocol/RemoveObjectivePacket.php index 25dd8298b..3889f3b79 100644 --- a/src/pocketmine/network/mcpe/protocol/RemoveObjectivePacket.php +++ b/src/pocketmine/network/mcpe/protocol/RemoveObjectivePacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class RemoveObjectivePacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::REMOVE_OBJECTIVE_PACKET; @@ -41,7 +41,7 @@ class RemoveObjectivePacket extends DataPacket{ $this->putString($this->objectiveName); } - public function handle(NetworkSession $session) : bool{ - return $session->handleRemoveObjective($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleRemoveObjective($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/RequestChunkRadiusPacket.php b/src/pocketmine/network/mcpe/protocol/RequestChunkRadiusPacket.php index 3cb552b6b..37cc96ee9 100644 --- a/src/pocketmine/network/mcpe/protocol/RequestChunkRadiusPacket.php +++ b/src/pocketmine/network/mcpe/protocol/RequestChunkRadiusPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class RequestChunkRadiusPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::REQUEST_CHUNK_RADIUS_PACKET; @@ -42,7 +42,7 @@ class RequestChunkRadiusPacket extends DataPacket{ $this->putVarInt($this->radius); } - public function handle(NetworkSession $session) : bool{ - return $session->handleRequestChunkRadius($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleRequestChunkRadius($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/ResourcePackChunkDataPacket.php b/src/pocketmine/network/mcpe/protocol/ResourcePackChunkDataPacket.php index 6f51d6adf..529d81f11 100644 --- a/src/pocketmine/network/mcpe/protocol/ResourcePackChunkDataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ResourcePackChunkDataPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class ResourcePackChunkDataPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_CHUNK_DATA_PACKET; @@ -56,7 +56,7 @@ class ResourcePackChunkDataPacket extends DataPacket{ $this->put($this->data); } - public function handle(NetworkSession $session) : bool{ - return $session->handleResourcePackChunkData($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleResourcePackChunkData($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/ResourcePackChunkRequestPacket.php b/src/pocketmine/network/mcpe/protocol/ResourcePackChunkRequestPacket.php index 4d17634ed..8d6d0188e 100644 --- a/src/pocketmine/network/mcpe/protocol/ResourcePackChunkRequestPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ResourcePackChunkRequestPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class ResourcePackChunkRequestPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_CHUNK_REQUEST_PACKET; @@ -47,7 +47,7 @@ class ResourcePackChunkRequestPacket extends DataPacket{ $this->putLInt($this->chunkIndex); } - public function handle(NetworkSession $session) : bool{ - return $session->handleResourcePackChunkRequest($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleResourcePackChunkRequest($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/ResourcePackClientResponsePacket.php b/src/pocketmine/network/mcpe/protocol/ResourcePackClientResponsePacket.php index 1d1b2c3fa..5b560e1e8 100644 --- a/src/pocketmine/network/mcpe/protocol/ResourcePackClientResponsePacket.php +++ b/src/pocketmine/network/mcpe/protocol/ResourcePackClientResponsePacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class ResourcePackClientResponsePacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_CLIENT_RESPONSE_PACKET; @@ -57,7 +57,7 @@ class ResourcePackClientResponsePacket extends DataPacket{ } } - public function handle(NetworkSession $session) : bool{ - return $session->handleResourcePackClientResponse($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleResourcePackClientResponse($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/ResourcePackDataInfoPacket.php b/src/pocketmine/network/mcpe/protocol/ResourcePackDataInfoPacket.php index 777cc8e77..ba3d4a290 100644 --- a/src/pocketmine/network/mcpe/protocol/ResourcePackDataInfoPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ResourcePackDataInfoPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class ResourcePackDataInfoPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_DATA_INFO_PACKET; @@ -59,7 +59,7 @@ class ResourcePackDataInfoPacket extends DataPacket{ $this->putString($this->sha256); } - public function handle(NetworkSession $session) : bool{ - return $session->handleResourcePackDataInfo($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleResourcePackDataInfo($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/ResourcePackStackPacket.php b/src/pocketmine/network/mcpe/protocol/ResourcePackStackPacket.php index 319528e44..58493fd76 100644 --- a/src/pocketmine/network/mcpe/protocol/ResourcePackStackPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ResourcePackStackPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\resourcepacks\ResourcePack; class ResourcePackStackPacket extends DataPacket{ @@ -76,7 +76,7 @@ class ResourcePackStackPacket extends DataPacket{ } } - public function handle(NetworkSession $session) : bool{ - return $session->handleResourcePackStack($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleResourcePackStack($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/ResourcePacksInfoPacket.php b/src/pocketmine/network/mcpe/protocol/ResourcePacksInfoPacket.php index e6af50106..8b7535591 100644 --- a/src/pocketmine/network/mcpe/protocol/ResourcePacksInfoPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ResourcePacksInfoPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\resourcepacks\ResourcePack; class ResourcePacksInfoPacket extends DataPacket{ @@ -81,7 +81,7 @@ class ResourcePacksInfoPacket extends DataPacket{ } } - public function handle(NetworkSession $session) : bool{ - return $session->handleResourcePacksInfo($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleResourcePacksInfo($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/RespawnPacket.php b/src/pocketmine/network/mcpe/protocol/RespawnPacket.php index d6c088ba6..7fb40ac2d 100644 --- a/src/pocketmine/network/mcpe/protocol/RespawnPacket.php +++ b/src/pocketmine/network/mcpe/protocol/RespawnPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\math\Vector3; -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class RespawnPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::RESPAWN_PACKET; @@ -43,7 +43,7 @@ class RespawnPacket extends DataPacket{ $this->putVector3($this->position); } - public function handle(NetworkSession $session) : bool{ - return $session->handleRespawn($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleRespawn($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/RiderJumpPacket.php b/src/pocketmine/network/mcpe/protocol/RiderJumpPacket.php index ca3e8df0f..f1eb66e62 100644 --- a/src/pocketmine/network/mcpe/protocol/RiderJumpPacket.php +++ b/src/pocketmine/network/mcpe/protocol/RiderJumpPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class RiderJumpPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::RIDER_JUMP_PACKET; @@ -43,7 +43,7 @@ class RiderJumpPacket extends DataPacket{ $this->putVarInt($this->jumpStrength); } - public function handle(NetworkSession $session) : bool{ - return $session->handleRiderJump($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleRiderJump($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/ServerSettingsRequestPacket.php b/src/pocketmine/network/mcpe/protocol/ServerSettingsRequestPacket.php index bccf9ed16..c8513b3d0 100644 --- a/src/pocketmine/network/mcpe/protocol/ServerSettingsRequestPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ServerSettingsRequestPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class ServerSettingsRequestPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::SERVER_SETTINGS_REQUEST_PACKET; @@ -38,7 +38,7 @@ class ServerSettingsRequestPacket extends DataPacket{ //No payload } - public function handle(NetworkSession $session) : bool{ - return $session->handleServerSettingsRequest($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleServerSettingsRequest($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/ServerSettingsResponsePacket.php b/src/pocketmine/network/mcpe/protocol/ServerSettingsResponsePacket.php index c3a5b3fb2..a1d374494 100644 --- a/src/pocketmine/network/mcpe/protocol/ServerSettingsResponsePacket.php +++ b/src/pocketmine/network/mcpe/protocol/ServerSettingsResponsePacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class ServerSettingsResponsePacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::SERVER_SETTINGS_RESPONSE_PACKET; @@ -45,7 +45,7 @@ class ServerSettingsResponsePacket extends DataPacket{ $this->putString($this->formData); } - public function handle(NetworkSession $session) : bool{ - return $session->handleServerSettingsResponse($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleServerSettingsResponse($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/ServerToClientHandshakePacket.php b/src/pocketmine/network/mcpe/protocol/ServerToClientHandshakePacket.php index b5a5defd9..c3fd0d9e6 100644 --- a/src/pocketmine/network/mcpe/protocol/ServerToClientHandshakePacket.php +++ b/src/pocketmine/network/mcpe/protocol/ServerToClientHandshakePacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class ServerToClientHandshakePacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::SERVER_TO_CLIENT_HANDSHAKE_PACKET; @@ -49,7 +49,7 @@ class ServerToClientHandshakePacket extends DataPacket{ $this->putString($this->jwt); } - public function handle(NetworkSession $session) : bool{ - return $session->handleServerToClientHandshake($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleServerToClientHandshake($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/SetCommandsEnabledPacket.php b/src/pocketmine/network/mcpe/protocol/SetCommandsEnabledPacket.php index 82f28fc88..1b4dcd1e9 100644 --- a/src/pocketmine/network/mcpe/protocol/SetCommandsEnabledPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetCommandsEnabledPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class SetCommandsEnabledPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::SET_COMMANDS_ENABLED_PACKET; @@ -42,7 +42,7 @@ class SetCommandsEnabledPacket extends DataPacket{ $this->putBool($this->enabled); } - public function handle(NetworkSession $session) : bool{ - return $session->handleSetCommandsEnabled($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleSetCommandsEnabled($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/SetDefaultGameTypePacket.php b/src/pocketmine/network/mcpe/protocol/SetDefaultGameTypePacket.php index a3adaa43f..a52f2a26b 100644 --- a/src/pocketmine/network/mcpe/protocol/SetDefaultGameTypePacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetDefaultGameTypePacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class SetDefaultGameTypePacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::SET_DEFAULT_GAME_TYPE_PACKET; @@ -41,7 +41,7 @@ class SetDefaultGameTypePacket extends DataPacket{ $this->putUnsignedVarInt($this->gamemode); } - public function handle(NetworkSession $session) : bool{ - return $session->handleSetDefaultGameType($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleSetDefaultGameType($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/SetDifficultyPacket.php b/src/pocketmine/network/mcpe/protocol/SetDifficultyPacket.php index a3f75035e..e4becdd5f 100644 --- a/src/pocketmine/network/mcpe/protocol/SetDifficultyPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetDifficultyPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class SetDifficultyPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::SET_DIFFICULTY_PACKET; @@ -42,7 +42,7 @@ class SetDifficultyPacket extends DataPacket{ $this->putUnsignedVarInt($this->difficulty); } - public function handle(NetworkSession $session) : bool{ - return $session->handleSetDifficulty($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleSetDifficulty($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/SetDisplayObjectivePacket.php b/src/pocketmine/network/mcpe/protocol/SetDisplayObjectivePacket.php index 534c66b01..3eb7b4a29 100644 --- a/src/pocketmine/network/mcpe/protocol/SetDisplayObjectivePacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetDisplayObjectivePacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class SetDisplayObjectivePacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::SET_DISPLAY_OBJECTIVE_PACKET; @@ -57,7 +57,7 @@ class SetDisplayObjectivePacket extends DataPacket{ $this->putVarInt($this->sortOrder); } - public function handle(NetworkSession $session) : bool{ - return $session->handleSetDisplayObjective($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleSetDisplayObjective($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/SetEntityDataPacket.php b/src/pocketmine/network/mcpe/protocol/SetEntityDataPacket.php index 48c483953..aa0206c96 100644 --- a/src/pocketmine/network/mcpe/protocol/SetEntityDataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetEntityDataPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class SetEntityDataPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::SET_ENTITY_DATA_PACKET; @@ -46,7 +46,7 @@ class SetEntityDataPacket extends DataPacket{ $this->putEntityMetadata($this->metadata); } - public function handle(NetworkSession $session) : bool{ - return $session->handleSetEntityData($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleSetEntityData($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/SetEntityLinkPacket.php b/src/pocketmine/network/mcpe/protocol/SetEntityLinkPacket.php index 4d695948e..577b2d1d7 100644 --- a/src/pocketmine/network/mcpe/protocol/SetEntityLinkPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetEntityLinkPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\network\mcpe\protocol\types\EntityLink; class SetEntityLinkPacket extends DataPacket{ @@ -43,7 +43,7 @@ class SetEntityLinkPacket extends DataPacket{ $this->putEntityLink($this->link); } - public function handle(NetworkSession $session) : bool{ - return $session->handleSetEntityLink($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleSetEntityLink($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/SetEntityMotionPacket.php b/src/pocketmine/network/mcpe/protocol/SetEntityMotionPacket.php index acecb5123..4d4eafe14 100644 --- a/src/pocketmine/network/mcpe/protocol/SetEntityMotionPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetEntityMotionPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\math\Vector3; -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class SetEntityMotionPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::SET_ENTITY_MOTION_PACKET; @@ -47,7 +47,7 @@ class SetEntityMotionPacket extends DataPacket{ $this->putVector3($this->motion); } - public function handle(NetworkSession $session) : bool{ - return $session->handleSetEntityMotion($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleSetEntityMotion($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/SetHealthPacket.php b/src/pocketmine/network/mcpe/protocol/SetHealthPacket.php index 736f9deca..c25f228d4 100644 --- a/src/pocketmine/network/mcpe/protocol/SetHealthPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetHealthPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class SetHealthPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::SET_HEALTH_PACKET; @@ -42,7 +42,7 @@ class SetHealthPacket extends DataPacket{ $this->putVarInt($this->health); } - public function handle(NetworkSession $session) : bool{ - return $session->handleSetHealth($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleSetHealth($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/SetLastHurtByPacket.php b/src/pocketmine/network/mcpe/protocol/SetLastHurtByPacket.php index 25cc3d9f4..5591b867a 100644 --- a/src/pocketmine/network/mcpe/protocol/SetLastHurtByPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetLastHurtByPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class SetLastHurtByPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::SET_LAST_HURT_BY_PACKET; @@ -41,7 +41,7 @@ class SetLastHurtByPacket extends DataPacket{ $this->putVarInt($this->entityTypeId); } - public function handle(NetworkSession $session) : bool{ - return $session->handleSetLastHurtBy($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleSetLastHurtBy($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/SetLocalPlayerAsInitializedPacket.php b/src/pocketmine/network/mcpe/protocol/SetLocalPlayerAsInitializedPacket.php index 46f4a00bc..9d8652a69 100644 --- a/src/pocketmine/network/mcpe/protocol/SetLocalPlayerAsInitializedPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetLocalPlayerAsInitializedPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class SetLocalPlayerAsInitializedPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::SET_LOCAL_PLAYER_AS_INITIALIZED_PACKET; @@ -41,7 +41,7 @@ class SetLocalPlayerAsInitializedPacket extends DataPacket{ $this->putEntityRuntimeId($this->entityRuntimeId); } - public function handle(NetworkSession $session) : bool{ - return $session->handleSetLocalPlayerAsInitialized($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleSetLocalPlayerAsInitialized($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/SetPlayerGameTypePacket.php b/src/pocketmine/network/mcpe/protocol/SetPlayerGameTypePacket.php index 22e88ab1d..5c8ecb914 100644 --- a/src/pocketmine/network/mcpe/protocol/SetPlayerGameTypePacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetPlayerGameTypePacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class SetPlayerGameTypePacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::SET_PLAYER_GAME_TYPE_PACKET; @@ -42,7 +42,7 @@ class SetPlayerGameTypePacket extends DataPacket{ $this->putVarInt($this->gamemode); } - public function handle(NetworkSession $session) : bool{ - return $session->handleSetPlayerGameType($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleSetPlayerGameType($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/SetScorePacket.php b/src/pocketmine/network/mcpe/protocol/SetScorePacket.php index aa36a19f5..c65fa38ab 100644 --- a/src/pocketmine/network/mcpe/protocol/SetScorePacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetScorePacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\network\mcpe\protocol\types\ScorePacketEntry; class SetScorePacket extends DataPacket{ @@ -59,7 +59,7 @@ class SetScorePacket extends DataPacket{ } } - public function handle(NetworkSession $session) : bool{ - return $session->handleSetScore($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleSetScore($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/SetSpawnPositionPacket.php b/src/pocketmine/network/mcpe/protocol/SetSpawnPositionPacket.php index 1788ca16c..4ebb0edeb 100644 --- a/src/pocketmine/network/mcpe/protocol/SetSpawnPositionPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetSpawnPositionPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class SetSpawnPositionPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::SET_SPAWN_POSITION_PACKET; @@ -57,7 +57,7 @@ class SetSpawnPositionPacket extends DataPacket{ $this->putBool($this->spawnForced); } - public function handle(NetworkSession $session) : bool{ - return $session->handleSetSpawnPosition($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleSetSpawnPosition($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/SetTimePacket.php b/src/pocketmine/network/mcpe/protocol/SetTimePacket.php index 4f72115e9..bbda12491 100644 --- a/src/pocketmine/network/mcpe/protocol/SetTimePacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetTimePacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class SetTimePacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::SET_TIME_PACKET; @@ -41,7 +41,7 @@ class SetTimePacket extends DataPacket{ $this->putVarInt($this->time); } - public function handle(NetworkSession $session) : bool{ - return $session->handleSetTime($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleSetTime($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/SetTitlePacket.php b/src/pocketmine/network/mcpe/protocol/SetTitlePacket.php index a819d0364..c793dbb32 100644 --- a/src/pocketmine/network/mcpe/protocol/SetTitlePacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetTitlePacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class SetTitlePacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::SET_TITLE_PACKET; @@ -66,7 +66,7 @@ class SetTitlePacket extends DataPacket{ $this->putVarInt($this->fadeOutTime); } - public function handle(NetworkSession $session) : bool{ - return $session->handleSetTitle($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleSetTitle($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/ShowCreditsPacket.php b/src/pocketmine/network/mcpe/protocol/ShowCreditsPacket.php index 15715e5b2..d8b325480 100644 --- a/src/pocketmine/network/mcpe/protocol/ShowCreditsPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ShowCreditsPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class ShowCreditsPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::SHOW_CREDITS_PACKET; @@ -50,7 +50,7 @@ class ShowCreditsPacket extends DataPacket{ $this->putVarInt($this->status); } - public function handle(NetworkSession $session) : bool{ - return $session->handleShowCredits($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleShowCredits($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/ShowProfilePacket.php b/src/pocketmine/network/mcpe/protocol/ShowProfilePacket.php index 4a7eaee19..afb00dcb9 100644 --- a/src/pocketmine/network/mcpe/protocol/ShowProfilePacket.php +++ b/src/pocketmine/network/mcpe/protocol/ShowProfilePacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class ShowProfilePacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::SHOW_PROFILE_PACKET; @@ -41,7 +41,7 @@ class ShowProfilePacket extends DataPacket{ $this->putString($this->xuid); } - public function handle(NetworkSession $session) : bool{ - return $session->handleShowProfile($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleShowProfile($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/ShowStoreOfferPacket.php b/src/pocketmine/network/mcpe/protocol/ShowStoreOfferPacket.php index 23ee62038..0cc39362c 100644 --- a/src/pocketmine/network/mcpe/protocol/ShowStoreOfferPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ShowStoreOfferPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class ShowStoreOfferPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::SHOW_STORE_OFFER_PACKET; @@ -45,7 +45,7 @@ class ShowStoreOfferPacket extends DataPacket{ $this->putBool($this->showAll); } - public function handle(NetworkSession $session) : bool{ - return $session->handleShowStoreOffer($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleShowStoreOffer($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/SimpleEventPacket.php b/src/pocketmine/network/mcpe/protocol/SimpleEventPacket.php index b56e13695..58d57c185 100644 --- a/src/pocketmine/network/mcpe/protocol/SimpleEventPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SimpleEventPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class SimpleEventPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::SIMPLE_EVENT_PACKET; @@ -44,7 +44,7 @@ class SimpleEventPacket extends DataPacket{ $this->putLShort($this->eventType); } - public function handle(NetworkSession $session) : bool{ - return $session->handleSimpleEvent($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleSimpleEvent($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/SpawnExperienceOrbPacket.php b/src/pocketmine/network/mcpe/protocol/SpawnExperienceOrbPacket.php index 628ef4a97..a727f066d 100644 --- a/src/pocketmine/network/mcpe/protocol/SpawnExperienceOrbPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SpawnExperienceOrbPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\math\Vector3; -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class SpawnExperienceOrbPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::SPAWN_EXPERIENCE_ORB_PACKET; @@ -47,7 +47,7 @@ class SpawnExperienceOrbPacket extends DataPacket{ $this->putVarInt($this->amount); } - public function handle(NetworkSession $session) : bool{ - return $session->handleSpawnExperienceOrb($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleSpawnExperienceOrb($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/StartGamePacket.php b/src/pocketmine/network/mcpe/protocol/StartGamePacket.php index 11d834f2c..8e958bd39 100644 --- a/src/pocketmine/network/mcpe/protocol/StartGamePacket.php +++ b/src/pocketmine/network/mcpe/protocol/StartGamePacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\math\Vector3; -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\network\mcpe\protocol\types\PlayerPermissions; class StartGamePacket extends DataPacket{ @@ -228,7 +228,7 @@ class StartGamePacket extends DataPacket{ $this->putVarInt($this->enchantmentSeed); } - public function handle(NetworkSession $session) : bool{ - return $session->handleStartGame($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleStartGame($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/StopSoundPacket.php b/src/pocketmine/network/mcpe/protocol/StopSoundPacket.php index d48d4b96f..74cdbb221 100644 --- a/src/pocketmine/network/mcpe/protocol/StopSoundPacket.php +++ b/src/pocketmine/network/mcpe/protocol/StopSoundPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class StopSoundPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::STOP_SOUND_PACKET; @@ -47,7 +47,7 @@ class StopSoundPacket extends DataPacket{ $this->putBool($this->stopAll); } - public function handle(NetworkSession $session) : bool{ - return $session->handleStopSound($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleStopSound($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/StructureBlockUpdatePacket.php b/src/pocketmine/network/mcpe/protocol/StructureBlockUpdatePacket.php index cc409bfb3..4bbad7173 100644 --- a/src/pocketmine/network/mcpe/protocol/StructureBlockUpdatePacket.php +++ b/src/pocketmine/network/mcpe/protocol/StructureBlockUpdatePacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class StructureBlockUpdatePacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::STRUCTURE_BLOCK_UPDATE_PACKET; @@ -38,7 +38,7 @@ class StructureBlockUpdatePacket extends DataPacket{ //TODO } - public function handle(NetworkSession $session) : bool{ - return $session->handleStructureBlockUpdate($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleStructureBlockUpdate($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/SubClientLoginPacket.php b/src/pocketmine/network/mcpe/protocol/SubClientLoginPacket.php index 5d1d72ab0..e29a96e77 100644 --- a/src/pocketmine/network/mcpe/protocol/SubClientLoginPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SubClientLoginPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class SubClientLoginPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::SUB_CLIENT_LOGIN_PACKET; @@ -41,7 +41,7 @@ class SubClientLoginPacket extends DataPacket{ $this->putString($this->connectionRequestData); } - public function handle(NetworkSession $session) : bool{ - return $session->handleSubClientLogin($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleSubClientLogin($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/TakeItemEntityPacket.php b/src/pocketmine/network/mcpe/protocol/TakeItemEntityPacket.php index c0e66fa7d..b5706530f 100644 --- a/src/pocketmine/network/mcpe/protocol/TakeItemEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/TakeItemEntityPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class TakeItemEntityPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::TAKE_ITEM_ENTITY_PACKET; @@ -45,7 +45,7 @@ class TakeItemEntityPacket extends DataPacket{ $this->putEntityRuntimeId($this->eid); } - public function handle(NetworkSession $session) : bool{ - return $session->handleTakeItemEntity($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleTakeItemEntity($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/TextPacket.php b/src/pocketmine/network/mcpe/protocol/TextPacket.php index 532fd28e1..4604c922c 100644 --- a/src/pocketmine/network/mcpe/protocol/TextPacket.php +++ b/src/pocketmine/network/mcpe/protocol/TextPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class TextPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::TEXT_PACKET; @@ -124,7 +124,7 @@ class TextPacket extends DataPacket{ $this->putString($this->platformChatId); } - public function handle(NetworkSession $session) : bool{ - return $session->handleText($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleText($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/TransferPacket.php b/src/pocketmine/network/mcpe/protocol/TransferPacket.php index 1bf5270c2..6e841ac0d 100644 --- a/src/pocketmine/network/mcpe/protocol/TransferPacket.php +++ b/src/pocketmine/network/mcpe/protocol/TransferPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class TransferPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::TRANSFER_PACKET; @@ -45,7 +45,7 @@ class TransferPacket extends DataPacket{ $this->putLShort($this->port); } - public function handle(NetworkSession $session) : bool{ - return $session->handleTransfer($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleTransfer($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/UnknownPacket.php b/src/pocketmine/network/mcpe/protocol/UnknownPacket.php index 3acec2287..6daf12bfb 100644 --- a/src/pocketmine/network/mcpe/protocol/UnknownPacket.php +++ b/src/pocketmine/network/mcpe/protocol/UnknownPacket.php @@ -25,7 +25,7 @@ declare(strict_types=1); namespace pocketmine\network\mcpe\protocol; -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class UnknownPacket extends DataPacket{ public const NETWORK_ID = -1; //Invalid, do not try to write this @@ -53,7 +53,7 @@ class UnknownPacket extends DataPacket{ $this->put($this->payload); } - public function handle(NetworkSession $session) : bool{ + public function handle(SessionHandler $handler) : bool{ return false; } } diff --git a/src/pocketmine/network/mcpe/protocol/UpdateAttributesPacket.php b/src/pocketmine/network/mcpe/protocol/UpdateAttributesPacket.php index d8b609557..77e1b9718 100644 --- a/src/pocketmine/network/mcpe/protocol/UpdateAttributesPacket.php +++ b/src/pocketmine/network/mcpe/protocol/UpdateAttributesPacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\entity\Attribute; -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class UpdateAttributesPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::UPDATE_ATTRIBUTES_PACKET; @@ -47,7 +47,7 @@ class UpdateAttributesPacket extends DataPacket{ $this->putAttributeList(...$this->entries); } - public function handle(NetworkSession $session) : bool{ - return $session->handleUpdateAttributes($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleUpdateAttributes($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/UpdateBlockPacket.php b/src/pocketmine/network/mcpe/protocol/UpdateBlockPacket.php index ff27e23cf..db7066328 100644 --- a/src/pocketmine/network/mcpe/protocol/UpdateBlockPacket.php +++ b/src/pocketmine/network/mcpe/protocol/UpdateBlockPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class UpdateBlockPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::UPDATE_BLOCK_PACKET; @@ -70,7 +70,7 @@ class UpdateBlockPacket extends DataPacket{ $this->putUnsignedVarInt($this->dataLayerId); } - public function handle(NetworkSession $session) : bool{ - return $session->handleUpdateBlock($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleUpdateBlock($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/UpdateBlockSyncedPacket.php b/src/pocketmine/network/mcpe/protocol/UpdateBlockSyncedPacket.php index f99bb5731..0ac93c3bf 100644 --- a/src/pocketmine/network/mcpe/protocol/UpdateBlockSyncedPacket.php +++ b/src/pocketmine/network/mcpe/protocol/UpdateBlockSyncedPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class UpdateBlockSyncedPacket extends UpdateBlockPacket{ public const NETWORK_ID = ProtocolInfo::UPDATE_BLOCK_SYNCED_PACKET; @@ -47,7 +47,7 @@ class UpdateBlockSyncedPacket extends UpdateBlockPacket{ $this->putUnsignedVarLong($this->uvarint64_2); } - public function handle(NetworkSession $session) : bool{ - return $session->handleUpdateBlockSynced($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleUpdateBlockSynced($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/UpdateEquipPacket.php b/src/pocketmine/network/mcpe/protocol/UpdateEquipPacket.php index 7a7908918..fc5ba6934 100644 --- a/src/pocketmine/network/mcpe/protocol/UpdateEquipPacket.php +++ b/src/pocketmine/network/mcpe/protocol/UpdateEquipPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class UpdateEquipPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::UPDATE_EQUIP_PACKET; @@ -57,7 +57,7 @@ class UpdateEquipPacket extends DataPacket{ $this->put($this->namedtag); } - public function handle(NetworkSession $session) : bool{ - return $session->handleUpdateEquip($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleUpdateEquip($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/UpdateTradePacket.php b/src/pocketmine/network/mcpe/protocol/UpdateTradePacket.php index a1c38553e..291d745ba 100644 --- a/src/pocketmine/network/mcpe/protocol/UpdateTradePacket.php +++ b/src/pocketmine/network/mcpe/protocol/UpdateTradePacket.php @@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\network\mcpe\protocol\types\WindowTypes; class UpdateTradePacket extends DataPacket{ @@ -78,7 +78,7 @@ class UpdateTradePacket extends DataPacket{ $this->put($this->offers); } - public function handle(NetworkSession $session) : bool{ - return $session->handleUpdateTrade($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleUpdateTrade($this); } } diff --git a/src/pocketmine/network/mcpe/protocol/WSConnectPacket.php b/src/pocketmine/network/mcpe/protocol/WSConnectPacket.php index 251407471..8619b15c8 100644 --- a/src/pocketmine/network/mcpe/protocol/WSConnectPacket.php +++ b/src/pocketmine/network/mcpe/protocol/WSConnectPacket.php @@ -25,7 +25,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; class WSConnectPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::W_S_CONNECT_PACKET; @@ -41,7 +41,7 @@ class WSConnectPacket extends DataPacket{ $this->putString($this->serverUri); } - public function handle(NetworkSession $session) : bool{ - return $session->handleWSConnect($this); + public function handle(SessionHandler $handler) : bool{ + return $handler->handleWSConnect($this); } }