From f969f3b77fe51d4e3bb5a5cfcd6cc132fbf2a4f9 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 18 Jul 2018 17:23:49 +0100 Subject: [PATCH 01/20] Flatten NetworkSession hierarchy in preparation for refactor --- src/pocketmine/Player.php | 23 +- .../network/mcpe/NetworkSession.php | 143 ++++++--- .../mcpe/PlayerNetworkSessionAdapter.php | 281 ------------------ 3 files changed, 116 insertions(+), 331 deletions(-) delete mode 100644 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 8a8e5732c..ef90720f7 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -96,7 +96,7 @@ 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; @@ -183,11 +183,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 NetworkSession */ + protected $networkSession; /** @var int */ protected $protocol = -1; @@ -714,14 +711,14 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $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); } /** * @return bool */ public function isConnected() : bool{ - return $this->sessionAdapter !== null; + return $this->networkSession !== null; } /** @@ -3032,8 +3029,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * @param DataPacket $packet */ public function handleDataPacket(DataPacket $packet){ - if($this->sessionAdapter !== null){ - $this->sessionAdapter->handleDataPacket($packet); + if($this->networkSession !== null){ + $this->networkSession->handleDataPacket($packet); } } @@ -3054,7 +3051,7 @@ 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); } /** @@ -3304,8 +3301,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ if($this->isConnected() and !$this->closed){ try{ - $this->sessionAdapter->serverDisconnect($reason, $notify); - $this->sessionAdapter = null; + $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); diff --git a/src/pocketmine/network/mcpe/NetworkSession.php b/src/pocketmine/network/mcpe/NetworkSession.php index 67265e947..d30613395 100644 --- a/src/pocketmine/network/mcpe/NetworkSession.php +++ b/src/pocketmine/network/mcpe/NetworkSession.php @@ -23,6 +23,8 @@ declare(strict_types=1); namespace pocketmine\network\mcpe; +use pocketmine\event\server\DataPacketReceiveEvent; +use pocketmine\event\server\DataPacketSendEvent; use pocketmine\network\mcpe\protocol\AddBehaviorTreePacket; use pocketmine\network\mcpe\protocol\AddEntityPacket; use pocketmine\network\mcpe\protocol\AddHangingEntityPacket; @@ -136,13 +138,74 @@ use pocketmine\network\mcpe\protocol\UpdateBlockSyncedPacket; use pocketmine\network\mcpe\protocol\UpdateEquipPacket; use pocketmine\network\mcpe\protocol\UpdateTradePacket; use pocketmine\network\mcpe\protocol\WSConnectPacket; +use pocketmine\network\NetworkInterface; +use pocketmine\Player; +use pocketmine\Server; +use pocketmine\timings\Timings; -abstract class NetworkSession{ +class NetworkSession{ - abstract public function handleDataPacket(DataPacket $packet); + + /** @var Server */ + private $server; + /** @var Player */ + private $player; + /** @var NetworkInterface */ + private $interface; + + public function __construct(Server $server, Player $player, NetworkInterface $interface){ + $this->server = $server; + $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 false; + return $this->player->handleLogin($packet); } public function handlePlayStatus(PlayStatusPacket $packet) : bool{ @@ -154,7 +217,7 @@ abstract class NetworkSession{ } public function handleClientToServerHandshake(ClientToServerHandshakePacket $packet) : bool{ - return false; + return false; //TODO } public function handleDisconnect(DisconnectPacket $packet) : bool{ @@ -170,10 +233,14 @@ abstract class NetworkSession{ } public function handleResourcePackClientResponse(ResourcePackClientResponsePacket $packet) : bool{ - return false; + return $this->player->handleResourcePackClientResponse($packet); } public function handleText(TextPacket $packet) : bool{ + if($packet->type === TextPacket::TYPE_CHAT){ + return $this->player->chat($packet->message); + } + return false; } @@ -214,7 +281,7 @@ abstract class NetworkSession{ } public function handleMovePlayer(MovePlayerPacket $packet) : bool{ - return false; + return $this->player->handleMovePlayer($packet); } public function handleRiderJump(RiderJumpPacket $packet) : bool{ @@ -234,7 +301,7 @@ abstract class NetworkSession{ } public function handleLevelSoundEvent(LevelSoundEventPacket $packet) : bool{ - return false; + return $this->player->handleLevelSoundEvent($packet); } public function handleLevelEvent(LevelEventPacket $packet) : bool{ @@ -246,7 +313,7 @@ abstract class NetworkSession{ } public function handleEntityEvent(EntityEventPacket $packet) : bool{ - return false; + return $this->player->handleEntityEvent($packet); } public function handleMobEffect(MobEffectPacket $packet) : bool{ @@ -258,35 +325,35 @@ abstract class NetworkSession{ } public function handleInventoryTransaction(InventoryTransactionPacket $packet) : bool{ - return false; + return $this->player->handleInventoryTransaction($packet); } public function handleMobEquipment(MobEquipmentPacket $packet) : bool{ - return false; + return $this->player->handleMobEquipment($packet); } public function handleMobArmorEquipment(MobArmorEquipmentPacket $packet) : bool{ - return false; + return true; //Not used } public function handleInteract(InteractPacket $packet) : bool{ - return false; + return $this->player->handleInteract($packet); } public function handleBlockPickRequest(BlockPickRequestPacket $packet) : bool{ - return false; + return $this->player->handleBlockPickRequest($packet); } public function handleEntityPickRequest(EntityPickRequestPacket $packet) : bool{ - return false; + return false; //TODO } public function handlePlayerAction(PlayerActionPacket $packet) : bool{ - return false; + return $this->player->handlePlayerAction($packet); } public function handleEntityFall(EntityFallPacket $packet) : bool{ - return false; + return true; //Not used } public function handleHurtArmor(HurtArmorPacket $packet) : bool{ @@ -314,7 +381,7 @@ abstract class NetworkSession{ } public function handleAnimate(AnimatePacket $packet) : bool{ - return false; + return $this->player->handleAnimate($packet); } public function handleRespawn(RespawnPacket $packet) : bool{ @@ -326,11 +393,11 @@ abstract class NetworkSession{ } public function handleContainerClose(ContainerClosePacket $packet) : bool{ - return false; + return $this->player->handleContainerClose($packet); } public function handlePlayerHotbar(PlayerHotbarPacket $packet) : bool{ - return false; + return true; //this packet is useless } public function handleInventoryContent(InventoryContentPacket $packet) : bool{ @@ -350,7 +417,7 @@ abstract class NetworkSession{ } public function handleCraftingEvent(CraftingEventPacket $packet) : bool{ - return false; + return true; //this is a broken useless packet, so we don't use it } public function handleGuiDataPickItem(GuiDataPickItemPacket $packet) : bool{ @@ -358,15 +425,15 @@ abstract class NetworkSession{ } public function handleAdventureSettings(AdventureSettingsPacket $packet) : bool{ - return false; + return $this->player->handleAdventureSettings($packet); } public function handleBlockEntityData(BlockEntityDataPacket $packet) : bool{ - return false; + return $this->player->handleBlockEntityData($packet); } public function handlePlayerInput(PlayerInputPacket $packet) : bool{ - return false; + return false; //TODO } public function handleFullChunkData(FullChunkDataPacket $packet) : bool{ @@ -386,7 +453,7 @@ abstract class NetworkSession{ } public function handleSetPlayerGameType(SetPlayerGameTypePacket $packet) : bool{ - return false; + return $this->player->handleSetPlayerGameType($packet); } public function handlePlayerList(PlayerListPacket $packet) : bool{ @@ -402,7 +469,7 @@ abstract class NetworkSession{ } public function handleSpawnExperienceOrb(SpawnExperienceOrbPacket $packet) : bool{ - return false; + return false; //TODO } public function handleClientboundMapItemData(ClientboundMapItemDataPacket $packet) : bool{ @@ -410,11 +477,13 @@ abstract class NetworkSession{ } public function handleMapInfoRequest(MapInfoRequestPacket $packet) : bool{ - return false; + return false; //TODO } public function handleRequestChunkRadius(RequestChunkRadiusPacket $packet) : bool{ - return false; + $this->player->setViewDistance($packet->radius); + + return true; } public function handleChunkRadiusUpdated(ChunkRadiusUpdatedPacket $packet) : bool{ @@ -422,7 +491,7 @@ abstract class NetworkSession{ } public function handleItemFrameDropItem(ItemFrameDropItemPacket $packet) : bool{ - return false; + return $this->player->handleItemFrameDropItem($packet); } public function handleGameRulesChanged(GameRulesChangedPacket $packet) : bool{ @@ -434,11 +503,11 @@ abstract class NetworkSession{ } public function handleBossEvent(BossEventPacket $packet) : bool{ - return false; + return false; //TODO } public function handleShowCredits(ShowCreditsPacket $packet) : bool{ - return false; + return false; //TODO: handle resume } public function handleAvailableCommands(AvailableCommandsPacket $packet) : bool{ @@ -446,11 +515,11 @@ abstract class NetworkSession{ } public function handleCommandRequest(CommandRequestPacket $packet) : bool{ - return false; + return $this->player->chat($packet->command); } public function handleCommandBlockUpdate(CommandBlockUpdatePacket $packet) : bool{ - return false; + return false; //TODO } public function handleCommandOutput(CommandOutputPacket $packet) : bool{ @@ -474,7 +543,7 @@ abstract class NetworkSession{ } public function handleResourcePackChunkRequest(ResourcePackChunkRequestPacket $packet) : bool{ - return false; + return $this->player->handleResourcePackChunkRequest($packet); } public function handleTransfer(TransferPacket $packet) : bool{ @@ -510,7 +579,7 @@ abstract class NetworkSession{ } public function handlePlayerSkin(PlayerSkinPacket $packet) : bool{ - return false; + return $this->player->changeSkin($packet->skin, $packet->newSkinName, $packet->oldSkinName); } public function handleSubClientLogin(SubClientLoginPacket $packet) : bool{ @@ -526,7 +595,7 @@ abstract class NetworkSession{ } public function handleBookEdit(BookEditPacket $packet) : bool{ - return false; + return $this->player->handleBookEdit($packet); } public function handleNpcRequest(NpcRequestPacket $packet) : bool{ @@ -542,11 +611,11 @@ abstract class NetworkSession{ } public function handleModalFormResponse(ModalFormResponsePacket $packet) : bool{ - return false; + return false; //TODO: GUI stuff } public function handleServerSettingsRequest(ServerSettingsRequestPacket $packet) : bool{ - return false; + return false; //TODO: GUI stuff } public function handleServerSettingsResponse(ServerSettingsResponsePacket $packet) : bool{ diff --git a/src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php b/src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php deleted file mode 100644 index bc4895bf9..000000000 --- a/src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter.php +++ /dev/null @@ -1,281 +0,0 @@ -server = $server; - $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); - } - - return false; - } - - public function handleMovePlayer(MovePlayerPacket $packet) : bool{ - return $this->player->handleMovePlayer($packet); - } - - public function handleLevelSoundEvent(LevelSoundEventPacket $packet) : bool{ - return $this->player->handleLevelSoundEvent($packet); - } - - public function handleEntityEvent(EntityEventPacket $packet) : bool{ - return $this->player->handleEntityEvent($packet); - } - - public function handleInventoryTransaction(InventoryTransactionPacket $packet) : bool{ - return $this->player->handleInventoryTransaction($packet); - } - - public function handleMobEquipment(MobEquipmentPacket $packet) : bool{ - return $this->player->handleMobEquipment($packet); - } - - public function handleMobArmorEquipment(MobArmorEquipmentPacket $packet) : bool{ - return true; //Not used - } - - public function handleInteract(InteractPacket $packet) : bool{ - return $this->player->handleInteract($packet); - } - - public function handleBlockPickRequest(BlockPickRequestPacket $packet) : bool{ - return $this->player->handleBlockPickRequest($packet); - } - - public function handleEntityPickRequest(EntityPickRequestPacket $packet) : bool{ - return false; //TODO - } - - public function handlePlayerAction(PlayerActionPacket $packet) : bool{ - return $this->player->handlePlayerAction($packet); - } - - public function handleEntityFall(EntityFallPacket $packet) : bool{ - return true; //Not used - } - - public function handleAnimate(AnimatePacket $packet) : bool{ - return $this->player->handleAnimate($packet); - } - - public function handleContainerClose(ContainerClosePacket $packet) : bool{ - return $this->player->handleContainerClose($packet); - } - - public function handlePlayerHotbar(PlayerHotbarPacket $packet) : bool{ - return true; //this packet is useless - } - - public function handleCraftingEvent(CraftingEventPacket $packet) : bool{ - return true; //this is a broken useless packet, so we don't use it - } - - public function handleAdventureSettings(AdventureSettingsPacket $packet) : bool{ - return $this->player->handleAdventureSettings($packet); - } - - public function handleBlockEntityData(BlockEntityDataPacket $packet) : bool{ - return $this->player->handleBlockEntityData($packet); - } - - public function handlePlayerInput(PlayerInputPacket $packet) : bool{ - return false; //TODO - } - - public function handleSetPlayerGameType(SetPlayerGameTypePacket $packet) : bool{ - return $this->player->handleSetPlayerGameType($packet); - } - - public function handleSpawnExperienceOrb(SpawnExperienceOrbPacket $packet) : bool{ - return false; //TODO - } - - public function handleMapInfoRequest(MapInfoRequestPacket $packet) : bool{ - return false; //TODO - } - - public function handleRequestChunkRadius(RequestChunkRadiusPacket $packet) : bool{ - $this->player->setViewDistance($packet->radius); - - return true; - } - - public function handleItemFrameDropItem(ItemFrameDropItemPacket $packet) : bool{ - return $this->player->handleItemFrameDropItem($packet); - } - - public function handleBossEvent(BossEventPacket $packet) : bool{ - return false; //TODO - } - - public function handleShowCredits(ShowCreditsPacket $packet) : bool{ - return false; //TODO: handle resume - } - - public function handleCommandRequest(CommandRequestPacket $packet) : bool{ - return $this->player->chat($packet->command); - } - - public function handleCommandBlockUpdate(CommandBlockUpdatePacket $packet) : bool{ - 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 handleBookEdit(BookEditPacket $packet) : bool{ - return $this->player->handleBookEdit($packet); - } - - public function handleModalFormResponse(ModalFormResponsePacket $packet) : bool{ - return false; //TODO: GUI stuff - } - - public function handleServerSettingsRequest(ServerSettingsRequestPacket $packet) : bool{ - return false; //TODO: GUI stuff - } -} From 85647c03bf2a90409ccba999779878b72bb07ee2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 18 Jul 2018 17:47:28 +0100 Subject: [PATCH 02/20] Move IP/port to NetworkSession --- src/pocketmine/Player.php | 23 ++++++++----------- .../network/mcpe/NetworkSession.php | 23 ++++++++++++++++++- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index ef90720f7..440869eae 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -189,11 +189,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ /** @var int */ protected $protocol = -1; - /** @var string */ - protected $ip; - /** @var int */ - protected $port; - /** * @var int * Last measurement of player's latency in milliseconds. @@ -698,8 +693,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $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); @@ -711,7 +704,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->allowMovementCheats = (bool) $this->server->getProperty("player.anti-cheat.allow-movement-cheats", false); - $this->networkSession = new NetworkSession($this->server, $this, $interface); + $this->networkSession = new NetworkSession($this->server, $this, $interface, $ip, $port); } /** @@ -806,14 +799,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(); } /** @@ -2106,8 +2099,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->server->getLogger()->info($this->getServer()->getLanguage()->translateString("pocketmine.player.logIn", [ TextFormat::AQUA . $this->username . TextFormat::WHITE, - $this->ip, - $this->port, + $this->networkSession->getIp(), + $this->networkSession->getPort(), $this->id, $this->level->getName(), round($this->x, 4), @@ -3301,6 +3294,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ if($this->isConnected() and !$this->closed){ try{ + $ip = $this->networkSession->getIp(); + $port = $this->networkSession->getPort(); $this->networkSession->serverDisconnect($reason, $notify); $this->networkSession = null; @@ -3364,8 +3359,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) ])); diff --git a/src/pocketmine/network/mcpe/NetworkSession.php b/src/pocketmine/network/mcpe/NetworkSession.php index d30613395..b54041575 100644 --- a/src/pocketmine/network/mcpe/NetworkSession.php +++ b/src/pocketmine/network/mcpe/NetworkSession.php @@ -152,11 +152,32 @@ class NetworkSession{ private $player; /** @var NetworkInterface */ private $interface; + /** @var string */ + private $ip; + /** @var int */ + private $port; - public function __construct(Server $server, Player $player, NetworkInterface $interface){ + public function __construct(Server $server, Player $player, NetworkInterface $interface, string $ip, int $port){ $this->server = $server; $this->player = $player; $this->interface = $interface; + + $this->ip = $ip; + $this->port = $port; + } + + /** + * @return string + */ + public function getIp() : string{ + return $this->ip; + } + + /** + * @return int + */ + public function getPort() : int{ + return $this->port; } public function handleDataPacket(DataPacket $packet) : void{ From bdd9a7eb52cfbeca58295d2b86bf732ed1de43ba Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 19 Jul 2018 14:52:34 +0100 Subject: [PATCH 03/20] Kill BatchPacket, clean up batching related things DataPacketSendEvent and DataPacketReceiveEvent will no longer capture BatchPackets In most places strings are now used instead of DataPackets, to remove limitations on what data can be sent to a network interface Removed CraftingManager's cyclic dependency on Server There is a lot more work to do aside from this, but this commit is intended to clean up what is necessary to fix the handling of BatchPacket. --- src/pocketmine/Player.php | 14 +- src/pocketmine/Server.php | 46 +++---- src/pocketmine/inventory/CraftingManager.php | 18 ++- src/pocketmine/level/Level.php | 5 +- src/pocketmine/network/Network.php | 3 - src/pocketmine/network/NetworkInterface.php | 11 +- .../network/mcpe/ChunkRequestTask.php | 16 +-- .../network/mcpe/CompressBatchedTask.php | 30 ++--- .../network/mcpe/NetworkCompression.php | 47 +++++++ .../network/mcpe/NetworkSession.php | 25 +++- ...ncapsulatedPacket.php => PacketStream.php} | 18 ++- .../network/mcpe/RakLibInterface.php | 47 ++----- .../network/mcpe/protocol/BatchPacket.php | 122 ------------------ .../network/mcpe/protocol/DataPacket.php | 4 - .../network/mcpe/protocol/PacketPool.php | 2 - 15 files changed, 152 insertions(+), 256 deletions(-) create mode 100644 src/pocketmine/network/mcpe/NetworkCompression.php rename src/pocketmine/network/mcpe/{CachedEncapsulatedPacket.php => PacketStream.php} (66%) delete mode 100644 src/pocketmine/network/mcpe/protocol/BatchPacket.php diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 440869eae..836545e7f 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -100,7 +100,6 @@ 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; @@ -714,6 +713,13 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return $this->networkSession !== null; } + /** + * @return NetworkSession + */ + public function getNetworkSession() : NetworkSession{ + return $this->networkSession; + } + /** * Gets the username * @return string @@ -934,7 +940,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; } @@ -942,7 +948,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){ @@ -2120,7 +2126,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->sendAllInventories(); $this->inventory->sendCreativeContents(); $this->inventory->sendHeldItem($this); - $this->dataPacket($this->server->getCraftingManager()->getCraftingDataPacket()); + $this->networkSession->getInterface()->putPacket($this, $this->server->getCraftingManager()->getCraftingDataPacket()); $this->server->addOnlinePlayer($this); $this->server->sendFullPlayerListData($this); diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index e0b920ad1..b7f1a0cc7 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, false, $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/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..461bc7440 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,14 @@ 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 + * @param Player $player + * @param string $payload + * @param bool $needACK + * @param bool $immediate * * @return int|null */ - public function putPacket(Player $player, DataPacket $packet, bool $needACK = false, bool $immediate = true) : ?int; + public function putPacket(Player $player, string $payload, bool $needACK = false, bool $immediate = true) : ?int; /** * 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 @@ +port = $port; } + public function getInterface() : NetworkInterface{ + return $this->interface; + } + /** * @return string */ @@ -180,6 +185,15 @@ class NetworkSession{ return $this->port; } + public function handleEncoded(string $payload) : void{ + //TODO: decryption if enabled + + $stream = new PacketStream(NetworkCompression::decompress($payload)); + while(!$stream->feof()){ + $this->handleDataPacket(PacketPool::getPacket($stream->getString())); + } + } + public function handleDataPacket(DataPacket $packet) : void{ $timings = Timings::getReceiveDataPacketTimings($packet); $timings->startTiming(); @@ -207,7 +221,8 @@ class NetworkSession{ return false; } - $this->interface->putPacket($this->player, $packet, false, $immediate); + //TODO: implement buffering (this is just a quick fix) + $this->server->batchPackets([$this->player], [$packet], true, $immediate); return true; }finally{ diff --git a/src/pocketmine/network/mcpe/CachedEncapsulatedPacket.php b/src/pocketmine/network/mcpe/PacketStream.php similarity index 66% rename from src/pocketmine/network/mcpe/CachedEncapsulatedPacket.php rename to src/pocketmine/network/mcpe/PacketStream.php index 74bf3d464..9a0f4e977 100644 --- a/src/pocketmine/network/mcpe/CachedEncapsulatedPacket.php +++ b/src/pocketmine/network/mcpe/PacketStream.php @@ -23,13 +23,19 @@ declare(strict_types=1); namespace pocketmine\network\mcpe; -use raklib\protocol\EncapsulatedPacket; +use pocketmine\network\mcpe\protocol\DataPacket; +use pocketmine\network\mcpe\protocol\PacketPool; -class CachedEncapsulatedPacket extends EncapsulatedPacket{ - /** @var string|null */ - private $internalData = null; +class PacketStream extends NetworkBinaryStream{ - public function toInternalBinary() : string{ - return $this->internalData ?? ($this->internalData = parent::toInternalBinary()); + public function putPacket(DataPacket $packet) : void{ + if(!$packet->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..aca42af67 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; @@ -153,13 +152,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,37 +214,18 @@ 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 $needACK = false, bool $immediate = true) : ?int{ 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->identifierACK = $this->identifiersACK[$identifier]++; + $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, ($needACK ? RakLib::FLAG_NEED_ACK : 0) | ($immediate ? RakLib::PRIORITY_IMMEDIATE : RakLib::PRIORITY_NORMAL)); + return $pk->identifierACK; } return null; 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/DataPacket.php b/src/pocketmine/network/mcpe/protocol/DataPacket.php index 1201971d1..9e05043db 100644 --- a/src/pocketmine/network/mcpe/protocol/DataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/DataPacket.php @@ -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; } diff --git a/src/pocketmine/network/mcpe/protocol/PacketPool.php b/src/pocketmine/network/mcpe/protocol/PacketPool.php index 962932f1a..d27545f7c 100644 --- a/src/pocketmine/network/mcpe/protocol/PacketPool.php +++ b/src/pocketmine/network/mcpe/protocol/PacketPool.php @@ -143,8 +143,6 @@ class PacketPool{ static::registerPacket(new UpdateBlockSyncedPacket()); static::registerPacket(new MoveEntityDeltaPacket()); static::registerPacket(new SetLocalPlayerAsInitializedPacket()); - - static::registerPacket(new BatchPacket()); } /** From 64ecc373be17ec47a43f188075a2571184374050 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 19 Jul 2018 15:12:40 +0100 Subject: [PATCH 04/20] Split up session base logic and packet handling this will allow for mutable packet handlers which can be used to cleanly implement multi-stage game sessions. --- .../network/mcpe/NetworkSession.php | 574 +---------------- .../network/mcpe/handler/SessionHandler.php | 598 ++++++++++++++++++ .../mcpe/handler/SimpleSessionHandler.php | 241 +++++++ .../mcpe/protocol/AddBehaviorTreePacket.php | 6 +- .../network/mcpe/protocol/AddEntityPacket.php | 6 +- .../mcpe/protocol/AddHangingEntityPacket.php | 6 +- .../mcpe/protocol/AddItemEntityPacket.php | 6 +- .../mcpe/protocol/AddPaintingPacket.php | 6 +- .../network/mcpe/protocol/AddPlayerPacket.php | 6 +- .../mcpe/protocol/AdventureSettingsPacket.php | 6 +- .../network/mcpe/protocol/AnimatePacket.php | 6 +- .../mcpe/protocol/AvailableCommandsPacket.php | 6 +- .../mcpe/protocol/BlockEntityDataPacket.php | 6 +- .../mcpe/protocol/BlockEventPacket.php | 6 +- .../mcpe/protocol/BlockPickRequestPacket.php | 6 +- .../network/mcpe/protocol/BookEditPacket.php | 6 +- .../network/mcpe/protocol/BossEventPacket.php | 6 +- .../network/mcpe/protocol/CameraPacket.php | 6 +- .../mcpe/protocol/ChangeDimensionPacket.php | 6 +- .../protocol/ChunkRadiusUpdatedPacket.php | 6 +- .../ClientToServerHandshakePacket.php | 6 +- .../protocol/ClientboundMapItemDataPacket.php | 6 +- .../protocol/CommandBlockUpdatePacket.php | 6 +- .../mcpe/protocol/CommandOutputPacket.php | 6 +- .../mcpe/protocol/CommandRequestPacket.php | 6 +- .../mcpe/protocol/ContainerClosePacket.php | 6 +- .../mcpe/protocol/ContainerOpenPacket.php | 6 +- .../mcpe/protocol/ContainerSetDataPacket.php | 6 +- .../mcpe/protocol/CraftingDataPacket.php | 6 +- .../mcpe/protocol/CraftingEventPacket.php | 6 +- .../network/mcpe/protocol/DataPacket.php | 16 +- .../mcpe/protocol/DisconnectPacket.php | 6 +- .../mcpe/protocol/EntityEventPacket.php | 6 +- .../mcpe/protocol/EntityFallPacket.php | 6 +- .../mcpe/protocol/EntityPickRequestPacket.php | 6 +- .../network/mcpe/protocol/EventPacket.php | 6 +- .../network/mcpe/protocol/ExplodePacket.php | 6 +- .../mcpe/protocol/FullChunkDataPacket.php | 6 +- .../mcpe/protocol/GameRulesChangedPacket.php | 6 +- .../mcpe/protocol/GuiDataPickItemPacket.php | 6 +- .../network/mcpe/protocol/HurtArmorPacket.php | 6 +- .../network/mcpe/protocol/InteractPacket.php | 6 +- .../mcpe/protocol/InventoryContentPacket.php | 6 +- .../mcpe/protocol/InventorySlotPacket.php | 6 +- .../protocol/InventoryTransactionPacket.php | 6 +- .../mcpe/protocol/ItemFrameDropItemPacket.php | 6 +- .../network/mcpe/protocol/LabTablePacket.php | 6 +- .../mcpe/protocol/LevelEventPacket.php | 6 +- .../mcpe/protocol/LevelSoundEventPacket.php | 6 +- .../network/mcpe/protocol/LoginPacket.php | 6 +- .../mcpe/protocol/MapInfoRequestPacket.php | 6 +- .../mcpe/protocol/MobArmorEquipmentPacket.php | 6 +- .../network/mcpe/protocol/MobEffectPacket.php | 6 +- .../mcpe/protocol/MobEquipmentPacket.php | 6 +- .../mcpe/protocol/ModalFormRequestPacket.php | 6 +- .../mcpe/protocol/ModalFormResponsePacket.php | 6 +- .../protocol/MoveEntityAbsolutePacket.php | 6 +- .../mcpe/protocol/MoveEntityDeltaPacket.php | 6 +- .../mcpe/protocol/MovePlayerPacket.php | 6 +- .../mcpe/protocol/NpcRequestPacket.php | 6 +- .../mcpe/protocol/PhotoTransferPacket.php | 6 +- .../network/mcpe/protocol/PlaySoundPacket.php | 6 +- .../mcpe/protocol/PlayStatusPacket.php | 6 +- .../mcpe/protocol/PlayerActionPacket.php | 6 +- .../mcpe/protocol/PlayerHotbarPacket.php | 6 +- .../mcpe/protocol/PlayerInputPacket.php | 6 +- .../mcpe/protocol/PlayerListPacket.php | 6 +- .../mcpe/protocol/PlayerSkinPacket.php | 6 +- .../mcpe/protocol/PurchaseReceiptPacket.php | 6 +- .../mcpe/protocol/RemoveEntityPacket.php | 6 +- .../mcpe/protocol/RemoveObjectivePacket.php | 6 +- .../protocol/RequestChunkRadiusPacket.php | 6 +- .../protocol/ResourcePackChunkDataPacket.php | 6 +- .../ResourcePackChunkRequestPacket.php | 6 +- .../ResourcePackClientResponsePacket.php | 6 +- .../protocol/ResourcePackDataInfoPacket.php | 6 +- .../mcpe/protocol/ResourcePackStackPacket.php | 6 +- .../mcpe/protocol/ResourcePacksInfoPacket.php | 6 +- .../network/mcpe/protocol/RespawnPacket.php | 6 +- .../network/mcpe/protocol/RiderJumpPacket.php | 6 +- .../protocol/ServerSettingsRequestPacket.php | 6 +- .../protocol/ServerSettingsResponsePacket.php | 6 +- .../ServerToClientHandshakePacket.php | 6 +- .../protocol/SetCommandsEnabledPacket.php | 6 +- .../protocol/SetDefaultGameTypePacket.php | 6 +- .../mcpe/protocol/SetDifficultyPacket.php | 6 +- .../protocol/SetDisplayObjectivePacket.php | 6 +- .../mcpe/protocol/SetEntityDataPacket.php | 6 +- .../mcpe/protocol/SetEntityLinkPacket.php | 6 +- .../mcpe/protocol/SetEntityMotionPacket.php | 6 +- .../network/mcpe/protocol/SetHealthPacket.php | 6 +- .../mcpe/protocol/SetLastHurtByPacket.php | 6 +- .../SetLocalPlayerAsInitializedPacket.php | 6 +- .../mcpe/protocol/SetPlayerGameTypePacket.php | 6 +- .../network/mcpe/protocol/SetScorePacket.php | 6 +- .../mcpe/protocol/SetSpawnPositionPacket.php | 6 +- .../network/mcpe/protocol/SetTimePacket.php | 6 +- .../network/mcpe/protocol/SetTitlePacket.php | 6 +- .../mcpe/protocol/ShowCreditsPacket.php | 6 +- .../mcpe/protocol/ShowProfilePacket.php | 6 +- .../mcpe/protocol/ShowStoreOfferPacket.php | 6 +- .../mcpe/protocol/SimpleEventPacket.php | 6 +- .../protocol/SpawnExperienceOrbPacket.php | 6 +- .../network/mcpe/protocol/StartGamePacket.php | 6 +- .../network/mcpe/protocol/StopSoundPacket.php | 6 +- .../protocol/StructureBlockUpdatePacket.php | 6 +- .../mcpe/protocol/SubClientLoginPacket.php | 6 +- .../mcpe/protocol/TakeItemEntityPacket.php | 6 +- .../network/mcpe/protocol/TextPacket.php | 6 +- .../network/mcpe/protocol/TransferPacket.php | 6 +- .../network/mcpe/protocol/UnknownPacket.php | 4 +- .../mcpe/protocol/UpdateAttributesPacket.php | 6 +- .../mcpe/protocol/UpdateBlockPacket.php | 6 +- .../mcpe/protocol/UpdateBlockSyncedPacket.php | 6 +- .../mcpe/protocol/UpdateEquipPacket.php | 6 +- .../mcpe/protocol/UpdateTradePacket.php | 6 +- .../network/mcpe/protocol/WSConnectPacket.php | 6 +- 117 files changed, 1195 insertions(+), 910 deletions(-) create mode 100644 src/pocketmine/network/mcpe/handler/SessionHandler.php create mode 100644 src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php diff --git a/src/pocketmine/network/mcpe/NetworkSession.php b/src/pocketmine/network/mcpe/NetworkSession.php index 6d72ea00d..e23e1d31b 100644 --- a/src/pocketmine/network/mcpe/NetworkSession.php +++ b/src/pocketmine/network/mcpe/NetworkSession.php @@ -25,120 +25,11 @@ namespace pocketmine\network\mcpe; use pocketmine\event\server\DataPacketReceiveEvent; use pocketmine\event\server\DataPacketSendEvent; -use pocketmine\network\mcpe\protocol\AddBehaviorTreePacket; -use pocketmine\network\mcpe\protocol\AddEntityPacket; -use pocketmine\network\mcpe\protocol\AddHangingEntityPacket; -use pocketmine\network\mcpe\protocol\AddItemEntityPacket; -use pocketmine\network\mcpe\protocol\AddPaintingPacket; -use pocketmine\network\mcpe\protocol\AddPlayerPacket; -use pocketmine\network\mcpe\protocol\AdventureSettingsPacket; -use pocketmine\network\mcpe\protocol\AnimatePacket; -use pocketmine\network\mcpe\protocol\AvailableCommandsPacket; -use pocketmine\network\mcpe\protocol\BlockEntityDataPacket; -use pocketmine\network\mcpe\protocol\BlockEventPacket; -use pocketmine\network\mcpe\protocol\BlockPickRequestPacket; -use pocketmine\network\mcpe\protocol\BookEditPacket; -use pocketmine\network\mcpe\protocol\BossEventPacket; -use pocketmine\network\mcpe\protocol\CameraPacket; -use pocketmine\network\mcpe\protocol\ChangeDimensionPacket; -use pocketmine\network\mcpe\protocol\ChunkRadiusUpdatedPacket; -use pocketmine\network\mcpe\protocol\ClientboundMapItemDataPacket; -use pocketmine\network\mcpe\protocol\ClientToServerHandshakePacket; -use pocketmine\network\mcpe\protocol\CommandBlockUpdatePacket; -use pocketmine\network\mcpe\protocol\CommandOutputPacket; -use pocketmine\network\mcpe\protocol\CommandRequestPacket; -use pocketmine\network\mcpe\protocol\ContainerClosePacket; -use pocketmine\network\mcpe\protocol\ContainerOpenPacket; -use pocketmine\network\mcpe\protocol\ContainerSetDataPacket; -use pocketmine\network\mcpe\protocol\CraftingDataPacket; -use pocketmine\network\mcpe\protocol\CraftingEventPacket; +use pocketmine\network\mcpe\handler\SessionHandler; +use pocketmine\network\mcpe\handler\SimpleSessionHandler; use pocketmine\network\mcpe\protocol\DataPacket; use pocketmine\network\mcpe\protocol\DisconnectPacket; -use pocketmine\network\mcpe\protocol\EntityEventPacket; -use pocketmine\network\mcpe\protocol\EntityFallPacket; -use pocketmine\network\mcpe\protocol\EntityPickRequestPacket; -use pocketmine\network\mcpe\protocol\EventPacket; -use pocketmine\network\mcpe\protocol\ExplodePacket; -use pocketmine\network\mcpe\protocol\FullChunkDataPacket; -use pocketmine\network\mcpe\protocol\GameRulesChangedPacket; -use pocketmine\network\mcpe\protocol\GuiDataPickItemPacket; -use pocketmine\network\mcpe\protocol\HurtArmorPacket; -use pocketmine\network\mcpe\protocol\InteractPacket; -use pocketmine\network\mcpe\protocol\InventoryContentPacket; -use pocketmine\network\mcpe\protocol\InventorySlotPacket; -use pocketmine\network\mcpe\protocol\InventoryTransactionPacket; -use pocketmine\network\mcpe\protocol\ItemFrameDropItemPacket; -use pocketmine\network\mcpe\protocol\LabTablePacket; -use pocketmine\network\mcpe\protocol\LevelEventPacket; -use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; -use pocketmine\network\mcpe\protocol\LoginPacket; -use pocketmine\network\mcpe\protocol\MapInfoRequestPacket; -use pocketmine\network\mcpe\protocol\MobArmorEquipmentPacket; -use pocketmine\network\mcpe\protocol\MobEffectPacket; -use pocketmine\network\mcpe\protocol\MobEquipmentPacket; -use pocketmine\network\mcpe\protocol\ModalFormRequestPacket; -use pocketmine\network\mcpe\protocol\ModalFormResponsePacket; -use pocketmine\network\mcpe\protocol\MoveEntityAbsolutePacket; -use pocketmine\network\mcpe\protocol\MoveEntityDeltaPacket; -use pocketmine\network\mcpe\protocol\MovePlayerPacket; -use pocketmine\network\mcpe\protocol\NpcRequestPacket; use pocketmine\network\mcpe\protocol\PacketPool; -use pocketmine\network\mcpe\protocol\PhotoTransferPacket; -use pocketmine\network\mcpe\protocol\PlayerActionPacket; -use pocketmine\network\mcpe\protocol\PlayerHotbarPacket; -use pocketmine\network\mcpe\protocol\PlayerInputPacket; -use pocketmine\network\mcpe\protocol\PlayerListPacket; -use pocketmine\network\mcpe\protocol\PlayerSkinPacket; -use pocketmine\network\mcpe\protocol\PlaySoundPacket; -use pocketmine\network\mcpe\protocol\PlayStatusPacket; -use pocketmine\network\mcpe\protocol\PurchaseReceiptPacket; -use pocketmine\network\mcpe\protocol\RemoveEntityPacket; -use pocketmine\network\mcpe\protocol\RemoveObjectivePacket; -use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket; -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\RiderJumpPacket; -use pocketmine\network\mcpe\protocol\ServerSettingsRequestPacket; -use pocketmine\network\mcpe\protocol\ServerSettingsResponsePacket; -use pocketmine\network\mcpe\protocol\ServerToClientHandshakePacket; -use pocketmine\network\mcpe\protocol\SetCommandsEnabledPacket; -use pocketmine\network\mcpe\protocol\SetDefaultGameTypePacket; -use pocketmine\network\mcpe\protocol\SetDifficultyPacket; -use pocketmine\network\mcpe\protocol\SetDisplayObjectivePacket; -use pocketmine\network\mcpe\protocol\SetEntityDataPacket; -use pocketmine\network\mcpe\protocol\SetEntityLinkPacket; -use pocketmine\network\mcpe\protocol\SetEntityMotionPacket; -use pocketmine\network\mcpe\protocol\SetHealthPacket; -use pocketmine\network\mcpe\protocol\SetLastHurtByPacket; -use pocketmine\network\mcpe\protocol\SetLocalPlayerAsInitializedPacket; -use pocketmine\network\mcpe\protocol\SetPlayerGameTypePacket; -use pocketmine\network\mcpe\protocol\SetScorePacket; -use pocketmine\network\mcpe\protocol\SetSpawnPositionPacket; -use pocketmine\network\mcpe\protocol\SetTimePacket; -use pocketmine\network\mcpe\protocol\SetTitlePacket; -use pocketmine\network\mcpe\protocol\ShowCreditsPacket; -use pocketmine\network\mcpe\protocol\ShowProfilePacket; -use pocketmine\network\mcpe\protocol\ShowStoreOfferPacket; -use pocketmine\network\mcpe\protocol\SimpleEventPacket; -use pocketmine\network\mcpe\protocol\SpawnExperienceOrbPacket; -use pocketmine\network\mcpe\protocol\StartGamePacket; -use pocketmine\network\mcpe\protocol\StopSoundPacket; -use pocketmine\network\mcpe\protocol\StructureBlockUpdatePacket; -use pocketmine\network\mcpe\protocol\SubClientLoginPacket; -use pocketmine\network\mcpe\protocol\TakeItemEntityPacket; -use pocketmine\network\mcpe\protocol\TextPacket; -use pocketmine\network\mcpe\protocol\TransferPacket; -use pocketmine\network\mcpe\protocol\UpdateAttributesPacket; -use pocketmine\network\mcpe\protocol\UpdateBlockPacket; -use pocketmine\network\mcpe\protocol\UpdateBlockSyncedPacket; -use pocketmine\network\mcpe\protocol\UpdateEquipPacket; -use pocketmine\network\mcpe\protocol\UpdateTradePacket; -use pocketmine\network\mcpe\protocol\WSConnectPacket; use pocketmine\network\NetworkInterface; use pocketmine\Player; use pocketmine\Server; @@ -158,6 +49,9 @@ class NetworkSession{ /** @var int */ private $port; + /** @var SessionHandler */ + private $handler; + public function __construct(Server $server, Player $player, NetworkInterface $interface, string $ip, int $port){ $this->server = $server; $this->player = $player; @@ -165,6 +59,8 @@ class NetworkSession{ $this->ip = $ip; $this->port = $port; + + $this->handler = new SimpleSessionHandler($player); } public function getInterface() : NetworkInterface{ @@ -205,7 +101,7 @@ class NetworkSession{ } $this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this->player, $packet)); - if(!$ev->isCancelled() and !$packet->handle($this)){ + if(!$ev->isCancelled() and !$packet->handle($this->handler)){ $this->server->getLogger()->debug("Unhandled " . $packet->getName() . " received from " . $this->player->getName() . ": 0x" . bin2hex($packet->buffer)); } @@ -239,458 +135,4 @@ class NetworkSession{ } $this->interface->close($this->player, $notify ? $reason : ""); } - - public function handleLogin(LoginPacket $packet) : bool{ - return $this->player->handleLogin($packet); - } - - public function handlePlayStatus(PlayStatusPacket $packet) : bool{ - return false; - } - - public function handleServerToClientHandshake(ServerToClientHandshakePacket $packet) : bool{ - return false; - } - - public function handleClientToServerHandshake(ClientToServerHandshakePacket $packet) : bool{ - return false; //TODO - } - - public function handleDisconnect(DisconnectPacket $packet) : bool{ - return false; - } - - public function handleResourcePacksInfo(ResourcePacksInfoPacket $packet) : bool{ - return false; - } - - public function handleResourcePackStack(ResourcePackStackPacket $packet) : bool{ - return false; - } - - 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); - } - - return false; - } - - public function handleSetTime(SetTimePacket $packet) : bool{ - return false; - } - - public function handleStartGame(StartGamePacket $packet) : bool{ - return false; - } - - public function handleAddPlayer(AddPlayerPacket $packet) : bool{ - return false; - } - - public function handleAddEntity(AddEntityPacket $packet) : bool{ - return false; - } - - public function handleRemoveEntity(RemoveEntityPacket $packet) : bool{ - return false; - } - - public function handleAddItemEntity(AddItemEntityPacket $packet) : bool{ - return false; - } - - public function handleAddHangingEntity(AddHangingEntityPacket $packet) : bool{ - return false; - } - - public function handleTakeItemEntity(TakeItemEntityPacket $packet) : bool{ - return false; - } - - public function handleMoveEntityAbsolute(MoveEntityAbsolutePacket $packet) : bool{ - return false; - } - - public function handleMovePlayer(MovePlayerPacket $packet) : bool{ - return $this->player->handleMovePlayer($packet); - } - - public function handleRiderJump(RiderJumpPacket $packet) : bool{ - return false; - } - - public function handleUpdateBlock(UpdateBlockPacket $packet) : bool{ - return false; - } - - public function handleAddPainting(AddPaintingPacket $packet) : bool{ - return false; - } - - public function handleExplode(ExplodePacket $packet) : bool{ - return false; - } - - public function handleLevelSoundEvent(LevelSoundEventPacket $packet) : bool{ - return $this->player->handleLevelSoundEvent($packet); - } - - public function handleLevelEvent(LevelEventPacket $packet) : bool{ - return false; - } - - public function handleBlockEvent(BlockEventPacket $packet) : bool{ - return false; - } - - public function handleEntityEvent(EntityEventPacket $packet) : bool{ - return $this->player->handleEntityEvent($packet); - } - - public function handleMobEffect(MobEffectPacket $packet) : bool{ - return false; - } - - public function handleUpdateAttributes(UpdateAttributesPacket $packet) : bool{ - return false; - } - - public function handleInventoryTransaction(InventoryTransactionPacket $packet) : bool{ - return $this->player->handleInventoryTransaction($packet); - } - - public function handleMobEquipment(MobEquipmentPacket $packet) : bool{ - return $this->player->handleMobEquipment($packet); - } - - public function handleMobArmorEquipment(MobArmorEquipmentPacket $packet) : bool{ - return true; //Not used - } - - public function handleInteract(InteractPacket $packet) : bool{ - return $this->player->handleInteract($packet); - } - - public function handleBlockPickRequest(BlockPickRequestPacket $packet) : bool{ - return $this->player->handleBlockPickRequest($packet); - } - - public function handleEntityPickRequest(EntityPickRequestPacket $packet) : bool{ - return false; //TODO - } - - public function handlePlayerAction(PlayerActionPacket $packet) : bool{ - return $this->player->handlePlayerAction($packet); - } - - public function handleEntityFall(EntityFallPacket $packet) : bool{ - return true; //Not used - } - - public function handleHurtArmor(HurtArmorPacket $packet) : bool{ - return false; - } - - public function handleSetEntityData(SetEntityDataPacket $packet) : bool{ - return false; - } - - public function handleSetEntityMotion(SetEntityMotionPacket $packet) : bool{ - return false; - } - - public function handleSetEntityLink(SetEntityLinkPacket $packet) : bool{ - return false; - } - - public function handleSetHealth(SetHealthPacket $packet) : bool{ - return false; - } - - public function handleSetSpawnPosition(SetSpawnPositionPacket $packet) : bool{ - return false; - } - - public function handleAnimate(AnimatePacket $packet) : bool{ - return $this->player->handleAnimate($packet); - } - - public function handleRespawn(RespawnPacket $packet) : bool{ - return false; - } - - public function handleContainerOpen(ContainerOpenPacket $packet) : bool{ - return false; - } - - public function handleContainerClose(ContainerClosePacket $packet) : bool{ - return $this->player->handleContainerClose($packet); - } - - public function handlePlayerHotbar(PlayerHotbarPacket $packet) : bool{ - return true; //this packet is useless - } - - public function handleInventoryContent(InventoryContentPacket $packet) : bool{ - return false; - } - - public function handleInventorySlot(InventorySlotPacket $packet) : bool{ - return false; - } - - public function handleContainerSetData(ContainerSetDataPacket $packet) : bool{ - return false; - } - - public function handleCraftingData(CraftingDataPacket $packet) : bool{ - return false; - } - - public function handleCraftingEvent(CraftingEventPacket $packet) : bool{ - return true; //this is a broken useless packet, so we don't use it - } - - public function handleGuiDataPickItem(GuiDataPickItemPacket $packet) : bool{ - return false; - } - - public function handleAdventureSettings(AdventureSettingsPacket $packet) : bool{ - return $this->player->handleAdventureSettings($packet); - } - - public function handleBlockEntityData(BlockEntityDataPacket $packet) : bool{ - return $this->player->handleBlockEntityData($packet); - } - - public function handlePlayerInput(PlayerInputPacket $packet) : bool{ - return false; //TODO - } - - public function handleFullChunkData(FullChunkDataPacket $packet) : bool{ - return false; - } - - public function handleSetCommandsEnabled(SetCommandsEnabledPacket $packet) : bool{ - return false; - } - - public function handleSetDifficulty(SetDifficultyPacket $packet) : bool{ - return false; - } - - public function handleChangeDimension(ChangeDimensionPacket $packet) : bool{ - return false; - } - - public function handleSetPlayerGameType(SetPlayerGameTypePacket $packet) : bool{ - return $this->player->handleSetPlayerGameType($packet); - } - - public function handlePlayerList(PlayerListPacket $packet) : bool{ - return false; - } - - public function handleSimpleEvent(SimpleEventPacket $packet) : bool{ - return false; - } - - public function handleEvent(EventPacket $packet) : bool{ - return false; - } - - public function handleSpawnExperienceOrb(SpawnExperienceOrbPacket $packet) : bool{ - return false; //TODO - } - - public function handleClientboundMapItemData(ClientboundMapItemDataPacket $packet) : bool{ - return false; - } - - public function handleMapInfoRequest(MapInfoRequestPacket $packet) : bool{ - return false; //TODO - } - - public function handleRequestChunkRadius(RequestChunkRadiusPacket $packet) : bool{ - $this->player->setViewDistance($packet->radius); - - return true; - } - - public function handleChunkRadiusUpdated(ChunkRadiusUpdatedPacket $packet) : bool{ - return false; - } - - public function handleItemFrameDropItem(ItemFrameDropItemPacket $packet) : bool{ - return $this->player->handleItemFrameDropItem($packet); - } - - public function handleGameRulesChanged(GameRulesChangedPacket $packet) : bool{ - return false; - } - - public function handleCamera(CameraPacket $packet) : bool{ - return false; - } - - public function handleBossEvent(BossEventPacket $packet) : bool{ - return false; //TODO - } - - public function handleShowCredits(ShowCreditsPacket $packet) : bool{ - return false; //TODO: handle resume - } - - public function handleAvailableCommands(AvailableCommandsPacket $packet) : bool{ - return false; - } - - public function handleCommandRequest(CommandRequestPacket $packet) : bool{ - return $this->player->chat($packet->command); - } - - public function handleCommandBlockUpdate(CommandBlockUpdatePacket $packet) : bool{ - return false; //TODO - } - - public function handleCommandOutput(CommandOutputPacket $packet) : bool{ - return false; - } - - public function handleUpdateTrade(UpdateTradePacket $packet) : bool{ - return false; - } - - public function handleUpdateEquip(UpdateEquipPacket $packet) : bool{ - return false; - } - - public function handleResourcePackDataInfo(ResourcePackDataInfoPacket $packet) : bool{ - return false; - } - - public function handleResourcePackChunkData(ResourcePackChunkDataPacket $packet) : bool{ - return false; - } - - public function handleResourcePackChunkRequest(ResourcePackChunkRequestPacket $packet) : bool{ - return $this->player->handleResourcePackChunkRequest($packet); - } - - public function handleTransfer(TransferPacket $packet) : bool{ - return false; - } - - public function handlePlaySound(PlaySoundPacket $packet) : bool{ - return false; - } - - public function handleStopSound(StopSoundPacket $packet) : bool{ - return false; - } - - public function handleSetTitle(SetTitlePacket $packet) : bool{ - return false; - } - - public function handleAddBehaviorTree(AddBehaviorTreePacket $packet) : bool{ - return false; - } - - public function handleStructureBlockUpdate(StructureBlockUpdatePacket $packet) : bool{ - return false; - } - - public function handleShowStoreOffer(ShowStoreOfferPacket $packet) : bool{ - return false; - } - - public function handlePurchaseReceipt(PurchaseReceiptPacket $packet) : bool{ - return false; - } - - public function handlePlayerSkin(PlayerSkinPacket $packet) : bool{ - return $this->player->changeSkin($packet->skin, $packet->newSkinName, $packet->oldSkinName); - } - - 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 $this->player->handleBookEdit($packet); - } - - 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; //TODO: GUI stuff - } - - public function handleServerSettingsRequest(ServerSettingsRequestPacket $packet) : bool{ - return false; //TODO: GUI stuff - } - - 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 handleUpdateBlockSynced(UpdateBlockSyncedPacket $packet) : bool{ - return false; - } - - public function handleMoveEntityDelta(MoveEntityDeltaPacket $packet) : bool{ - return false; - } - - public function handleSetLocalPlayerAsInitialized(SetLocalPlayerAsInitializedPacket $packet) : bool{ - return false; - } } 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 @@ +player = $player; + } + + 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); + } + + return false; + } + + public function handleMovePlayer(MovePlayerPacket $packet) : bool{ + return $this->player->handleMovePlayer($packet); + } + + public function handleLevelSoundEvent(LevelSoundEventPacket $packet) : bool{ + return $this->player->handleLevelSoundEvent($packet); + } + + public function handleEntityEvent(EntityEventPacket $packet) : bool{ + return $this->player->handleEntityEvent($packet); + } + + public function handleInventoryTransaction(InventoryTransactionPacket $packet) : bool{ + return $this->player->handleInventoryTransaction($packet); + } + + public function handleMobEquipment(MobEquipmentPacket $packet) : bool{ + return $this->player->handleMobEquipment($packet); + } + + public function handleMobArmorEquipment(MobArmorEquipmentPacket $packet) : bool{ + return true; //Not used + } + + public function handleInteract(InteractPacket $packet) : bool{ + return $this->player->handleInteract($packet); + } + + public function handleBlockPickRequest(BlockPickRequestPacket $packet) : bool{ + return $this->player->handleBlockPickRequest($packet); + } + + public function handleEntityPickRequest(EntityPickRequestPacket $packet) : bool{ + return false; //TODO + } + + public function handlePlayerAction(PlayerActionPacket $packet) : bool{ + return $this->player->handlePlayerAction($packet); + } + + public function handleEntityFall(EntityFallPacket $packet) : bool{ + return true; //Not used + } + + public function handleAnimate(AnimatePacket $packet) : bool{ + return $this->player->handleAnimate($packet); + } + + public function handleContainerClose(ContainerClosePacket $packet) : bool{ + return $this->player->handleContainerClose($packet); + } + + public function handlePlayerHotbar(PlayerHotbarPacket $packet) : bool{ + return true; //this packet is useless + } + + public function handleCraftingEvent(CraftingEventPacket $packet) : bool{ + return true; //this is a broken useless packet, so we don't use it + } + + public function handleAdventureSettings(AdventureSettingsPacket $packet) : bool{ + return $this->player->handleAdventureSettings($packet); + } + + public function handleBlockEntityData(BlockEntityDataPacket $packet) : bool{ + return $this->player->handleBlockEntityData($packet); + } + + public function handlePlayerInput(PlayerInputPacket $packet) : bool{ + return false; //TODO + } + + public function handleSetPlayerGameType(SetPlayerGameTypePacket $packet) : bool{ + return $this->player->handleSetPlayerGameType($packet); + } + + public function handleSpawnExperienceOrb(SpawnExperienceOrbPacket $packet) : bool{ + return false; //TODO + } + + public function handleMapInfoRequest(MapInfoRequestPacket $packet) : bool{ + return false; //TODO + } + + public function handleRequestChunkRadius(RequestChunkRadiusPacket $packet) : bool{ + $this->player->setViewDistance($packet->radius); + + return true; + } + + public function handleItemFrameDropItem(ItemFrameDropItemPacket $packet) : bool{ + return $this->player->handleItemFrameDropItem($packet); + } + + public function handleBossEvent(BossEventPacket $packet) : bool{ + return false; //TODO + } + + public function handleShowCredits(ShowCreditsPacket $packet) : bool{ + return false; //TODO: handle resume + } + + public function handleCommandRequest(CommandRequestPacket $packet) : bool{ + return $this->player->chat($packet->command); + } + + public function handleCommandBlockUpdate(CommandBlockUpdatePacket $packet) : bool{ + 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); + } + + public function handleModalFormResponse(ModalFormResponsePacket $packet) : bool{ + return false; //TODO: GUI stuff + } + + 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/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 9e05043db..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{ @@ -105,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..af971f952 100644 --- a/src/pocketmine/network/mcpe/protocol/LoginPacket.php +++ b/src/pocketmine/network/mcpe/protocol/LoginPacket.php @@ -26,7 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\utils\BinaryStream; use pocketmine\utils\MainLogger; use pocketmine\utils\Utils; @@ -143,7 +143,7 @@ class LoginPacket extends DataPacket{ //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/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); } } From cdcafb1e75edfc1c771104297e94cccfb86f7174 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 19 Jul 2018 15:19:33 +0100 Subject: [PATCH 05/20] PacketPool: Properly deal with varint packet IDs now that BatchPacket is gone --- src/pocketmine/network/mcpe/protocol/PacketPool.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/network/mcpe/protocol/PacketPool.php b/src/pocketmine/network/mcpe/protocol/PacketPool.php index d27545f7c..d7facb48a 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; @@ -165,8 +167,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; } From 08621604cd90c25553e8c6ce8190c372efe82c64 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 19 Jul 2018 15:43:38 +0100 Subject: [PATCH 06/20] PacketPool: remove redundant comment this was added to signify that these were normal, while BatchPacket was a hack. Since this has now been corrected, there's no need for the comment. --- src/pocketmine/network/mcpe/protocol/PacketPool.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pocketmine/network/mcpe/protocol/PacketPool.php b/src/pocketmine/network/mcpe/protocol/PacketPool.php index d7facb48a..88f6b0c0a 100644 --- a/src/pocketmine/network/mcpe/protocol/PacketPool.php +++ b/src/pocketmine/network/mcpe/protocol/PacketPool.php @@ -32,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()); From e16f20affaf790d7de96820a362e59e4f2f5cc87 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 19 Jul 2018 16:40:00 +0100 Subject: [PATCH 07/20] NetworkSession: added getHandler() and setHandler(), SessionHandler->setUp() now not useless --- src/pocketmine/network/mcpe/NetworkSession.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/network/mcpe/NetworkSession.php b/src/pocketmine/network/mcpe/NetworkSession.php index e23e1d31b..6cd32b683 100644 --- a/src/pocketmine/network/mcpe/NetworkSession.php +++ b/src/pocketmine/network/mcpe/NetworkSession.php @@ -60,7 +60,7 @@ class NetworkSession{ $this->ip = $ip; $this->port = $port; - $this->handler = new SimpleSessionHandler($player); + $this->setHandler(new SimpleSessionHandler($player)); } public function getInterface() : NetworkInterface{ @@ -81,6 +81,15 @@ class NetworkSession{ return $this->port; } + public function getHandler() : SessionHandler{ + return $this->handler; + } + + public function setHandler(SessionHandler $handler) : void{ + $this->handler = $handler; + $this->handler->setUp(); + } + public function handleEncoded(string $payload) : void{ //TODO: decryption if enabled From 25cfcada262c2b2017d3f9058a83172c36f29489 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 20 Jul 2018 11:36:56 +0100 Subject: [PATCH 08/20] Player: clean up container close handling --- src/pocketmine/Player.php | 51 +++++++++++-------- .../mcpe/handler/SimpleSessionHandler.php | 2 +- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 836545e7f..986faf486 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -104,7 +104,6 @@ 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; @@ -2840,25 +2839,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 @@ -3752,6 +3732,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]; @@ -3772,6 +3756,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(!$this->spawned or $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. * diff --git a/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php b/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php index 8fe0e0533..1e8ede160 100644 --- a/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php +++ b/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php @@ -146,7 +146,7 @@ class SimpleSessionHandler extends SessionHandler{ } public function handleContainerClose(ContainerClosePacket $packet) : bool{ - return $this->player->handleContainerClose($packet); + return $this->player->doCloseWindow($packet->windowId); } public function handlePlayerHotbar(PlayerHotbarPacket $packet) : bool{ From 57a86d9ed7ed9cfa0a785e536b6c28c1a259ff8c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 20 Jul 2018 12:39:48 +0100 Subject: [PATCH 09/20] Player: remove useless InteractPacket handler all the things we cared about in here don't exist anymore, so there's no sense in the handler still existing. It can be restored when we want to use the things it still does. --- src/pocketmine/Player.php | 26 ------------------- .../mcpe/handler/SimpleSessionHandler.php | 2 +- 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 986faf486..5910c3f2e 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -106,7 +106,6 @@ use pocketmine\network\mcpe\protocol\BookEditPacket; use pocketmine\network\mcpe\protocol\ChunkRadiusUpdatedPacket; 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; @@ -2625,31 +2624,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ 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); diff --git a/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php b/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php index 1e8ede160..b640192bb 100644 --- a/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php +++ b/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php @@ -122,7 +122,7 @@ class SimpleSessionHandler extends SessionHandler{ } public function handleInteract(InteractPacket $packet) : bool{ - return $this->player->handleInteract($packet); + return false; //TODO } public function handleBlockPickRequest(BlockPickRequestPacket $packet) : bool{ From aae19d45b739377190b484721d576f4bf016364d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 20 Jul 2018 12:41:16 +0100 Subject: [PATCH 10/20] Player: remove useless handleDataPacket() leftover --- src/pocketmine/Player.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 5910c3f2e..b20da0b71 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2976,17 +2976,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return true; } - /** - * Called when a packet is received from the client. This method will call DataPacketReceiveEvent. - * - * @param DataPacket $packet - */ - public function handleDataPacket(DataPacket $packet){ - if($this->networkSession !== null){ - $this->networkSession->handleDataPacket($packet); - } - } - /** * @param DataPacket $packet * @param bool $needACK From 0fecb79addb08db9b08189496033d061d2dd1374 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 20 Jul 2018 13:02:36 +0100 Subject: [PATCH 11/20] Player: separate some PlayerActionPacket handling logic out into their own functions these are public, because later on the session handler will be calling these instead of the player itself. --- src/pocketmine/Player.php | 87 ++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 34 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index b20da0b71..ae250fcc1 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2664,42 +2664,13 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ 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)); - } - } + $this->startBreakBlock($pos, $packet->face); break; case PlayerActionPacket::ACTION_ABORT_BREAK: case PlayerActionPacket::ACTION_STOP_BREAK: - $this->level->broadcastLevelEvent($pos, LevelEventPacket::EVENT_BLOCK_STOP_BREAK); + $this->stopBreakBlock($pos); break; case PlayerActionPacket::ACTION_START_SLEEPING: //unused @@ -2733,9 +2704,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ 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 + $this->continueBreakBlock($pos, $packet->face); break; case PlayerActionPacket::ACTION_START_SWIMMING: break; //TODO @@ -2752,6 +2721,56 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return true; } + 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; + } + + $block = $target->getSide($face); + if($block->getId() === Block::FIRE){ + $this->level->setBlock($block, BlockFactory::get(Block::AIR)); + return true; + } + + 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); From 3cd105ff33be54bf5d8b4cda45ea9e88fff23184 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 20 Jul 2018 13:07:06 +0100 Subject: [PATCH 12/20] Remove remnants of needACK functionality this has been broken for a long time and hasn't been used for even longer. --- src/pocketmine/Player.php | 21 ++++++++----------- src/pocketmine/Server.php | 2 +- src/pocketmine/network/NetworkInterface.php | 5 +---- .../network/mcpe/RakLibInterface.php | 14 ++----------- 4 files changed, 13 insertions(+), 29 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index ae250fcc1..17997d025 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1902,7 +1902,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $pk = new PlayStatusPacket(); $pk->status = $status; $pk->protocol = $this->protocol; - $this->sendDataPacket($pk, false, $immediate); + $this->sendDataPacket($pk, $immediate); } public function onVerifyCompleted(LoginPacket $packet, ?string $error, bool $signedByMojang) : void{ @@ -2997,12 +2997,11 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ /** * @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; } @@ -3017,22 +3016,20 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ /** * @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); } /** diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index b7f1a0cc7..0d4a6f1df 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -1893,7 +1893,7 @@ class Server{ */ public function broadcastPacketsCallback(string $payload, array $players, bool $immediate = false){ foreach($players as $i){ - $i->getNetworkSession()->getInterface()->putPacket($i, $payload, false, $immediate); + $i->getNetworkSession()->getInterface()->putPacket($i, $payload, $immediate); } } diff --git a/src/pocketmine/network/NetworkInterface.php b/src/pocketmine/network/NetworkInterface.php index 461bc7440..f06526873 100644 --- a/src/pocketmine/network/NetworkInterface.php +++ b/src/pocketmine/network/NetworkInterface.php @@ -43,12 +43,9 @@ interface NetworkInterface{ * * @param Player $player * @param string $payload - * @param bool $needACK * @param bool $immediate - * - * @return int|null */ - public function putPacket(Player $player, string $payload, 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/RakLibInterface.php b/src/pocketmine/network/mcpe/RakLibInterface.php index aca42af67..9aaeeda9f 100644 --- a/src/pocketmine/network/mcpe/RakLibInterface.php +++ b/src/pocketmine/network/mcpe/RakLibInterface.php @@ -62,9 +62,6 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{ /** @var string[] */ private $identifiers = []; - /** @var int[] */ - private $identifiersACK = []; - /** @var ServerHandler */ private $interface; @@ -111,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); } } @@ -119,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]); } @@ -142,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); } @@ -214,21 +208,17 @@ class RakLibInterface implements ServerInstance, AdvancedNetworkInterface{ } } - public function putPacket(Player $player, string $payload, 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]; $pk = new EncapsulatedPacket(); - $pk->identifierACK = $this->identifiersACK[$identifier]++; $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; + $this->interface->sendEncapsulated($identifier, $pk, ($immediate ? RakLib::PRIORITY_IMMEDIATE : RakLib::PRIORITY_NORMAL)); } - - return null; } public function updatePing(string $identifier, int $pingMS) : void{ From 7633136a86235eec507581fb6e6e4230f170e5e5 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 20 Jul 2018 13:22:08 +0100 Subject: [PATCH 13/20] Player: move max players check to somewhere that makes sense --- src/pocketmine/Player.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 17997d025..493c70bca 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1846,10 +1846,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->locale = $packet->locale; } - if(count($this->server->getOnlinePlayers()) >= $this->server->getMaxPlayers() and $this->kick("disconnectionScreen.serverFull", false)){ - return true; - } - $this->randomClientId = $packet->clientId; $this->uuid = UUID::fromString($packet->clientUUID); @@ -1878,6 +1874,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; } From a4939b6bf11e3da6f3ffc569540fafd8eba84545 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 20 Jul 2018 15:34:47 +0100 Subject: [PATCH 14/20] Player: re-structure a whole bunch of construction mess This consolidates the Player entity construction and makes it more organized and consistent. There is of course a lot more work to do apart from this on player construction. --- src/pocketmine/Player.php | 156 ++++++++++++++++++-------------------- 1 file changed, 75 insertions(+), 81 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 493c70bca..53f928e4f 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1803,15 +1803,6 @@ 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; @@ -1939,10 +1930,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")){ @@ -1953,41 +1940,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } - $this->namedtag = $this->server->getOfflinePlayerData($this->username); - - $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()){ - $this->gamemode = $this->server->getGamemode(); - $this->namedtag->setInt("playerGameType", $this->gamemode); - } - - $this->allowFlight = $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); - } - - $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; @@ -2036,7 +1988,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->dataPacket($pk); break; case ResourcePackClientResponsePacket::STATUS_COMPLETED: - $this->completeLoginSequence(); + $this->_actuallyConstruct(); break; default: return false; @@ -2045,12 +1997,28 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ 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); + protected 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); - 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()); @@ -2058,14 +2026,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ 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); - }else{ - $this->spawnPosition = $this->level->getSafeSpawn(); - } - } - $spawnPosition = $this->getSpawn(); $pk = new StartGamePacket(); @@ -2097,25 +2057,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $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->networkSession->getIp(), - $this->networkSession->getPort(), - $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); @@ -2128,6 +2069,59 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->server->addOnlinePlayer($this); $this->server->sendFullPlayerListData($this); + + $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) + ])); + } + + 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->gamemode = $this->namedtag->getInt("playerGameType", self::SURVIVAL) & 0x03; + if($this->server->getForceGamemode()){ + $this->gamemode = $this->server->getGamemode(); + $this->namedtag->setInt("playerGameType", $this->gamemode); + } + + $this->setAllowFlight($this->isCreative()); + $this->keepMovement = $this->isSpectator() || $this->allowMovementCheats(); + if($this->isOp()){ + $this->setRemoveFormat(false); + } + + $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; + } + + 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); + }else{ + $this->spawnPosition = $this->level->getSafeSpawn(); + } + } } /** From 97a1483f758cf13215f548f2227f279db020abb7 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 20 Jul 2018 15:38:53 +0100 Subject: [PATCH 15/20] Player: remove useless crap from "constructor" 1. this isn't really the player constructor 2. this shit isn't needed until we start using the player as an actual player --- src/pocketmine/Player.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 53f928e4f..c71033b7c 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -88,7 +88,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; @@ -688,14 +687,10 @@ 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->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); From f626b9e8a079cfa2d12f9daaeea8d59e223841e6 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 20 Jul 2018 17:09:04 +0100 Subject: [PATCH 16/20] Initial mass migration to session handlers This introduces several new session handlers, splitting up session handling into several new states: - Login: Only allows handling the LoginPacket. This is the only time LoginPacket can be sent, and it'll be discarded when sent at any other time. - Resource packs: Handles only the resource packs sequence (downloading packs and such). This is the only time ResourcePackClientResponse and ResourcePackChunkRequest will be handled. - Pre-spawn: Only chunk radius requests are accepted during this state. SimpleNetworkHandler handles all the "rest" of the logic that hasn't yet been separated out into their own dedicated handlers. There's also a NullNetworkHandler which discards all packets while it's active. This solves a large number of issues with the security of the login sequence. It solves a range of possible DoS attacks and crashes, while also allowing great code simplification and cleanup. --- src/pocketmine/Player.php | 216 ++---------------- .../network/mcpe/NetworkSession.php | 31 ++- .../mcpe/handler/LoginSessionHandler.php | 89 ++++++++ .../mcpe/handler/NullSessionHandler.php | 31 +++ .../mcpe/handler/PreSpawnSessionHandler.php | 99 ++++++++ .../handler/ResourcePacksSessionHandler.php | 128 +++++++++++ .../mcpe/handler/SimpleSessionHandler.php | 15 -- .../network/mcpe/protocol/LoginPacket.php | 13 +- 8 files changed, 409 insertions(+), 213 deletions(-) create mode 100644 src/pocketmine/network/mcpe/handler/LoginSessionHandler.php create mode 100644 src/pocketmine/network/mcpe/handler/NullSessionHandler.php create mode 100644 src/pocketmine/network/mcpe/handler/PreSpawnSessionHandler.php create mode 100644 src/pocketmine/network/mcpe/handler/ResourcePacksSessionHandler.php diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index c71033b7c..f5cf35998 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -114,26 +114,16 @@ 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; @@ -143,7 +133,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; @@ -182,9 +171,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ /** @var NetworkSession */ protected $networkSession; - /** @var int */ - protected $protocol = -1; - /** * @var int * Last measurement of player's latency in milliseconds. @@ -993,7 +979,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); @@ -1799,59 +1785,17 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } 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; - } - + $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,13 +1828,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, $immediate); - } - public function onVerifyCompleted(LoginPacket $packet, ?string $error, bool $signedByMojang) : void{ if($this->closed){ return; @@ -1935,64 +1872,12 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } - $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); + $this->networkSession->onLoginSuccess(); } - 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->_actuallyConstruct(); - break; - default: - return false; - } - - return true; - } - - protected function _actuallyConstruct(){ + public function _actuallyConstruct(){ $namedtag = $this->server->getOfflinePlayerData($this->username); //TODO: make this async if(($level = $this->server->getLevelByName($namedtag->getString("Level", "", true))) === null){ @@ -2021,50 +1906,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return; } - $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->sendCommandData(); - $this->sendSettings(); - $this->sendPotionEffects($this); - $this->sendData($this); - - $this->sendAllInventories(); - $this->inventory->sendCreativeContents(); - $this->inventory->sendHeldItem($this); - $this->networkSession->getInterface()->putPacket($this, $this->server->getCraftingManager()->getCraftingDataPacket()); - - $this->server->addOnlinePlayer($this); - $this->server->sendFullPlayerListData($this); - $this->server->getLogger()->info($this->getServer()->getLanguage()->translateString("pocketmine.player.logIn", [ TextFormat::AQUA . $this->username . TextFormat::WHITE, $this->networkSession->getIp(), @@ -2075,6 +1916,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ round($this->y, 4), round($this->z, 4) ])); + + $this->server->addOnlinePlayer($this); } protected function initHumanData() : void{ @@ -2128,7 +1971,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * @return bool */ public function chat(string $message) : bool{ - if(!$this->spawned or !$this->isAlive()){ + if(!$this->isAlive()){ return false; } @@ -2172,7 +2015,7 @@ 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){ + }elseif((!$this->isAlive()) 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{ @@ -2204,7 +2047,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } public function handleEntityEvent(EntityEventPacket $packet) : bool{ - if(!$this->spawned or !$this->isAlive()){ + if(!$this->isAlive()){ return true; } $this->doCloseInventory(); @@ -2232,7 +2075,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * @return bool */ public function handleInventoryTransaction(InventoryTransactionPacket $packet) : bool{ - if(!$this->spawned or !$this->isAlive()){ + if(!$this->isAlive()){ return false; } @@ -2594,7 +2437,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } public function handleMobEquipment(MobEquipmentPacket $packet) : bool{ - if(!$this->spawned or !$this->isAlive()){ + if(!$this->isAlive()){ return true; } @@ -2644,7 +2487,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } 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)){ + if(!$this->isAlive() and $packet->action !== PlayerActionPacket::ACTION_RESPAWN and $packet->action !== PlayerActionPacket::ACTION_DIMENSION_CHANGE_REQUEST){ return true; } @@ -2668,7 +2511,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->stopSleep(); break; case PlayerActionPacket::ACTION_RESPAWN: - if(!$this->spawned or $this->isAlive() or !$this->isOnline()){ + if($this->isAlive() or !$this->isOnline()){ break; } @@ -2781,7 +2624,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } public function handleAnimate(AnimatePacket $packet) : bool{ - if(!$this->spawned or !$this->isAlive()){ + if(!$this->isAlive()){ return true; } @@ -2805,7 +2648,7 @@ 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()){ + if(!$this->isAlive()){ return false; } @@ -2854,7 +2697,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } public function handleBlockEntityData(BlockEntityDataPacket $packet) : bool{ - if(!$this->spawned or !$this->isAlive()){ + if(!$this->isAlive()){ return true; } $this->doCloseInventory(); @@ -2890,7 +2733,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } public function handleItemFrameDropItem(ItemFrameDropItemPacket $packet) : bool{ - if(!$this->spawned or !$this->isAlive()){ + if(!$this->isAlive()){ return true; } @@ -2917,25 +2760,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); @@ -3732,7 +3556,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * @return bool */ public function doCloseWindow(int $windowId) : bool{ - if(!$this->spawned or $windowId === 0){ + if($windowId === 0){ return false; } @@ -3844,7 +3668,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/network/mcpe/NetworkSession.php b/src/pocketmine/network/mcpe/NetworkSession.php index 6cd32b683..a0ec1bf97 100644 --- a/src/pocketmine/network/mcpe/NetworkSession.php +++ b/src/pocketmine/network/mcpe/NetworkSession.php @@ -25,11 +25,15 @@ namespace pocketmine\network\mcpe; use pocketmine\event\server\DataPacketReceiveEvent; use pocketmine\event\server\DataPacketSendEvent; +use pocketmine\network\mcpe\handler\LoginSessionHandler; +use pocketmine\network\mcpe\handler\PreSpawnSessionHandler; +use pocketmine\network\mcpe\handler\ResourcePacksSessionHandler; use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\network\mcpe\handler\SimpleSessionHandler; use pocketmine\network\mcpe\protocol\DataPacket; use pocketmine\network\mcpe\protocol\DisconnectPacket; use pocketmine\network\mcpe\protocol\PacketPool; +use pocketmine\network\mcpe\protocol\PlayStatusPacket; use pocketmine\network\NetworkInterface; use pocketmine\Player; use pocketmine\Server; @@ -60,7 +64,7 @@ class NetworkSession{ $this->ip = $ip; $this->port = $port; - $this->setHandler(new SimpleSessionHandler($player)); + $this->setHandler(new LoginSessionHandler($player, $this)); } public function getInterface() : NetworkInterface{ @@ -144,4 +148,29 @@ class NetworkSession{ } $this->interface->close($this->player, $notify ? $reason : ""); } + + //TODO: onEnableEncryption() step + + public function onLoginSuccess() : void{ + $pk = new PlayStatusPacket(); + $pk->status = PlayStatusPacket::LOGIN_SUCCESS; + $this->sendDataPacket($pk); + + $this->setHandler(new ResourcePacksSessionHandler($this->server, $this->player, $this)); + } + + public function onResourcePacksDone() : void{ + $this->player->_actuallyConstruct(); + + $this->setHandler(new PreSpawnSessionHandler($this->server, $this->player, $this)); + } + + public function onSpawn() : void{ + $pk = new PlayStatusPacket(); + $pk->status = PlayStatusPacket::PLAYER_SPAWN; + $this->sendDataPacket($pk); + + //TODO: split this up even further + $this->setHandler(new SimpleSessionHandler($this->player)); + } } 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/handler/NullSessionHandler.php b/src/pocketmine/network/mcpe/handler/NullSessionHandler.php new file mode 100644 index 000000000..a36a3989d --- /dev/null +++ b/src/pocketmine/network/mcpe/handler/NullSessionHandler.php @@ -0,0 +1,31 @@ +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..cfb50ed9d --- /dev/null +++ b/src/pocketmine/network/mcpe/handler/ResourcePacksSessionHandler.php @@ -0,0 +1,128 @@ +server = $server; + $this->player = $player; + $this->session = $session; + } + + public function setUp() : void{ + $pk = new ResourcePacksInfoPacket(); + $manager = $this->server->getResourcePackManager(); + $pk->resourcePackEntries = $manager->getResourceStack(); + $pk->mustAccept = $manager->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: + $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->player->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->session->sendDataPacket($pk); + } + + break; + case ResourcePackClientResponsePacket::STATUS_HAVE_ALL_PACKS: + $pk = new ResourcePackStackPacket(); + $manager = $this->server->getResourcePackManager(); + $pk->resourcePackStack = $manager->getResourceStack(); + $pk->mustAccept = $manager->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{ + $manager = $this->server->getResourcePackManager(); + $pack = $manager->getPackById($packet->packId); + if(!($pack instanceof ResourcePack)){ + $this->player->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->session->sendDataPacket($pk); + + return true; + } +} diff --git a/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php b/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php index b640192bb..7bad4b51e 100644 --- a/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php +++ b/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php @@ -42,7 +42,6 @@ use pocketmine\network\mcpe\protocol\InventoryTransactionPacket; use pocketmine\network\mcpe\protocol\ItemFrameDropItemPacket; use pocketmine\network\mcpe\protocol\LabTablePacket; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; -use pocketmine\network\mcpe\protocol\LoginPacket; use pocketmine\network\mcpe\protocol\MapInfoRequestPacket; use pocketmine\network\mcpe\protocol\MobArmorEquipmentPacket; use pocketmine\network\mcpe\protocol\MobEquipmentPacket; @@ -53,8 +52,6 @@ use pocketmine\network\mcpe\protocol\PlayerHotbarPacket; use pocketmine\network\mcpe\protocol\PlayerInputPacket; use pocketmine\network\mcpe\protocol\PlayerSkinPacket; use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket; -use pocketmine\network\mcpe\protocol\ResourcePackChunkRequestPacket; -use pocketmine\network\mcpe\protocol\ResourcePackClientResponsePacket; use pocketmine\network\mcpe\protocol\ServerSettingsRequestPacket; use pocketmine\network\mcpe\protocol\SetLocalPlayerAsInitializedPacket; use pocketmine\network\mcpe\protocol\SetPlayerGameTypePacket; @@ -77,18 +74,10 @@ class SimpleSessionHandler extends SessionHandler{ $this->player = $player; } - 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); @@ -207,10 +196,6 @@ class SimpleSessionHandler extends SessionHandler{ 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); } diff --git a/src/pocketmine/network/mcpe/protocol/LoginPacket.php b/src/pocketmine/network/mcpe/protocol/LoginPacket.php index af971f952..d6aaff9eb 100644 --- a/src/pocketmine/network/mcpe/protocol/LoginPacket.php +++ b/src/pocketmine/network/mcpe/protocol/LoginPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; #include +use pocketmine\entity\Skin; use pocketmine\network\mcpe\handler\SessionHandler; use pocketmine\utils\BinaryStream; use pocketmine\utils\MainLogger; @@ -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,7 +139,15 @@ 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{ From 015ee90571263c3514ec45d8dca4799341bf00d0 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 20 Jul 2018 18:11:29 +0100 Subject: [PATCH 17/20] Split PlayerActionPacket handling into two classes, death is now a session state --- src/pocketmine/Player.php | 117 +----------------- .../network/mcpe/NetworkSession.php | 9 ++ .../mcpe/handler/DeathSessionHandler.php | 61 +++++++++ .../mcpe/handler/SimpleSessionHandler.php | 54 +++++++- 4 files changed, 128 insertions(+), 113 deletions(-) create mode 100644 src/pocketmine/network/mcpe/handler/DeathSessionHandler.php diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index f5cf35998..5f3b5a03d 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -113,8 +113,6 @@ 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\RespawnPacket; use pocketmine\network\mcpe\protocol\SetPlayerGameTypePacket; use pocketmine\network\mcpe\protocol\SetSpawnPositionPacket; use pocketmine\network\mcpe\protocol\SetTitlePacket; @@ -1019,13 +1017,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; @@ -1489,7 +1480,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; } @@ -1971,10 +1962,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * @return bool */ public function chat(string $message) : bool{ - if(!$this->isAlive()){ - return false; - } - $this->doCloseInventory(); $message = TextFormat::clean($message, $this->removeFormat); @@ -2015,9 +2002,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()) 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){ @@ -2047,9 +2031,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } public function handleEntityEvent(EntityEventPacket $packet) : bool{ - if(!$this->isAlive()){ - return true; - } $this->doCloseInventory(); switch($packet->event){ @@ -2075,10 +2056,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * @return bool */ public function handleInventoryTransaction(InventoryTransactionPacket $packet) : bool{ - if(!$this->isAlive()){ - return false; - } - if($this->isSpectator()){ $this->sendAllInventories(); return true; @@ -2437,10 +2414,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } public function handleMobEquipment(MobEquipmentPacket $packet) : bool{ - if(!$this->isAlive()){ - return true; - } - $item = $this->inventory->getItem($packet->hotbarSlot); if(!$item->equals($packet->item)){ @@ -2486,73 +2459,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } - public function handlePlayerAction(PlayerActionPacket $packet) : bool{ - if(!$this->isAlive() and $packet->action !== PlayerActionPacket::ACTION_RESPAWN and $packet->action !== PlayerActionPacket::ACTION_DIMENSION_CHANGE_REQUEST){ - return true; - } - - $packet->entityRuntimeId = $this->id; - $pos = new Vector3($packet->x, $packet->y, $packet->z); - - switch($packet->action){ - case PlayerActionPacket::ACTION_START_BREAK: - $this->startBreakBlock($pos, $packet->face); - - break; - - case PlayerActionPacket::ACTION_ABORT_BREAK: - case PlayerActionPacket::ACTION_STOP_BREAK: - $this->stopBreakBlock($pos); - break; - case PlayerActionPacket::ACTION_START_SLEEPING: - //unused - break; - case PlayerActionPacket::ACTION_STOP_SLEEPING: - $this->stopSleep(); - break; - case PlayerActionPacket::ACTION_RESPAWN: - if($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: - $this->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->server->getLogger()->debug("Unhandled/unknown player action type " . $packet->action . " from " . $this->getName()); - return false; - } - - $this->setUsingItem(false); - - return true; - } - public function startBreakBlock(Vector3 $pos, int $face) : bool{ if($pos->distanceSquared($this) > 10000){ return false; //TODO: maybe this should throw an exception instead? @@ -2624,10 +2530,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } public function handleAnimate(AnimatePacket $packet) : bool{ - if(!$this->isAlive()){ - return true; - } - $this->server->getPluginManager()->callEvent($ev = new PlayerAnimationEvent($this, $packet->action)); if($ev->isCancelled()){ return true; @@ -2648,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->isAlive()){ - return false; - } - if($item->isNull()){ $this->server->getLogger()->debug($this->getName() . " attempted to drop a null item (" . $item . ")"); return true; @@ -2697,9 +2595,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } public function handleBlockEntityData(BlockEntityDataPacket $packet) : bool{ - if(!$this->isAlive()){ - return true; - } $this->doCloseInventory(); $pos = new Vector3($packet->x, $packet->y, $packet->z); @@ -2733,10 +2628,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } public function handleItemFrameDropItem(ItemFrameDropItemPacket $packet) : bool{ - if(!$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); @@ -3223,7 +3114,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ parent::kill(); - $this->sendRespawnPacket($this->getSpawn()); + $this->networkSession->onDeath(); } protected function onDeath() : void{ @@ -3372,7 +3263,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; @@ -3406,6 +3297,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->spawnToAll(); $this->scheduleUpdate(); + + $this->networkSession->onRespawn(); } protected function applyPostDamageEffects(EntityDamageEvent $source) : void{ diff --git a/src/pocketmine/network/mcpe/NetworkSession.php b/src/pocketmine/network/mcpe/NetworkSession.php index a0ec1bf97..c7f19f646 100644 --- a/src/pocketmine/network/mcpe/NetworkSession.php +++ b/src/pocketmine/network/mcpe/NetworkSession.php @@ -25,6 +25,7 @@ namespace pocketmine\network\mcpe; use pocketmine\event\server\DataPacketReceiveEvent; use pocketmine\event\server\DataPacketSendEvent; +use pocketmine\network\mcpe\handler\DeathSessionHandler; use pocketmine\network\mcpe\handler\LoginSessionHandler; use pocketmine\network\mcpe\handler\PreSpawnSessionHandler; use pocketmine\network\mcpe\handler\ResourcePacksSessionHandler; @@ -173,4 +174,12 @@ class NetworkSession{ //TODO: split this up even further $this->setHandler(new SimpleSessionHandler($this->player)); } + + public function onDeath() : void{ + $this->setHandler(new DeathSessionHandler($this->player, $this)); + } + + public function onRespawn() : void{ + $this->setHandler(new SimpleSessionHandler($this->player)); + } } 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/SimpleSessionHandler.php b/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php index 7bad4b51e..a408d8530 100644 --- a/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php +++ b/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\network\mcpe\handler; +use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\AdventureSettingsPacket; use pocketmine\network\mcpe\protocol\AnimatePacket; use pocketmine\network\mcpe\protocol\BlockEntityDataPacket; @@ -123,7 +124,58 @@ class SimpleSessionHandler extends SessionHandler{ } 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{ From 30c044f0283370e7ef4b6e6e1aad12f8666d7a3b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 20 Jul 2018 18:48:46 +0100 Subject: [PATCH 18/20] Unwrap more code from packet handlers --- src/pocketmine/Player.php | 37 +++++++------------ src/pocketmine/inventory/PlayerInventory.php | 29 +-------------- .../mcpe/handler/SimpleSessionHandler.php | 13 +++++-- 3 files changed, 24 insertions(+), 55 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 5f3b5a03d..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; @@ -100,7 +101,6 @@ use pocketmine\network\mcpe\protocol\AdventureSettingsPacket; use pocketmine\network\mcpe\protocol\AnimatePacket; use pocketmine\network\mcpe\protocol\AvailableCommandsPacket; 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\DataPacket; @@ -111,7 +111,6 @@ 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\SetPlayerGameTypePacket; use pocketmine\network\mcpe\protocol\SetSpawnPositionPacket; @@ -2413,27 +2412,29 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return false; //TODO } - public function handleMobEquipment(MobEquipmentPacket $packet) : bool{ - $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 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(); @@ -2456,7 +2457,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } return true; - } public function startBreakBlock(Vector3 $pos, int $face) : bool{ @@ -2529,8 +2529,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } - public function handleAnimate(AnimatePacket $packet) : bool{ - $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; } @@ -2618,15 +2618,6 @@ 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{ $tile = $this->level->getTileAt($packet->x, $packet->y, $packet->z); if($tile instanceof ItemFrame){ 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/network/mcpe/handler/SimpleSessionHandler.php b/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php index a408d8530..ca080fd29 100644 --- a/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php +++ b/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php @@ -104,7 +104,7 @@ class SimpleSessionHandler extends SessionHandler{ } public function handleMobEquipment(MobEquipmentPacket $packet) : bool{ - return $this->player->handleMobEquipment($packet); + return $this->player->equipItem($packet->hotbarSlot); } public function handleMobArmorEquipment(MobArmorEquipmentPacket $packet) : bool{ @@ -116,7 +116,7 @@ class SimpleSessionHandler extends SessionHandler{ } 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{ @@ -183,7 +183,7 @@ class SimpleSessionHandler extends SessionHandler{ } public function handleAnimate(AnimatePacket $packet) : bool{ - return $this->player->handleAnimate($packet); + return $this->player->animate($packet->action); } public function handleContainerClose(ContainerClosePacket $packet) : bool{ @@ -211,7 +211,12 @@ class SimpleSessionHandler extends SessionHandler{ } 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{ From 59f6821c29be07c4904e4dfdb6cdeb16da3f4373 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 20 Jul 2018 20:08:12 +0100 Subject: [PATCH 19/20] Allow parameterizing ResourcePackManager to session handler this will open the way (in the future) for custom managers to be used, instead of a global thing. --- .../network/mcpe/NetworkSession.php | 2 +- .../handler/ResourcePacksSessionHandler.php | 30 ++++++++----------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/pocketmine/network/mcpe/NetworkSession.php b/src/pocketmine/network/mcpe/NetworkSession.php index c7f19f646..ba4b14e52 100644 --- a/src/pocketmine/network/mcpe/NetworkSession.php +++ b/src/pocketmine/network/mcpe/NetworkSession.php @@ -157,7 +157,7 @@ class NetworkSession{ $pk->status = PlayStatusPacket::LOGIN_SUCCESS; $this->sendDataPacket($pk); - $this->setHandler(new ResourcePacksSessionHandler($this->server, $this->player, $this)); + $this->setHandler(new ResourcePacksSessionHandler($this->player, $this, $this->server->getResourcePackManager())); } public function onResourcePacksDone() : void{ diff --git a/src/pocketmine/network/mcpe/handler/ResourcePacksSessionHandler.php b/src/pocketmine/network/mcpe/handler/ResourcePacksSessionHandler.php index cfb50ed9d..c64d7bd47 100644 --- a/src/pocketmine/network/mcpe/handler/ResourcePacksSessionHandler.php +++ b/src/pocketmine/network/mcpe/handler/ResourcePacksSessionHandler.php @@ -32,7 +32,7 @@ use pocketmine\network\mcpe\protocol\ResourcePacksInfoPacket; use pocketmine\network\mcpe\protocol\ResourcePackStackPacket; use pocketmine\Player; use pocketmine\resourcepacks\ResourcePack; -use pocketmine\Server; +use pocketmine\resourcepacks\ResourcePackManager; /** * Handler used for the resource packs sequence phase of the session. This handler takes care of downloading resource @@ -40,24 +40,23 @@ use pocketmine\Server; */ class ResourcePacksSessionHandler extends SessionHandler{ - /** @var Server */ - private $server; /** @var Player */ private $player; /** @var NetworkSession */ private $session; + /** @var ResourcePackManager */ + private $resourcePackManager; - public function __construct(Server $server, Player $player, NetworkSession $session){ - $this->server = $server; + public function __construct(Player $player, NetworkSession $session, ResourcePackManager $resourcePackManager){ $this->player = $player; $this->session = $session; + $this->resourcePackManager = $resourcePackManager; } public function setUp() : void{ $pk = new ResourcePacksInfoPacket(); - $manager = $this->server->getResourcePackManager(); - $pk->resourcePackEntries = $manager->getResourceStack(); - $pk->mustAccept = $manager->resourcePacksRequired(); + $pk->resourcePackEntries = $this->resourcePackManager->getResourceStack(); + $pk->mustAccept = $this->resourcePackManager->resourcePacksRequired(); $this->session->sendDataPacket($pk); } @@ -68,13 +67,12 @@ class ResourcePacksSessionHandler extends SessionHandler{ $this->player->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); + $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->server->getLogger()->debug("Got a resource pack request for unknown pack with UUID " . $uuid . ", available packs: " . implode(", ", $manager->getPackIdList())); + $this->player->getServer()->getLogger()->debug("Got a resource pack request for unknown pack with UUID " . $uuid . ", available packs: " . implode(", ", $this->resourcePackManager->getPackIdList())); return false; } @@ -91,9 +89,8 @@ class ResourcePacksSessionHandler extends SessionHandler{ break; case ResourcePackClientResponsePacket::STATUS_HAVE_ALL_PACKS: $pk = new ResourcePackStackPacket(); - $manager = $this->server->getResourcePackManager(); - $pk->resourcePackStack = $manager->getResourceStack(); - $pk->mustAccept = $manager->resourcePacksRequired(); + $pk->resourcePackStack = $this->resourcePackManager->getResourceStack(); + $pk->mustAccept = $this->resourcePackManager->resourcePacksRequired(); $this->session->sendDataPacket($pk); break; case ResourcePackClientResponsePacket::STATUS_COMPLETED: @@ -107,11 +104,10 @@ class ResourcePacksSessionHandler extends SessionHandler{ } public function handleResourcePackChunkRequest(ResourcePackChunkRequestPacket $packet) : bool{ - $manager = $this->server->getResourcePackManager(); - $pack = $manager->getPackById($packet->packId); + $pack = $this->resourcePackManager->getPackById($packet->packId); if(!($pack instanceof ResourcePack)){ $this->player->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())); + $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; } From c257a791e16a4edc1b3c1c2c3f5e053553b7fdc4 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 21 Jul 2018 09:33:21 +0100 Subject: [PATCH 20/20] ResourcePacksSessionHandler: move max pack chunk size to const --- .../network/mcpe/handler/ResourcePacksSessionHandler.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pocketmine/network/mcpe/handler/ResourcePacksSessionHandler.php b/src/pocketmine/network/mcpe/handler/ResourcePacksSessionHandler.php index c64d7bd47..da51a41ca 100644 --- a/src/pocketmine/network/mcpe/handler/ResourcePacksSessionHandler.php +++ b/src/pocketmine/network/mcpe/handler/ResourcePacksSessionHandler.php @@ -39,6 +39,7 @@ use pocketmine\resourcepacks\ResourcePackManager; * packs to the client. */ class ResourcePacksSessionHandler extends SessionHandler{ + private const PACK_CHUNK_SIZE = 1048576; //1MB /** @var Player */ private $player; @@ -79,8 +80,8 @@ class ResourcePacksSessionHandler extends SessionHandler{ $pk = new ResourcePackDataInfoPacket(); $pk->packId = $pack->getPackId(); - $pk->maxChunkSize = 1048576; //1MB - $pk->chunkCount = (int) ceil($pack->getPackSize() / $pk->maxChunkSize); + $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); @@ -115,8 +116,8 @@ class ResourcePacksSessionHandler extends SessionHandler{ $pk = new ResourcePackChunkDataPacket(); $pk->packId = $pack->getPackId(); $pk->chunkIndex = $packet->chunkIndex; - $pk->data = $pack->getPackChunk(1048576 * $packet->chunkIndex, 1048576); - $pk->progress = (1048576 * $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;