From 0cd1e82c521b31cd0ca70c9ef6999da033ea9eb4 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 24 Feb 2017 13:28:11 +0000 Subject: [PATCH 01/96] Fixed encode/decode of ResourcePacksInfoPacket and ResourcePackClientResponsePacket --- .../ResourcePackClientResponsePacket.php | 18 +++++++++++++----- .../protocol/ResourcePacksInfoPacket.php | 19 +++++++++++++++++-- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/pocketmine/network/protocol/ResourcePackClientResponsePacket.php b/src/pocketmine/network/protocol/ResourcePackClientResponsePacket.php index 42a714f03..e74740649 100644 --- a/src/pocketmine/network/protocol/ResourcePackClientResponsePacket.php +++ b/src/pocketmine/network/protocol/ResourcePackClientResponsePacket.php @@ -27,16 +27,24 @@ namespace pocketmine\network\protocol; class ResourcePackClientResponsePacket extends DataPacket{ const NETWORK_ID = Info::RESOURCE_PACK_CLIENT_RESPONSE_PACKET; - public $unknownByte; - public $unknownShort; + public $status; //TODO: add constants for status types + public $packIds = []; public function decode(){ - $this->unknownByte = $this->getByte(); - $this->unknownShort = $this->getShort(); + $this->status = $this->getByte(); + $entryCount = $this->getLShort(); + while($entryCount-- > 0){ + $this->packIds[] = $this->getString(); + } } public function encode(){ - + $this->reset(); + $this->putByte($this->status); + $this->putLShort(count($this->packIds)); + foreach($this->packIds as $id){ + $this->putString($id); + } } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/ResourcePacksInfoPacket.php b/src/pocketmine/network/protocol/ResourcePacksInfoPacket.php index 26aa79beb..0f844cee3 100644 --- a/src/pocketmine/network/protocol/ResourcePacksInfoPacket.php +++ b/src/pocketmine/network/protocol/ResourcePacksInfoPacket.php @@ -36,20 +36,35 @@ class ResourcePacksInfoPacket extends DataPacket{ public $resourcePackEntries = []; public function decode(){ + $this->mustAccept = $this->getBool(); + $behaviorPackCount = $this->getLShort(); + while($behaviorPackCount-- > 0){ + $id = $this->getString(); + $version = $this->getString(); + $size = $this->getLLong(); + $this->behaviorPackEntries[] = new ResourcePackInfoEntry($id, $version, $size); + } + $resourcePackCount = $this->getLShort(); + while($resourcePackCount-- > 0){ + $id = $this->getString(); + $version = $this->getString(); + $size = $this->getLLong(); + $this->resourcePackEntries[] = new ResourcePackInfoEntry($id, $version, $size); + } } public function encode(){ $this->reset(); $this->putBool($this->mustAccept); - $this->putShort(count($this->behaviorPackEntries)); + $this->putLShort(count($this->behaviorPackEntries)); foreach($this->behaviorPackEntries as $entry){ $this->putString($entry->getPackId()); $this->putString($entry->getVersion()); $this->putLLong($entry->getPackSize()); } - $this->putShort(count($this->resourcePackEntries)); + $this->putLShort(count($this->resourcePackEntries)); foreach($this->resourcePackEntries as $entry){ $this->putString($entry->getPackId()); $this->putString($entry->getVersion()); From eb13cec5d0f663e27f57f4ee9d0809d6710251f1 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 24 Feb 2017 17:25:40 +0000 Subject: [PATCH 02/96] Added new packets --- src/pocketmine/network/Network.php | 2 + .../network/protocol/PlayStatusPacket.php | 2 + .../ResourcePackClientResponsePacket.php | 5 ++ .../protocol/ResourcePackStackPacket.php | 73 +++++++++++++++++++ .../protocol/ResourcePacksInfoPacket.php | 4 +- .../network/protocol/RiderJumpPacket.php | 41 +++++++++++ .../resourcepacks/ResourcePackInfoEntry.php | 2 +- 7 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 src/pocketmine/network/protocol/ResourcePackStackPacket.php create mode 100644 src/pocketmine/network/protocol/RiderJumpPacket.php diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index 9418159db..ac198cc44 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -77,6 +77,7 @@ use pocketmine\network\protocol\RequestChunkRadiusPacket; use pocketmine\network\protocol\ResourcePackClientResponsePacket; use pocketmine\network\protocol\ResourcePacksInfoPacket; use pocketmine\network\protocol\RespawnPacket; +use pocketmine\network\protocol\RiderJumpPacket; use pocketmine\network\protocol\SetCommandsEnabledPacket; use pocketmine\network\protocol\SetDifficultyPacket; use pocketmine\network\protocol\SetEntityDataPacket; @@ -353,6 +354,7 @@ class Network{ $this->registerPacket(ProtocolInfo::RESOURCE_PACK_CLIENT_RESPONSE_PACKET, ResourcePackClientResponsePacket::class); $this->registerPacket(ProtocolInfo::RESOURCE_PACKS_INFO_PACKET, ResourcePacksInfoPacket::class); $this->registerPacket(ProtocolInfo::RESPAWN_PACKET, RespawnPacket::class); + $this->registerPacket(ProtocolInfo::RIDER_JUMP_PACKET, RiderJumpPacket::class); $this->registerPacket(ProtocolInfo::SET_COMMANDS_ENABLED_PACKET, SetCommandsEnabledPacket::class); $this->registerPacket(ProtocolInfo::SET_DIFFICULTY_PACKET, SetDifficultyPacket::class); $this->registerPacket(ProtocolInfo::SET_ENTITY_DATA_PACKET, SetEntityDataPacket::class); diff --git a/src/pocketmine/network/protocol/PlayStatusPacket.php b/src/pocketmine/network/protocol/PlayStatusPacket.php index 47b695ff6..2feaa3e55 100644 --- a/src/pocketmine/network/protocol/PlayStatusPacket.php +++ b/src/pocketmine/network/protocol/PlayStatusPacket.php @@ -31,6 +31,8 @@ class PlayStatusPacket extends DataPacket{ const LOGIN_FAILED_CLIENT = 1; const LOGIN_FAILED_SERVER = 2; const PLAYER_SPAWN = 3; + const LOGIN_FAILED_INVALID_TENANT = 4; + const LOGIN_FAILED_EDITION_MISMATCH = 5; public $status; diff --git a/src/pocketmine/network/protocol/ResourcePackClientResponsePacket.php b/src/pocketmine/network/protocol/ResourcePackClientResponsePacket.php index e74740649..32ff17267 100644 --- a/src/pocketmine/network/protocol/ResourcePackClientResponsePacket.php +++ b/src/pocketmine/network/protocol/ResourcePackClientResponsePacket.php @@ -27,6 +27,11 @@ namespace pocketmine\network\protocol; class ResourcePackClientResponsePacket extends DataPacket{ const NETWORK_ID = Info::RESOURCE_PACK_CLIENT_RESPONSE_PACKET; + const STATUS_REFUSED = 1; + const STATUS_SEND_PACKS = 2; + const STATUS_HAVE_ALL_PACKS = 3; + const STATUS_COMPLETED = 4; + public $status; //TODO: add constants for status types public $packIds = []; diff --git a/src/pocketmine/network/protocol/ResourcePackStackPacket.php b/src/pocketmine/network/protocol/ResourcePackStackPacket.php new file mode 100644 index 000000000..3a9fb43a8 --- /dev/null +++ b/src/pocketmine/network/protocol/ResourcePackStackPacket.php @@ -0,0 +1,73 @@ + + + +use pocketmine\resourcepacks\ResourcePackInfoEntry; + +class ResourcePackStackPacket extends DataPacket{ + const NETWORK_ID = Info::RESOURCE_PACK_STACK_PACKET; + + public $mustAccept = false; + + /** @var ResourcePackInfoEntry[] */ + public $behaviorPackStack = []; + /** @var ResourcePackInfoEntry[] */ + public $resourcePackStack = []; + + public function decode(){ + $this->mustAccept = $this->getBool(); + $behaviorPackCount = $this->getLShort(); + while($behaviorPackCountCount-- > 0){ + $packId = $this->getString(); + $version = $this->getString(); + $this->behaviorPackStack[] = new ResourcePackInfoEntry($packId, $version); + } + + $resourcePackCount = $this->getLShort(); + while($resourcePackCount-- > 0){ + $packId = $this->getString(); + $version = $this->getString(); + $this->resourcePackStack[] = new ResourcePackInfoEntry($packId, $version); + } + } + + public function encode(){ + $this->reset(); + $this->putBool($this->mustAccept); + + $this->putLShort(count($this->behaviorPackStack)); + foreach($this->behaviorPackStack as $entry){ + $this->putString($entry->getPackId()); + $this->putString($entry->getVersion()); + } + + $this->putLShort(count($this->resourcePackStack)); + foreach($this->resourcePackStack as $entry){ + $this->putString($entry->getPackId()); + $this->putString($entry->getVersion()); + } + } +} \ No newline at end of file diff --git a/src/pocketmine/network/protocol/ResourcePacksInfoPacket.php b/src/pocketmine/network/protocol/ResourcePacksInfoPacket.php index 0f844cee3..7dd85cce0 100644 --- a/src/pocketmine/network/protocol/ResourcePacksInfoPacket.php +++ b/src/pocketmine/network/protocol/ResourcePacksInfoPacket.php @@ -21,11 +21,11 @@ namespace pocketmine\network\protocol; -use pocketmine\resourcepacks\ResourcePackInfoEntry; - #include +use pocketmine\resourcepacks\ResourcePackInfoEntry; + class ResourcePacksInfoPacket extends DataPacket{ const NETWORK_ID = Info::RESOURCE_PACKS_INFO_PACKET; diff --git a/src/pocketmine/network/protocol/RiderJumpPacket.php b/src/pocketmine/network/protocol/RiderJumpPacket.php new file mode 100644 index 000000000..636082487 --- /dev/null +++ b/src/pocketmine/network/protocol/RiderJumpPacket.php @@ -0,0 +1,41 @@ + + + +class RiderJumpPacket extends DataPacket{ + const NETWORK_ID = Info::RIDER_JUMP_PACKET; + + public $unknown; + + public function decode(){ + $this->unknown = $this->getVarInt(); + } + + public function encode(){ + $this->reset(); + $this->putVarInt($this->unknown); + } +} \ No newline at end of file diff --git a/src/pocketmine/resourcepacks/ResourcePackInfoEntry.php b/src/pocketmine/resourcepacks/ResourcePackInfoEntry.php index edb70b768..db955c0cd 100644 --- a/src/pocketmine/resourcepacks/ResourcePackInfoEntry.php +++ b/src/pocketmine/resourcepacks/ResourcePackInfoEntry.php @@ -26,7 +26,7 @@ class ResourcePackInfoEntry{ protected $version; protected $packSize; - public function __construct(string $packId, string $version, $packSize){ + public function __construct(string $packId, string $version, $packSize = 0){ $this->packId = $packId; $this->version = $version; $this->packSize = $packSize; From 8bf3b6bbea581e98eb118e4f25aaab457de8def4 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 24 Feb 2017 19:58:24 +0000 Subject: [PATCH 03/96] Added ShowCreditsPacket --- src/pocketmine/network/Network.php | 2 + .../network/protocol/ShowCreditsPacket.php | 47 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/pocketmine/network/protocol/ShowCreditsPacket.php diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index ac198cc44..45cd58cb3 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -87,6 +87,7 @@ use pocketmine\network\protocol\SetHealthPacket; use pocketmine\network\protocol\SetPlayerGameTypePacket; use pocketmine\network\protocol\SetSpawnPositionPacket; use pocketmine\network\protocol\SetTimePacket; +use pocketmine\network\protocol\ShowCreditsPacket; use pocketmine\network\protocol\SpawnExperienceOrbPacket; use pocketmine\network\protocol\StartGamePacket; use pocketmine\network\protocol\TakeItemEntityPacket; @@ -364,6 +365,7 @@ class Network{ $this->registerPacket(ProtocolInfo::SET_PLAYER_GAME_TYPE_PACKET, SetPlayerGameTypePacket::class); $this->registerPacket(ProtocolInfo::SET_SPAWN_POSITION_PACKET, SetSpawnPositionPacket::class); $this->registerPacket(ProtocolInfo::SET_TIME_PACKET, SetTimePacket::class); + $this->registerPacket(ProtocolInfo::SHOW_CREDITS_PACKET, ShowCreditsPacket::class); $this->registerPacket(ProtocolInfo::SPAWN_EXPERIENCE_ORB_PACKET, SpawnExperienceOrbPacket::class); $this->registerPacket(ProtocolInfo::START_GAME_PACKET, StartGamePacket::class); $this->registerPacket(ProtocolInfo::TAKE_ITEM_ENTITY_PACKET, TakeItemEntityPacket::class); diff --git a/src/pocketmine/network/protocol/ShowCreditsPacket.php b/src/pocketmine/network/protocol/ShowCreditsPacket.php new file mode 100644 index 000000000..751831ae5 --- /dev/null +++ b/src/pocketmine/network/protocol/ShowCreditsPacket.php @@ -0,0 +1,47 @@ + + + +class ShowCreditsPacket extends DataPacket{ + const NETWORK_ID = Info::SHOW_CREDITS_PACKET; + + const STATUS_START_CREDITS = 0; + const STATUS_END_CREDITS = 1; + + public $playerEid; + public $status; + + public function decode(){ + $this->playerEid = $this->getEntityId(); + $this->status = $this->getVarInt(); + } + + public function encode(){ + $this->reset(); + $this->putEntityId($this->playerEid); + $this->putVarInt($this->status); + } +} \ No newline at end of file From 477cb77002af5ab9e9b7d80f618d0c43a12d3f7f Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 26 Feb 2017 15:51:11 +0000 Subject: [PATCH 04/96] Exploded Player->handleDataPacket() into 70+ methods --- src/pocketmine/Player.php | 2541 +++++++++-------- src/pocketmine/network/Network.php | 5 +- .../network/PocketEditionNetworkSession.php | 263 ++ src/pocketmine/network/RakLibInterface.php | 5 +- .../network/protocol/AddEntityPacket.php | 5 + .../protocol/AddHangingEntityPacket.php | 6 + .../network/protocol/AddItemEntityPacket.php | 6 + .../network/protocol/AddItemPacket.php | 6 + .../network/protocol/AddPaintingPacket.php | 6 + .../network/protocol/AddPlayerPacket.php | 6 + .../protocol/AdventureSettingsPacket.php | 6 + .../network/protocol/AnimatePacket.php | 6 + .../protocol/AvailableCommandsPacket.php | 6 + .../network/protocol/BatchPacket.php | 6 + .../protocol/BlockEntityDataPacket.php | 6 + .../network/protocol/BlockEventPacket.php | 6 + .../protocol/ChangeDimensionPacket.php | 6 + .../protocol/ChunkRadiusUpdatedPacket.php | 6 + .../network/protocol/CommandStepPacket.php | 6 + .../network/protocol/ContainerClosePacket.php | 5 + .../network/protocol/ContainerOpenPacket.php | 6 + .../protocol/ContainerSetContentPacket.php | 6 + .../protocol/ContainerSetDataPacket.php | 6 + .../protocol/ContainerSetSlotPacket.php | 5 + .../network/protocol/CraftingDataPacket.php | 5 + .../network/protocol/CraftingEventPacket.php | 5 + .../network/protocol/DataPacket.php | 3 + .../network/protocol/DisconnectPacket.php | 6 + .../network/protocol/DropItemPacket.php | 6 + .../network/protocol/EntityEventPacket.php | 6 + .../network/protocol/ExplodePacket.php | 6 + .../network/protocol/FullChunkDataPacket.php | 6 + .../network/protocol/HurtArmorPacket.php | 6 + src/pocketmine/network/protocol/Info.php | 2 +- .../network/protocol/InteractPacket.php | 6 + .../protocol/InventoryActionPacket.php | 6 + .../protocol/ItemFrameDropItemPacket.php | 6 + .../network/protocol/LevelEventPacket.php | 6 + .../protocol/LevelSoundEventPacket.php | 6 + .../network/protocol/LoginPacket.php | 6 + .../protocol/MobArmorEquipmentPacket.php | 6 + .../network/protocol/MobEffectPacket.php | 6 + .../network/protocol/MobEquipmentPacket.php | 6 + .../network/protocol/MoveEntityPacket.php | 6 + .../network/protocol/MovePlayerPacket.php | 6 + .../network/protocol/PlayStatusPacket.php | 6 + .../network/protocol/PlayerActionPacket.php | 6 + .../network/protocol/PlayerFallPacket.php | 6 + .../network/protocol/PlayerInputPacket.php | 6 + .../network/protocol/PlayerListPacket.php | 6 + .../network/protocol/RemoveBlockPacket.php | 6 + .../network/protocol/RemoveEntityPacket.php | 6 + .../protocol/ReplaceItemInSlotPacket.php | 5 + .../protocol/RequestChunkRadiusPacket.php | 7 + .../ResourcePackClientResponsePacket.php | 6 + .../protocol/ResourcePackStackPacket.php | 5 + .../protocol/ResourcePacksInfoPacket.php | 5 + .../network/protocol/RespawnPacket.php | 6 + .../network/protocol/RiderJumpPacket.php | 6 + .../protocol/SetCommandsEnabledPacket.php | 6 + .../network/protocol/SetDifficultyPacket.php | 6 + .../network/protocol/SetEntityDataPacket.php | 5 + .../network/protocol/SetEntityLinkPacket.php | 6 + .../protocol/SetEntityMotionPacket.php | 6 + .../network/protocol/SetHealthPacket.php | 6 + .../protocol/SetPlayerGameTypePacket.php | 6 + .../protocol/SetSpawnPositionPacket.php | 6 + .../network/protocol/SetTimePacket.php | 6 + .../network/protocol/ShowCreditsPacket.php | 6 + .../protocol/SpawnExperienceOrbPacket.php | 6 + .../network/protocol/StartGamePacket.php | 6 + .../network/protocol/TakeItemEntityPacket.php | 5 + .../network/protocol/TextPacket.php | 6 + .../network/protocol/TransferPacket.php | 6 + .../protocol/UpdateAttributesPacket.php | 5 + .../network/protocol/UpdateBlockPacket.php | 6 + .../network/protocol/UseItemPacket.php | 6 + 77 files changed, 2105 insertions(+), 1130 deletions(-) create mode 100644 src/pocketmine/network/PocketEditionNetworkSession.php diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 827ab813e..cef80e0d9 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -101,34 +101,80 @@ use pocketmine\nbt\tag\ListTag; use pocketmine\nbt\tag\LongTag; use pocketmine\nbt\tag\ShortTag; use pocketmine\nbt\tag\StringTag; +use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\protocol\AddEntityPacket; +use pocketmine\network\protocol\AddHangingEntityPacket; +use pocketmine\network\protocol\AddItemEntityPacket; +use pocketmine\network\protocol\AddItemPacket; +use pocketmine\network\protocol\AddPaintingPacket; +use pocketmine\network\protocol\AddPlayerPacket; use pocketmine\network\protocol\AdventureSettingsPacket; use pocketmine\network\protocol\AnimatePacket; use pocketmine\network\protocol\AvailableCommandsPacket; use pocketmine\network\protocol\BatchPacket; +use pocketmine\network\protocol\BlockEntityDataPacket; +use pocketmine\network\protocol\BlockEventPacket; +use pocketmine\network\protocol\ChangeDimensionPacket; use pocketmine\network\protocol\ChunkRadiusUpdatedPacket; +use pocketmine\network\protocol\CommandStepPacket; use pocketmine\network\protocol\ContainerClosePacket; +use pocketmine\network\protocol\ContainerOpenPacket; use pocketmine\network\protocol\ContainerSetContentPacket; +use pocketmine\network\protocol\ContainerSetDataPacket; +use pocketmine\network\protocol\ContainerSetSlotPacket; +use pocketmine\network\protocol\CraftingDataPacket; +use pocketmine\network\protocol\CraftingEventPacket; use pocketmine\network\protocol\DataPacket; use pocketmine\network\protocol\DisconnectPacket; +use pocketmine\network\protocol\DropItemPacket; use pocketmine\network\protocol\EntityEventPacket; +use pocketmine\network\protocol\ExplodePacket; use pocketmine\network\protocol\FullChunkDataPacket; +use pocketmine\network\protocol\HurtArmorPacket; use pocketmine\network\protocol\Info as ProtocolInfo; use pocketmine\network\protocol\InteractPacket; +use pocketmine\network\protocol\InventoryActionPacket; +use pocketmine\network\protocol\ItemFrameDropItemPacket; +use pocketmine\network\protocol\LevelEventPacket; +use pocketmine\network\protocol\LevelSoundEventPacket; +use pocketmine\network\protocol\LoginPacket; +use pocketmine\network\protocol\MobArmorEquipmentPacket; +use pocketmine\network\protocol\MobEffectPacket; +use pocketmine\network\protocol\MobEquipmentPacket; +use pocketmine\network\protocol\MoveEntityPacket; use pocketmine\network\protocol\MovePlayerPacket; use pocketmine\network\protocol\PlayerActionPacket; +use pocketmine\network\protocol\PlayerFallPacket; +use pocketmine\network\protocol\PlayerInputPacket; +use pocketmine\network\protocol\PlayerListPacket; use pocketmine\network\protocol\PlayStatusPacket; +use pocketmine\network\protocol\RemoveBlockPacket; +use pocketmine\network\protocol\RemoveEntityPacket; +use pocketmine\network\protocol\ReplaceItemInSlotPacket; +use pocketmine\network\protocol\RequestChunkRadiusPacket; +use pocketmine\network\protocol\ResourcePackClientResponsePacket; use pocketmine\network\protocol\ResourcePacksInfoPacket; +use pocketmine\network\protocol\ResourcePackStackPacket; use pocketmine\network\protocol\RespawnPacket; +use pocketmine\network\protocol\RiderJumpPacket; +use pocketmine\network\protocol\SetCommandsEnabledPacket; +use pocketmine\network\protocol\SetDifficultyPacket; +use pocketmine\network\protocol\SetEntityDataPacket; +use pocketmine\network\protocol\SetEntityLinkPacket; use pocketmine\network\protocol\SetEntityMotionPacket; use pocketmine\network\protocol\SetHealthPacket; use pocketmine\network\protocol\SetPlayerGameTypePacket; use pocketmine\network\protocol\SetSpawnPositionPacket; use pocketmine\network\protocol\SetTimePacket; +use pocketmine\network\protocol\ShowCreditsPacket; +use pocketmine\network\protocol\SpawnExperienceOrbPacket; use pocketmine\network\protocol\StartGamePacket; use pocketmine\network\protocol\TakeItemEntityPacket; use pocketmine\network\protocol\TextPacket; +use pocketmine\network\protocol\TransferPacket; use pocketmine\network\protocol\UpdateAttributesPacket; use pocketmine\network\protocol\UpdateBlockPacket; +use pocketmine\network\protocol\UseItemPacket; use pocketmine\network\SourceInterface; use pocketmine\permission\PermissibleBase; use pocketmine\permission\PermissionAttachment; @@ -142,7 +188,7 @@ use pocketmine\utils\UUID; /** * Main class that handles networking, recovery, and packet sending to the server part */ -class Player extends Human implements CommandSender, InventoryHolder, ChunkLoader, IPlayer{ +class Player extends Human implements CommandSender, InventoryHolder, ChunkLoader, IPlayer, PocketEditionNetworkSession{ const SURVIVAL = 0; const CREATIVE = 1; @@ -1832,6 +1878,1373 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->server->onPlayerLogin($this); } + public function handleLogin(LoginPacket $packet) : bool{ + if($this->loggedIn){ + return false; + } + + $this->username = TextFormat::clean($packet->username); + $this->displayName = $this->username; + $this->iusername = strtolower($this->username); + $this->setDataProperty(self::DATA_NAMETAG, self::DATA_TYPE_STRING, $this->username, false); + + if(count($this->server->getOnlinePlayers()) >= $this->server->getMaxPlayers() and $this->kick("disconnectionScreen.serverFull", false)){ + return true; + } + + if($packet->protocol !== ProtocolInfo::CURRENT_PROTOCOL){ + if($packet->protocol < ProtocolInfo::CURRENT_PROTOCOL){ + $message = "disconnectionScreen.outdatedClient"; + + $pk = new PlayStatusPacket(); + $pk->status = PlayStatusPacket::LOGIN_FAILED_CLIENT; + $this->directDataPacket($pk); + }else{ + $message = "disconnectionScreen.outdatedServer"; + + $pk = new PlayStatusPacket(); + $pk->status = PlayStatusPacket::LOGIN_FAILED_SERVER; + $this->directDataPacket($pk); + } + $this->close("", $message, false); + + return true; + } + + $this->randomClientId = $packet->clientId; + + $this->uuid = UUID::fromString($packet->clientUUID); + $this->rawUUID = $this->uuid->toBinary(); + + $valid = true; + $len = strlen($packet->username); + if($len > 16 or $len < 3){ + $valid = false; + } + for($i = 0; $i < $len and $valid; ++$i){ + $c = ord($packet->username{$i}); + if(($c >= ord("a") and $c <= ord("z")) or + ($c >= ord("A") and $c <= ord("Z")) or + ($c >= ord("0") and $c <= ord("9")) or $c === ord("_") + ){ + continue; + } + + $valid = false; + break; + } + + if(!$valid or $this->iusername === "rcon" or $this->iusername === "console"){ + $this->close("", "disconnectionScreen.invalidName"); + + return true; + } + + if(strlen($packet->skin) !== 64 * 32 * 4 and strlen($packet->skin) !== 64 * 64 * 4){ + $this->close("", "disconnectionScreen.invalidSkin"); + return true; + } + + $this->setSkin($packet->skin, $packet->skinId); + + $this->server->getPluginManager()->callEvent($ev = new PlayerPreLoginEvent($this, "Plugin reason")); + if($ev->isCancelled()){ + $this->close("", $ev->getKickMessage()); + + return true; + } + + $this->onPlayerPreLogin(); + + return true; + } + + public function handlePlayStatus(PlayStatusPacket $packet) : bool{ + return false; + } + + public function handleDisconnect(DisconnectPacket $packet) : bool{ + return false; + } + + public function handleBatch(BatchPacket $packet) : bool{ + $this->server->getNetwork()->processBatch($packet, $this); + return true; + } + + public function handleResourcePacksInfo(ResourcePacksInfoPacket $packet) : bool{ + return false; + } + + public function handleResourcePackStack(ResourcePackStackPacket $packet) : bool{ + return false; + } + + public function handleResourcePackClientResponse(ResourcePackClientResponsePacket $packet) : bool{ + // TODO: Implement resource packs + return true; + } + + public function handleText(TextPacket $packet) : bool{ + if($this->spawned === false or !$this->isAlive()){ + return true; + } + + $this->craftingType = 0; + if($packet->type === TextPacket::TYPE_CHAT){ + $packet->message = TextFormat::clean($packet->message, $this->removeFormat); + foreach(explode("\n", $packet->message) as $message){ + if(trim($message) != "" and strlen($message) <= 255 and $this->messageCounter-- > 0){ + if(substr($message, 0, 2) === "./"){ //Command (./ = fast hack for old plugins post 0.16) + $message = substr($message, 1); + } + + $ev = new PlayerCommandPreprocessEvent($this, $message); + + if(mb_strlen($ev->getMessage(), "UTF-8") > 320){ + $ev->setCancelled(); + } + $this->server->getPluginManager()->callEvent($ev); + + if($ev->isCancelled()){ + break; + } + + if(substr($ev->getMessage(), 0, 1) === "/"){ + Timings::$playerCommandTimer->startTiming(); + $this->server->dispatchCommand($ev->getPlayer(), substr($ev->getMessage(), 1)); + Timings::$playerCommandTimer->stopTiming(); + }else{ + $this->server->getPluginManager()->callEvent($ev = new PlayerChatEvent($this, $ev->getMessage())); + if(!$ev->isCancelled()){ + $this->server->broadcastMessage($this->getServer()->getLanguage()->translateString($ev->getFormat(), [$ev->getPlayer()->getDisplayName(), $ev->getMessage()]), $ev->getRecipients()); + } + } + } + } + } + + return true; + } + + 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 handleMoveEntity(MoveEntityPacket $packet) : bool{ + return false; + } + + public function handleMovePlayer(MovePlayerPacket $packet) : bool{ + $newPos = new Vector3($packet->x, $packet->y - $this->getEyeHeight(), $packet->z); + + if($newPos->distanceSquared($this) == 0 and ($packet->yaw % 360) === $this->yaw and ($packet->pitch % 360) === $this->pitch){ //player hasn't moved, just client spamming packets + return true; + } + + $revert = false; + if(!$this->isAlive() or $this->spawned !== true){ + $revert = true; + $this->forceMovement = new Vector3($this->x, $this->y, $this->z); + } + + if($this->teleportPosition !== null or ($this->forceMovement instanceof Vector3 and ($newPos->distanceSquared($this->forceMovement) > 0.1 or $revert))){ + $this->sendPosition($this->forceMovement, $packet->yaw, $packet->pitch, MovePlayerPacket::MODE_RESET); + }else{ + $packet->yaw %= 360; + $packet->pitch %= 360; + + if($packet->yaw < 0){ + $packet->yaw += 360; + } + + $this->setRotation($packet->yaw, $packet->pitch); + $this->newPosition = $newPos; + $this->forceMovement = null; + } + + return true; + } + + public function handleRiderJump(RiderJumpPacket $packet) : bool{ + return false; + } + + public function handleRemoveBlock(RemoveBlockPacket $packet) : bool{ + if($this->spawned === false or !$this->isAlive()){ + return true; + } + + $this->craftingType = 0; + + $vector = new Vector3($packet->x, $packet->y, $packet->z); + + if($this->isCreative()){ + $item = $this->inventory->getItemInHand(); + }else{ + $item = $this->inventory->getItemInHand(); + } + + $oldItem = clone $item; + + if($this->canInteract($vector->add(0.5, 0.5, 0.5), $this->isCreative() ? 13 : 6) and $this->level->useBreakOn($vector, $item, $this, true)){ + if($this->isSurvival()){ + if(!$item->deepEquals($oldItem) or $item->getCount() !== $oldItem->getCount()){ + $this->inventory->setItemInHand($item); + $this->inventory->sendHeldItem($this->hasSpawned); + } + + $this->exhaust(0.025, PlayerExhaustEvent::CAUSE_MINING); + } + return true; + } + + $this->inventory->sendContents($this); + $target = $this->level->getBlock($vector); + $tile = $this->level->getTile($vector); + + $this->level->sendBlocks([$this], [$target], UpdateBlockPacket::FLAG_ALL_PRIORITY); + + $this->inventory->sendHeldItem($this); + + if($tile instanceof Spawnable){ + $tile->spawnTo($this); + } + + return true; + } + + 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 false; + } + + public function handleLevelEvent(LevelEventPacket $packet) : bool{ + return false; + } + + public function handleBlockEvent(BlockEventPacket $packet) : bool{ + return false; + } + + public function handleEntityEvent(EntityEventPacket $packet) : bool{ + if($this->spawned === false or !$this->isAlive()){ + return true; + } + $this->craftingType = 0; + + $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false); //TODO: check if this should be true + + switch($packet->event){ + case EntityEventPacket::USE_ITEM: //Eating + $slot = $this->inventory->getItemInHand(); + + if($slot->canBeConsumed()){ + $ev = new PlayerItemConsumeEvent($this, $slot); + if(!$slot->canBeConsumedBy($this)){ + $ev->setCancelled(); + } + $this->server->getPluginManager()->callEvent($ev); + if(!$ev->isCancelled()){ + $slot->onConsume($this); + }else{ + $this->inventory->sendContents($this); + } + } + break; + default: + return false; + } + + return true; + } + + public function handleMobEffect(MobEffectPacket $packet) : bool{ + return false; + } + + public function handleUpdateAttributes(UpdateAttributesPacket $packet) : bool{ + return false; + } + + public function handleMobEquipment(MobEquipmentPacket $packet) : bool{ + if($this->spawned === false or !$this->isAlive()){ + return true; + } + + if($packet->slot === 0x28 or $packet->slot === 0 or $packet->slot === 255){ //0 for 0.8.0 compatibility + $packet->slot = -1; //Air + }else{ + $packet->slot -= 9; //Get real block slot + } + + /** @var Item $item */ + $item = null; + + if($this->isCreative()){ //Creative mode match + $item = $packet->item; + $slot = Item::getCreativeItemIndex($item); + }else{ + $item = $this->inventory->getItem($packet->slot); + $slot = $packet->slot; + } + + if($packet->slot === -1){ //Air + if($this->isCreative()){ + $found = false; + for($i = 0; $i < $this->inventory->getHotbarSize(); ++$i){ + if($this->inventory->getHotbarSlotIndex($i) === -1){ + $this->inventory->setHeldItemIndex($i); + $found = true; + break; + } + } + + if(!$found){ //couldn't find a empty slot (error) + $this->inventory->sendContents($this); + return true; + } + }else{ + if($packet->selectedSlot >= 0 and $packet->selectedSlot < 9){ + $this->inventory->setHeldItemIndex($packet->selectedSlot, false); + $this->inventory->setHeldItemSlot($packet->slot); + }else{ + $this->inventory->sendContents($this); + return true; + } + } + }elseif($item === null or $slot === -1 or !$item->deepEquals($packet->item)){ // packet error or not implemented + $this->inventory->sendContents($this); + return true; + }elseif($this->isCreative()){ + $this->inventory->setHeldItemIndex($packet->selectedSlot, false); + $this->inventory->setItem($packet->selectedSlot, $item); + $this->inventory->setHeldItemSlot($packet->selectedSlot); + }else{ + if($packet->selectedSlot >= 0 and $packet->selectedSlot < $this->inventory->getHotbarSize()){ + $this->inventory->setHeldItemIndex($packet->selectedSlot, false); + $this->inventory->setHeldItemSlot($slot); + }else{ + $this->inventory->sendContents($this); + return true; + } + } + + $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false); + + return true; + } + + public function handleMobArmorEquipment(MobArmorEquipmentPacket $packet) : bool{ + return false; + } + + public function handleInteract(InteractPacket $packet) : bool{ + if($this->spawned === false or !$this->isAlive()){ + return true; + } + + $this->craftingType = 0; + + $target = $this->level->getEntity($packet->target); + + $cancelled = false; + switch($packet->action){ + case InteractPacket::ACTION_LEFT_CLICK: //Attack + if($target instanceof Player and $this->server->getConfigBoolean("pvp", true) === false){ + $cancelled = true; + } + + if($target instanceof Entity and $this->getGamemode() !== Player::VIEW and $this->isAlive() and $target->isAlive()){ + if($target instanceof DroppedItem or $target instanceof Arrow){ + $this->kick("Attempting to attack an invalid entity"); + $this->server->getLogger()->warning($this->getServer()->getLanguage()->translateString("pocketmine.player.invalidEntity", [$this->getName()])); + break; + } + + $item = $this->inventory->getItemInHand(); + $damageTable = [ + Item::WOODEN_SWORD => 4, + Item::GOLD_SWORD => 4, + Item::STONE_SWORD => 5, + Item::IRON_SWORD => 6, + Item::DIAMOND_SWORD => 7, + + Item::WOODEN_AXE => 3, + Item::GOLD_AXE => 3, + Item::STONE_AXE => 3, + Item::IRON_AXE => 5, + Item::DIAMOND_AXE => 6, + + Item::WOODEN_PICKAXE => 2, + Item::GOLD_PICKAXE => 2, + Item::STONE_PICKAXE => 3, + Item::IRON_PICKAXE => 4, + Item::DIAMOND_PICKAXE => 5, + + Item::WOODEN_SHOVEL => 1, + Item::GOLD_SHOVEL => 1, + Item::STONE_SHOVEL => 2, + Item::IRON_SHOVEL => 3, + Item::DIAMOND_SHOVEL => 4, + ]; + + $damage = [ + EntityDamageEvent::MODIFIER_BASE => $damageTable[$item->getId()] ?? 1, + ]; + + if(!$this->canInteract($target, 8)){ + $cancelled = true; + }elseif($target instanceof Player){ + if(($target->getGamemode() & 0x01) > 0){ + break; + }elseif($this->server->getConfigBoolean("pvp") !== true or $this->server->getDifficulty() === 0){ + $cancelled = true; + } + + $armorValues = [ + Item::LEATHER_CAP => 1, + Item::LEATHER_TUNIC => 3, + Item::LEATHER_PANTS => 2, + Item::LEATHER_BOOTS => 1, + Item::CHAIN_HELMET => 1, + Item::CHAIN_CHESTPLATE => 5, + Item::CHAIN_LEGGINGS => 4, + Item::CHAIN_BOOTS => 1, + Item::GOLD_HELMET => 1, + Item::GOLD_CHESTPLATE => 5, + Item::GOLD_LEGGINGS => 3, + Item::GOLD_BOOTS => 1, + Item::IRON_HELMET => 2, + Item::IRON_CHESTPLATE => 6, + Item::IRON_LEGGINGS => 5, + Item::IRON_BOOTS => 2, + Item::DIAMOND_HELMET => 3, + Item::DIAMOND_CHESTPLATE => 8, + Item::DIAMOND_LEGGINGS => 6, + Item::DIAMOND_BOOTS => 3, + ]; + $points = 0; + foreach($target->getInventory()->getArmorContents() as $index => $i){ + if(isset($armorValues[$i->getId()])){ + $points += $armorValues[$i->getId()]; + } + } + + $damage[EntityDamageEvent::MODIFIER_ARMOR] = -floor($damage[EntityDamageEvent::MODIFIER_BASE] * $points * 0.04); + } + + $ev = new EntityDamageByEntityEvent($this, $target, EntityDamageEvent::CAUSE_ENTITY_ATTACK, $damage); + if($cancelled){ + $ev->setCancelled(); + } + + $target->attack($ev->getFinalDamage(), $ev); + + if($ev->isCancelled()){ + if($item->isTool() and $this->isSurvival()){ + $this->inventory->sendContents($this); + } + break; + } + + if($this->isSurvival()){ + if($item->isTool()){ + if($item->useOn($target) and $item->getDamage() >= $item->getMaxDurability()){ + $this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1)); + }else{ + $this->inventory->setItemInHand($item); + } + } + + $this->exhaust(0.3, PlayerExhaustEvent::CAUSE_ATTACK); + } + } + break; + default: + return false; //TODO: handle other actions + } + + return true; + } + + public function handleUseItem(UseItemPacket $packet) : bool{ + if($this->spawned === false or !$this->isAlive()){ + return true; + } + + $blockVector = new Vector3($packet->x, $packet->y, $packet->z); + + $this->craftingType = 0; + + if($packet->face >= 0 and $packet->face <= 5){ //Use Block, place + $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false); + + if(!$this->canInteract($blockVector->add(0.5, 0.5, 0.5), 13) or $this->isSpectator()){ + }elseif($this->isCreative()){ + $item = $this->inventory->getItemInHand(); + if($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this) === true){ + return true; + } + }elseif(!$this->inventory->getItemInHand()->deepEquals($packet->item)){ + $this->inventory->sendHeldItem($this); + }else{ + $item = $this->inventory->getItemInHand(); + $oldItem = clone $item; + //TODO: Implement adventure mode checks + if($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this)){ + if(!$item->deepEquals($oldItem) or $item->getCount() !== $oldItem->getCount()){ + $this->inventory->setItemInHand($item); + $this->inventory->sendHeldItem($this->hasSpawned); + } + return true; + } + } + + $this->inventory->sendHeldItem($this); + + if($blockVector->distanceSquared($this) > 10000){ + return true; + } + $target = $this->level->getBlock($blockVector); + $block = $target->getSide($packet->face); + + $this->level->sendBlocks([$this], [$target, $block], UpdateBlockPacket::FLAG_ALL_PRIORITY); + return true; + }elseif($packet->face === -1){ + $aimPos = new Vector3( + -sin($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI), + -sin($this->pitch / 180 * M_PI), + cos($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI) + ); + + if($this->isCreative()){ + $item = $this->inventory->getItemInHand(); + }elseif(!$this->inventory->getItemInHand()->deepEquals($packet->item)){ + $this->inventory->sendHeldItem($this); + return true; + }else{ + $item = $this->inventory->getItemInHand(); + } + + $ev = new PlayerInteractEvent($this, $item, $aimPos, $packet->face, PlayerInteractEvent::RIGHT_CLICK_AIR); + + $this->server->getPluginManager()->callEvent($ev); + + if($ev->isCancelled()){ + $this->inventory->sendHeldItem($this); + return true; + } + + if($item->getId() === Item::SNOWBALL){ + $nbt = new CompoundTag("", [ + "Pos" => new ListTag("Pos", [ + new DoubleTag("", $this->x), + new DoubleTag("", $this->y + $this->getEyeHeight()), + new DoubleTag("", $this->z) + ]), + "Motion" => new ListTag("Motion", [ + new DoubleTag("", $aimPos->x), + new DoubleTag("", $aimPos->y), + new DoubleTag("", $aimPos->z) + ]), + "Rotation" => new ListTag("Rotation", [ + new FloatTag("", $this->yaw), + new FloatTag("", $this->pitch) + ]), + ]); + + $f = 1.5; + $snowball = Entity::createEntity("Snowball", $this->getLevel(), $nbt, $this); + $snowball->setMotion($snowball->getMotion()->multiply($f)); + if($this->isSurvival()){ + $item->setCount($item->getCount() - 1); + $this->inventory->setItemInHand($item->getCount() > 0 ? $item : Item::get(Item::AIR)); + } + if($snowball instanceof Projectile){ + $this->server->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($snowball)); + if($projectileEv->isCancelled()){ + $snowball->kill(); + }else{ + $snowball->spawnToAll(); + $this->level->addSound(new LaunchSound($this), $this->getViewers()); + } + }else{ + $snowball->spawnToAll(); + } + } + + $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, true); + $this->startAction = $this->server->getTick(); + } + + return true; + } + + public function handlePlayerAction(PlayerActionPacket $packet) : bool{ + if($this->spawned === false or (!$this->isAlive() and $packet->action !== PlayerActionPacket::ACTION_RESPAWN and $packet->action !== PlayerActionPacket::ACTION_DIMENSION_CHANGE)){ + return true; + } + + $packet->eid = $this->id; + $pos = new Vector3($packet->x, $packet->y, $packet->z); + + switch($packet->action){ + case PlayerActionPacket::ACTION_START_BREAK: + if($this->lastBreak !== PHP_INT_MAX or $pos->distanceSquared($this) > 10000){ + break; + } + $target = $this->level->getBlock($pos); + $ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $target, $packet->face, $target->getId() === 0 ? PlayerInteractEvent::LEFT_CLICK_AIR : PlayerInteractEvent::LEFT_CLICK_BLOCK); + $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, new Air()); + break; + } + $this->lastBreak = microtime(true); + break; + case PlayerActionPacket::ACTION_ABORT_BREAK: + $this->lastBreak = PHP_INT_MAX; + break; + case PlayerActionPacket::ACTION_STOP_BREAK: + break; + case PlayerActionPacket::ACTION_RELEASE_ITEM: + if($this->startAction > -1 and $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION)){ + if($this->inventory->getItemInHand()->getId() === Item::BOW){ + $bow = $this->inventory->getItemInHand(); + if($this->isSurvival() and !$this->inventory->contains(Item::get(Item::ARROW, 0, 1))){ + $this->inventory->sendContents($this); + break; + } + + $nbt = new CompoundTag("", [ + "Pos" => new ListTag("Pos", [ + new DoubleTag("", $this->x), + new DoubleTag("", $this->y + $this->getEyeHeight()), + new DoubleTag("", $this->z) + ]), + "Motion" => new ListTag("Motion", [ + new DoubleTag("", -sin($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI)), + new DoubleTag("", -sin($this->pitch / 180 * M_PI)), + new DoubleTag("", cos($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI)) + ]), + "Rotation" => new ListTag("Rotation", [ + new FloatTag("", $this->yaw), + new FloatTag("", $this->pitch) + ]), + "Fire" => new ShortTag("Fire", $this->isOnFire() ? 45 * 60 : 0) + ]); + + $diff = ($this->server->getTick() - $this->startAction); + $p = $diff / 20; + $f = min((($p ** 2) + $p * 2) / 3, 1) * 2; + $ev = new EntityShootBowEvent($this, $bow, Entity::createEntity("Arrow", $this->getLevel(), $nbt, $this, $f == 2 ? true : false), $f); + + if($f < 0.1 or $diff < 5){ + $ev->setCancelled(); + } + + $this->server->getPluginManager()->callEvent($ev); + + if($ev->isCancelled()){ + $ev->getProjectile()->kill(); + $this->inventory->sendContents($this); + }else{ + $ev->getProjectile()->setMotion($ev->getProjectile()->getMotion()->multiply($ev->getForce())); + if($this->isSurvival()){ + $this->inventory->removeItem(Item::get(Item::ARROW, 0, 1)); + $bow->setDamage($bow->getDamage() + 1); + if($bow->getDamage() >= 385){ + $this->inventory->setItemInHand(Item::get(Item::AIR, 0, 0)); + }else{ + $this->inventory->setItemInHand($bow); + } + } + if($ev->getProjectile() instanceof Projectile){ + $this->server->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($ev->getProjectile())); + if($projectileEv->isCancelled()){ + $ev->getProjectile()->kill(); + }else{ + $ev->getProjectile()->spawnToAll(); + $this->level->addSound(new LaunchSound($this), $this->getViewers()); + } + }else{ + $ev->getProjectile()->spawnToAll(); + } + } + } + }elseif($this->inventory->getItemInHand()->getId() === Item::BUCKET and $this->inventory->getItemInHand()->getDamage() === 1){ //Milk! + $this->server->getPluginManager()->callEvent($ev = new PlayerItemConsumeEvent($this, $this->inventory->getItemInHand())); + if($ev->isCancelled()){ + $this->inventory->sendContents($this); + break; + } + + $pk = new EntityEventPacket(); + $pk->eid = $this->getId(); + $pk->event = EntityEventPacket::USE_ITEM; + $this->dataPacket($pk); + $this->server->broadcastPacket($this->getViewers(), $pk); + + if($this->isSurvival()){ + $slot = $this->inventory->getItemInHand(); + --$slot->count; + $this->inventory->setItemInHand($slot); + $this->inventory->addItem(Item::get(Item::BUCKET, 0, 1)); + } + + $this->removeAllEffects(); + }else{ + $this->inventory->sendContents($this); + } + break; + case PlayerActionPacket::ACTION_STOP_SLEEPING: + $this->stopSleep(); + break; + case PlayerActionPacket::ACTION_RESPAWN: + if($this->spawned === false or $this->isAlive() or !$this->isOnline()){ + break; + } + + if($this->server->isHardcore()){ + $this->setBanned(true); + break; + } + + $this->craftingType = 0; + + $this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $this->getSpawn())); + + $this->teleport($ev->getRespawnPosition()); + + $this->setSprinting(false); + $this->setSneaking(false); + + $this->extinguish(); + $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, 400, false); + $this->deadTicks = 0; + $this->noDamageTicks = 60; + + $this->setHealth($this->getMaxHealth()); + + $this->removeAllEffects(); + $this->sendData($this); + + $this->sendSettings(); + $this->inventory->sendContents($this); + $this->inventory->sendArmorContents($this); + + $this->spawnToAll(); + $this->scheduleUpdate(); + break; + case PlayerActionPacket::ACTION_JUMP: + return true; + case PlayerActionPacket::ACTION_START_SPRINT: + $ev = new PlayerToggleSprintEvent($this, true); + $this->server->getPluginManager()->callEvent($ev); + if($ev->isCancelled()){ + $this->sendData($this); + }else{ + $this->setSprinting(true); + } + break; + case PlayerActionPacket::ACTION_STOP_SPRINT: + $ev = new PlayerToggleSprintEvent($this, false); + $this->server->getPluginManager()->callEvent($ev); + if($ev->isCancelled()){ + $this->sendData($this); + }else{ + $this->setSprinting(false); + } + break; + case PlayerActionPacket::ACTION_START_SNEAK: + $ev = new PlayerToggleSneakEvent($this, true); + $this->server->getPluginManager()->callEvent($ev); + if($ev->isCancelled()){ + $this->sendData($this); + }else{ + $this->setSneaking(true); + } + return true; + case PlayerActionPacket::ACTION_STOP_SNEAK: + $ev = new PlayerToggleSneakEvent($this, false); + $this->server->getPluginManager()->callEvent($ev); + if($ev->isCancelled()){ + $this->sendData($this); + }else{ + $this->setSneaking(false); + } + return true; + default: + assert(false, "Unhandled player action " . $packet->action . " from " . $this->getName()); + } + + $this->startAction = -1; + $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false); + + return true; + } + + public function handlePlayerFall(PlayerFallPacket $packet) : bool{ + return false; + } + + 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{ + if($this->spawned === false or !$this->isAlive()){ + return true; + } + + $this->server->getPluginManager()->callEvent($ev = new PlayerAnimationEvent($this, $packet->action)); + if($ev->isCancelled()){ + return true; + } + + $pk = new AnimatePacket(); + $pk->eid = $this->getId(); + $pk->action = $ev->getAnimationType(); + $this->server->broadcastPacket($this->getViewers(), $pk); + + return true; + } + + public function handleRespawn(RespawnPacket $packet) : bool{ + return false; + } + + public function handleDropItem(DropItemPacket $packet) : bool{ + if($this->spawned === false or !$this->isAlive()){ + return true; + } + + if($packet->item->getId() === Item::AIR){ + // Windows 10 Edition drops the contents of the crafting grid on container close - including air. + return true; + } + + $item = $this->inventory->getItemInHand(); + $ev = new PlayerDropItemEvent($this, $item); + $this->server->getPluginManager()->callEvent($ev); + if($ev->isCancelled()){ + $this->inventory->sendContents($this); + return true; + } + + $this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1)); + $motion = $this->getDirectionVector()->multiply(0.4); + + $this->level->dropItem($this->add(0, 1.3, 0), $item, $motion, 40); + + $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false); + + return true; + } + + public function handleInventoryAction(InventoryActionPacket $packet) : bool{ + return false; + } + + public function handleContainerOpen(ContainerOpenPacket $packet) : bool{ + return false; + } + + public function handleContainerClose(ContainerClosePacket $packet) : bool{ + if($this->spawned === false or $packet->windowid === 0){ + return true; + } + + $this->craftingType = 0; + $this->currentTransaction = null; + if(isset($this->windowIndex[$packet->windowid])){ + $this->server->getPluginManager()->callEvent(new InventoryCloseEvent($this->windowIndex[$packet->windowid], $this)); + $this->removeWindow($this->windowIndex[$packet->windowid]); + }else{ + unset($this->windowIndex[$packet->windowid]); + } + + return true; + } + + public function handleContainerSetSlot(ContainerSetSlotPacket $packet) : bool{ + if($this->spawned === false or !$this->isAlive()){ + return true; + } + + if($packet->slot < 0){ + return false; + } + + if($packet->windowid === 0){ //Our inventory + if($packet->slot >= $this->inventory->getSize()){ + return false; + } + if($this->isCreative()){ + if(Item::getCreativeItemIndex($packet->item) !== -1){ + $this->inventory->setItem($packet->slot, $packet->item); + $this->inventory->setHotbarSlotIndex($packet->slot, $packet->slot); //links $hotbar[$packet->slot] to $slots[$packet->slot] + } + } + $transaction = new BaseTransaction($this->inventory, $packet->slot, $this->inventory->getItem($packet->slot), $packet->item); + }elseif($packet->windowid === ContainerSetContentPacket::SPECIAL_ARMOR){ //Our armor + if($packet->slot >= 4){ + return false; + } + + $transaction = new BaseTransaction($this->inventory, $packet->slot + $this->inventory->getSize(), $this->inventory->getArmorItem($packet->slot), $packet->item); + }elseif(isset($this->windowIndex[$packet->windowid])){ + $this->craftingType = 0; + $inv = $this->windowIndex[$packet->windowid]; + $transaction = new BaseTransaction($inv, $packet->slot, $inv->getItem($packet->slot), $packet->item); + }else{ + return false; + } + + if($transaction->getSourceItem()->deepEquals($transaction->getTargetItem()) and $transaction->getTargetItem()->getCount() === $transaction->getSourceItem()->getCount()){ //No changes! + //No changes, just a local inventory update sent by the client + return true; + } + + if($this->currentTransaction === null or $this->currentTransaction->getCreationTime() < (microtime(true) - 8)){ + if($this->currentTransaction !== null){ + foreach($this->currentTransaction->getInventories() as $inventory){ + if($inventory instanceof PlayerInventory){ + $inventory->sendArmorContents($this); + } + $inventory->sendContents($this); + } + } + $this->currentTransaction = new SimpleTransactionGroup($this); + } + + $this->currentTransaction->addTransaction($transaction); + + if($this->currentTransaction->canExecute()){ + $achievements = []; + foreach($this->currentTransaction->getTransactions() as $ts){ + $inv = $ts->getInventory(); + if($inv instanceof FurnaceInventory){ + if($ts->getSlot() === 2){ + switch($inv->getResult()->getId()){ + case Item::IRON_INGOT: + $achievements[] = "acquireIron"; + break; + } + } + } + } + + if($this->currentTransaction->execute()){ + foreach($achievements as $a){ + $this->awardAchievement($a); + } + } + + $this->currentTransaction = null; + } + + return true; + } + + public function handleContainerSetData(ContainerSetDataPacket $packet) : bool{ + return false; + } + + public function handleContainerSetContent(ContainerSetContentPacket $packet) : bool{ + return false; + } + + public function handleCraftingData(CraftingDataPacket $packet) : bool{ + return false; + } + + public function handleCraftingEvent(CraftingEventPacket $packet) : bool{ + if($this->spawned === false or !$this->isAlive()){ + return true; + } + + $recipe = $this->server->getCraftingManager()->getRecipe($packet->id); + + if($recipe === null or (($recipe instanceof BigShapelessRecipe or $recipe instanceof BigShapedRecipe) and $this->craftingType === 0)){ + $this->inventory->sendContents($this); + return true; + } + + $canCraft = true; + + if($recipe instanceof ShapedRecipe){ + for($x = 0; $x < 3 and $canCraft; ++$x){ + for($y = 0; $y < 3; ++$y){ + /** @var Item $item */ + $item = $packet->input[$y * 3 + $x]; + $ingredient = $recipe->getIngredient($x, $y); + if($item->getCount() > 0){ + if($ingredient === null or !$ingredient->deepEquals($item, !$ingredient->hasAnyDamageValue(), $ingredient->hasCompoundTag())){ + $canCraft = false; + break; + } + } + } + } + }elseif($recipe instanceof ShapelessRecipe){ + $needed = $recipe->getIngredientList(); + + for($x = 0; $x < 3 and $canCraft; ++$x){ + for($y = 0; $y < 3; ++$y){ + /** @var Item $item */ + $item = clone $packet->input[$y * 3 + $x]; + + foreach($needed as $k => $n){ + if($n->deepEquals($item, !$n->hasAnyDamageValue(), $n->hasCompoundTag())){ + $remove = min($n->getCount(), $item->getCount()); + $n->setCount($n->getCount() - $remove); + $item->setCount($item->getCount() - $remove); + + if($n->getCount() === 0){ + unset($needed[$k]); + } + } + } + + if($item->getCount() > 0){ + $canCraft = false; + break; + } + } + } + + if(count($needed) > 0){ + $canCraft = false; + } + }else{ + $canCraft = false; + } + + /** @var Item[] $ingredients */ + $ingredients = $packet->input; + $result = $packet->output[0]; + + if(!$canCraft or !$recipe->getResult()->deepEquals($result)){ + $this->server->getLogger()->debug("Unmatched recipe " . $recipe->getId() . " from player " . $this->getName() . ": expected " . $recipe->getResult() . ", got " . $result . ", using: " . implode(", ", $ingredients)); + $this->inventory->sendContents($this); + return true; + } + + $used = array_fill(0, $this->inventory->getSize(), 0); + + foreach($ingredients as $ingredient){ + $slot = -1; + foreach($this->inventory->getContents() as $index => $item){ + if($ingredient->getId() !== 0 and $ingredient->equals($item, !$ingredient->hasAnyDamageValue(), $ingredient->hasCompoundTag()) and ($item->getCount() - $used[$index]) >= 1){ + $slot = $index; + $used[$index]++; + break; + } + } + + if($ingredient->getId() !== 0 and $slot === -1){ + $canCraft = false; + break; + } + } + + if(!$canCraft){ + $this->server->getLogger()->debug("Unmatched recipe " . $recipe->getId() . " from player " . $this->getName() . ": client does not have enough items, using: " . implode(", ", $ingredients)); + $this->inventory->sendContents($this); + return true; + } + + $this->server->getPluginManager()->callEvent($ev = new CraftItemEvent($this, $ingredients, $recipe)); + + if($ev->isCancelled()){ + $this->inventory->sendContents($this); + return true; + } + + foreach($used as $slot => $count){ + if($count === 0){ + continue; + } + + $item = $this->inventory->getItem($slot); + + if($item->getCount() > $count){ + $newItem = clone $item; + $newItem->setCount($item->getCount() - $count); + }else{ + $newItem = Item::get(Item::AIR, 0, 0); + } + + $this->inventory->setItem($slot, $newItem); + } + + $extraItem = $this->inventory->addItem($recipe->getResult()); + if(count($extraItem) > 0){ + foreach($extraItem as $item){ + $this->level->dropItem($this, $item); + } + } + + switch($recipe->getResult()->getId()){ + case Item::WORKBENCH: + $this->awardAchievement("buildWorkBench"); + break; + case Item::WOODEN_PICKAXE: + $this->awardAchievement("buildPickaxe"); + break; + case Item::FURNACE: + $this->awardAchievement("buildFurnace"); + break; + case Item::WOODEN_HOE: + $this->awardAchievement("buildHoe"); + break; + case Item::BREAD: + $this->awardAchievement("makeBread"); + break; + case Item::CAKE: + //TODO: detect complex recipes like cake that leave remains + $this->awardAchievement("bakeCake"); + $this->inventory->addItem(Item::get(Item::BUCKET, 0, 3)); + break; + case Item::STONE_PICKAXE: + case Item::GOLD_PICKAXE: + case Item::IRON_PICKAXE: + case Item::DIAMOND_PICKAXE: + $this->awardAchievement("buildBetterPickaxe"); + break; + case Item::WOODEN_SWORD: + $this->awardAchievement("buildSword"); + break; + case Item::DIAMOND: + $this->awardAchievement("diamond"); + break; + } + + + return true; + } + + public function handleAdventureSettings(AdventureSettingsPacket $packet) : bool{ + if($packet->isFlying and !$this->allowFlight and !$this->server->getAllowFlight()){ + $this->kick("Flying is not enabled on this server"); + return true; + }elseif($packet->isFlying !== $this->isFlying()){ + $this->server->getPluginManager()->callEvent($ev = new PlayerToggleFlightEvent($this, $packet->isFlying)); + if($ev->isCancelled()){ + $this->sendSettings(); + }else{ + $this->flying = $ev->isFlying(); + } + return true; + }else{ + return false; + } + } + + public function handleBlockEntityData(BlockEntityDataPacket $packet) : bool{ + if($this->spawned === false or !$this->isAlive()){ + return true; + } + $this->craftingType = 0; + + $pos = new Vector3($packet->x, $packet->y, $packet->z); + if($pos->distanceSquared($this) > 10000){ + return true; + } + + $t = $this->level->getTile($pos); + if($t instanceof Spawnable){ + $nbt = new NBT(NBT::LITTLE_ENDIAN); + $nbt->read($packet->namedtag, false, true); + $nbt = $nbt->getData(); + if(!$t->updateCompoundTag($nbt, $this)){ + $t->spawnTo($this); + } + } + + return true; + } + + 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{ + if($packet->gamemode !== ($this->gamemode & 0x01)){ + //GUI gamemode change, set it back to original for now (only possible through client bug or hack with current allowed client permissions) + $pk = new SetPlayerGameTypePacket(); + $pk->gamemode = $this->gamemode & 0x01; + $this->dataPacket($pk); + $this->sendSettings(); + } + return true; + } + + public function handlePlayerList(PlayerListPacket $packet) : bool{ + return false; + } + + public function handleSpawnExperienceOrb(SpawnExperienceOrbPacket $packet) : bool{ + return false; //TODO + } + + public function handleRequestChunkRadius(RequestChunkRadiusPacket $packet) : bool{ + $this->setViewDistance($packet->radius); + + return true; + } + + public function handleChunkRadiusUpdated(ChunkRadiusUpdatedPacket $packet) : bool{ + return false; + } + + public function handleItemFrameDropItem(ItemFrameDropItemPacket $packet) : bool{ + if($this->spawned === false or !$this->isAlive()){ + return true; + } + + $tile = $this->level->getTile($this->temporalVector->setComponents($packet->x, $packet->y, $packet->z)); + if($tile instanceof ItemFrame){ + if($this->isSpectator()){ + $tile->spawnTo($this); + return true; + } + + if(lcg_value() <= $tile->getItemDropChance()){ + $this->level->dropItem($tile->getBlock(), $tile->getItem()); + } + $tile->setItem(null); + $tile->setItemRotation(0); + } + + return true; + } + + public function handleReplaceItemInSlot(ReplaceItemInSlotPacket $packet) : bool{ + return false; + } + + public function handleAddItem(AddItemPacket $packet) : bool{ + return false; + } + + public function handleShowCredits(ShowCreditsPacket $packet) : bool{ + return false; //TODO: handle resume + } + + public function handleAvailableCommands(AvailableCommandsPacket $packet) : bool{ + return false; + } + + public function handleCommandStep(CommandStepPacket $packet) : bool{ + if($this->spawned === false or !$this->isAlive()){ + return true; + } + $this->craftingType = 0; + $commandText = $packet->command; + if($packet->args !== null){ + foreach($packet->args as $arg){ //command ordering will be an issue + $commandText .= " " . $arg; + } + } + $this->server->getPluginManager()->callEvent($ev = new PlayerCommandPreprocessEvent($this, "/" . $commandText)); + if($ev->isCancelled()){ + return true; + } + + Timings::$playerCommandTimer->startTiming(); + $this->server->dispatchCommand($ev->getPlayer(), substr($ev->getMessage(), 1)); + Timings::$playerCommandTimer->stopTiming(); + + return true; + } + + public function handleTransfer(TransferPacket $packet) : bool{ + return false; + } + /** * Handles a Minecraft packet * TODO: Separate all of this in handlers @@ -1846,11 +3259,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return; } - if($packet::NETWORK_ID === ProtocolInfo::BATCH_PACKET){ - /** @var BatchPacket $packet */ - $this->server->getNetwork()->processBatch($packet, $this); - return; - } $timings = Timings::getReceiveDataPacketTimings($packet); @@ -1862,1127 +3270,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return; } - switch($packet::NETWORK_ID){ - case ProtocolInfo::LOGIN_PACKET: - if($this->loggedIn){ - break; - } - - $this->username = TextFormat::clean($packet->username); - $this->displayName = $this->username; - $this->iusername = strtolower($this->username); - $this->setDataProperty(self::DATA_NAMETAG, self::DATA_TYPE_STRING, $this->username, false); - - if(count($this->server->getOnlinePlayers()) >= $this->server->getMaxPlayers() and $this->kick("disconnectionScreen.serverFull", false)){ - break; - } - - if($packet->protocol !== ProtocolInfo::CURRENT_PROTOCOL){ - if($packet->protocol < ProtocolInfo::CURRENT_PROTOCOL){ - $message = "disconnectionScreen.outdatedClient"; - - $pk = new PlayStatusPacket(); - $pk->status = PlayStatusPacket::LOGIN_FAILED_CLIENT; - $this->directDataPacket($pk); - }else{ - $message = "disconnectionScreen.outdatedServer"; - - $pk = new PlayStatusPacket(); - $pk->status = PlayStatusPacket::LOGIN_FAILED_SERVER; - $this->directDataPacket($pk); - } - $this->close("", $message, false); - - break; - } - - $this->randomClientId = $packet->clientId; - - $this->uuid = UUID::fromString($packet->clientUUID); - $this->rawUUID = $this->uuid->toBinary(); - - $valid = true; - $len = strlen($packet->username); - if($len > 16 or $len < 3){ - $valid = false; - } - for($i = 0; $i < $len and $valid; ++$i){ - $c = ord($packet->username{$i}); - if(($c >= ord("a") and $c <= ord("z")) or - ($c >= ord("A") and $c <= ord("Z")) or - ($c >= ord("0") and $c <= ord("9")) or $c === ord("_") - ){ - continue; - } - - $valid = false; - break; - } - - if(!$valid or $this->iusername === "rcon" or $this->iusername === "console"){ - $this->close("", "disconnectionScreen.invalidName"); - - break; - } - - if(strlen($packet->skin) !== 64 * 32 * 4 and strlen($packet->skin) !== 64 * 64 * 4){ - $this->close("", "disconnectionScreen.invalidSkin"); - break; - } - - $this->setSkin($packet->skin, $packet->skinId); - - $this->server->getPluginManager()->callEvent($ev = new PlayerPreLoginEvent($this, "Plugin reason")); - if($ev->isCancelled()){ - $this->close("", $ev->getKickMessage()); - - break; - } - - $this->onPlayerPreLogin(); - - break; - case ProtocolInfo::MOVE_PLAYER_PACKET: - $newPos = new Vector3($packet->x, $packet->y - $this->getEyeHeight(), $packet->z); - - if($newPos->distanceSquared($this) == 0 and ($packet->yaw % 360) === $this->yaw and ($packet->pitch % 360) === $this->pitch){ //player hasn't moved, just client spamming packets - break; - } - - $revert = false; - if(!$this->isAlive() or $this->spawned !== true){ - $revert = true; - $this->forceMovement = new Vector3($this->x, $this->y, $this->z); - } - - if($this->teleportPosition !== null or ($this->forceMovement instanceof Vector3 and ($newPos->distanceSquared($this->forceMovement) > 0.1 or $revert))){ - $this->sendPosition($this->forceMovement, $packet->yaw, $packet->pitch, MovePlayerPacket::MODE_RESET); - }else{ - $packet->yaw %= 360; - $packet->pitch %= 360; - - if($packet->yaw < 0){ - $packet->yaw += 360; - } - - $this->setRotation($packet->yaw, $packet->pitch); - $this->newPosition = $newPos; - $this->forceMovement = null; - } - - break; - case ProtocolInfo::ADVENTURE_SETTINGS_PACKET: - //TODO: player abilities, check for other changes - if($packet->isFlying and !$this->allowFlight and !$this->server->getAllowFlight()){ - $this->kick("Flying is not enabled on this server"); - break; - }else{ - $this->server->getPluginManager()->callEvent($ev = new PlayerToggleFlightEvent($this, $packet->isFlying)); - if($ev->isCancelled()){ - $this->sendSettings(); - }else{ - $this->flying = $ev->isFlying(); - } - break; - } - break; - case ProtocolInfo::MOB_EQUIPMENT_PACKET: - if($this->spawned === false or !$this->isAlive()){ - break; - } - - if($packet->slot === 0x28 or $packet->slot === 0 or $packet->slot === 255){ //0 for 0.8.0 compatibility - $packet->slot = -1; //Air - }else{ - $packet->slot -= 9; //Get real block slot - } - - /** @var Item $item */ - $item = null; - - if($this->isCreative()){ //Creative mode match - $item = $packet->item; - $slot = Item::getCreativeItemIndex($item); - }else{ - $item = $this->inventory->getItem($packet->slot); - $slot = $packet->slot; - } - - if($packet->slot === -1){ //Air - if($this->isCreative()){ - $found = false; - for($i = 0; $i < $this->inventory->getHotbarSize(); ++$i){ - if($this->inventory->getHotbarSlotIndex($i) === -1){ - $this->inventory->setHeldItemIndex($i); - $found = true; - break; - } - } - - if(!$found){ //couldn't find a empty slot (error) - $this->inventory->sendContents($this); - break; - } - }else{ - if($packet->selectedSlot >= 0 and $packet->selectedSlot < 9){ - $this->inventory->setHeldItemIndex($packet->selectedSlot, false); - $this->inventory->setHeldItemSlot($packet->slot); - }else{ - $this->inventory->sendContents($this); - break; - } - } - }elseif($item === null or $slot === -1 or !$item->deepEquals($packet->item)){ // packet error or not implemented - $this->inventory->sendContents($this); - break; - }elseif($this->isCreative()){ - $this->inventory->setHeldItemIndex($packet->selectedSlot, false); - $this->inventory->setItem($packet->selectedSlot, $item); - $this->inventory->setHeldItemSlot($packet->selectedSlot); - }else{ - if($packet->selectedSlot >= 0 and $packet->selectedSlot < $this->inventory->getHotbarSize()){ - $this->inventory->setHeldItemIndex($packet->selectedSlot, false); - $this->inventory->setHeldItemSlot($slot); - }else{ - $this->inventory->sendContents($this); - break; - } - } - - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false); - break; - case ProtocolInfo::USE_ITEM_PACKET: - if($this->spawned === false or !$this->isAlive()){ - break; - } - - $blockVector = new Vector3($packet->x, $packet->y, $packet->z); - - $this->craftingType = 0; - - if($packet->face >= 0 and $packet->face <= 5){ //Use Block, place - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false); - - if(!$this->canInteract($blockVector->add(0.5, 0.5, 0.5), 13) or $this->isSpectator()){ - }elseif($this->isCreative()){ - $item = $this->inventory->getItemInHand(); - if($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this) === true){ - break; - } - }elseif(!$this->inventory->getItemInHand()->deepEquals($packet->item)){ - $this->inventory->sendHeldItem($this); - }else{ - $item = $this->inventory->getItemInHand(); - $oldItem = clone $item; - //TODO: Implement adventure mode checks - if($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this)){ - if(!$item->deepEquals($oldItem) or $item->getCount() !== $oldItem->getCount()){ - $this->inventory->setItemInHand($item); - $this->inventory->sendHeldItem($this->hasSpawned); - } - break; - } - } - - $this->inventory->sendHeldItem($this); - - if($blockVector->distanceSquared($this) > 10000){ - break; - } - $target = $this->level->getBlock($blockVector); - $block = $target->getSide($packet->face); - - $this->level->sendBlocks([$this], [$target, $block], UpdateBlockPacket::FLAG_ALL_PRIORITY); - break; - }elseif($packet->face === -1){ - $aimPos = new Vector3( - -sin($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI), - -sin($this->pitch / 180 * M_PI), - cos($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI) - ); - - if($this->isCreative()){ - $item = $this->inventory->getItemInHand(); - }elseif(!$this->inventory->getItemInHand()->deepEquals($packet->item)){ - $this->inventory->sendHeldItem($this); - break; - }else{ - $item = $this->inventory->getItemInHand(); - } - - $ev = new PlayerInteractEvent($this, $item, $aimPos, $packet->face, PlayerInteractEvent::RIGHT_CLICK_AIR); - - $this->server->getPluginManager()->callEvent($ev); - - if($ev->isCancelled()){ - $this->inventory->sendHeldItem($this); - break; - } - - if($item->getId() === Item::SNOWBALL){ - $nbt = new CompoundTag("", [ - "Pos" => new ListTag("Pos", [ - new DoubleTag("", $this->x), - new DoubleTag("", $this->y + $this->getEyeHeight()), - new DoubleTag("", $this->z) - ]), - "Motion" => new ListTag("Motion", [ - new DoubleTag("", $aimPos->x), - new DoubleTag("", $aimPos->y), - new DoubleTag("", $aimPos->z) - ]), - "Rotation" => new ListTag("Rotation", [ - new FloatTag("", $this->yaw), - new FloatTag("", $this->pitch) - ]), - ]); - - $f = 1.5; - $snowball = Entity::createEntity("Snowball", $this->getLevel(), $nbt, $this); - $snowball->setMotion($snowball->getMotion()->multiply($f)); - if($this->isSurvival()){ - $item->setCount($item->getCount() - 1); - $this->inventory->setItemInHand($item->getCount() > 0 ? $item : Item::get(Item::AIR)); - } - if($snowball instanceof Projectile){ - $this->server->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($snowball)); - if($projectileEv->isCancelled()){ - $snowball->kill(); - }else{ - $snowball->spawnToAll(); - $this->level->addSound(new LaunchSound($this), $this->getViewers()); - } - }else{ - $snowball->spawnToAll(); - } - } - - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, true); - $this->startAction = $this->server->getTick(); - } - break; - case ProtocolInfo::PLAYER_ACTION_PACKET: - if($this->spawned === false or (!$this->isAlive() and $packet->action !== PlayerActionPacket::ACTION_RESPAWN and $packet->action !== PlayerActionPacket::ACTION_DIMENSION_CHANGE)){ - break; - } - - $pos = new Vector3($packet->x, $packet->y, $packet->z); - - switch($packet->action){ - case PlayerActionPacket::ACTION_START_BREAK: - if($this->lastBreak !== PHP_INT_MAX or $pos->distanceSquared($this) > 10000){ - break; - } - $target = $this->level->getBlock($pos); - $ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $target, $packet->face, $target->getId() === 0 ? PlayerInteractEvent::LEFT_CLICK_AIR : PlayerInteractEvent::LEFT_CLICK_BLOCK); - $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, new Air()); - break; - } - $this->lastBreak = microtime(true); - break; - case PlayerActionPacket::ACTION_ABORT_BREAK: - $this->lastBreak = PHP_INT_MAX; - break; - case PlayerActionPacket::ACTION_STOP_BREAK: - break; - case PlayerActionPacket::ACTION_RELEASE_ITEM: - if($this->startAction > -1 and $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION)){ - if($this->inventory->getItemInHand()->getId() === Item::BOW){ - $bow = $this->inventory->getItemInHand(); - if($this->isSurvival() and !$this->inventory->contains(Item::get(Item::ARROW, 0, 1))){ - $this->inventory->sendContents($this); - break; - } - - $nbt = new CompoundTag("", [ - "Pos" => new ListTag("Pos", [ - new DoubleTag("", $this->x), - new DoubleTag("", $this->y + $this->getEyeHeight()), - new DoubleTag("", $this->z) - ]), - "Motion" => new ListTag("Motion", [ - new DoubleTag("", -sin($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI)), - new DoubleTag("", -sin($this->pitch / 180 * M_PI)), - new DoubleTag("", cos($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI)) - ]), - "Rotation" => new ListTag("Rotation", [ - new FloatTag("", $this->yaw), - new FloatTag("", $this->pitch) - ]), - "Fire" => new ShortTag("Fire", $this->isOnFire() ? 45 * 60 : 0) - ]); - - $diff = ($this->server->getTick() - $this->startAction); - $p = $diff / 20; - $f = min((($p ** 2) + $p * 2) / 3, 1) * 2; - $ev = new EntityShootBowEvent($this, $bow, Entity::createEntity("Arrow", $this->getLevel(), $nbt, $this, $f == 2 ? true : false), $f); - - if($f < 0.1 or $diff < 5){ - $ev->setCancelled(); - } - - $this->server->getPluginManager()->callEvent($ev); - - if($ev->isCancelled()){ - $ev->getProjectile()->kill(); - $this->inventory->sendContents($this); - }else{ - $ev->getProjectile()->setMotion($ev->getProjectile()->getMotion()->multiply($ev->getForce())); - if($this->isSurvival()){ - $this->inventory->removeItem(Item::get(Item::ARROW, 0, 1)); - $bow->setDamage($bow->getDamage() + 1); - if($bow->getDamage() >= 385){ - $this->inventory->setItemInHand(Item::get(Item::AIR, 0, 0)); - }else{ - $this->inventory->setItemInHand($bow); - } - } - if($ev->getProjectile() instanceof Projectile){ - $this->server->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($ev->getProjectile())); - if($projectileEv->isCancelled()){ - $ev->getProjectile()->kill(); - }else{ - $ev->getProjectile()->spawnToAll(); - $this->level->addSound(new LaunchSound($this), $this->getViewers()); - } - }else{ - $ev->getProjectile()->spawnToAll(); - } - } - } - }elseif($this->inventory->getItemInHand()->getId() === Item::BUCKET and $this->inventory->getItemInHand()->getDamage() === 1){ //Milk! - $this->server->getPluginManager()->callEvent($ev = new PlayerItemConsumeEvent($this, $this->inventory->getItemInHand())); - if($ev->isCancelled()){ - $this->inventory->sendContents($this); - break; - } - - $pk = new EntityEventPacket(); - $pk->eid = $this->getId(); - $pk->event = EntityEventPacket::USE_ITEM; - $this->dataPacket($pk); - $this->server->broadcastPacket($this->getViewers(), $pk); - - if($this->isSurvival()){ - $slot = $this->inventory->getItemInHand(); - --$slot->count; - $this->inventory->setItemInHand($slot); - $this->inventory->addItem(Item::get(Item::BUCKET, 0, 1)); - } - - $this->removeAllEffects(); - }else{ - $this->inventory->sendContents($this); - } - break; - case PlayerActionPacket::ACTION_STOP_SLEEPING: - $this->stopSleep(); - break; - case PlayerActionPacket::ACTION_RESPAWN: - if($this->spawned === false or $this->isAlive() or !$this->isOnline()){ - break; - } - - if($this->server->isHardcore()){ - $this->setBanned(true); - break; - } - - $this->craftingType = 0; - - $this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $this->getSpawn())); - - $this->teleport($ev->getRespawnPosition()); - - $this->setSprinting(false); - $this->setSneaking(false); - - $this->extinguish(); - $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, 400, false); - $this->deadTicks = 0; - $this->noDamageTicks = 60; - - $this->setHealth($this->getMaxHealth()); - - $this->removeAllEffects(); - $this->sendData($this); - - $this->sendSettings(); - $this->inventory->sendContents($this); - $this->inventory->sendArmorContents($this); - - $this->spawnToAll(); - $this->scheduleUpdate(); - break; - case PlayerActionPacket::ACTION_JUMP: - break 2; - case PlayerActionPacket::ACTION_START_SPRINT: - $ev = new PlayerToggleSprintEvent($this, true); - $this->server->getPluginManager()->callEvent($ev); - if($ev->isCancelled()){ - $this->sendData($this); - }else{ - $this->setSprinting(true); - } - break; - case PlayerActionPacket::ACTION_STOP_SPRINT: - $ev = new PlayerToggleSprintEvent($this, false); - $this->server->getPluginManager()->callEvent($ev); - if($ev->isCancelled()){ - $this->sendData($this); - }else{ - $this->setSprinting(false); - } - break; - case PlayerActionPacket::ACTION_START_SNEAK: - $ev = new PlayerToggleSneakEvent($this, true); - $this->server->getPluginManager()->callEvent($ev); - if($ev->isCancelled()){ - $this->sendData($this); - }else{ - $this->setSneaking(true); - } - break 2; - case PlayerActionPacket::ACTION_STOP_SNEAK: - $ev = new PlayerToggleSneakEvent($this, false); - $this->server->getPluginManager()->callEvent($ev); - if($ev->isCancelled()){ - $this->sendData($this); - }else{ - $this->setSneaking(false); - } - break 2; - default: - assert(false, "Unhandled player action " . $packet->action . " from " . $this->getName()); - } - - $this->startAction = -1; - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false); - break; - - case ProtocolInfo::REMOVE_BLOCK_PACKET: - if($this->spawned === false or !$this->isAlive()){ - break; - } - $this->craftingType = 0; - - $vector = new Vector3($packet->x, $packet->y, $packet->z); - - if($this->isCreative()){ - $item = $this->inventory->getItemInHand(); - }else{ - $item = $this->inventory->getItemInHand(); - } - - $oldItem = clone $item; - - if($this->canInteract($vector->add(0.5, 0.5, 0.5), $this->isCreative() ? 13 : 6) and $this->level->useBreakOn($vector, $item, $this, true)){ - if($this->isSurvival()){ - if(!$item->deepEquals($oldItem) or $item->getCount() !== $oldItem->getCount()){ - $this->inventory->setItemInHand($item); - $this->inventory->sendHeldItem($this->hasSpawned); - } - - $this->exhaust(0.025, PlayerExhaustEvent::CAUSE_MINING); - } - break; - } - - $this->inventory->sendContents($this); - $target = $this->level->getBlock($vector); - $tile = $this->level->getTile($vector); - - $this->level->sendBlocks([$this], [$target], UpdateBlockPacket::FLAG_ALL_PRIORITY); - - $this->inventory->sendHeldItem($this); - - if($tile instanceof Spawnable){ - $tile->spawnTo($this); - } - break; - - case ProtocolInfo::MOB_ARMOR_EQUIPMENT_PACKET: - break; - - case ProtocolInfo::INTERACT_PACKET: - if($this->spawned === false or !$this->isAlive()){ - break; - } - - $this->craftingType = 0; - - $target = $this->level->getEntity($packet->target); - - $cancelled = false; - switch($packet->action){ - case InteractPacket::ACTION_LEFT_CLICK: //Attack - if($target instanceof Player and $this->server->getConfigBoolean("pvp", true) === false){ - $cancelled = true; - } - - if($target instanceof Entity and $this->getGamemode() !== Player::VIEW and $this->isAlive() and $target->isAlive()){ - if($target instanceof DroppedItem or $target instanceof Arrow){ - $this->kick("Attempting to attack an invalid entity"); - $this->server->getLogger()->warning($this->getServer()->getLanguage()->translateString("pocketmine.player.invalidEntity", [$this->getName()])); - break; - } - - $item = $this->inventory->getItemInHand(); - $damageTable = [ - Item::WOODEN_SWORD => 4, - Item::GOLD_SWORD => 4, - Item::STONE_SWORD => 5, - Item::IRON_SWORD => 6, - Item::DIAMOND_SWORD => 7, - - Item::WOODEN_AXE => 3, - Item::GOLD_AXE => 3, - Item::STONE_AXE => 3, - Item::IRON_AXE => 5, - Item::DIAMOND_AXE => 6, - - Item::WOODEN_PICKAXE => 2, - Item::GOLD_PICKAXE => 2, - Item::STONE_PICKAXE => 3, - Item::IRON_PICKAXE => 4, - Item::DIAMOND_PICKAXE => 5, - - Item::WOODEN_SHOVEL => 1, - Item::GOLD_SHOVEL => 1, - Item::STONE_SHOVEL => 2, - Item::IRON_SHOVEL => 3, - Item::DIAMOND_SHOVEL => 4, - ]; - - $damage = [ - EntityDamageEvent::MODIFIER_BASE => $damageTable[$item->getId()] ?? 1, - ]; - - if(!$this->canInteract($target, 8)){ - $cancelled = true; - }elseif($target instanceof Player){ - if(($target->getGamemode() & 0x01) > 0){ - break; - }elseif($this->server->getConfigBoolean("pvp") !== true or $this->server->getDifficulty() === 0){ - $cancelled = true; - } - - $armorValues = [ - Item::LEATHER_CAP => 1, - Item::LEATHER_TUNIC => 3, - Item::LEATHER_PANTS => 2, - Item::LEATHER_BOOTS => 1, - Item::CHAIN_HELMET => 1, - Item::CHAIN_CHESTPLATE => 5, - Item::CHAIN_LEGGINGS => 4, - Item::CHAIN_BOOTS => 1, - Item::GOLD_HELMET => 1, - Item::GOLD_CHESTPLATE => 5, - Item::GOLD_LEGGINGS => 3, - Item::GOLD_BOOTS => 1, - Item::IRON_HELMET => 2, - Item::IRON_CHESTPLATE => 6, - Item::IRON_LEGGINGS => 5, - Item::IRON_BOOTS => 2, - Item::DIAMOND_HELMET => 3, - Item::DIAMOND_CHESTPLATE => 8, - Item::DIAMOND_LEGGINGS => 6, - Item::DIAMOND_BOOTS => 3, - ]; - $points = 0; - foreach($target->getInventory()->getArmorContents() as $index => $i){ - if(isset($armorValues[$i->getId()])){ - $points += $armorValues[$i->getId()]; - } - } - - $damage[EntityDamageEvent::MODIFIER_ARMOR] = -floor($damage[EntityDamageEvent::MODIFIER_BASE] * $points * 0.04); - } - - $ev = new EntityDamageByEntityEvent($this, $target, EntityDamageEvent::CAUSE_ENTITY_ATTACK, $damage); - if($cancelled){ - $ev->setCancelled(); - } - - $target->attack($ev->getFinalDamage(), $ev); - - if($ev->isCancelled()){ - if($item->isTool() and $this->isSurvival()){ - $this->inventory->sendContents($this); - } - break; - } - - if($this->isSurvival()){ - if($item->isTool()){ - if($item->useOn($target) and $item->getDamage() >= $item->getMaxDurability()){ - $this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1)); - }else{ - $this->inventory->setItemInHand($item); - } - } - - $this->exhaust(0.3, PlayerExhaustEvent::CAUSE_ATTACK); - } - } - break; - default: - break; //TODO: handle other actions - } - - break; - case ProtocolInfo::ANIMATE_PACKET: - if($this->spawned === false or !$this->isAlive()){ - break; - } - - $this->server->getPluginManager()->callEvent($ev = new PlayerAnimationEvent($this, $packet->action)); - if($ev->isCancelled()){ - break; - } - - $pk = new AnimatePacket(); - $pk->eid = $this->getId(); - $pk->action = $ev->getAnimationType(); - $this->server->broadcastPacket($this->getViewers(), $pk); - break; - case ProtocolInfo::SET_HEALTH_PACKET: //Not used - break; - case ProtocolInfo::ENTITY_EVENT_PACKET: - if($this->spawned === false or !$this->isAlive()){ - break; - } - $this->craftingType = 0; - - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false); //TODO: check if this should be true - - switch($packet->event){ - case EntityEventPacket::USE_ITEM: //Eating - $slot = $this->inventory->getItemInHand(); - - if($slot->canBeConsumed()){ - $ev = new PlayerItemConsumeEvent($this, $slot); - if(!$slot->canBeConsumedBy($this)){ - $ev->setCancelled(); - } - $this->server->getPluginManager()->callEvent($ev); - if(!$ev->isCancelled()){ - $slot->onConsume($this); - }else{ - $this->inventory->sendContents($this); - } - } - break; - } - break; - case ProtocolInfo::DROP_ITEM_PACKET: - if($this->spawned === false or !$this->isAlive()){ - break; - } - - if($packet->item->getId() === Item::AIR){ - // Windows 10 Edition drops the contents of the crafting grid on container close - including air. - break; - } - - $item = $this->inventory->getItemInHand(); - $ev = new PlayerDropItemEvent($this, $item); - $this->server->getPluginManager()->callEvent($ev); - if($ev->isCancelled()){ - $this->inventory->sendContents($this); - break; - } - - $this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1)); - $motion = $this->getDirectionVector()->multiply(0.4); - - $this->level->dropItem($this->add(0, 1.3, 0), $item, $motion, 40); - - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false); - break; - case ProtocolInfo::COMMAND_STEP_PACKET: - if($this->spawned === false or !$this->isAlive()){ - break; - } - $this->craftingType = 0; - $commandText = $packet->command; - if($packet->args !== null){ - foreach($packet->args as $arg){ //command ordering will be an issue - $commandText .= " " . $arg; - } - } - $this->server->getPluginManager()->callEvent($ev = new PlayerCommandPreprocessEvent($this, "/" . $commandText)); - if($ev->isCancelled()){ - break; - } - - Timings::$playerCommandTimer->startTiming(); - $this->server->dispatchCommand($ev->getPlayer(), substr($ev->getMessage(), 1)); - Timings::$playerCommandTimer->stopTiming(); - break; - case ProtocolInfo::TEXT_PACKET: - if($this->spawned === false or !$this->isAlive()){ - break; - } - $this->craftingType = 0; - if($packet->type === TextPacket::TYPE_CHAT){ - $packet->message = TextFormat::clean($packet->message, $this->removeFormat); - foreach(explode("\n", $packet->message) as $message){ - if(trim($message) != "" and strlen($message) <= 255 and $this->messageCounter-- > 0){ - if(substr($message, 0, 2) === "./"){ //Command (./ = fast hack for old plugins post 0.16) - $message = substr($message, 1); - } - - $ev = new PlayerCommandPreprocessEvent($this, $message); - - if(mb_strlen($ev->getMessage(), "UTF-8") > 320){ - $ev->setCancelled(); - } - $this->server->getPluginManager()->callEvent($ev); - - if($ev->isCancelled()){ - break; - } - - if(substr($ev->getMessage(), 0, 1) === "/"){ - Timings::$playerCommandTimer->startTiming(); - $this->server->dispatchCommand($ev->getPlayer(), substr($ev->getMessage(), 1)); - Timings::$playerCommandTimer->stopTiming(); - }else{ - $this->server->getPluginManager()->callEvent($ev = new PlayerChatEvent($this, $ev->getMessage())); - if(!$ev->isCancelled()){ - $this->server->broadcastMessage($this->getServer()->getLanguage()->translateString($ev->getFormat(), [$ev->getPlayer()->getDisplayName(), $ev->getMessage()]), $ev->getRecipients()); - } - } - } - } - } - break; - case ProtocolInfo::CONTAINER_CLOSE_PACKET: - if($this->spawned === false or $packet->windowid === 0){ - break; - } - $this->craftingType = 0; - $this->currentTransaction = null; - if(isset($this->windowIndex[$packet->windowid])){ - $this->server->getPluginManager()->callEvent(new InventoryCloseEvent($this->windowIndex[$packet->windowid], $this)); - $this->removeWindow($this->windowIndex[$packet->windowid]); - }else{ - unset($this->windowIndex[$packet->windowid]); - } - break; - - case ProtocolInfo::CRAFTING_EVENT_PACKET: - if($this->spawned === false or !$this->isAlive()){ - break; - }elseif(!isset($this->windowIndex[$packet->windowId])){ - $this->inventory->sendContents($this); - $pk = new ContainerClosePacket(); - $pk->windowid = $packet->windowId; - $this->dataPacket($pk); - break; - } - - $recipe = $this->server->getCraftingManager()->getRecipe($packet->id); - - if($recipe === null or (($recipe instanceof BigShapelessRecipe or $recipe instanceof BigShapedRecipe) and $this->craftingType === 0)){ - $this->inventory->sendContents($this); - break; - } - - $canCraft = true; - - if($recipe instanceof ShapedRecipe){ - for($x = 0; $x < 3 and $canCraft; ++$x){ - for($y = 0; $y < 3; ++$y){ - /** @var Item $item */ - $item = $packet->input[$y * 3 + $x]; - $ingredient = $recipe->getIngredient($x, $y); - if($item->getCount() > 0){ - if($ingredient === null or !$ingredient->deepEquals($item, !$ingredient->hasAnyDamageValue(), $ingredient->hasCompoundTag())){ - $canCraft = false; - break; - } - } - } - } - }elseif($recipe instanceof ShapelessRecipe){ - $needed = $recipe->getIngredientList(); - - for($x = 0; $x < 3 and $canCraft; ++$x){ - for($y = 0; $y < 3; ++$y){ - /** @var Item $item */ - $item = clone $packet->input[$y * 3 + $x]; - - foreach($needed as $k => $n){ - if($n->deepEquals($item, !$n->hasAnyDamageValue(), $n->hasCompoundTag())){ - $remove = min($n->getCount(), $item->getCount()); - $n->setCount($n->getCount() - $remove); - $item->setCount($item->getCount() - $remove); - - if($n->getCount() === 0){ - unset($needed[$k]); - } - } - } - - if($item->getCount() > 0){ - $canCraft = false; - break; - } - } - } - - if(count($needed) > 0){ - $canCraft = false; - } - }else{ - $canCraft = false; - } - - /** @var Item[] $ingredients */ - $ingredients = $packet->input; - $result = $packet->output[0]; - - if(!$canCraft or !$recipe->getResult()->deepEquals($result)){ - $this->server->getLogger()->debug("Unmatched recipe " . $recipe->getId() . " from player " . $this->getName() . ": expected " . $recipe->getResult() . ", got " . $result . ", using: " . implode(", ", $ingredients)); - $this->inventory->sendContents($this); - break; - } - - $used = array_fill(0, $this->inventory->getSize(), 0); - - foreach($ingredients as $ingredient){ - $slot = -1; - foreach($this->inventory->getContents() as $index => $item){ - if($ingredient->getId() !== 0 and $ingredient->equals($item, !$ingredient->hasAnyDamageValue(), $ingredient->hasCompoundTag()) and ($item->getCount() - $used[$index]) >= 1){ - $slot = $index; - $used[$index]++; - break; - } - } - - if($ingredient->getId() !== 0 and $slot === -1){ - $canCraft = false; - break; - } - } - - if(!$canCraft){ - $this->server->getLogger()->debug("Unmatched recipe " . $recipe->getId() . " from player " . $this->getName() . ": client does not have enough items, using: " . implode(", ", $ingredients)); - $this->inventory->sendContents($this); - break; - } - - $this->server->getPluginManager()->callEvent($ev = new CraftItemEvent($this, $ingredients, $recipe)); - - if($ev->isCancelled()){ - $this->inventory->sendContents($this); - break; - } - - foreach($used as $slot => $count){ - if($count === 0){ - continue; - } - - $item = $this->inventory->getItem($slot); - - if($item->getCount() > $count){ - $newItem = clone $item; - $newItem->setCount($item->getCount() - $count); - }else{ - $newItem = Item::get(Item::AIR, 0, 0); - } - - $this->inventory->setItem($slot, $newItem); - } - - $extraItem = $this->inventory->addItem($recipe->getResult()); - if(count($extraItem) > 0){ - foreach($extraItem as $item){ - $this->level->dropItem($this, $item); - } - } - - switch($recipe->getResult()->getId()){ - case Item::WORKBENCH: - $this->awardAchievement("buildWorkBench"); - break; - case Item::WOODEN_PICKAXE: - $this->awardAchievement("buildPickaxe"); - break; - case Item::FURNACE: - $this->awardAchievement("buildFurnace"); - break; - case Item::WOODEN_HOE: - $this->awardAchievement("buildHoe"); - break; - case Item::BREAD: - $this->awardAchievement("makeBread"); - break; - case Item::CAKE: - //TODO: detect complex recipes like cake that leave remains - $this->awardAchievement("bakeCake"); - $this->inventory->addItem(Item::get(Item::BUCKET, 0, 3)); - break; - case Item::STONE_PICKAXE: - case Item::GOLD_PICKAXE: - case Item::IRON_PICKAXE: - case Item::DIAMOND_PICKAXE: - $this->awardAchievement("buildBetterPickaxe"); - break; - case Item::WOODEN_SWORD: - $this->awardAchievement("buildSword"); - break; - case Item::DIAMOND: - $this->awardAchievement("diamond"); - break; - } - - break; - - case ProtocolInfo::CONTAINER_SET_SLOT_PACKET: - if($this->spawned === false or !$this->isAlive()){ - break; - } - - if($packet->slot < 0){ - break; - } - - if($packet->windowid === 0){ //Our inventory - if($packet->slot >= $this->inventory->getSize()){ - break; - } - if($this->isCreative()){ - if(Item::getCreativeItemIndex($packet->item) !== -1){ - $this->inventory->setItem($packet->slot, $packet->item); - $this->inventory->setHotbarSlotIndex($packet->slot, $packet->slot); //links $hotbar[$packet->slot] to $slots[$packet->slot] - } - } - $transaction = new BaseTransaction($this->inventory, $packet->slot, $this->inventory->getItem($packet->slot), $packet->item); - }elseif($packet->windowid === ContainerSetContentPacket::SPECIAL_ARMOR){ //Our armor - if($packet->slot >= 4){ - break; - } - - $transaction = new BaseTransaction($this->inventory, $packet->slot + $this->inventory->getSize(), $this->inventory->getArmorItem($packet->slot), $packet->item); - }elseif(isset($this->windowIndex[$packet->windowid])){ - $this->craftingType = 0; - $inv = $this->windowIndex[$packet->windowid]; - $transaction = new BaseTransaction($inv, $packet->slot, $inv->getItem($packet->slot), $packet->item); - }else{ - break; - } - - if($transaction->getSourceItem()->deepEquals($transaction->getTargetItem()) and $transaction->getTargetItem()->getCount() === $transaction->getSourceItem()->getCount()){ //No changes! - //No changes, just a local inventory update sent by the server - break; - } - - if($this->currentTransaction === null or $this->currentTransaction->getCreationTime() < (microtime(true) - 8)){ - if($this->currentTransaction !== null){ - foreach($this->currentTransaction->getInventories() as $inventory){ - if($inventory instanceof PlayerInventory){ - $inventory->sendArmorContents($this); - } - $inventory->sendContents($this); - } - } - $this->currentTransaction = new SimpleTransactionGroup($this); - } - - $this->currentTransaction->addTransaction($transaction); - - if($this->currentTransaction->canExecute()){ - $achievements = []; - foreach($this->currentTransaction->getTransactions() as $ts){ - $inv = $ts->getInventory(); - if($inv instanceof FurnaceInventory){ - if($ts->getSlot() === 2){ - switch($inv->getResult()->getId()){ - case Item::IRON_INGOT: - $achievements[] = "acquireIron"; - break; - } - } - } - } - - if($this->currentTransaction->execute()){ - foreach($achievements as $a){ - $this->awardAchievement($a); - } - } - - $this->currentTransaction = null; - } - - break; - case ProtocolInfo::BLOCK_ENTITY_DATA_PACKET: - if($this->spawned === false or !$this->isAlive()){ - break; - } - $this->craftingType = 0; - - $pos = new Vector3($packet->x, $packet->y, $packet->z); - if($pos->distanceSquared($this) > 10000){ - break; - } - - $t = $this->level->getTile($pos); - if($t instanceof Spawnable){ - $nbt = new NBT(NBT::LITTLE_ENDIAN); - $nbt->read($packet->namedtag, false, true); - $nbt = $nbt->getData(); - if(!$t->updateCompoundTag($nbt, $this)){ - $t->spawnTo($this); - } - } - break; - case ProtocolInfo::REQUEST_CHUNK_RADIUS_PACKET: - $this->setViewDistance($packet->radius); - break; - case ProtocolInfo::SET_PLAYER_GAME_TYPE_PACKET: - if($packet->gamemode !== ($this->gamemode & 0x01)){ - //GUI gamemode change, set it back to original for now (only possible through client bug or hack with current allowed client permissions) - $pk = new SetPlayerGameTypePacket(); - $pk->gamemode = $this->gamemode & 0x01; - $this->dataPacket($pk); - $this->sendSettings(); - } - break; - case ProtocolInfo::ITEM_FRAME_DROP_ITEM_PACKET: - if($this->spawned === false or !$this->isAlive()){ - break; - } - - $tile = $this->level->getTile($this->temporalVector->setComponents($packet->x, $packet->y, $packet->z)); - if($tile instanceof ItemFrame){ - if($this->isSpectator()){ - $tile->spawnTo($this); - break; - } - - if(lcg_value() <= $tile->getItemDropChance()){ - $this->level->dropItem($tile->getBlock(), $tile->getItem()); - } - $tile->setItem(null); - $tile->setItemRotation(0); - } - - break; - default: - break; - } $timings->stopTiming(); } diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index 45cd58cb3..4ee22988a 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -252,7 +252,10 @@ class Network{ $pk->decode(); assert($pk->feof(), "Still " . strlen(substr($pk->buffer, $pk->offset)) . " bytes unread in " . get_class($pk)); - $p->handleDataPacket($pk); + if(!$pk->handle($p)){ + $logger = $this->server->getLogger(); + $logger->debug("Unhandled " . get_class($pk) . " received from " . $p->getName()); + } } } }catch(\Throwable $e){ diff --git a/src/pocketmine/network/PocketEditionNetworkSession.php b/src/pocketmine/network/PocketEditionNetworkSession.php new file mode 100644 index 000000000..7c8706798 --- /dev/null +++ b/src/pocketmine/network/PocketEditionNetworkSession.php @@ -0,0 +1,263 @@ +decode(); assert($pk->feof(), "Still " . strlen(substr($pk->buffer, $pk->offset)) . " bytes unread!"); - $this->players[$identifier]->handleDataPacket($pk); + if(!$pk->handle($this->players[$identifier])){ + $logger = $this->server->getLogger(); + $logger->debug("Unhandled " . get_class($pk) . " received from " . $this->players[$identifier]->getName()); + } } } }catch(\Throwable $e){ diff --git a/src/pocketmine/network/protocol/AddEntityPacket.php b/src/pocketmine/network/protocol/AddEntityPacket.php index b987fd4c6..7bc018bcc 100644 --- a/src/pocketmine/network/protocol/AddEntityPacket.php +++ b/src/pocketmine/network/protocol/AddEntityPacket.php @@ -24,6 +24,7 @@ namespace pocketmine\network\protocol; #include use pocketmine\entity\Attribute; +use pocketmine\network\PocketEditionNetworkSession; class AddEntityPacket extends DataPacket{ const NETWORK_ID = Info::ADD_ENTITY_PACKET; @@ -72,4 +73,8 @@ class AddEntityPacket extends DataPacket{ } } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleAddEntity($this); + } + } diff --git a/src/pocketmine/network/protocol/AddHangingEntityPacket.php b/src/pocketmine/network/protocol/AddHangingEntityPacket.php index 1cba0a649..5ed7b32f5 100644 --- a/src/pocketmine/network/protocol/AddHangingEntityPacket.php +++ b/src/pocketmine/network/protocol/AddHangingEntityPacket.php @@ -23,6 +23,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class AddHangingEntityPacket extends DataPacket{ const NETWORK_ID = Info::ADD_HANGING_ENTITY_PACKET; @@ -45,4 +47,8 @@ class AddHangingEntityPacket extends DataPacket{ $this->putVarInt($this->unknown); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleAddHangingEntity($this); + } + } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/AddItemEntityPacket.php b/src/pocketmine/network/protocol/AddItemEntityPacket.php index ac6486463..fc38ec153 100644 --- a/src/pocketmine/network/protocol/AddItemEntityPacket.php +++ b/src/pocketmine/network/protocol/AddItemEntityPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class AddItemEntityPacket extends DataPacket{ const NETWORK_ID = Info::ADD_ITEM_ENTITY_PACKET; @@ -49,4 +51,8 @@ class AddItemEntityPacket extends DataPacket{ $this->putVector3f($this->speedX, $this->speedY, $this->speedZ); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleAddItemEntity($this); + } + } diff --git a/src/pocketmine/network/protocol/AddItemPacket.php b/src/pocketmine/network/protocol/AddItemPacket.php index af50d545c..a67aa7170 100644 --- a/src/pocketmine/network/protocol/AddItemPacket.php +++ b/src/pocketmine/network/protocol/AddItemPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class AddItemPacket extends DataPacket{ const NETWORK_ID = Info::ADD_ITEM_PACKET; @@ -38,4 +40,8 @@ class AddItemPacket extends DataPacket{ $this->putSlot($this->item); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleAddItem($this); + } + } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/AddPaintingPacket.php b/src/pocketmine/network/protocol/AddPaintingPacket.php index 3cc3e550b..eff76d0f1 100644 --- a/src/pocketmine/network/protocol/AddPaintingPacket.php +++ b/src/pocketmine/network/protocol/AddPaintingPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class AddPaintingPacket extends DataPacket{ const NETWORK_ID = Info::ADD_PAINTING_PACKET; @@ -47,4 +49,8 @@ class AddPaintingPacket extends DataPacket{ $this->putString($this->title); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleAddPainting($this); + } + } diff --git a/src/pocketmine/network/protocol/AddPlayerPacket.php b/src/pocketmine/network/protocol/AddPlayerPacket.php index 892cb391c..7b6fbd8c2 100644 --- a/src/pocketmine/network/protocol/AddPlayerPacket.php +++ b/src/pocketmine/network/protocol/AddPlayerPacket.php @@ -23,6 +23,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class AddPlayerPacket extends DataPacket{ const NETWORK_ID = Info::ADD_PLAYER_PACKET; @@ -60,4 +62,8 @@ class AddPlayerPacket extends DataPacket{ $this->putEntityMetadata($this->metadata); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleAddPlayer($this); + } + } diff --git a/src/pocketmine/network/protocol/AdventureSettingsPacket.php b/src/pocketmine/network/protocol/AdventureSettingsPacket.php index 0a5745679..b5612f187 100644 --- a/src/pocketmine/network/protocol/AdventureSettingsPacket.php +++ b/src/pocketmine/network/protocol/AdventureSettingsPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class AdventureSettingsPacket extends DataPacket{ const NETWORK_ID = Info::ADVENTURE_SETTINGS_PACKET; @@ -95,4 +97,8 @@ class AdventureSettingsPacket extends DataPacket{ $this->putUnsignedVarInt($this->userPermission); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleAdventureSettings($this); + } + } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/AnimatePacket.php b/src/pocketmine/network/protocol/AnimatePacket.php index c0d27012d..7b713fa3a 100644 --- a/src/pocketmine/network/protocol/AnimatePacket.php +++ b/src/pocketmine/network/protocol/AnimatePacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class AnimatePacket extends DataPacket{ const NETWORK_ID = Info::ANIMATE_PACKET; @@ -41,4 +43,8 @@ class AnimatePacket extends DataPacket{ $this->putEntityId($this->eid); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleAnimate($this); + } + } diff --git a/src/pocketmine/network/protocol/AvailableCommandsPacket.php b/src/pocketmine/network/protocol/AvailableCommandsPacket.php index 3f86e126b..ef1907ade 100644 --- a/src/pocketmine/network/protocol/AvailableCommandsPacket.php +++ b/src/pocketmine/network/protocol/AvailableCommandsPacket.php @@ -23,6 +23,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class AvailableCommandsPacket extends DataPacket{ const NETWORK_ID = Info::AVAILABLE_COMMANDS_PACKET; @@ -39,4 +41,8 @@ class AvailableCommandsPacket extends DataPacket{ $this->putString($this->unknown); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleAvailableCommands($this); + } + } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/BatchPacket.php b/src/pocketmine/network/protocol/BatchPacket.php index f8a6ecbda..ed7d475db 100644 --- a/src/pocketmine/network/protocol/BatchPacket.php +++ b/src/pocketmine/network/protocol/BatchPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class BatchPacket extends DataPacket{ const NETWORK_ID = Info::BATCH_PACKET; @@ -38,4 +40,8 @@ class BatchPacket extends DataPacket{ $this->putString($this->payload); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleBatch($this); + } + } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/BlockEntityDataPacket.php b/src/pocketmine/network/protocol/BlockEntityDataPacket.php index df01e6142..0527a9006 100644 --- a/src/pocketmine/network/protocol/BlockEntityDataPacket.php +++ b/src/pocketmine/network/protocol/BlockEntityDataPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class BlockEntityDataPacket extends DataPacket{ const NETWORK_ID = Info::BLOCK_ENTITY_DATA_PACKET; @@ -43,4 +45,8 @@ class BlockEntityDataPacket extends DataPacket{ $this->put($this->namedtag); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleBlockEntityData($this); + } + } diff --git a/src/pocketmine/network/protocol/BlockEventPacket.php b/src/pocketmine/network/protocol/BlockEventPacket.php index 14b4ca274..da3ff64e8 100644 --- a/src/pocketmine/network/protocol/BlockEventPacket.php +++ b/src/pocketmine/network/protocol/BlockEventPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class BlockEventPacket extends DataPacket{ const NETWORK_ID = Info::BLOCK_EVENT_PACKET; @@ -44,4 +46,8 @@ class BlockEventPacket extends DataPacket{ $this->putVarInt($this->case2); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleBlockEvent($this); + } + } diff --git a/src/pocketmine/network/protocol/ChangeDimensionPacket.php b/src/pocketmine/network/protocol/ChangeDimensionPacket.php index 54a9b443a..da422c0a4 100644 --- a/src/pocketmine/network/protocol/ChangeDimensionPacket.php +++ b/src/pocketmine/network/protocol/ChangeDimensionPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class ChangeDimensionPacket extends DataPacket{ const NETWORK_ID = Info::CHANGE_DIMENSION_PACKET; @@ -47,4 +49,8 @@ class ChangeDimensionPacket extends DataPacket{ $this->putBool($this->unknown); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleChangeDimension($this); + } + } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/ChunkRadiusUpdatedPacket.php b/src/pocketmine/network/protocol/ChunkRadiusUpdatedPacket.php index a97c8b32a..029de4d60 100644 --- a/src/pocketmine/network/protocol/ChunkRadiusUpdatedPacket.php +++ b/src/pocketmine/network/protocol/ChunkRadiusUpdatedPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class ChunkRadiusUpdatedPacket extends DataPacket{ const NETWORK_ID = Info::CHUNK_RADIUS_UPDATED_PACKET; @@ -37,4 +39,8 @@ class ChunkRadiusUpdatedPacket extends DataPacket{ $this->putVarInt($this->radius); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleChunkRadiusUpdated($this); + } + } diff --git a/src/pocketmine/network/protocol/CommandStepPacket.php b/src/pocketmine/network/protocol/CommandStepPacket.php index 0aef29977..6d76dbc8d 100644 --- a/src/pocketmine/network/protocol/CommandStepPacket.php +++ b/src/pocketmine/network/protocol/CommandStepPacket.php @@ -23,6 +23,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class CommandStepPacket extends DataPacket{ const NETWORK_ID = Info::COMMAND_STEP_PACKET; @@ -65,4 +67,8 @@ class CommandStepPacket extends DataPacket{ } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleCommandStep($this); + } + } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/ContainerClosePacket.php b/src/pocketmine/network/protocol/ContainerClosePacket.php index f60788a0a..9af31d553 100644 --- a/src/pocketmine/network/protocol/ContainerClosePacket.php +++ b/src/pocketmine/network/protocol/ContainerClosePacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class ContainerClosePacket extends DataPacket{ const NETWORK_ID = Info::CONTAINER_CLOSE_PACKET; @@ -38,4 +40,7 @@ class ContainerClosePacket extends DataPacket{ $this->putByte($this->windowid); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleContainerClose($this); + } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/ContainerOpenPacket.php b/src/pocketmine/network/protocol/ContainerOpenPacket.php index 5968d7977..5d9ebc730 100644 --- a/src/pocketmine/network/protocol/ContainerOpenPacket.php +++ b/src/pocketmine/network/protocol/ContainerOpenPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class ContainerOpenPacket extends DataPacket{ const NETWORK_ID = Info::CONTAINER_OPEN_PACKET; @@ -48,4 +50,8 @@ class ContainerOpenPacket extends DataPacket{ $this->putEntityId($this->entityId); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleContainerOpen($this); + } + } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/ContainerSetContentPacket.php b/src/pocketmine/network/protocol/ContainerSetContentPacket.php index 00e078be3..d105d3862 100644 --- a/src/pocketmine/network/protocol/ContainerSetContentPacket.php +++ b/src/pocketmine/network/protocol/ContainerSetContentPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class ContainerSetContentPacket extends DataPacket{ const NETWORK_ID = Info::CONTAINER_SET_CONTENT_PACKET; @@ -73,4 +75,8 @@ class ContainerSetContentPacket extends DataPacket{ } } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleContainerSetContent($this); + } + } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/ContainerSetDataPacket.php b/src/pocketmine/network/protocol/ContainerSetDataPacket.php index d2756a928..235fec96d 100644 --- a/src/pocketmine/network/protocol/ContainerSetDataPacket.php +++ b/src/pocketmine/network/protocol/ContainerSetDataPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class ContainerSetDataPacket extends DataPacket{ const NETWORK_ID = Info::CONTAINER_SET_DATA_PACKET; @@ -42,4 +44,8 @@ class ContainerSetDataPacket extends DataPacket{ $this->putVarInt($this->value); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleContainerSetData($this); + } + } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/ContainerSetSlotPacket.php b/src/pocketmine/network/protocol/ContainerSetSlotPacket.php index 912e0cd64..f91da7d9d 100644 --- a/src/pocketmine/network/protocol/ContainerSetSlotPacket.php +++ b/src/pocketmine/network/protocol/ContainerSetSlotPacket.php @@ -24,6 +24,7 @@ namespace pocketmine\network\protocol; #include use pocketmine\item\Item; +use pocketmine\network\PocketEditionNetworkSession; class ContainerSetSlotPacket extends DataPacket{ const NETWORK_ID = Info::CONTAINER_SET_SLOT_PACKET; @@ -52,4 +53,8 @@ class ContainerSetSlotPacket extends DataPacket{ $this->putByte($this->unknown); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleContainerSetSlot($this); + } + } diff --git a/src/pocketmine/network/protocol/CraftingDataPacket.php b/src/pocketmine/network/protocol/CraftingDataPacket.php index 4ecccc738..601aae635 100644 --- a/src/pocketmine/network/protocol/CraftingDataPacket.php +++ b/src/pocketmine/network/protocol/CraftingDataPacket.php @@ -29,6 +29,7 @@ use pocketmine\inventory\MultiRecipe; use pocketmine\inventory\ShapedRecipe; use pocketmine\inventory\ShapelessRecipe; use pocketmine\item\Item; +use pocketmine\network\PocketEditionNetworkSession; use pocketmine\utils\BinaryStream; class CraftingDataPacket extends DataPacket{ @@ -198,4 +199,8 @@ class CraftingDataPacket extends DataPacket{ $this->putBool($this->cleanRecipes); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleCraftingData($this); + } + } diff --git a/src/pocketmine/network/protocol/CraftingEventPacket.php b/src/pocketmine/network/protocol/CraftingEventPacket.php index ffc294b19..4db2e113c 100644 --- a/src/pocketmine/network/protocol/CraftingEventPacket.php +++ b/src/pocketmine/network/protocol/CraftingEventPacket.php @@ -24,6 +24,7 @@ namespace pocketmine\network\protocol; #include use pocketmine\item\Item; +use pocketmine\network\PocketEditionNetworkSession; class CraftingEventPacket extends DataPacket{ const NETWORK_ID = Info::CRAFTING_EVENT_PACKET; @@ -62,4 +63,8 @@ class CraftingEventPacket extends DataPacket{ } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleCraftingEvent($this); + } + } diff --git a/src/pocketmine/network/protocol/DataPacket.php b/src/pocketmine/network/protocol/DataPacket.php index 94d989ee1..7f0890de6 100644 --- a/src/pocketmine/network/protocol/DataPacket.php +++ b/src/pocketmine/network/protocol/DataPacket.php @@ -25,6 +25,7 @@ namespace pocketmine\network\protocol; use pocketmine\entity\Entity; use pocketmine\item\Item; +use pocketmine\network\PocketEditionNetworkSession; use pocketmine\utils\BinaryStream; use pocketmine\utils\Utils; @@ -43,6 +44,8 @@ abstract class DataPacket extends BinaryStream{ abstract public function decode(); + abstract public function handle(PocketEditionNetworkSession $session) : bool; + public function reset(){ $this->buffer = chr($this::NETWORK_ID); $this->offset = 0; diff --git a/src/pocketmine/network/protocol/DisconnectPacket.php b/src/pocketmine/network/protocol/DisconnectPacket.php index e3873eeab..5a9531c0b 100644 --- a/src/pocketmine/network/protocol/DisconnectPacket.php +++ b/src/pocketmine/network/protocol/DisconnectPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class DisconnectPacket extends DataPacket{ const NETWORK_ID = Info::DISCONNECT_PACKET; @@ -41,4 +43,8 @@ class DisconnectPacket extends DataPacket{ $this->putString($this->message); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleDisconnect($this); + } + } diff --git a/src/pocketmine/network/protocol/DropItemPacket.php b/src/pocketmine/network/protocol/DropItemPacket.php index 49a53f82a..ff4e48606 100644 --- a/src/pocketmine/network/protocol/DropItemPacket.php +++ b/src/pocketmine/network/protocol/DropItemPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class DropItemPacket extends DataPacket{ const NETWORK_ID = Info::DROP_ITEM_PACKET; @@ -39,4 +41,8 @@ class DropItemPacket extends DataPacket{ } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleDropItem($this); + } + } diff --git a/src/pocketmine/network/protocol/EntityEventPacket.php b/src/pocketmine/network/protocol/EntityEventPacket.php index 64510980b..68f31a1aa 100644 --- a/src/pocketmine/network/protocol/EntityEventPacket.php +++ b/src/pocketmine/network/protocol/EntityEventPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class EntityEventPacket extends DataPacket{ const NETWORK_ID = Info::ENTITY_EVENT_PACKET; @@ -62,4 +64,8 @@ class EntityEventPacket extends DataPacket{ $this->putVarInt($this->unknown); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleEntityEvent($this); + } + } diff --git a/src/pocketmine/network/protocol/ExplodePacket.php b/src/pocketmine/network/protocol/ExplodePacket.php index 7804b5ca2..46906ef26 100644 --- a/src/pocketmine/network/protocol/ExplodePacket.php +++ b/src/pocketmine/network/protocol/ExplodePacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class ExplodePacket extends DataPacket{ const NETWORK_ID = Info::EXPLODE_PACKET; @@ -54,4 +56,8 @@ class ExplodePacket extends DataPacket{ } } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleExplode($this); + } + } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/FullChunkDataPacket.php b/src/pocketmine/network/protocol/FullChunkDataPacket.php index 02d9870fe..171719c82 100644 --- a/src/pocketmine/network/protocol/FullChunkDataPacket.php +++ b/src/pocketmine/network/protocol/FullChunkDataPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class FullChunkDataPacket extends DataPacket{ const NETWORK_ID = Info::FULL_CHUNK_DATA_PACKET; @@ -42,4 +44,8 @@ class FullChunkDataPacket extends DataPacket{ $this->putString($this->data); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleFullChunkData($this); + } + } diff --git a/src/pocketmine/network/protocol/HurtArmorPacket.php b/src/pocketmine/network/protocol/HurtArmorPacket.php index e16147283..5c6265935 100644 --- a/src/pocketmine/network/protocol/HurtArmorPacket.php +++ b/src/pocketmine/network/protocol/HurtArmorPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class HurtArmorPacket extends DataPacket{ const NETWORK_ID = Info::HURT_ARMOR_PACKET; @@ -38,4 +40,8 @@ class HurtArmorPacket extends DataPacket{ $this->putVarInt($this->health); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleHurtArmor($this); + } + } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/Info.php b/src/pocketmine/network/protocol/Info.php index 227432767..644191ae9 100644 --- a/src/pocketmine/network/protocol/Info.php +++ b/src/pocketmine/network/protocol/Info.php @@ -117,4 +117,4 @@ interface Info{ const RESOURCE_PACK_CHUNK_REQUEST_PACKET = 0x51; const TRANSFER_PACKET = 0x52; -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/InteractPacket.php b/src/pocketmine/network/protocol/InteractPacket.php index fada11c3d..4200e9ee6 100644 --- a/src/pocketmine/network/protocol/InteractPacket.php +++ b/src/pocketmine/network/protocol/InteractPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class InteractPacket extends DataPacket{ const NETWORK_ID = Info::INTERACT_PACKET; @@ -46,4 +48,8 @@ class InteractPacket extends DataPacket{ $this->putEntityId($this->target); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleInteract($this); + } + } diff --git a/src/pocketmine/network/protocol/InventoryActionPacket.php b/src/pocketmine/network/protocol/InventoryActionPacket.php index f31c569a4..86cb3db3a 100644 --- a/src/pocketmine/network/protocol/InventoryActionPacket.php +++ b/src/pocketmine/network/protocol/InventoryActionPacket.php @@ -23,6 +23,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class InventoryActionPacket extends DataPacket{ const NETWORK_ID = Info::INVENTORY_ACTION_PACKET; @@ -37,4 +39,8 @@ class InventoryActionPacket extends DataPacket{ $this->putUnsignedVarInt($this->unknown); $this->putSlot($this->item); } + + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleInventoryAction($this); + } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/ItemFrameDropItemPacket.php b/src/pocketmine/network/protocol/ItemFrameDropItemPacket.php index 267d79a27..4dc3bb8ba 100644 --- a/src/pocketmine/network/protocol/ItemFrameDropItemPacket.php +++ b/src/pocketmine/network/protocol/ItemFrameDropItemPacket.php @@ -23,6 +23,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class ItemFrameDropItemPacket extends DataPacket{ const NETWORK_ID = Info::ITEM_FRAME_DROP_ITEM_PACKET; @@ -39,4 +41,8 @@ class ItemFrameDropItemPacket extends DataPacket{ } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleItemFrameDropItem($this); + } + } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/LevelEventPacket.php b/src/pocketmine/network/protocol/LevelEventPacket.php index 86aa244cb..0ff2677ee 100644 --- a/src/pocketmine/network/protocol/LevelEventPacket.php +++ b/src/pocketmine/network/protocol/LevelEventPacket.php @@ -23,6 +23,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class LevelEventPacket extends DataPacket{ const NETWORK_ID = Info::LEVEL_EVENT_PACKET; @@ -107,4 +109,8 @@ class LevelEventPacket extends DataPacket{ $this->putVarInt($this->data); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleLevelEvent($this); + } + } diff --git a/src/pocketmine/network/protocol/LevelSoundEventPacket.php b/src/pocketmine/network/protocol/LevelSoundEventPacket.php index 66bd9f079..357a8913f 100644 --- a/src/pocketmine/network/protocol/LevelSoundEventPacket.php +++ b/src/pocketmine/network/protocol/LevelSoundEventPacket.php @@ -23,6 +23,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class LevelSoundEventPacket extends DataPacket{ const NETWORK_ID = Info::LEVEL_SOUND_EVENT_PACKET; @@ -146,4 +148,8 @@ class LevelSoundEventPacket extends DataPacket{ $this->putBool($this->unknownBool); $this->putBool($this->unknownBool2); } + + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleLevelSoundEvent($this); + } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/LoginPacket.php b/src/pocketmine/network/protocol/LoginPacket.php index 2b50f78fe..dfd1d0fef 100644 --- a/src/pocketmine/network/protocol/LoginPacket.php +++ b/src/pocketmine/network/protocol/LoginPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class LoginPacket extends DataPacket{ const NETWORK_ID = Info::LOGIN_PACKET; @@ -93,4 +95,8 @@ class LoginPacket extends DataPacket{ return json_decode(base64_decode($payloadB64), true); } + + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleLogin($this); + } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/MobArmorEquipmentPacket.php b/src/pocketmine/network/protocol/MobArmorEquipmentPacket.php index 465376dbf..0f5c8bf75 100644 --- a/src/pocketmine/network/protocol/MobArmorEquipmentPacket.php +++ b/src/pocketmine/network/protocol/MobArmorEquipmentPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class MobArmorEquipmentPacket extends DataPacket{ const NETWORK_ID = Info::MOB_ARMOR_EQUIPMENT_PACKET; @@ -47,4 +49,8 @@ class MobArmorEquipmentPacket extends DataPacket{ $this->putSlot($this->slots[3]); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleMobArmorEquipment($this); + } + } diff --git a/src/pocketmine/network/protocol/MobEffectPacket.php b/src/pocketmine/network/protocol/MobEffectPacket.php index 13deabae6..266af8daa 100644 --- a/src/pocketmine/network/protocol/MobEffectPacket.php +++ b/src/pocketmine/network/protocol/MobEffectPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class MobEffectPacket extends DataPacket{ const NETWORK_ID = Info::MOB_EFFECT_PACKET; @@ -52,4 +54,8 @@ class MobEffectPacket extends DataPacket{ $this->putVarInt($this->duration); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleMobEffect($this); + } + } diff --git a/src/pocketmine/network/protocol/MobEquipmentPacket.php b/src/pocketmine/network/protocol/MobEquipmentPacket.php index 3ef75287f..c43241760 100644 --- a/src/pocketmine/network/protocol/MobEquipmentPacket.php +++ b/src/pocketmine/network/protocol/MobEquipmentPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class MobEquipmentPacket extends DataPacket{ const NETWORK_ID = Info::MOB_EQUIPMENT_PACKET; @@ -50,4 +52,8 @@ class MobEquipmentPacket extends DataPacket{ $this->putByte($this->unknownByte); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleMobEquipment($this); + } + } diff --git a/src/pocketmine/network/protocol/MoveEntityPacket.php b/src/pocketmine/network/protocol/MoveEntityPacket.php index d9a047a42..b04f9881d 100644 --- a/src/pocketmine/network/protocol/MoveEntityPacket.php +++ b/src/pocketmine/network/protocol/MoveEntityPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class MoveEntityPacket extends DataPacket{ const NETWORK_ID = Info::MOVE_ENTITY_PACKET; @@ -52,4 +54,8 @@ class MoveEntityPacket extends DataPacket{ $this->putByte($this->headYaw / (360.0 / 256)); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleMoveEntity($this); + } + } diff --git a/src/pocketmine/network/protocol/MovePlayerPacket.php b/src/pocketmine/network/protocol/MovePlayerPacket.php index a48218ada..ad3e3ce33 100644 --- a/src/pocketmine/network/protocol/MovePlayerPacket.php +++ b/src/pocketmine/network/protocol/MovePlayerPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class MovePlayerPacket extends DataPacket{ const NETWORK_ID = Info::MOVE_PLAYER_PACKET; @@ -62,4 +64,8 @@ class MovePlayerPacket extends DataPacket{ $this->putBool($this->onGround); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleMovePlayer($this); + } + } diff --git a/src/pocketmine/network/protocol/PlayStatusPacket.php b/src/pocketmine/network/protocol/PlayStatusPacket.php index 2feaa3e55..0a4dee85f 100644 --- a/src/pocketmine/network/protocol/PlayStatusPacket.php +++ b/src/pocketmine/network/protocol/PlayStatusPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class PlayStatusPacket extends DataPacket{ const NETWORK_ID = Info::PLAY_STATUS_PACKET; @@ -45,4 +47,8 @@ class PlayStatusPacket extends DataPacket{ $this->putInt($this->status); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handlePlayStatus($this); + } + } diff --git a/src/pocketmine/network/protocol/PlayerActionPacket.php b/src/pocketmine/network/protocol/PlayerActionPacket.php index ff0c6d760..bc15bddda 100644 --- a/src/pocketmine/network/protocol/PlayerActionPacket.php +++ b/src/pocketmine/network/protocol/PlayerActionPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class PlayerActionPacket extends DataPacket{ const NETWORK_ID = Info::PLAYER_ACTION_PACKET; @@ -67,4 +69,8 @@ class PlayerActionPacket extends DataPacket{ $this->putVarInt($this->face); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handlePlayerAction($this); + } + } diff --git a/src/pocketmine/network/protocol/PlayerFallPacket.php b/src/pocketmine/network/protocol/PlayerFallPacket.php index 91333e6c9..fd6d324b6 100644 --- a/src/pocketmine/network/protocol/PlayerFallPacket.php +++ b/src/pocketmine/network/protocol/PlayerFallPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class PlayerFallPacket extends DataPacket{ const NETWORK_ID = Info::PLAYER_FALL_PACKET; @@ -36,4 +38,8 @@ class PlayerFallPacket extends DataPacket{ public function encode(){ } + + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handlePlayerFall($this); + } } diff --git a/src/pocketmine/network/protocol/PlayerInputPacket.php b/src/pocketmine/network/protocol/PlayerInputPacket.php index 6ae9edd33..df746b253 100644 --- a/src/pocketmine/network/protocol/PlayerInputPacket.php +++ b/src/pocketmine/network/protocol/PlayerInputPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class PlayerInputPacket extends DataPacket{ const NETWORK_ID = Info::PLAYER_INPUT_PACKET; @@ -43,4 +45,8 @@ class PlayerInputPacket extends DataPacket{ } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handlePlayerInput($this); + } + } diff --git a/src/pocketmine/network/protocol/PlayerListPacket.php b/src/pocketmine/network/protocol/PlayerListPacket.php index 27c14e918..eb0cbf49e 100644 --- a/src/pocketmine/network/protocol/PlayerListPacket.php +++ b/src/pocketmine/network/protocol/PlayerListPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class PlayerListPacket extends DataPacket{ const NETWORK_ID = Info::PLAYER_LIST_PACKET; @@ -61,4 +63,8 @@ class PlayerListPacket extends DataPacket{ } } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handlePlayerList($this); + } + } diff --git a/src/pocketmine/network/protocol/RemoveBlockPacket.php b/src/pocketmine/network/protocol/RemoveBlockPacket.php index 97538c9d5..f9b7281a1 100644 --- a/src/pocketmine/network/protocol/RemoveBlockPacket.php +++ b/src/pocketmine/network/protocol/RemoveBlockPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class RemoveBlockPacket extends DataPacket{ const NETWORK_ID = Info::REMOVE_BLOCK_PACKET; @@ -39,4 +41,8 @@ class RemoveBlockPacket extends DataPacket{ } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleRemoveBlock($this); + } + } diff --git a/src/pocketmine/network/protocol/RemoveEntityPacket.php b/src/pocketmine/network/protocol/RemoveEntityPacket.php index 13c5c8072..250a15e89 100644 --- a/src/pocketmine/network/protocol/RemoveEntityPacket.php +++ b/src/pocketmine/network/protocol/RemoveEntityPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class RemoveEntityPacket extends DataPacket{ const NETWORK_ID = Info::REMOVE_ENTITY_PACKET; @@ -38,4 +40,8 @@ class RemoveEntityPacket extends DataPacket{ $this->putEntityId($this->eid); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleRemoveEntity($this); + } + } diff --git a/src/pocketmine/network/protocol/ReplaceItemInSlotPacket.php b/src/pocketmine/network/protocol/ReplaceItemInSlotPacket.php index fa0bd3141..af0ac6d51 100644 --- a/src/pocketmine/network/protocol/ReplaceItemInSlotPacket.php +++ b/src/pocketmine/network/protocol/ReplaceItemInSlotPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class ReplaceItemInSlotPacket extends DataPacket{ const NETWORK_ID = Info::REPLACE_ITEM_IN_SLOT_PACKET; @@ -38,4 +40,7 @@ class ReplaceItemInSlotPacket extends DataPacket{ $this->putSlot($this->item); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleReplaceItemInSlot($this); + } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/RequestChunkRadiusPacket.php b/src/pocketmine/network/protocol/RequestChunkRadiusPacket.php index 51bda5f6c..35d728010 100644 --- a/src/pocketmine/network/protocol/RequestChunkRadiusPacket.php +++ b/src/pocketmine/network/protocol/RequestChunkRadiusPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class RequestChunkRadiusPacket extends DataPacket{ const NETWORK_ID = Info::REQUEST_CHUNK_RADIUS_PACKET; @@ -34,6 +36,11 @@ class RequestChunkRadiusPacket extends DataPacket{ } public function encode(){ + + } + + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleRequestChunkRadius($this); } } diff --git a/src/pocketmine/network/protocol/ResourcePackClientResponsePacket.php b/src/pocketmine/network/protocol/ResourcePackClientResponsePacket.php index 32ff17267..d3dfad043 100644 --- a/src/pocketmine/network/protocol/ResourcePackClientResponsePacket.php +++ b/src/pocketmine/network/protocol/ResourcePackClientResponsePacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class ResourcePackClientResponsePacket extends DataPacket{ const NETWORK_ID = Info::RESOURCE_PACK_CLIENT_RESPONSE_PACKET; @@ -52,4 +54,8 @@ class ResourcePackClientResponsePacket extends DataPacket{ } } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleResourcePackClientResponse($this); + } + } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/ResourcePackStackPacket.php b/src/pocketmine/network/protocol/ResourcePackStackPacket.php index 3a9fb43a8..9965a6b77 100644 --- a/src/pocketmine/network/protocol/ResourcePackStackPacket.php +++ b/src/pocketmine/network/protocol/ResourcePackStackPacket.php @@ -25,6 +25,7 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; use pocketmine\resourcepacks\ResourcePackInfoEntry; class ResourcePackStackPacket extends DataPacket{ @@ -70,4 +71,8 @@ class ResourcePackStackPacket extends DataPacket{ $this->putString($entry->getVersion()); } } + + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleResourcePackStack($this); + } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/ResourcePacksInfoPacket.php b/src/pocketmine/network/protocol/ResourcePacksInfoPacket.php index 7dd85cce0..e9f247627 100644 --- a/src/pocketmine/network/protocol/ResourcePacksInfoPacket.php +++ b/src/pocketmine/network/protocol/ResourcePacksInfoPacket.php @@ -24,6 +24,7 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; use pocketmine\resourcepacks\ResourcePackInfoEntry; class ResourcePacksInfoPacket extends DataPacket{ @@ -71,4 +72,8 @@ class ResourcePacksInfoPacket extends DataPacket{ $this->putLLong($entry->getPackSize()); } } + + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleResourcePacksInfo($this); + } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/RespawnPacket.php b/src/pocketmine/network/protocol/RespawnPacket.php index b7dd15dfc..d6da04814 100644 --- a/src/pocketmine/network/protocol/RespawnPacket.php +++ b/src/pocketmine/network/protocol/RespawnPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class RespawnPacket extends DataPacket{ const NETWORK_ID = Info::RESPAWN_PACKET; @@ -44,4 +46,8 @@ class RespawnPacket extends DataPacket{ $this->putLFloat($this->z); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleRespawn($this); + } + } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/RiderJumpPacket.php b/src/pocketmine/network/protocol/RiderJumpPacket.php index 636082487..120bb14b7 100644 --- a/src/pocketmine/network/protocol/RiderJumpPacket.php +++ b/src/pocketmine/network/protocol/RiderJumpPacket.php @@ -25,6 +25,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class RiderJumpPacket extends DataPacket{ const NETWORK_ID = Info::RIDER_JUMP_PACKET; @@ -38,4 +40,8 @@ class RiderJumpPacket extends DataPacket{ $this->reset(); $this->putVarInt($this->unknown); } + + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleRiderJump($this); + } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/SetCommandsEnabledPacket.php b/src/pocketmine/network/protocol/SetCommandsEnabledPacket.php index b23edeb0a..6bf0762cb 100644 --- a/src/pocketmine/network/protocol/SetCommandsEnabledPacket.php +++ b/src/pocketmine/network/protocol/SetCommandsEnabledPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class SetCommandsEnabledPacket extends DataPacket{ const NETWORK_ID = Info::SET_COMMANDS_ENABLED_PACKET; @@ -38,4 +40,8 @@ class SetCommandsEnabledPacket extends DataPacket{ $this->putBool($this->enabled); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleSetCommandsEnabled($this); + } + } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/SetDifficultyPacket.php b/src/pocketmine/network/protocol/SetDifficultyPacket.php index c56031f50..8d89d33c8 100644 --- a/src/pocketmine/network/protocol/SetDifficultyPacket.php +++ b/src/pocketmine/network/protocol/SetDifficultyPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class SetDifficultyPacket extends DataPacket{ const NETWORK_ID = Info::SET_DIFFICULTY_PACKET; @@ -38,4 +40,8 @@ class SetDifficultyPacket extends DataPacket{ $this->putUnsignedVarInt($this->difficulty); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleSetDifficulty($this); + } + } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/SetEntityDataPacket.php b/src/pocketmine/network/protocol/SetEntityDataPacket.php index 32b369746..99fbb572d 100644 --- a/src/pocketmine/network/protocol/SetEntityDataPacket.php +++ b/src/pocketmine/network/protocol/SetEntityDataPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class SetEntityDataPacket extends DataPacket{ const NETWORK_ID = Info::SET_ENTITY_DATA_PACKET; @@ -40,4 +42,7 @@ class SetEntityDataPacket extends DataPacket{ $this->putEntityMetadata($this->metadata); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleSetEntityData($this); + } } diff --git a/src/pocketmine/network/protocol/SetEntityLinkPacket.php b/src/pocketmine/network/protocol/SetEntityLinkPacket.php index 6f1caf861..fff314e19 100644 --- a/src/pocketmine/network/protocol/SetEntityLinkPacket.php +++ b/src/pocketmine/network/protocol/SetEntityLinkPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class SetEntityLinkPacket extends DataPacket{ const NETWORK_ID = Info::SET_ENTITY_LINK_PACKET; @@ -42,4 +44,8 @@ class SetEntityLinkPacket extends DataPacket{ $this->putByte($this->type); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleSetEntityLink($this); + } + } diff --git a/src/pocketmine/network/protocol/SetEntityMotionPacket.php b/src/pocketmine/network/protocol/SetEntityMotionPacket.php index 15a735ea8..529fbde53 100644 --- a/src/pocketmine/network/protocol/SetEntityMotionPacket.php +++ b/src/pocketmine/network/protocol/SetEntityMotionPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class SetEntityMotionPacket extends DataPacket{ const NETWORK_ID = Info::SET_ENTITY_MOTION_PACKET; @@ -42,4 +44,8 @@ class SetEntityMotionPacket extends DataPacket{ $this->putVector3f($this->motionX, $this->motionY, $this->motionZ); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleSetEntityMotion($this); + } + } diff --git a/src/pocketmine/network/protocol/SetHealthPacket.php b/src/pocketmine/network/protocol/SetHealthPacket.php index 9d1ccbae5..e9efa13fc 100644 --- a/src/pocketmine/network/protocol/SetHealthPacket.php +++ b/src/pocketmine/network/protocol/SetHealthPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class SetHealthPacket extends DataPacket{ const NETWORK_ID = Info::SET_HEALTH_PACKET; @@ -38,4 +40,8 @@ class SetHealthPacket extends DataPacket{ $this->putVarInt($this->health); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleSetHealth($this); + } + } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/SetPlayerGameTypePacket.php b/src/pocketmine/network/protocol/SetPlayerGameTypePacket.php index b47e08825..31d633ab8 100644 --- a/src/pocketmine/network/protocol/SetPlayerGameTypePacket.php +++ b/src/pocketmine/network/protocol/SetPlayerGameTypePacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class SetPlayerGameTypePacket extends DataPacket{ const NETWORK_ID = Info::SET_PLAYER_GAME_TYPE_PACKET; @@ -38,4 +40,8 @@ class SetPlayerGameTypePacket extends DataPacket{ $this->putVarInt($this->gamemode); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleSetPlayerGameType($this); + } + } diff --git a/src/pocketmine/network/protocol/SetSpawnPositionPacket.php b/src/pocketmine/network/protocol/SetSpawnPositionPacket.php index 8638ef283..1669674f7 100644 --- a/src/pocketmine/network/protocol/SetSpawnPositionPacket.php +++ b/src/pocketmine/network/protocol/SetSpawnPositionPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class SetSpawnPositionPacket extends DataPacket{ const NETWORK_ID = Info::SET_SPAWN_POSITION_PACKET; @@ -44,4 +46,8 @@ class SetSpawnPositionPacket extends DataPacket{ $this->putBool($this->unknownBool); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleSetSpawnPosition($this); + } + } diff --git a/src/pocketmine/network/protocol/SetTimePacket.php b/src/pocketmine/network/protocol/SetTimePacket.php index ab399a5a8..c3d78152c 100644 --- a/src/pocketmine/network/protocol/SetTimePacket.php +++ b/src/pocketmine/network/protocol/SetTimePacket.php @@ -23,6 +23,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class SetTimePacket extends DataPacket{ const NETWORK_ID = Info::SET_TIME_PACKET; @@ -39,4 +41,8 @@ class SetTimePacket extends DataPacket{ $this->putBool($this->started); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleSetTime($this); + } + } diff --git a/src/pocketmine/network/protocol/ShowCreditsPacket.php b/src/pocketmine/network/protocol/ShowCreditsPacket.php index 751831ae5..6b5dddaad 100644 --- a/src/pocketmine/network/protocol/ShowCreditsPacket.php +++ b/src/pocketmine/network/protocol/ShowCreditsPacket.php @@ -25,6 +25,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class ShowCreditsPacket extends DataPacket{ const NETWORK_ID = Info::SHOW_CREDITS_PACKET; @@ -44,4 +46,8 @@ class ShowCreditsPacket extends DataPacket{ $this->putEntityId($this->playerEid); $this->putVarInt($this->status); } + + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleShowCredits($this); + } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/SpawnExperienceOrbPacket.php b/src/pocketmine/network/protocol/SpawnExperienceOrbPacket.php index c3b04545c..afc7b8dc2 100644 --- a/src/pocketmine/network/protocol/SpawnExperienceOrbPacket.php +++ b/src/pocketmine/network/protocol/SpawnExperienceOrbPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class SpawnExperienceOrbPacket extends DataPacket{ const NETWORK_ID = Info::SPAWN_EXPERIENCE_ORB_PACKET; @@ -41,4 +43,8 @@ class SpawnExperienceOrbPacket extends DataPacket{ $this->putVector3f($this->x, $this->y, $this->z); $this->putVarInt($this->amount); } + + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleSpawnExperienceOrb($this); + } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/StartGamePacket.php b/src/pocketmine/network/protocol/StartGamePacket.php index 83080aa69..6dccecd7e 100644 --- a/src/pocketmine/network/protocol/StartGamePacket.php +++ b/src/pocketmine/network/protocol/StartGamePacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class StartGamePacket extends DataPacket{ const NETWORK_ID = Info::START_GAME_PACKET; @@ -78,4 +80,8 @@ class StartGamePacket extends DataPacket{ $this->putString($this->worldName); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleStartGame($this); + } + } diff --git a/src/pocketmine/network/protocol/TakeItemEntityPacket.php b/src/pocketmine/network/protocol/TakeItemEntityPacket.php index 61799541b..dead24ad9 100644 --- a/src/pocketmine/network/protocol/TakeItemEntityPacket.php +++ b/src/pocketmine/network/protocol/TakeItemEntityPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class TakeItemEntityPacket extends DataPacket{ const NETWORK_ID = Info::TAKE_ITEM_ENTITY_PACKET; @@ -40,4 +42,7 @@ class TakeItemEntityPacket extends DataPacket{ $this->putEntityId($this->eid); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleTakeItemEntity($this); + } } diff --git a/src/pocketmine/network/protocol/TextPacket.php b/src/pocketmine/network/protocol/TextPacket.php index c9a6bd75d..850fd18cd 100644 --- a/src/pocketmine/network/protocol/TextPacket.php +++ b/src/pocketmine/network/protocol/TextPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class TextPacket extends DataPacket{ const NETWORK_ID = Info::TEXT_PACKET; @@ -87,4 +89,8 @@ class TextPacket extends DataPacket{ } } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleText($this); + } + } diff --git a/src/pocketmine/network/protocol/TransferPacket.php b/src/pocketmine/network/protocol/TransferPacket.php index 5696e7bbe..0292b74ba 100644 --- a/src/pocketmine/network/protocol/TransferPacket.php +++ b/src/pocketmine/network/protocol/TransferPacket.php @@ -23,6 +23,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class TransferPacket extends DataPacket{ const NETWORK_ID = Info::TRANSFER_PACKET; @@ -39,4 +41,8 @@ class TransferPacket extends DataPacket{ $this->putLShort($this->port); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleTransfer($this); + } + } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/UpdateAttributesPacket.php b/src/pocketmine/network/protocol/UpdateAttributesPacket.php index fe7fc6095..f91282803 100644 --- a/src/pocketmine/network/protocol/UpdateAttributesPacket.php +++ b/src/pocketmine/network/protocol/UpdateAttributesPacket.php @@ -25,6 +25,7 @@ namespace pocketmine\network\protocol; use pocketmine\entity\Attribute; +use pocketmine\network\PocketEditionNetworkSession; class UpdateAttributesPacket extends DataPacket{ const NETWORK_ID = Info::UPDATE_ATTRIBUTES_PACKET; @@ -51,4 +52,8 @@ class UpdateAttributesPacket extends DataPacket{ } } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleUpdateAttributes($this); + } + } diff --git a/src/pocketmine/network/protocol/UpdateBlockPacket.php b/src/pocketmine/network/protocol/UpdateBlockPacket.php index b1595b279..6e557085b 100644 --- a/src/pocketmine/network/protocol/UpdateBlockPacket.php +++ b/src/pocketmine/network/protocol/UpdateBlockPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class UpdateBlockPacket extends DataPacket{ const NETWORK_ID = Info::UPDATE_BLOCK_PACKET; @@ -54,4 +56,8 @@ class UpdateBlockPacket extends DataPacket{ $this->putUnsignedVarInt(($this->flags << 4) | $this->blockData); } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleUpdateBlock($this); + } + } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/UseItemPacket.php b/src/pocketmine/network/protocol/UseItemPacket.php index 184a490c1..0aab03f2d 100644 --- a/src/pocketmine/network/protocol/UseItemPacket.php +++ b/src/pocketmine/network/protocol/UseItemPacket.php @@ -24,6 +24,8 @@ namespace pocketmine\network\protocol; #include +use pocketmine\network\PocketEditionNetworkSession; + class UseItemPacket extends DataPacket{ const NETWORK_ID = Info::USE_ITEM_PACKET; @@ -55,4 +57,8 @@ class UseItemPacket extends DataPacket{ } + public function handle(PocketEditionNetworkSession $session) : bool{ + return $session->handleUseItem($this); + } + } From 56990eb28b454c4c8203847e6fb0eb9631771e47 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 26 Feb 2017 16:21:01 +0000 Subject: [PATCH 05/96] MCPE protocol gets its own namespace --- src/pocketmine/CrashDump.php | 6 +- src/pocketmine/Player.php | 150 +++++++++--------- src/pocketmine/Server.php | 12 +- .../command/defaults/DifficultyCommand.php | 2 +- .../command/defaults/VersionCommand.php | 4 +- src/pocketmine/entity/Arrow.php | 2 +- src/pocketmine/entity/Effect.php | 2 +- src/pocketmine/entity/Entity.php | 6 +- src/pocketmine/entity/FallingSand.php | 2 +- src/pocketmine/entity/Human.php | 4 +- src/pocketmine/entity/Item.php | 2 +- src/pocketmine/entity/Living.php | 2 +- src/pocketmine/entity/PrimedTNT.php | 2 +- src/pocketmine/entity/Snowball.php | 2 +- src/pocketmine/entity/Squid.php | 4 +- src/pocketmine/entity/Villager.php | 2 +- src/pocketmine/entity/Zombie.php | 2 +- src/pocketmine/event/Timings.php | 2 +- .../event/server/DataPacketReceiveEvent.php | 2 +- .../event/server/DataPacketSendEvent.php | 2 +- src/pocketmine/inventory/BaseInventory.php | 4 +- src/pocketmine/inventory/ChestInventory.php | 2 +- .../inventory/ContainerInventory.php | 4 +- src/pocketmine/inventory/CraftingManager.php | 2 +- .../inventory/DoubleChestInventory.php | 2 +- src/pocketmine/inventory/PlayerInventory.php | 8 +- src/pocketmine/item/Food.php | 2 +- src/pocketmine/level/Explosion.php | 2 +- src/pocketmine/level/Level.php | 16 +- .../level/format/io/leveldb/LevelDB.php | 6 +- .../level/particle/DestroyBlockParticle.php | 2 +- .../level/particle/FloatingTextParticle.php | 4 +- .../level/particle/GenericParticle.php | 2 +- .../level/particle/MobSpawnParticle.php | 2 +- src/pocketmine/level/particle/Particle.php | 2 +- .../level/sound/AnvilBreakSound.php | 2 +- src/pocketmine/level/sound/AnvilFallSound.php | 2 +- src/pocketmine/level/sound/AnvilUseSound.php | 2 +- .../level/sound/BlazeShootSound.php | 2 +- src/pocketmine/level/sound/ClickSound.php | 2 +- src/pocketmine/level/sound/DoorBumpSound.php | 2 +- src/pocketmine/level/sound/DoorCrashSound.php | 2 +- src/pocketmine/level/sound/DoorSound.php | 2 +- .../level/sound/EndermanTeleportSound.php | 2 +- src/pocketmine/level/sound/FizzSound.php | 2 +- src/pocketmine/level/sound/GenericSound.php | 2 +- .../level/sound/GhastShootSound.php | 2 +- src/pocketmine/level/sound/GhastSound.php | 2 +- src/pocketmine/level/sound/LaunchSound.php | 2 +- src/pocketmine/level/sound/PopSound.php | 2 +- src/pocketmine/level/sound/Sound.php | 2 +- src/pocketmine/network/Network.php | 143 +++++++++-------- src/pocketmine/network/SourceInterface.php | 2 +- .../{ => mcpe}/CachedEncapsulatedPacket.php | 2 +- .../NetworkSession.php} | 146 ++++++++--------- .../network/{ => mcpe}/RakLibInterface.php | 13 +- .../{ => mcpe}/protocol/AddEntityPacket.php | 8 +- .../protocol/AddHangingEntityPacket.php | 8 +- .../protocol/AddItemEntityPacket.php | 8 +- .../{ => mcpe}/protocol/AddItemPacket.php | 8 +- .../{ => mcpe}/protocol/AddPaintingPacket.php | 8 +- .../{ => mcpe}/protocol/AddPlayerPacket.php | 8 +- .../protocol/AdventureSettingsPacket.php | 8 +- .../{ => mcpe}/protocol/AnimatePacket.php | 8 +- .../protocol/AvailableCommandsPacket.php | 8 +- .../{ => mcpe}/protocol/BatchPacket.php | 8 +- .../protocol/BlockEntityDataPacket.php | 8 +- .../{ => mcpe}/protocol/BlockEventPacket.php | 8 +- .../protocol/ChangeDimensionPacket.php | 8 +- .../protocol/ChunkRadiusUpdatedPacket.php | 8 +- .../{ => mcpe}/protocol/CommandStepPacket.php | 8 +- .../protocol/ContainerClosePacket.php | 8 +- .../protocol/ContainerOpenPacket.php | 8 +- .../protocol/ContainerSetContentPacket.php | 8 +- .../protocol/ContainerSetDataPacket.php | 8 +- .../protocol/ContainerSetSlotPacket.php | 8 +- .../protocol/CraftingDataPacket.php | 9 +- .../protocol/CraftingEventPacket.php | 8 +- .../{ => mcpe}/protocol/DataPacket.php | 6 +- .../{ => mcpe}/protocol/DisconnectPacket.php | 8 +- .../{ => mcpe}/protocol/DropItemPacket.php | 8 +- .../{ => mcpe}/protocol/EntityEventPacket.php | 8 +- .../{ => mcpe}/protocol/ExplodePacket.php | 8 +- .../protocol/FullChunkDataPacket.php | 8 +- .../{ => mcpe}/protocol/HurtArmorPacket.php | 8 +- .../{ => mcpe}/protocol/InteractPacket.php | 8 +- .../protocol/InventoryActionPacket.php | 8 +- .../protocol/ItemFrameDropItemPacket.php | 8 +- .../{ => mcpe}/protocol/LevelEventPacket.php | 8 +- .../protocol/LevelSoundEventPacket.php | 8 +- .../{ => mcpe}/protocol/LoginPacket.php | 10 +- .../protocol/MobArmorEquipmentPacket.php | 8 +- .../{ => mcpe}/protocol/MobEffectPacket.php | 8 +- .../protocol/MobEquipmentPacket.php | 8 +- .../{ => mcpe}/protocol/MoveEntityPacket.php | 8 +- .../{ => mcpe}/protocol/MovePlayerPacket.php | 8 +- .../{ => mcpe}/protocol/PlayStatusPacket.php | 8 +- .../protocol/PlayerActionPacket.php | 8 +- .../{ => mcpe}/protocol/PlayerFallPacket.php | 8 +- .../{ => mcpe}/protocol/PlayerInputPacket.php | 8 +- .../{ => mcpe}/protocol/PlayerListPacket.php | 8 +- .../protocol/ProtocolInfo.php} | 4 +- .../{ => mcpe}/protocol/RemoveBlockPacket.php | 8 +- .../protocol/RemoveEntityPacket.php | 8 +- .../protocol/ReplaceItemInSlotPacket.php | 8 +- .../protocol/RequestChunkRadiusPacket.php | 8 +- .../ResourcePackClientResponsePacket.php | 8 +- .../protocol/ResourcePackStackPacket.php | 10 +- .../protocol/ResourcePacksInfoPacket.php | 8 +- .../{ => mcpe}/protocol/RespawnPacket.php | 8 +- .../{ => mcpe}/protocol/RiderJumpPacket.php | 8 +- .../protocol/SetCommandsEnabledPacket.php | 8 +- .../protocol/SetDifficultyPacket.php | 8 +- .../protocol/SetEntityDataPacket.php | 8 +- .../protocol/SetEntityLinkPacket.php | 8 +- .../protocol/SetEntityMotionPacket.php | 8 +- .../{ => mcpe}/protocol/SetHealthPacket.php | 8 +- .../protocol/SetPlayerGameTypePacket.php | 8 +- .../protocol/SetSpawnPositionPacket.php | 8 +- .../{ => mcpe}/protocol/SetTimePacket.php | 8 +- .../{ => mcpe}/protocol/ShowCreditsPacket.php | 8 +- .../protocol/SpawnExperienceOrbPacket.php | 8 +- .../{ => mcpe}/protocol/StartGamePacket.php | 8 +- .../protocol/TakeItemEntityPacket.php | 8 +- .../{ => mcpe}/protocol/TextPacket.php | 8 +- .../{ => mcpe}/protocol/TransferPacket.php | 8 +- .../protocol/UpdateAttributesPacket.php | 8 +- .../{ => mcpe}/protocol/UpdateBlockPacket.php | 8 +- .../{ => mcpe}/protocol/UseItemPacket.php | 8 +- src/pocketmine/scheduler/SendUsageTask.php | 4 +- src/pocketmine/tile/Furnace.php | 2 +- src/pocketmine/tile/Spawnable.php | 2 +- 132 files changed, 600 insertions(+), 601 deletions(-) rename src/pocketmine/network/{ => mcpe}/CachedEncapsulatedPacket.php (96%) rename src/pocketmine/network/{PocketEditionNetworkSession.php => mcpe/NetworkSession.php} (62%) rename src/pocketmine/network/{ => mcpe}/RakLibInterface.php (95%) rename src/pocketmine/network/{ => mcpe}/protocol/AddEntityPacket.php (90%) rename src/pocketmine/network/{ => mcpe}/protocol/AddHangingEntityPacket.php (85%) rename src/pocketmine/network/{ => mcpe}/protocol/AddItemEntityPacket.php (85%) rename src/pocketmine/network/{ => mcpe}/protocol/AddItemPacket.php (82%) rename src/pocketmine/network/{ => mcpe}/protocol/AddPaintingPacket.php (85%) rename src/pocketmine/network/{ => mcpe}/protocol/AddPlayerPacket.php (88%) rename src/pocketmine/network/{ => mcpe}/protocol/AdventureSettingsPacket.php (93%) rename src/pocketmine/network/{ => mcpe}/protocol/AnimatePacket.php (84%) rename src/pocketmine/network/{ => mcpe}/protocol/AvailableCommandsPacket.php (83%) rename src/pocketmine/network/{ => mcpe}/protocol/BatchPacket.php (83%) rename src/pocketmine/network/{ => mcpe}/protocol/BlockEntityDataPacket.php (84%) rename src/pocketmine/network/{ => mcpe}/protocol/BlockEventPacket.php (84%) rename src/pocketmine/network/{ => mcpe}/protocol/ChangeDimensionPacket.php (84%) rename src/pocketmine/network/{ => mcpe}/protocol/ChunkRadiusUpdatedPacket.php (82%) rename src/pocketmine/network/{ => mcpe}/protocol/CommandStepPacket.php (89%) rename src/pocketmine/network/{ => mcpe}/protocol/ContainerClosePacket.php (82%) rename src/pocketmine/network/{ => mcpe}/protocol/ContainerOpenPacket.php (85%) rename src/pocketmine/network/{ => mcpe}/protocol/ContainerSetContentPacket.php (90%) rename src/pocketmine/network/{ => mcpe}/protocol/ContainerSetDataPacket.php (83%) rename src/pocketmine/network/{ => mcpe}/protocol/ContainerSetSlotPacket.php (86%) rename src/pocketmine/network/{ => mcpe}/protocol/CraftingDataPacket.php (95%) rename src/pocketmine/network/{ => mcpe}/protocol/CraftingEventPacket.php (87%) rename src/pocketmine/network/{ => mcpe}/protocol/DataPacket.php (96%) rename src/pocketmine/network/{ => mcpe}/protocol/DisconnectPacket.php (84%) rename src/pocketmine/network/{ => mcpe}/protocol/DropItemPacket.php (82%) rename src/pocketmine/network/{ => mcpe}/protocol/EntityEventPacket.php (88%) rename src/pocketmine/network/{ => mcpe}/protocol/ExplodePacket.php (86%) rename src/pocketmine/network/{ => mcpe}/protocol/FullChunkDataPacket.php (83%) rename src/pocketmine/network/{ => mcpe}/protocol/HurtArmorPacket.php (82%) rename src/pocketmine/network/{ => mcpe}/protocol/InteractPacket.php (85%) rename src/pocketmine/network/{ => mcpe}/protocol/InventoryActionPacket.php (82%) rename src/pocketmine/network/{ => mcpe}/protocol/ItemFrameDropItemPacket.php (82%) rename src/pocketmine/network/{ => mcpe}/protocol/LevelEventPacket.php (93%) rename src/pocketmine/network/{ => mcpe}/protocol/LevelSoundEventPacket.php (95%) rename src/pocketmine/network/{ => mcpe}/protocol/LoginPacket.php (90%) rename src/pocketmine/network/{ => mcpe}/protocol/MobArmorEquipmentPacket.php (86%) rename src/pocketmine/network/{ => mcpe}/protocol/MobEffectPacket.php (86%) rename src/pocketmine/network/{ => mcpe}/protocol/MobEquipmentPacket.php (87%) rename src/pocketmine/network/{ => mcpe}/protocol/MoveEntityPacket.php (87%) rename src/pocketmine/network/{ => mcpe}/protocol/MovePlayerPacket.php (89%) rename src/pocketmine/network/{ => mcpe}/protocol/PlayStatusPacket.php (84%) rename src/pocketmine/network/{ => mcpe}/protocol/PlayerActionPacket.php (89%) rename src/pocketmine/network/{ => mcpe}/protocol/PlayerFallPacket.php (82%) rename src/pocketmine/network/{ => mcpe}/protocol/PlayerInputPacket.php (84%) rename src/pocketmine/network/{ => mcpe}/protocol/PlayerListPacket.php (87%) rename src/pocketmine/network/{protocol/Info.php => mcpe/protocol/ProtocolInfo.php} (98%) rename src/pocketmine/network/{ => mcpe}/protocol/RemoveBlockPacket.php (82%) rename src/pocketmine/network/{ => mcpe}/protocol/RemoveEntityPacket.php (82%) rename src/pocketmine/network/{ => mcpe}/protocol/ReplaceItemInSlotPacket.php (81%) rename src/pocketmine/network/{ => mcpe}/protocol/RequestChunkRadiusPacket.php (81%) rename src/pocketmine/network/{ => mcpe}/protocol/ResourcePackClientResponsePacket.php (86%) rename src/pocketmine/network/{ => mcpe}/protocol/ResourcePackStackPacket.php (88%) rename src/pocketmine/network/{ => mcpe}/protocol/ResourcePacksInfoPacket.php (91%) rename src/pocketmine/network/{ => mcpe}/protocol/RespawnPacket.php (84%) rename src/pocketmine/network/{ => mcpe}/protocol/RiderJumpPacket.php (83%) rename src/pocketmine/network/{ => mcpe}/protocol/SetCommandsEnabledPacket.php (82%) rename src/pocketmine/network/{ => mcpe}/protocol/SetDifficultyPacket.php (83%) rename src/pocketmine/network/{ => mcpe}/protocol/SetEntityDataPacket.php (83%) rename src/pocketmine/network/{ => mcpe}/protocol/SetEntityLinkPacket.php (83%) rename src/pocketmine/network/{ => mcpe}/protocol/SetEntityMotionPacket.php (83%) rename src/pocketmine/network/{ => mcpe}/protocol/SetHealthPacket.php (82%) rename src/pocketmine/network/{ => mcpe}/protocol/SetPlayerGameTypePacket.php (82%) rename src/pocketmine/network/{ => mcpe}/protocol/SetSpawnPositionPacket.php (84%) rename src/pocketmine/network/{ => mcpe}/protocol/SetTimePacket.php (83%) rename src/pocketmine/network/{ => mcpe}/protocol/ShowCreditsPacket.php (84%) rename src/pocketmine/network/{ => mcpe}/protocol/SpawnExperienceOrbPacket.php (83%) rename src/pocketmine/network/{ => mcpe}/protocol/StartGamePacket.php (92%) rename src/pocketmine/network/{ => mcpe}/protocol/TakeItemEntityPacket.php (82%) rename src/pocketmine/network/{ => mcpe}/protocol/TextPacket.php (91%) rename src/pocketmine/network/{ => mcpe}/protocol/TransferPacket.php (83%) rename src/pocketmine/network/{ => mcpe}/protocol/UpdateAttributesPacket.php (86%) rename src/pocketmine/network/{ => mcpe}/protocol/UpdateBlockPacket.php (87%) rename src/pocketmine/network/{ => mcpe}/protocol/UseItemPacket.php (87%) diff --git a/src/pocketmine/CrashDump.php b/src/pocketmine/CrashDump.php index abf7db96b..5d30473d4 100644 --- a/src/pocketmine/CrashDump.php +++ b/src/pocketmine/CrashDump.php @@ -21,7 +21,7 @@ namespace pocketmine; -use pocketmine\network\protocol\Info; +use pocketmine\network\mcpe\protocol\ProtocolInfo; use pocketmine\plugin\PluginBase; use pocketmine\plugin\PluginLoadOrder; use pocketmine\utils\Utils; @@ -226,7 +226,7 @@ class CrashDump{ $this->data["general"] = []; $this->data["general"]["version"] = $version->get(false); $this->data["general"]["build"] = $version->getBuild(); - $this->data["general"]["protocol"] = Info::CURRENT_PROTOCOL; + $this->data["general"]["protocol"] = ProtocolInfo::CURRENT_PROTOCOL; $this->data["general"]["api"] = \pocketmine\API_VERSION; $this->data["general"]["git"] = \pocketmine\GIT_COMMIT; $this->data["general"]["raklib"] = RakLib::VERSION; @@ -235,7 +235,7 @@ class CrashDump{ $this->data["general"]["zend"] = zend_version(); $this->data["general"]["php_os"] = PHP_OS; $this->data["general"]["os"] = Utils::getOS(); - $this->addLine("PocketMine-MP version: " . $version->get(false) . " #" . $version->getBuild() . " [Protocol " . Info::CURRENT_PROTOCOL . "; API " . API_VERSION . "]"); + $this->addLine("PocketMine-MP version: " . $version->get(false) . " #" . $version->getBuild() . " [Protocol " . ProtocolInfo::CURRENT_PROTOCOL . "; API " . API_VERSION . "]"); $this->addLine("Git commit: " . GIT_COMMIT); $this->addLine("uname -a: " . php_uname("a")); $this->addLine("PHP Version: " . phpversion()); diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index cef80e0d9..1efdb7790 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -101,80 +101,80 @@ use pocketmine\nbt\tag\ListTag; use pocketmine\nbt\tag\LongTag; use pocketmine\nbt\tag\ShortTag; use pocketmine\nbt\tag\StringTag; -use pocketmine\network\PocketEditionNetworkSession; -use pocketmine\network\protocol\AddEntityPacket; -use pocketmine\network\protocol\AddHangingEntityPacket; -use pocketmine\network\protocol\AddItemEntityPacket; -use pocketmine\network\protocol\AddItemPacket; -use pocketmine\network\protocol\AddPaintingPacket; -use pocketmine\network\protocol\AddPlayerPacket; -use pocketmine\network\protocol\AdventureSettingsPacket; -use pocketmine\network\protocol\AnimatePacket; -use pocketmine\network\protocol\AvailableCommandsPacket; -use pocketmine\network\protocol\BatchPacket; -use pocketmine\network\protocol\BlockEntityDataPacket; -use pocketmine\network\protocol\BlockEventPacket; -use pocketmine\network\protocol\ChangeDimensionPacket; -use pocketmine\network\protocol\ChunkRadiusUpdatedPacket; -use pocketmine\network\protocol\CommandStepPacket; -use pocketmine\network\protocol\ContainerClosePacket; -use pocketmine\network\protocol\ContainerOpenPacket; -use pocketmine\network\protocol\ContainerSetContentPacket; -use pocketmine\network\protocol\ContainerSetDataPacket; -use pocketmine\network\protocol\ContainerSetSlotPacket; -use pocketmine\network\protocol\CraftingDataPacket; -use pocketmine\network\protocol\CraftingEventPacket; -use pocketmine\network\protocol\DataPacket; -use pocketmine\network\protocol\DisconnectPacket; -use pocketmine\network\protocol\DropItemPacket; -use pocketmine\network\protocol\EntityEventPacket; -use pocketmine\network\protocol\ExplodePacket; -use pocketmine\network\protocol\FullChunkDataPacket; -use pocketmine\network\protocol\HurtArmorPacket; -use pocketmine\network\protocol\Info as ProtocolInfo; -use pocketmine\network\protocol\InteractPacket; -use pocketmine\network\protocol\InventoryActionPacket; -use pocketmine\network\protocol\ItemFrameDropItemPacket; -use pocketmine\network\protocol\LevelEventPacket; -use pocketmine\network\protocol\LevelSoundEventPacket; -use pocketmine\network\protocol\LoginPacket; -use pocketmine\network\protocol\MobArmorEquipmentPacket; -use pocketmine\network\protocol\MobEffectPacket; -use pocketmine\network\protocol\MobEquipmentPacket; -use pocketmine\network\protocol\MoveEntityPacket; -use pocketmine\network\protocol\MovePlayerPacket; -use pocketmine\network\protocol\PlayerActionPacket; -use pocketmine\network\protocol\PlayerFallPacket; -use pocketmine\network\protocol\PlayerInputPacket; -use pocketmine\network\protocol\PlayerListPacket; -use pocketmine\network\protocol\PlayStatusPacket; -use pocketmine\network\protocol\RemoveBlockPacket; -use pocketmine\network\protocol\RemoveEntityPacket; -use pocketmine\network\protocol\ReplaceItemInSlotPacket; -use pocketmine\network\protocol\RequestChunkRadiusPacket; -use pocketmine\network\protocol\ResourcePackClientResponsePacket; -use pocketmine\network\protocol\ResourcePacksInfoPacket; -use pocketmine\network\protocol\ResourcePackStackPacket; -use pocketmine\network\protocol\RespawnPacket; -use pocketmine\network\protocol\RiderJumpPacket; -use pocketmine\network\protocol\SetCommandsEnabledPacket; -use pocketmine\network\protocol\SetDifficultyPacket; -use pocketmine\network\protocol\SetEntityDataPacket; -use pocketmine\network\protocol\SetEntityLinkPacket; -use pocketmine\network\protocol\SetEntityMotionPacket; -use pocketmine\network\protocol\SetHealthPacket; -use pocketmine\network\protocol\SetPlayerGameTypePacket; -use pocketmine\network\protocol\SetSpawnPositionPacket; -use pocketmine\network\protocol\SetTimePacket; -use pocketmine\network\protocol\ShowCreditsPacket; -use pocketmine\network\protocol\SpawnExperienceOrbPacket; -use pocketmine\network\protocol\StartGamePacket; -use pocketmine\network\protocol\TakeItemEntityPacket; -use pocketmine\network\protocol\TextPacket; -use pocketmine\network\protocol\TransferPacket; -use pocketmine\network\protocol\UpdateAttributesPacket; -use pocketmine\network\protocol\UpdateBlockPacket; -use pocketmine\network\protocol\UseItemPacket; +use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\protocol\AddEntityPacket; +use pocketmine\network\mcpe\protocol\AddHangingEntityPacket; +use pocketmine\network\mcpe\protocol\AddItemEntityPacket; +use pocketmine\network\mcpe\protocol\AddItemPacket; +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\BatchPacket; +use pocketmine\network\mcpe\protocol\BlockEntityDataPacket; +use pocketmine\network\mcpe\protocol\BlockEventPacket; +use pocketmine\network\mcpe\protocol\ChangeDimensionPacket; +use pocketmine\network\mcpe\protocol\ChunkRadiusUpdatedPacket; +use pocketmine\network\mcpe\protocol\CommandStepPacket; +use pocketmine\network\mcpe\protocol\ContainerClosePacket; +use pocketmine\network\mcpe\protocol\ContainerOpenPacket; +use pocketmine\network\mcpe\protocol\ContainerSetContentPacket; +use pocketmine\network\mcpe\protocol\ContainerSetDataPacket; +use pocketmine\network\mcpe\protocol\ContainerSetSlotPacket; +use pocketmine\network\mcpe\protocol\CraftingDataPacket; +use pocketmine\network\mcpe\protocol\CraftingEventPacket; +use pocketmine\network\mcpe\protocol\DataPacket; +use pocketmine\network\mcpe\protocol\DisconnectPacket; +use pocketmine\network\mcpe\protocol\DropItemPacket; +use pocketmine\network\mcpe\protocol\EntityEventPacket; +use pocketmine\network\mcpe\protocol\ExplodePacket; +use pocketmine\network\mcpe\protocol\FullChunkDataPacket; +use pocketmine\network\mcpe\protocol\HurtArmorPacket; +use pocketmine\network\mcpe\protocol\ProtocolInfo; +use pocketmine\network\mcpe\protocol\InteractPacket; +use pocketmine\network\mcpe\protocol\InventoryActionPacket; +use pocketmine\network\mcpe\protocol\ItemFrameDropItemPacket; +use pocketmine\network\mcpe\protocol\LevelEventPacket; +use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; +use pocketmine\network\mcpe\protocol\LoginPacket; +use pocketmine\network\mcpe\protocol\MobArmorEquipmentPacket; +use pocketmine\network\mcpe\protocol\MobEffectPacket; +use pocketmine\network\mcpe\protocol\MobEquipmentPacket; +use pocketmine\network\mcpe\protocol\MoveEntityPacket; +use pocketmine\network\mcpe\protocol\MovePlayerPacket; +use pocketmine\network\mcpe\protocol\PlayerActionPacket; +use pocketmine\network\mcpe\protocol\PlayerFallPacket; +use pocketmine\network\mcpe\protocol\PlayerInputPacket; +use pocketmine\network\mcpe\protocol\PlayerListPacket; +use pocketmine\network\mcpe\protocol\PlayStatusPacket; +use pocketmine\network\mcpe\protocol\RemoveBlockPacket; +use pocketmine\network\mcpe\protocol\RemoveEntityPacket; +use pocketmine\network\mcpe\protocol\ReplaceItemInSlotPacket; +use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket; +use pocketmine\network\mcpe\protocol\ResourcePackClientResponsePacket; +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\SetCommandsEnabledPacket; +use pocketmine\network\mcpe\protocol\SetDifficultyPacket; +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\SetPlayerGameTypePacket; +use pocketmine\network\mcpe\protocol\SetSpawnPositionPacket; +use pocketmine\network\mcpe\protocol\SetTimePacket; +use pocketmine\network\mcpe\protocol\ShowCreditsPacket; +use pocketmine\network\mcpe\protocol\SpawnExperienceOrbPacket; +use pocketmine\network\mcpe\protocol\StartGamePacket; +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\UseItemPacket; use pocketmine\network\SourceInterface; use pocketmine\permission\PermissibleBase; use pocketmine\permission\PermissionAttachment; @@ -188,7 +188,7 @@ use pocketmine\utils\UUID; /** * Main class that handles networking, recovery, and packet sending to the server part */ -class Player extends Human implements CommandSender, InventoryHolder, ChunkLoader, IPlayer, PocketEditionNetworkSession{ +class Player extends Human implements CommandSender, InventoryHolder, ChunkLoader, IPlayer, NetworkSession{ const SURVIVAL = 0; const CREATIVE = 1; diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index b386ce6d5..4474cdaef 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -48,8 +48,8 @@ use pocketmine\inventory\Recipe; use pocketmine\item\enchantment\Enchantment; use pocketmine\item\Item; use pocketmine\lang\BaseLang; -use pocketmine\level\format\io\LevelProviderManager; use pocketmine\level\format\io\leveldb\LevelDB; +use pocketmine\level\format\io\LevelProviderManager; use pocketmine\level\format\io\region\Anvil; use pocketmine\level\format\io\region\McRegion; use pocketmine\level\format\io\region\PMAnvil; @@ -74,13 +74,13 @@ use pocketmine\nbt\tag\LongTag; use pocketmine\nbt\tag\ShortTag; use pocketmine\nbt\tag\StringTag; use pocketmine\network\CompressBatchedTask; +use pocketmine\network\mcpe\protocol\BatchPacket; +use pocketmine\network\mcpe\protocol\DataPacket; +use pocketmine\network\mcpe\protocol\ProtocolInfo; +use pocketmine\network\mcpe\protocol\PlayerListPacket; +use pocketmine\network\mcpe\RakLibInterface; use pocketmine\network\Network; -use pocketmine\network\protocol\BatchPacket; -use pocketmine\network\protocol\DataPacket; -use pocketmine\network\protocol\Info as ProtocolInfo; -use pocketmine\network\protocol\PlayerListPacket; use pocketmine\network\query\QueryHandler; -use pocketmine\network\RakLibInterface; use pocketmine\network\rcon\RCON; use pocketmine\network\upnp\UPnP; use pocketmine\permission\BanList; diff --git a/src/pocketmine/command/defaults/DifficultyCommand.php b/src/pocketmine/command/defaults/DifficultyCommand.php index e49784fde..64650a47f 100644 --- a/src/pocketmine/command/defaults/DifficultyCommand.php +++ b/src/pocketmine/command/defaults/DifficultyCommand.php @@ -24,7 +24,7 @@ namespace pocketmine\command\defaults; use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\event\TranslationContainer; -use pocketmine\network\protocol\SetDifficultyPacket; +use pocketmine\network\mcpe\protocol\SetDifficultyPacket; use pocketmine\Server; class DifficultyCommand extends VanillaCommand{ diff --git a/src/pocketmine/command/defaults/VersionCommand.php b/src/pocketmine/command/defaults/VersionCommand.php index 54d091fdf..e18651b56 100644 --- a/src/pocketmine/command/defaults/VersionCommand.php +++ b/src/pocketmine/command/defaults/VersionCommand.php @@ -23,7 +23,7 @@ namespace pocketmine\command\defaults; use pocketmine\command\CommandSender; use pocketmine\event\TranslationContainer; -use pocketmine\network\protocol\Info; +use pocketmine\network\mcpe\protocol\ProtocolInfo; use pocketmine\plugin\Plugin; use pocketmine\utils\TextFormat; @@ -51,7 +51,7 @@ class VersionCommand extends VanillaCommand{ $sender->getServer()->getCodename(), $sender->getServer()->getApiVersion(), $sender->getServer()->getVersion(), - Info::CURRENT_PROTOCOL + ProtocolInfo::CURRENT_PROTOCOL ])); }else{ $pluginName = implode(" ", $args); diff --git a/src/pocketmine/entity/Arrow.php b/src/pocketmine/entity/Arrow.php index 969021323..a31a66b9e 100644 --- a/src/pocketmine/entity/Arrow.php +++ b/src/pocketmine/entity/Arrow.php @@ -24,7 +24,7 @@ namespace pocketmine\entity; use pocketmine\level\Level; use pocketmine\level\particle\CriticalParticle; use pocketmine\nbt\tag\CompoundTag; -use pocketmine\network\protocol\AddEntityPacket; +use pocketmine\network\mcpe\protocol\AddEntityPacket; use pocketmine\Player; class Arrow extends Projectile{ diff --git a/src/pocketmine/entity/Effect.php b/src/pocketmine/entity/Effect.php index 9837894e0..5511ef205 100644 --- a/src/pocketmine/entity/Effect.php +++ b/src/pocketmine/entity/Effect.php @@ -26,7 +26,7 @@ use pocketmine\event\entity\EntityEffectAddEvent; use pocketmine\event\entity\EntityEffectRemoveEvent; use pocketmine\event\entity\EntityRegainHealthEvent; use pocketmine\event\player\PlayerExhaustEvent; -use pocketmine\network\protocol\MobEffectPacket; +use pocketmine\network\mcpe\protocol\MobEffectPacket; use pocketmine\Player; class Effect{ diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index fef279be9..010d846de 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -52,9 +52,9 @@ use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\ListTag; use pocketmine\nbt\tag\ShortTag; use pocketmine\nbt\tag\StringTag; -use pocketmine\network\protocol\MobEffectPacket; -use pocketmine\network\protocol\RemoveEntityPacket; -use pocketmine\network\protocol\SetEntityDataPacket; +use pocketmine\network\mcpe\protocol\MobEffectPacket; +use pocketmine\network\mcpe\protocol\RemoveEntityPacket; +use pocketmine\network\mcpe\protocol\SetEntityDataPacket; use pocketmine\Player; use pocketmine\plugin\Plugin; use pocketmine\Server; diff --git a/src/pocketmine/entity/FallingSand.php b/src/pocketmine/entity/FallingSand.php index 3a7c9f8e7..945892eb4 100644 --- a/src/pocketmine/entity/FallingSand.php +++ b/src/pocketmine/entity/FallingSand.php @@ -29,7 +29,7 @@ use pocketmine\item\Item as ItemItem; use pocketmine\math\Vector3; use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\IntTag; -use pocketmine\network\protocol\AddEntityPacket; +use pocketmine\network\mcpe\protocol\AddEntityPacket; use pocketmine\Player; class FallingSand extends Entity{ diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index a91aef9c2..563eaf955 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -35,8 +35,8 @@ use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\ListTag; use pocketmine\nbt\tag\ShortTag; use pocketmine\nbt\tag\StringTag; -use pocketmine\network\protocol\AddPlayerPacket; -use pocketmine\network\protocol\RemoveEntityPacket; +use pocketmine\network\mcpe\protocol\AddPlayerPacket; +use pocketmine\network\mcpe\protocol\RemoveEntityPacket; use pocketmine\Player; use pocketmine\utils\UUID; diff --git a/src/pocketmine/entity/Item.php b/src/pocketmine/entity/Item.php index e67cf26fd..9ddb289dc 100644 --- a/src/pocketmine/entity/Item.php +++ b/src/pocketmine/entity/Item.php @@ -28,7 +28,7 @@ use pocketmine\item\Item as ItemItem; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\ShortTag; use pocketmine\nbt\tag\StringTag; -use pocketmine\network\protocol\AddItemEntityPacket; +use pocketmine\network\mcpe\protocol\AddItemEntityPacket; use pocketmine\Player; class Item extends Entity{ diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index 6da49eb88..e9b8d2429 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -31,7 +31,7 @@ use pocketmine\event\Timings; use pocketmine\item\Item as ItemItem; use pocketmine\math\Vector3; use pocketmine\nbt\tag\ShortTag; -use pocketmine\network\protocol\EntityEventPacket; +use pocketmine\network\mcpe\protocol\EntityEventPacket; use pocketmine\utils\BlockIterator; abstract class Living extends Entity implements Damageable{ diff --git a/src/pocketmine/entity/PrimedTNT.php b/src/pocketmine/entity/PrimedTNT.php index a098909c4..c03ef1772 100644 --- a/src/pocketmine/entity/PrimedTNT.php +++ b/src/pocketmine/entity/PrimedTNT.php @@ -25,7 +25,7 @@ use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\ExplosionPrimeEvent; use pocketmine\level\Explosion; use pocketmine\nbt\tag\ByteTag; -use pocketmine\network\protocol\AddEntityPacket; +use pocketmine\network\mcpe\protocol\AddEntityPacket; use pocketmine\Player; class PrimedTNT extends Entity implements Explosive{ diff --git a/src/pocketmine/entity/Snowball.php b/src/pocketmine/entity/Snowball.php index cc9b1aabf..e7d4cc4a6 100644 --- a/src/pocketmine/entity/Snowball.php +++ b/src/pocketmine/entity/Snowball.php @@ -23,7 +23,7 @@ namespace pocketmine\entity; use pocketmine\level\Level; use pocketmine\nbt\tag\CompoundTag; -use pocketmine\network\protocol\AddEntityPacket; +use pocketmine\network\mcpe\protocol\AddEntityPacket; use pocketmine\Player; class Snowball extends Projectile{ diff --git a/src/pocketmine/entity/Squid.php b/src/pocketmine/entity/Squid.php index 8167d58fa..9ad26640b 100644 --- a/src/pocketmine/entity/Squid.php +++ b/src/pocketmine/entity/Squid.php @@ -25,8 +25,8 @@ use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\item\Item as ItemItem; use pocketmine\math\Vector3; -use pocketmine\network\protocol\AddEntityPacket; -use pocketmine\network\protocol\EntityEventPacket; +use pocketmine\network\mcpe\protocol\AddEntityPacket; +use pocketmine\network\mcpe\protocol\EntityEventPacket; use pocketmine\Player; class Squid extends WaterAnimal implements Ageable{ diff --git a/src/pocketmine/entity/Villager.php b/src/pocketmine/entity/Villager.php index 50c0df314..dff059ef4 100644 --- a/src/pocketmine/entity/Villager.php +++ b/src/pocketmine/entity/Villager.php @@ -22,7 +22,7 @@ namespace pocketmine\entity; use pocketmine\nbt\tag\IntTag; -use pocketmine\network\protocol\AddEntityPacket; +use pocketmine\network\mcpe\protocol\AddEntityPacket; use pocketmine\Player; class Villager extends Creature implements NPC, Ageable{ diff --git a/src/pocketmine/entity/Zombie.php b/src/pocketmine/entity/Zombie.php index ea7ec1f5a..633631cdc 100644 --- a/src/pocketmine/entity/Zombie.php +++ b/src/pocketmine/entity/Zombie.php @@ -23,7 +23,7 @@ namespace pocketmine\entity; use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\item\Item as ItemItem; -use pocketmine\network\protocol\AddEntityPacket; +use pocketmine\network\mcpe\protocol\AddEntityPacket; use pocketmine\Player; class Zombie extends Monster{ diff --git a/src/pocketmine/event/Timings.php b/src/pocketmine/event/Timings.php index 5052c848e..636ac1cba 100644 --- a/src/pocketmine/event/Timings.php +++ b/src/pocketmine/event/Timings.php @@ -22,7 +22,7 @@ namespace pocketmine\event; use pocketmine\entity\Entity; -use pocketmine\network\protocol\DataPacket; +use pocketmine\network\mcpe\protocol\DataPacket; use pocketmine\Player; use pocketmine\plugin\PluginManager; use pocketmine\scheduler\PluginTask; diff --git a/src/pocketmine/event/server/DataPacketReceiveEvent.php b/src/pocketmine/event/server/DataPacketReceiveEvent.php index 84a58e274..cc5b89360 100644 --- a/src/pocketmine/event/server/DataPacketReceiveEvent.php +++ b/src/pocketmine/event/server/DataPacketReceiveEvent.php @@ -22,7 +22,7 @@ namespace pocketmine\event\server; use pocketmine\event\Cancellable; -use pocketmine\network\protocol\DataPacket; +use pocketmine\network\mcpe\protocol\DataPacket; use pocketmine\Player; class DataPacketReceiveEvent extends ServerEvent implements Cancellable{ diff --git a/src/pocketmine/event/server/DataPacketSendEvent.php b/src/pocketmine/event/server/DataPacketSendEvent.php index b0b70b850..16848e499 100644 --- a/src/pocketmine/event/server/DataPacketSendEvent.php +++ b/src/pocketmine/event/server/DataPacketSendEvent.php @@ -22,7 +22,7 @@ namespace pocketmine\event\server; use pocketmine\event\Cancellable; -use pocketmine\network\protocol\DataPacket; +use pocketmine\network\mcpe\protocol\DataPacket; use pocketmine\Player; class DataPacketSendEvent extends ServerEvent implements Cancellable{ diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index 98781b5a5..4bd1d9431 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -25,8 +25,8 @@ use pocketmine\entity\Entity; use pocketmine\event\entity\EntityInventoryChangeEvent; use pocketmine\event\inventory\InventoryOpenEvent; use pocketmine\item\Item; -use pocketmine\network\protocol\ContainerSetContentPacket; -use pocketmine\network\protocol\ContainerSetSlotPacket; +use pocketmine\network\mcpe\protocol\ContainerSetContentPacket; +use pocketmine\network\mcpe\protocol\ContainerSetSlotPacket; use pocketmine\Player; use pocketmine\Server; diff --git a/src/pocketmine/inventory/ChestInventory.php b/src/pocketmine/inventory/ChestInventory.php index cc2839896..74cc9910d 100644 --- a/src/pocketmine/inventory/ChestInventory.php +++ b/src/pocketmine/inventory/ChestInventory.php @@ -22,7 +22,7 @@ namespace pocketmine\inventory; use pocketmine\level\Level; -use pocketmine\network\protocol\BlockEventPacket; +use pocketmine\network\mcpe\protocol\BlockEventPacket; use pocketmine\Player; use pocketmine\tile\Chest; diff --git a/src/pocketmine/inventory/ContainerInventory.php b/src/pocketmine/inventory/ContainerInventory.php index a11f6011f..e17c96964 100644 --- a/src/pocketmine/inventory/ContainerInventory.php +++ b/src/pocketmine/inventory/ContainerInventory.php @@ -22,8 +22,8 @@ namespace pocketmine\inventory; use pocketmine\math\Vector3; -use pocketmine\network\protocol\ContainerClosePacket; -use pocketmine\network\protocol\ContainerOpenPacket; +use pocketmine\network\mcpe\protocol\ContainerClosePacket; +use pocketmine\network\mcpe\protocol\ContainerOpenPacket; use pocketmine\Player; abstract class ContainerInventory extends BaseInventory{ diff --git a/src/pocketmine/inventory/CraftingManager.php b/src/pocketmine/inventory/CraftingManager.php index af0c56665..56f63f591 100644 --- a/src/pocketmine/inventory/CraftingManager.php +++ b/src/pocketmine/inventory/CraftingManager.php @@ -23,7 +23,7 @@ namespace pocketmine\inventory; use pocketmine\event\Timings; use pocketmine\item\Item; -use pocketmine\network\protocol\CraftingDataPacket; +use pocketmine\network\mcpe\protocol\CraftingDataPacket; use pocketmine\Server; use pocketmine\utils\Config; use pocketmine\utils\MainLogger; diff --git a/src/pocketmine/inventory/DoubleChestInventory.php b/src/pocketmine/inventory/DoubleChestInventory.php index a0a471916..deee9b58f 100644 --- a/src/pocketmine/inventory/DoubleChestInventory.php +++ b/src/pocketmine/inventory/DoubleChestInventory.php @@ -23,7 +23,7 @@ namespace pocketmine\inventory; use pocketmine\item\Item; use pocketmine\level\Level; -use pocketmine\network\protocol\BlockEventPacket; +use pocketmine\network\mcpe\protocol\BlockEventPacket; use pocketmine\Player; use pocketmine\tile\Chest; diff --git a/src/pocketmine/inventory/PlayerInventory.php b/src/pocketmine/inventory/PlayerInventory.php index 03ce4c8ff..d7bb9dde8 100644 --- a/src/pocketmine/inventory/PlayerInventory.php +++ b/src/pocketmine/inventory/PlayerInventory.php @@ -26,10 +26,10 @@ use pocketmine\event\entity\EntityArmorChangeEvent; use pocketmine\event\entity\EntityInventoryChangeEvent; use pocketmine\event\player\PlayerItemHeldEvent; use pocketmine\item\Item; -use pocketmine\network\protocol\ContainerSetContentPacket; -use pocketmine\network\protocol\ContainerSetSlotPacket; -use pocketmine\network\protocol\MobArmorEquipmentPacket; -use pocketmine\network\protocol\MobEquipmentPacket; +use pocketmine\network\mcpe\protocol\ContainerSetContentPacket; +use pocketmine\network\mcpe\protocol\ContainerSetSlotPacket; +use pocketmine\network\mcpe\protocol\MobArmorEquipmentPacket; +use pocketmine\network\mcpe\protocol\MobEquipmentPacket; use pocketmine\Player; use pocketmine\Server; diff --git a/src/pocketmine/item/Food.php b/src/pocketmine/item/Food.php index 8fc692017..c9c97aa7c 100644 --- a/src/pocketmine/item/Food.php +++ b/src/pocketmine/item/Food.php @@ -24,7 +24,7 @@ namespace pocketmine\item; use pocketmine\entity\Entity; use pocketmine\entity\Human; use pocketmine\event\entity\EntityEatItemEvent; -use pocketmine\network\protocol\EntityEventPacket; +use pocketmine\network\mcpe\protocol\EntityEventPacket; use pocketmine\Player; abstract class Food extends Item implements FoodSource{ diff --git a/src/pocketmine/level/Explosion.php b/src/pocketmine/level/Explosion.php index 301c52808..5ece506e2 100644 --- a/src/pocketmine/level/Explosion.php +++ b/src/pocketmine/level/Explosion.php @@ -38,7 +38,7 @@ use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\DoubleTag; use pocketmine\nbt\tag\FloatTag; use pocketmine\nbt\tag\ListTag; -use pocketmine\network\protocol\ExplodePacket; +use pocketmine\network\mcpe\protocol\ExplodePacket; use pocketmine\utils\Random; class Explosion{ diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 8641622b4..e16d13ad8 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -90,14 +90,14 @@ use pocketmine\nbt\tag\FloatTag; use pocketmine\nbt\tag\ListTag; use pocketmine\nbt\tag\ShortTag; use pocketmine\nbt\tag\StringTag; -use pocketmine\network\protocol\BatchPacket; -use pocketmine\network\protocol\DataPacket; -use pocketmine\network\protocol\FullChunkDataPacket; -use pocketmine\network\protocol\LevelEventPacket; -use pocketmine\network\protocol\MoveEntityPacket; -use pocketmine\network\protocol\SetEntityMotionPacket; -use pocketmine\network\protocol\SetTimePacket; -use pocketmine\network\protocol\UpdateBlockPacket; +use pocketmine\network\mcpe\protocol\BatchPacket; +use pocketmine\network\mcpe\protocol\DataPacket; +use pocketmine\network\mcpe\protocol\FullChunkDataPacket; +use pocketmine\network\mcpe\protocol\LevelEventPacket; +use pocketmine\network\mcpe\protocol\MoveEntityPacket; +use pocketmine\network\mcpe\protocol\SetEntityMotionPacket; +use pocketmine\network\mcpe\protocol\SetTimePacket; +use pocketmine\network\mcpe\protocol\UpdateBlockPacket; use pocketmine\Player; use pocketmine\plugin\Plugin; use pocketmine\Server; diff --git a/src/pocketmine/level/format/io/leveldb/LevelDB.php b/src/pocketmine/level/format/io/leveldb/LevelDB.php index 1107d8b02..67a1eebbe 100644 --- a/src/pocketmine/level/format/io/leveldb/LevelDB.php +++ b/src/pocketmine/level/format/io/leveldb/LevelDB.php @@ -22,18 +22,18 @@ namespace pocketmine\level\format\io\leveldb; use pocketmine\level\format\Chunk; -use pocketmine\level\format\SubChunk; use pocketmine\level\format\io\BaseLevelProvider; use pocketmine\level\format\io\ChunkUtils; -use pocketmine\level\generator\Generator; +use pocketmine\level\format\SubChunk; use pocketmine\level\generator\Flat; +use pocketmine\level\generator\Generator; use pocketmine\level\Level; use pocketmine\level\LevelException; use pocketmine\nbt\NBT; use pocketmine\nbt\tag\{ ByteTag, CompoundTag, FloatTag, IntTag, LongTag, StringTag }; -use pocketmine\network\protocol\Info as ProtocolInfo; +use pocketmine\network\mcpe\protocol\ProtocolInfo; use pocketmine\utils\Binary; use pocketmine\utils\MainLogger; diff --git a/src/pocketmine/level/particle/DestroyBlockParticle.php b/src/pocketmine/level/particle/DestroyBlockParticle.php index 783159c27..5ced4462f 100644 --- a/src/pocketmine/level/particle/DestroyBlockParticle.php +++ b/src/pocketmine/level/particle/DestroyBlockParticle.php @@ -23,7 +23,7 @@ namespace pocketmine\level\particle; use pocketmine\block\Block; use pocketmine\math\Vector3; -use pocketmine\network\protocol\LevelEventPacket; +use pocketmine\network\mcpe\protocol\LevelEventPacket; class DestroyBlockParticle extends Particle{ diff --git a/src/pocketmine/level/particle/FloatingTextParticle.php b/src/pocketmine/level/particle/FloatingTextParticle.php index d42e2735f..9ef93bc50 100644 --- a/src/pocketmine/level/particle/FloatingTextParticle.php +++ b/src/pocketmine/level/particle/FloatingTextParticle.php @@ -24,8 +24,8 @@ namespace pocketmine\level\particle; use pocketmine\entity\Entity; use pocketmine\entity\Item as ItemEntity; use pocketmine\math\Vector3; -use pocketmine\network\protocol\AddEntityPacket; -use pocketmine\network\protocol\RemoveEntityPacket; +use pocketmine\network\mcpe\protocol\AddEntityPacket; +use pocketmine\network\mcpe\protocol\RemoveEntityPacket; class FloatingTextParticle extends Particle{ //TODO: HACK! diff --git a/src/pocketmine/level/particle/GenericParticle.php b/src/pocketmine/level/particle/GenericParticle.php index 657e03475..698d42bb1 100644 --- a/src/pocketmine/level/particle/GenericParticle.php +++ b/src/pocketmine/level/particle/GenericParticle.php @@ -22,7 +22,7 @@ namespace pocketmine\level\particle; use pocketmine\math\Vector3; -use pocketmine\network\protocol\LevelEventPacket; +use pocketmine\network\mcpe\protocol\LevelEventPacket; class GenericParticle extends Particle{ diff --git a/src/pocketmine/level/particle/MobSpawnParticle.php b/src/pocketmine/level/particle/MobSpawnParticle.php index 0b5001158..98527129a 100644 --- a/src/pocketmine/level/particle/MobSpawnParticle.php +++ b/src/pocketmine/level/particle/MobSpawnParticle.php @@ -22,7 +22,7 @@ namespace pocketmine\level\particle; use pocketmine\math\Vector3; -use pocketmine\network\protocol\LevelEventPacket; +use pocketmine\network\mcpe\protocol\LevelEventPacket; class MobSpawnParticle extends Particle{ diff --git a/src/pocketmine/level/particle/Particle.php b/src/pocketmine/level/particle/Particle.php index a0a8e8016..b95817990 100644 --- a/src/pocketmine/level/particle/Particle.php +++ b/src/pocketmine/level/particle/Particle.php @@ -22,7 +22,7 @@ namespace pocketmine\level\particle; use pocketmine\math\Vector3; -use pocketmine\network\protocol\DataPacket; +use pocketmine\network\mcpe\protocol\DataPacket; abstract class Particle extends Vector3{ diff --git a/src/pocketmine/level/sound/AnvilBreakSound.php b/src/pocketmine/level/sound/AnvilBreakSound.php index 7418976cb..246c44c52 100644 --- a/src/pocketmine/level/sound/AnvilBreakSound.php +++ b/src/pocketmine/level/sound/AnvilBreakSound.php @@ -22,7 +22,7 @@ namespace pocketmine\level\sound; use pocketmine\math\Vector3; -use pocketmine\network\protocol\LevelEventPacket; +use pocketmine\network\mcpe\protocol\LevelEventPacket; class AnvilBreakSound extends GenericSound{ public function __construct(Vector3 $pos, $pitch = 0){ diff --git a/src/pocketmine/level/sound/AnvilFallSound.php b/src/pocketmine/level/sound/AnvilFallSound.php index c5b901495..f84b50e8d 100644 --- a/src/pocketmine/level/sound/AnvilFallSound.php +++ b/src/pocketmine/level/sound/AnvilFallSound.php @@ -22,7 +22,7 @@ namespace pocketmine\level\sound; use pocketmine\math\Vector3; -use pocketmine\network\protocol\LevelEventPacket; +use pocketmine\network\mcpe\protocol\LevelEventPacket; class AnvilFallSound extends GenericSound{ public function __construct(Vector3 $pos, $pitch = 0){ diff --git a/src/pocketmine/level/sound/AnvilUseSound.php b/src/pocketmine/level/sound/AnvilUseSound.php index 8be6d62ef..024ad017b 100644 --- a/src/pocketmine/level/sound/AnvilUseSound.php +++ b/src/pocketmine/level/sound/AnvilUseSound.php @@ -22,7 +22,7 @@ namespace pocketmine\level\sound; use pocketmine\math\Vector3; -use pocketmine\network\protocol\LevelEventPacket; +use pocketmine\network\mcpe\protocol\LevelEventPacket; class AnvilUseSound extends GenericSound{ public function __construct(Vector3 $pos, $pitch = 0){ diff --git a/src/pocketmine/level/sound/BlazeShootSound.php b/src/pocketmine/level/sound/BlazeShootSound.php index e020230fd..68d15dd93 100644 --- a/src/pocketmine/level/sound/BlazeShootSound.php +++ b/src/pocketmine/level/sound/BlazeShootSound.php @@ -22,7 +22,7 @@ namespace pocketmine\level\sound; use pocketmine\math\Vector3; -use pocketmine\network\protocol\LevelEventPacket; +use pocketmine\network\mcpe\protocol\LevelEventPacket; class BlazeShootSound extends GenericSound{ public function __construct(Vector3 $pos, $pitch = 0){ diff --git a/src/pocketmine/level/sound/ClickSound.php b/src/pocketmine/level/sound/ClickSound.php index 993d9eefd..3261fe9b0 100644 --- a/src/pocketmine/level/sound/ClickSound.php +++ b/src/pocketmine/level/sound/ClickSound.php @@ -22,7 +22,7 @@ namespace pocketmine\level\sound; use pocketmine\math\Vector3; -use pocketmine\network\protocol\LevelEventPacket; +use pocketmine\network\mcpe\protocol\LevelEventPacket; class ClickSound extends GenericSound{ public function __construct(Vector3 $pos, $pitch = 0){ diff --git a/src/pocketmine/level/sound/DoorBumpSound.php b/src/pocketmine/level/sound/DoorBumpSound.php index 8b0146791..0278ad4d5 100644 --- a/src/pocketmine/level/sound/DoorBumpSound.php +++ b/src/pocketmine/level/sound/DoorBumpSound.php @@ -22,7 +22,7 @@ namespace pocketmine\level\sound; use pocketmine\math\Vector3; -use pocketmine\network\protocol\LevelEventPacket; +use pocketmine\network\mcpe\protocol\LevelEventPacket; class DoorBumpSound extends GenericSound{ public function __construct(Vector3 $pos, $pitch = 0){ diff --git a/src/pocketmine/level/sound/DoorCrashSound.php b/src/pocketmine/level/sound/DoorCrashSound.php index 9468d9e28..2fc713f46 100644 --- a/src/pocketmine/level/sound/DoorCrashSound.php +++ b/src/pocketmine/level/sound/DoorCrashSound.php @@ -22,7 +22,7 @@ namespace pocketmine\level\sound; use pocketmine\math\Vector3; -use pocketmine\network\protocol\LevelEventPacket; +use pocketmine\network\mcpe\protocol\LevelEventPacket; class DoorCrashSound extends GenericSound{ public function __construct(Vector3 $pos, $pitch = 0){ diff --git a/src/pocketmine/level/sound/DoorSound.php b/src/pocketmine/level/sound/DoorSound.php index e6361f3ee..486d371e2 100644 --- a/src/pocketmine/level/sound/DoorSound.php +++ b/src/pocketmine/level/sound/DoorSound.php @@ -22,7 +22,7 @@ namespace pocketmine\level\sound; use pocketmine\math\Vector3; -use pocketmine\network\protocol\LevelEventPacket; +use pocketmine\network\mcpe\protocol\LevelEventPacket; class DoorSound extends GenericSound{ public function __construct(Vector3 $pos, $pitch = 0){ diff --git a/src/pocketmine/level/sound/EndermanTeleportSound.php b/src/pocketmine/level/sound/EndermanTeleportSound.php index c4e43130e..98f1b2e94 100644 --- a/src/pocketmine/level/sound/EndermanTeleportSound.php +++ b/src/pocketmine/level/sound/EndermanTeleportSound.php @@ -22,7 +22,7 @@ namespace pocketmine\level\sound; use pocketmine\math\Vector3; -use pocketmine\network\protocol\LevelEventPacket; +use pocketmine\network\mcpe\protocol\LevelEventPacket; class EndermanTeleportSound extends GenericSound{ public function __construct(Vector3 $pos){ diff --git a/src/pocketmine/level/sound/FizzSound.php b/src/pocketmine/level/sound/FizzSound.php index 241f0c7a0..32fd9a004 100644 --- a/src/pocketmine/level/sound/FizzSound.php +++ b/src/pocketmine/level/sound/FizzSound.php @@ -22,7 +22,7 @@ namespace pocketmine\level\sound; use pocketmine\math\Vector3; -use pocketmine\network\protocol\LevelEventPacket; +use pocketmine\network\mcpe\protocol\LevelEventPacket; class FizzSound extends GenericSound{ public function __construct(Vector3 $pos, $pitch = 0){ diff --git a/src/pocketmine/level/sound/GenericSound.php b/src/pocketmine/level/sound/GenericSound.php index e9f5fdcf2..f3e399cf1 100644 --- a/src/pocketmine/level/sound/GenericSound.php +++ b/src/pocketmine/level/sound/GenericSound.php @@ -22,7 +22,7 @@ namespace pocketmine\level\sound; use pocketmine\math\Vector3; -use pocketmine\network\protocol\LevelEventPacket; +use pocketmine\network\mcpe\protocol\LevelEventPacket; class GenericSound extends Sound{ diff --git a/src/pocketmine/level/sound/GhastShootSound.php b/src/pocketmine/level/sound/GhastShootSound.php index 215a0c178..d7dd0581f 100644 --- a/src/pocketmine/level/sound/GhastShootSound.php +++ b/src/pocketmine/level/sound/GhastShootSound.php @@ -22,7 +22,7 @@ namespace pocketmine\level\sound; use pocketmine\math\Vector3; -use pocketmine\network\protocol\LevelEventPacket; +use pocketmine\network\mcpe\protocol\LevelEventPacket; class GhastShootSound extends GenericSound{ public function __construct(Vector3 $pos, $pitch = 0){ diff --git a/src/pocketmine/level/sound/GhastSound.php b/src/pocketmine/level/sound/GhastSound.php index 46ad47783..0178c5302 100644 --- a/src/pocketmine/level/sound/GhastSound.php +++ b/src/pocketmine/level/sound/GhastSound.php @@ -22,7 +22,7 @@ namespace pocketmine\level\sound; use pocketmine\math\Vector3; -use pocketmine\network\protocol\LevelEventPacket; +use pocketmine\network\mcpe\protocol\LevelEventPacket; class GhastSound extends GenericSound{ public function __construct(Vector3 $pos, $pitch = 0){ diff --git a/src/pocketmine/level/sound/LaunchSound.php b/src/pocketmine/level/sound/LaunchSound.php index 4240f5c4c..3245c2da4 100644 --- a/src/pocketmine/level/sound/LaunchSound.php +++ b/src/pocketmine/level/sound/LaunchSound.php @@ -22,7 +22,7 @@ namespace pocketmine\level\sound; use pocketmine\math\Vector3; -use pocketmine\network\protocol\LevelEventPacket; +use pocketmine\network\mcpe\protocol\LevelEventPacket; class LaunchSound extends GenericSound{ public function __construct(Vector3 $pos, $pitch = 0){ diff --git a/src/pocketmine/level/sound/PopSound.php b/src/pocketmine/level/sound/PopSound.php index 6adf740ea..5d2862588 100644 --- a/src/pocketmine/level/sound/PopSound.php +++ b/src/pocketmine/level/sound/PopSound.php @@ -22,7 +22,7 @@ namespace pocketmine\level\sound; use pocketmine\math\Vector3; -use pocketmine\network\protocol\LevelEventPacket; +use pocketmine\network\mcpe\protocol\LevelEventPacket; class PopSound extends GenericSound{ public function __construct(Vector3 $pos, $pitch = 0){ diff --git a/src/pocketmine/level/sound/Sound.php b/src/pocketmine/level/sound/Sound.php index 9ec5ec4e5..2e84ad113 100644 --- a/src/pocketmine/level/sound/Sound.php +++ b/src/pocketmine/level/sound/Sound.php @@ -22,7 +22,7 @@ namespace pocketmine\level\sound; use pocketmine\math\Vector3; -use pocketmine\network\protocol\DataPacket; +use pocketmine\network\mcpe\protocol\DataPacket; abstract class Sound extends Vector3{ diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index 4ee22988a..f29cc153b 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -24,77 +24,76 @@ */ namespace pocketmine\network; -use pocketmine\network\protocol\AddEntityPacket; -use pocketmine\network\protocol\AddHangingEntityPacket; -use pocketmine\network\protocol\AddItemEntityPacket; -use pocketmine\network\protocol\AddItemPacket; -use pocketmine\network\protocol\AddPaintingPacket; -use pocketmine\network\protocol\AddPlayerPacket; -use pocketmine\network\protocol\AdventureSettingsPacket; -use pocketmine\network\protocol\AnimatePacket; -use pocketmine\network\protocol\AvailableCommandsPacket; -use pocketmine\network\protocol\BatchPacket; -use pocketmine\network\protocol\BlockEntityDataPacket; -use pocketmine\network\protocol\BlockEventPacket; -use pocketmine\network\protocol\ChangeDimensionPacket; -use pocketmine\network\protocol\ChunkRadiusUpdatedPacket; -use pocketmine\network\protocol\CommandStepPacket; -use pocketmine\network\protocol\ContainerClosePacket; -use pocketmine\network\protocol\ContainerOpenPacket; -use pocketmine\network\protocol\ContainerSetContentPacket; -use pocketmine\network\protocol\ContainerSetDataPacket; -use pocketmine\network\protocol\ContainerSetSlotPacket; -use pocketmine\network\protocol\CraftingDataPacket; -use pocketmine\network\protocol\CraftingEventPacket; -use pocketmine\network\protocol\DataPacket; -use pocketmine\network\protocol\DisconnectPacket; -use pocketmine\network\protocol\DropItemPacket; -use pocketmine\network\protocol\EntityEventPacket; -use pocketmine\network\protocol\ExplodePacket; -use pocketmine\network\protocol\FullChunkDataPacket; -use pocketmine\network\protocol\HurtArmorPacket; -use pocketmine\network\protocol\Info; -use pocketmine\network\protocol\Info as ProtocolInfo; -use pocketmine\network\protocol\InteractPacket; -use pocketmine\network\protocol\InventoryActionPacket; -use pocketmine\network\protocol\ItemFrameDropItemPacket; -use pocketmine\network\protocol\LevelEventPacket; -use pocketmine\network\protocol\LevelSoundEventPacket; -use pocketmine\network\protocol\LoginPacket; -use pocketmine\network\protocol\MobArmorEquipmentPacket; -use pocketmine\network\protocol\MobEquipmentPacket; -use pocketmine\network\protocol\MoveEntityPacket; -use pocketmine\network\protocol\MovePlayerPacket; -use pocketmine\network\protocol\PlayerActionPacket; -use pocketmine\network\protocol\PlayerFallPacket; -use pocketmine\network\protocol\PlayerInputPacket; -use pocketmine\network\protocol\PlayerListPacket; -use pocketmine\network\protocol\PlayStatusPacket; -use pocketmine\network\protocol\RemoveBlockPacket; -use pocketmine\network\protocol\RemoveEntityPacket; -use pocketmine\network\protocol\ReplaceItemInSlotPacket; -use pocketmine\network\protocol\RequestChunkRadiusPacket; -use pocketmine\network\protocol\ResourcePackClientResponsePacket; -use pocketmine\network\protocol\ResourcePacksInfoPacket; -use pocketmine\network\protocol\RespawnPacket; -use pocketmine\network\protocol\RiderJumpPacket; -use pocketmine\network\protocol\SetCommandsEnabledPacket; -use pocketmine\network\protocol\SetDifficultyPacket; -use pocketmine\network\protocol\SetEntityDataPacket; -use pocketmine\network\protocol\SetEntityLinkPacket; -use pocketmine\network\protocol\SetEntityMotionPacket; -use pocketmine\network\protocol\SetHealthPacket; -use pocketmine\network\protocol\SetPlayerGameTypePacket; -use pocketmine\network\protocol\SetSpawnPositionPacket; -use pocketmine\network\protocol\SetTimePacket; -use pocketmine\network\protocol\ShowCreditsPacket; -use pocketmine\network\protocol\SpawnExperienceOrbPacket; -use pocketmine\network\protocol\StartGamePacket; -use pocketmine\network\protocol\TakeItemEntityPacket; -use pocketmine\network\protocol\TextPacket; -use pocketmine\network\protocol\TransferPacket; -use pocketmine\network\protocol\UpdateBlockPacket; -use pocketmine\network\protocol\UseItemPacket; +use pocketmine\network\mcpe\protocol\AddEntityPacket; +use pocketmine\network\mcpe\protocol\AddHangingEntityPacket; +use pocketmine\network\mcpe\protocol\AddItemEntityPacket; +use pocketmine\network\mcpe\protocol\AddItemPacket; +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\BatchPacket; +use pocketmine\network\mcpe\protocol\BlockEntityDataPacket; +use pocketmine\network\mcpe\protocol\BlockEventPacket; +use pocketmine\network\mcpe\protocol\ChangeDimensionPacket; +use pocketmine\network\mcpe\protocol\ChunkRadiusUpdatedPacket; +use pocketmine\network\mcpe\protocol\CommandStepPacket; +use pocketmine\network\mcpe\protocol\ContainerClosePacket; +use pocketmine\network\mcpe\protocol\ContainerOpenPacket; +use pocketmine\network\mcpe\protocol\ContainerSetContentPacket; +use pocketmine\network\mcpe\protocol\ContainerSetDataPacket; +use pocketmine\network\mcpe\protocol\ContainerSetSlotPacket; +use pocketmine\network\mcpe\protocol\CraftingDataPacket; +use pocketmine\network\mcpe\protocol\CraftingEventPacket; +use pocketmine\network\mcpe\protocol\DataPacket; +use pocketmine\network\mcpe\protocol\DisconnectPacket; +use pocketmine\network\mcpe\protocol\DropItemPacket; +use pocketmine\network\mcpe\protocol\EntityEventPacket; +use pocketmine\network\mcpe\protocol\ExplodePacket; +use pocketmine\network\mcpe\protocol\FullChunkDataPacket; +use pocketmine\network\mcpe\protocol\HurtArmorPacket; +use pocketmine\network\mcpe\protocol\ProtocolInfo; +use pocketmine\network\mcpe\protocol\InteractPacket; +use pocketmine\network\mcpe\protocol\InventoryActionPacket; +use pocketmine\network\mcpe\protocol\ItemFrameDropItemPacket; +use pocketmine\network\mcpe\protocol\LevelEventPacket; +use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; +use pocketmine\network\mcpe\protocol\LoginPacket; +use pocketmine\network\mcpe\protocol\MobEquipmentPacket; +use pocketmine\network\mcpe\protocol\MobArmorEquipmentPacket; +use pocketmine\network\mcpe\protocol\MoveEntityPacket; +use pocketmine\network\mcpe\protocol\MovePlayerPacket; +use pocketmine\network\mcpe\protocol\PlayerActionPacket; +use pocketmine\network\mcpe\protocol\PlayerFallPacket; +use pocketmine\network\mcpe\protocol\PlayerInputPacket; +use pocketmine\network\mcpe\protocol\PlayerListPacket; +use pocketmine\network\mcpe\protocol\PlayStatusPacket; +use pocketmine\network\mcpe\protocol\RemoveBlockPacket; +use pocketmine\network\mcpe\protocol\RemoveEntityPacket; +use pocketmine\network\mcpe\protocol\ReplaceItemInSlotPacket; +use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket; +use pocketmine\network\mcpe\protocol\ResourcePackClientResponsePacket; +use pocketmine\network\mcpe\protocol\ResourcePacksInfoPacket; +use pocketmine\network\mcpe\protocol\RespawnPacket; +use pocketmine\network\mcpe\protocol\RiderJumpPacket; +use pocketmine\network\mcpe\protocol\SetCommandsEnabledPacket; +use pocketmine\network\mcpe\protocol\SetDifficultyPacket; +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\SetPlayerGameTypePacket; +use pocketmine\network\mcpe\protocol\SetSpawnPositionPacket; +use pocketmine\network\mcpe\protocol\SetTimePacket; +use pocketmine\network\mcpe\protocol\ShowCreditsPacket; +use pocketmine\network\mcpe\protocol\SpawnExperienceOrbPacket; +use pocketmine\network\mcpe\protocol\StartGamePacket; +use pocketmine\network\mcpe\protocol\TakeItemEntityPacket; +use pocketmine\network\mcpe\protocol\TextPacket; +use pocketmine\network\mcpe\protocol\TransferPacket; +use pocketmine\network\mcpe\protocol\UpdateBlockPacket; +use pocketmine\network\mcpe\protocol\UseItemPacket; use pocketmine\Player; use pocketmine\Server; use pocketmine\utils\BinaryStream; @@ -244,7 +243,7 @@ class Network{ $buf = $stream->getString(); if(($pk = $this->getPacket(ord($buf{0}))) !== null){ - if($pk::NETWORK_ID === Info::BATCH_PACKET){ + if($pk::NETWORK_ID === ProtocolInfo::BATCH_PACKET){ throw new \InvalidStateException("Invalid BatchPacket inside BatchPacket"); } diff --git a/src/pocketmine/network/SourceInterface.php b/src/pocketmine/network/SourceInterface.php index f662992a0..492c5b60c 100644 --- a/src/pocketmine/network/SourceInterface.php +++ b/src/pocketmine/network/SourceInterface.php @@ -24,7 +24,7 @@ */ namespace pocketmine\network; -use pocketmine\network\protocol\DataPacket; +use pocketmine\network\mcpe\protocol\DataPacket; use pocketmine\Player; /** diff --git a/src/pocketmine/network/CachedEncapsulatedPacket.php b/src/pocketmine/network/mcpe/CachedEncapsulatedPacket.php similarity index 96% rename from src/pocketmine/network/CachedEncapsulatedPacket.php rename to src/pocketmine/network/mcpe/CachedEncapsulatedPacket.php index 0ddcff4b7..57545d57c 100644 --- a/src/pocketmine/network/CachedEncapsulatedPacket.php +++ b/src/pocketmine/network/mcpe/CachedEncapsulatedPacket.php @@ -19,7 +19,7 @@ * */ -namespace pocketmine\network; +namespace pocketmine\network\mcpe; use raklib\protocol\EncapsulatedPacket; diff --git a/src/pocketmine/network/PocketEditionNetworkSession.php b/src/pocketmine/network/mcpe/NetworkSession.php similarity index 62% rename from src/pocketmine/network/PocketEditionNetworkSession.php rename to src/pocketmine/network/mcpe/NetworkSession.php index 7c8706798..bb86fe2d8 100644 --- a/src/pocketmine/network/PocketEditionNetworkSession.php +++ b/src/pocketmine/network/mcpe/NetworkSession.php @@ -20,82 +20,82 @@ */ -namespace pocketmine\network; +namespace pocketmine\network\mcpe; -use pocketmine\network\protocol\AddEntityPacket; -use pocketmine\network\protocol\AddHangingEntityPacket; -use pocketmine\network\protocol\AddItemEntityPacket; -use pocketmine\network\protocol\AddItemPacket; -use pocketmine\network\protocol\AddPaintingPacket; -use pocketmine\network\protocol\AddPlayerPacket; -use pocketmine\network\protocol\AdventureSettingsPacket; -use pocketmine\network\protocol\AnimatePacket; -use pocketmine\network\protocol\AvailableCommandsPacket; -use pocketmine\network\protocol\BatchPacket; -use pocketmine\network\protocol\BlockEntityDataPacket; -use pocketmine\network\protocol\BlockEventPacket; -use pocketmine\network\protocol\ChangeDimensionPacket; -use pocketmine\network\protocol\ChunkRadiusUpdatedPacket; -use pocketmine\network\protocol\CommandStepPacket; -use pocketmine\network\protocol\ContainerClosePacket; -use pocketmine\network\protocol\ContainerOpenPacket; -use pocketmine\network\protocol\ContainerSetContentPacket; -use pocketmine\network\protocol\ContainerSetDataPacket; -use pocketmine\network\protocol\ContainerSetSlotPacket; -use pocketmine\network\protocol\CraftingDataPacket; -use pocketmine\network\protocol\CraftingEventPacket; -use pocketmine\network\protocol\DisconnectPacket; -use pocketmine\network\protocol\DropItemPacket; -use pocketmine\network\protocol\EntityEventPacket; -use pocketmine\network\protocol\ExplodePacket; -use pocketmine\network\protocol\FullChunkDataPacket; -use pocketmine\network\protocol\HurtArmorPacket; -use pocketmine\network\protocol\InteractPacket; -use pocketmine\network\protocol\InventoryActionPacket; -use pocketmine\network\protocol\ItemFrameDropItemPacket; -use pocketmine\network\protocol\LevelEventPacket; -use pocketmine\network\protocol\LevelSoundEventPacket; -use pocketmine\network\protocol\LoginPacket; -use pocketmine\network\protocol\MobArmorEquipmentPacket; -use pocketmine\network\protocol\MobEffectPacket; -use pocketmine\network\protocol\MobEquipmentPacket; -use pocketmine\network\protocol\MoveEntityPacket; -use pocketmine\network\protocol\MovePlayerPacket; -use pocketmine\network\protocol\PlayerActionPacket; -use pocketmine\network\protocol\PlayerFallPacket; -use pocketmine\network\protocol\PlayerInputPacket; -use pocketmine\network\protocol\PlayerListPacket; -use pocketmine\network\protocol\PlayStatusPacket; -use pocketmine\network\protocol\RemoveBlockPacket; -use pocketmine\network\protocol\RemoveEntityPacket; -use pocketmine\network\protocol\ReplaceItemInSlotPacket; -use pocketmine\network\protocol\RequestChunkRadiusPacket; -use pocketmine\network\protocol\ResourcePackClientResponsePacket; -use pocketmine\network\protocol\ResourcePacksInfoPacket; -use pocketmine\network\protocol\ResourcePackStackPacket; -use pocketmine\network\protocol\RespawnPacket; -use pocketmine\network\protocol\RiderJumpPacket; -use pocketmine\network\protocol\SetCommandsEnabledPacket; -use pocketmine\network\protocol\SetDifficultyPacket; -use pocketmine\network\protocol\SetEntityDataPacket; -use pocketmine\network\protocol\SetEntityLinkPacket; -use pocketmine\network\protocol\SetEntityMotionPacket; -use pocketmine\network\protocol\SetHealthPacket; -use pocketmine\network\protocol\SetPlayerGameTypePacket; -use pocketmine\network\protocol\SetSpawnPositionPacket; -use pocketmine\network\protocol\SetTimePacket; -use pocketmine\network\protocol\ShowCreditsPacket; -use pocketmine\network\protocol\SpawnExperienceOrbPacket; -use pocketmine\network\protocol\StartGamePacket; -use pocketmine\network\protocol\TakeItemEntityPacket; -use pocketmine\network\protocol\TextPacket; -use pocketmine\network\protocol\TransferPacket; -use pocketmine\network\protocol\UpdateAttributesPacket; -use pocketmine\network\protocol\UpdateBlockPacket; -use pocketmine\network\protocol\UseItemPacket; +use pocketmine\network\mcpe\protocol\AddEntityPacket; +use pocketmine\network\mcpe\protocol\AddHangingEntityPacket; +use pocketmine\network\mcpe\protocol\AddItemEntityPacket; +use pocketmine\network\mcpe\protocol\AddItemPacket; +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\BatchPacket; +use pocketmine\network\mcpe\protocol\BlockEntityDataPacket; +use pocketmine\network\mcpe\protocol\BlockEventPacket; +use pocketmine\network\mcpe\protocol\ChangeDimensionPacket; +use pocketmine\network\mcpe\protocol\ChunkRadiusUpdatedPacket; +use pocketmine\network\mcpe\protocol\CommandStepPacket; +use pocketmine\network\mcpe\protocol\ContainerClosePacket; +use pocketmine\network\mcpe\protocol\ContainerOpenPacket; +use pocketmine\network\mcpe\protocol\ContainerSetContentPacket; +use pocketmine\network\mcpe\protocol\ContainerSetDataPacket; +use pocketmine\network\mcpe\protocol\ContainerSetSlotPacket; +use pocketmine\network\mcpe\protocol\CraftingDataPacket; +use pocketmine\network\mcpe\protocol\CraftingEventPacket; +use pocketmine\network\mcpe\protocol\DisconnectPacket; +use pocketmine\network\mcpe\protocol\DropItemPacket; +use pocketmine\network\mcpe\protocol\EntityEventPacket; +use pocketmine\network\mcpe\protocol\ExplodePacket; +use pocketmine\network\mcpe\protocol\FullChunkDataPacket; +use pocketmine\network\mcpe\protocol\HurtArmorPacket; +use pocketmine\network\mcpe\protocol\InteractPacket; +use pocketmine\network\mcpe\protocol\InventoryActionPacket; +use pocketmine\network\mcpe\protocol\ItemFrameDropItemPacket; +use pocketmine\network\mcpe\protocol\LevelEventPacket; +use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; +use pocketmine\network\mcpe\protocol\LoginPacket; +use pocketmine\network\mcpe\protocol\MobArmorEquipmentPacket; +use pocketmine\network\mcpe\protocol\MobEffectPacket; +use pocketmine\network\mcpe\protocol\MobEquipmentPacket; +use pocketmine\network\mcpe\protocol\MoveEntityPacket; +use pocketmine\network\mcpe\protocol\MovePlayerPacket; +use pocketmine\network\mcpe\protocol\PlayerActionPacket; +use pocketmine\network\mcpe\protocol\PlayerFallPacket; +use pocketmine\network\mcpe\protocol\PlayerInputPacket; +use pocketmine\network\mcpe\protocol\PlayerListPacket; +use pocketmine\network\mcpe\protocol\PlayStatusPacket; +use pocketmine\network\mcpe\protocol\RemoveBlockPacket; +use pocketmine\network\mcpe\protocol\RemoveEntityPacket; +use pocketmine\network\mcpe\protocol\ReplaceItemInSlotPacket; +use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket; +use pocketmine\network\mcpe\protocol\ResourcePackClientResponsePacket; +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\SetCommandsEnabledPacket; +use pocketmine\network\mcpe\protocol\SetDifficultyPacket; +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\SetPlayerGameTypePacket; +use pocketmine\network\mcpe\protocol\SetSpawnPositionPacket; +use pocketmine\network\mcpe\protocol\SetTimePacket; +use pocketmine\network\mcpe\protocol\ShowCreditsPacket; +use pocketmine\network\mcpe\protocol\SpawnExperienceOrbPacket; +use pocketmine\network\mcpe\protocol\StartGamePacket; +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\UseItemPacket; -interface PocketEditionNetworkSession{ +interface NetworkSession{ public function handleLogin(LoginPacket $packet) : bool; diff --git a/src/pocketmine/network/RakLibInterface.php b/src/pocketmine/network/mcpe/RakLibInterface.php similarity index 95% rename from src/pocketmine/network/RakLibInterface.php rename to src/pocketmine/network/mcpe/RakLibInterface.php index 9920a0f0d..b723c8acb 100644 --- a/src/pocketmine/network/RakLibInterface.php +++ b/src/pocketmine/network/mcpe/RakLibInterface.php @@ -19,12 +19,13 @@ * */ -namespace pocketmine\network; +namespace pocketmine\network\mcpe; use pocketmine\event\player\PlayerCreationEvent; -use pocketmine\network\protocol\DataPacket; -use pocketmine\network\protocol\Info; -use pocketmine\network\protocol\Info as ProtocolInfo; +use pocketmine\network\AdvancedSourceInterface; +use pocketmine\network\mcpe\protocol\DataPacket; +use pocketmine\network\mcpe\protocol\ProtocolInfo; +use pocketmine\network\Network; use pocketmine\Player; use pocketmine\Server; use raklib\protocol\EncapsulatedPacket; @@ -175,8 +176,8 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{ $this->interface->sendOption("name", "MCPE;" . rtrim(addcslashes($name, ";"), '\\') . ";" . - Info::CURRENT_PROTOCOL . ";" . - Info::MINECRAFT_VERSION_NETWORK . ";" . + ProtocolInfo::CURRENT_PROTOCOL . ";" . + ProtocolInfo::MINECRAFT_VERSION_NETWORK . ";" . $info->getPlayerCount() . ";" . $info->getMaxPlayerCount() ); diff --git a/src/pocketmine/network/protocol/AddEntityPacket.php b/src/pocketmine/network/mcpe/protocol/AddEntityPacket.php similarity index 90% rename from src/pocketmine/network/protocol/AddEntityPacket.php rename to src/pocketmine/network/mcpe/protocol/AddEntityPacket.php index 7bc018bcc..cbb5a974c 100644 --- a/src/pocketmine/network/protocol/AddEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddEntityPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include use pocketmine\entity\Attribute; -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class AddEntityPacket extends DataPacket{ - const NETWORK_ID = Info::ADD_ENTITY_PACKET; + const NETWORK_ID = ProtocolInfo::ADD_ENTITY_PACKET; public $eid; public $type; @@ -73,7 +73,7 @@ class AddEntityPacket extends DataPacket{ } } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleAddEntity($this); } diff --git a/src/pocketmine/network/protocol/AddHangingEntityPacket.php b/src/pocketmine/network/mcpe/protocol/AddHangingEntityPacket.php similarity index 85% rename from src/pocketmine/network/protocol/AddHangingEntityPacket.php rename to src/pocketmine/network/mcpe/protocol/AddHangingEntityPacket.php index 5ed7b32f5..4550e9823 100644 --- a/src/pocketmine/network/protocol/AddHangingEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddHangingEntityPacket.php @@ -19,14 +19,14 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class AddHangingEntityPacket extends DataPacket{ - const NETWORK_ID = Info::ADD_HANGING_ENTITY_PACKET; + const NETWORK_ID = ProtocolInfo::ADD_HANGING_ENTITY_PACKET; public $entityUniqueId; public $entityRuntimeId; @@ -47,7 +47,7 @@ class AddHangingEntityPacket extends DataPacket{ $this->putVarInt($this->unknown); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleAddHangingEntity($this); } diff --git a/src/pocketmine/network/protocol/AddItemEntityPacket.php b/src/pocketmine/network/mcpe/protocol/AddItemEntityPacket.php similarity index 85% rename from src/pocketmine/network/protocol/AddItemEntityPacket.php rename to src/pocketmine/network/mcpe/protocol/AddItemEntityPacket.php index fc38ec153..f1fd7930e 100644 --- a/src/pocketmine/network/protocol/AddItemEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddItemEntityPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class AddItemEntityPacket extends DataPacket{ - const NETWORK_ID = Info::ADD_ITEM_ENTITY_PACKET; + const NETWORK_ID = ProtocolInfo::ADD_ITEM_ENTITY_PACKET; public $eid; public $item; @@ -51,7 +51,7 @@ class AddItemEntityPacket extends DataPacket{ $this->putVector3f($this->speedX, $this->speedY, $this->speedZ); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleAddItemEntity($this); } diff --git a/src/pocketmine/network/protocol/AddItemPacket.php b/src/pocketmine/network/mcpe/protocol/AddItemPacket.php similarity index 82% rename from src/pocketmine/network/protocol/AddItemPacket.php rename to src/pocketmine/network/mcpe/protocol/AddItemPacket.php index a67aa7170..397d87f9d 100644 --- a/src/pocketmine/network/protocol/AddItemPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddItemPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class AddItemPacket extends DataPacket{ - const NETWORK_ID = Info::ADD_ITEM_PACKET; + const NETWORK_ID = ProtocolInfo::ADD_ITEM_PACKET; public $item; @@ -40,7 +40,7 @@ class AddItemPacket extends DataPacket{ $this->putSlot($this->item); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleAddItem($this); } diff --git a/src/pocketmine/network/protocol/AddPaintingPacket.php b/src/pocketmine/network/mcpe/protocol/AddPaintingPacket.php similarity index 85% rename from src/pocketmine/network/protocol/AddPaintingPacket.php rename to src/pocketmine/network/mcpe/protocol/AddPaintingPacket.php index eff76d0f1..c2af0e398 100644 --- a/src/pocketmine/network/protocol/AddPaintingPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddPaintingPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class AddPaintingPacket extends DataPacket{ - const NETWORK_ID = Info::ADD_PAINTING_PACKET; + const NETWORK_ID = ProtocolInfo::ADD_PAINTING_PACKET; public $eid; public $x; @@ -49,7 +49,7 @@ class AddPaintingPacket extends DataPacket{ $this->putString($this->title); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleAddPainting($this); } diff --git a/src/pocketmine/network/protocol/AddPlayerPacket.php b/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php similarity index 88% rename from src/pocketmine/network/protocol/AddPlayerPacket.php rename to src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php index 7b6fbd8c2..aad154a7d 100644 --- a/src/pocketmine/network/protocol/AddPlayerPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php @@ -19,14 +19,14 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class AddPlayerPacket extends DataPacket{ - const NETWORK_ID = Info::ADD_PLAYER_PACKET; + const NETWORK_ID = ProtocolInfo::ADD_PLAYER_PACKET; public $uuid; public $username; @@ -62,7 +62,7 @@ class AddPlayerPacket extends DataPacket{ $this->putEntityMetadata($this->metadata); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleAddPlayer($this); } diff --git a/src/pocketmine/network/protocol/AdventureSettingsPacket.php b/src/pocketmine/network/mcpe/protocol/AdventureSettingsPacket.php similarity index 93% rename from src/pocketmine/network/protocol/AdventureSettingsPacket.php rename to src/pocketmine/network/mcpe/protocol/AdventureSettingsPacket.php index b5612f187..8cc7989ac 100644 --- a/src/pocketmine/network/protocol/AdventureSettingsPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AdventureSettingsPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class AdventureSettingsPacket extends DataPacket{ - const NETWORK_ID = Info::ADVENTURE_SETTINGS_PACKET; + const NETWORK_ID = ProtocolInfo::ADVENTURE_SETTINGS_PACKET; const PERMISSION_NORMAL = 0; const PERMISSION_OPERATOR = 1; @@ -97,7 +97,7 @@ class AdventureSettingsPacket extends DataPacket{ $this->putUnsignedVarInt($this->userPermission); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleAdventureSettings($this); } diff --git a/src/pocketmine/network/protocol/AnimatePacket.php b/src/pocketmine/network/mcpe/protocol/AnimatePacket.php similarity index 84% rename from src/pocketmine/network/protocol/AnimatePacket.php rename to src/pocketmine/network/mcpe/protocol/AnimatePacket.php index 7b713fa3a..ecd0e64de 100644 --- a/src/pocketmine/network/protocol/AnimatePacket.php +++ b/src/pocketmine/network/mcpe/protocol/AnimatePacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class AnimatePacket extends DataPacket{ - const NETWORK_ID = Info::ANIMATE_PACKET; + const NETWORK_ID = ProtocolInfo::ANIMATE_PACKET; public $action; public $eid; @@ -43,7 +43,7 @@ class AnimatePacket extends DataPacket{ $this->putEntityId($this->eid); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleAnimate($this); } diff --git a/src/pocketmine/network/protocol/AvailableCommandsPacket.php b/src/pocketmine/network/mcpe/protocol/AvailableCommandsPacket.php similarity index 83% rename from src/pocketmine/network/protocol/AvailableCommandsPacket.php rename to src/pocketmine/network/mcpe/protocol/AvailableCommandsPacket.php index ef1907ade..fc458e074 100644 --- a/src/pocketmine/network/protocol/AvailableCommandsPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AvailableCommandsPacket.php @@ -19,14 +19,14 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class AvailableCommandsPacket extends DataPacket{ - const NETWORK_ID = Info::AVAILABLE_COMMANDS_PACKET; + const NETWORK_ID = ProtocolInfo::AVAILABLE_COMMANDS_PACKET; public $commands; //JSON-encoded command data public $unknown; @@ -41,7 +41,7 @@ class AvailableCommandsPacket extends DataPacket{ $this->putString($this->unknown); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleAvailableCommands($this); } diff --git a/src/pocketmine/network/protocol/BatchPacket.php b/src/pocketmine/network/mcpe/protocol/BatchPacket.php similarity index 83% rename from src/pocketmine/network/protocol/BatchPacket.php rename to src/pocketmine/network/mcpe/protocol/BatchPacket.php index ed7d475db..6eb101479 100644 --- a/src/pocketmine/network/protocol/BatchPacket.php +++ b/src/pocketmine/network/mcpe/protocol/BatchPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class BatchPacket extends DataPacket{ - const NETWORK_ID = Info::BATCH_PACKET; + const NETWORK_ID = ProtocolInfo::BATCH_PACKET; public $payload; @@ -40,7 +40,7 @@ class BatchPacket extends DataPacket{ $this->putString($this->payload); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleBatch($this); } diff --git a/src/pocketmine/network/protocol/BlockEntityDataPacket.php b/src/pocketmine/network/mcpe/protocol/BlockEntityDataPacket.php similarity index 84% rename from src/pocketmine/network/protocol/BlockEntityDataPacket.php rename to src/pocketmine/network/mcpe/protocol/BlockEntityDataPacket.php index 0527a9006..9a5eeea48 100644 --- a/src/pocketmine/network/protocol/BlockEntityDataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/BlockEntityDataPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class BlockEntityDataPacket extends DataPacket{ - const NETWORK_ID = Info::BLOCK_ENTITY_DATA_PACKET; + const NETWORK_ID = ProtocolInfo::BLOCK_ENTITY_DATA_PACKET; public $x; public $y; @@ -45,7 +45,7 @@ class BlockEntityDataPacket extends DataPacket{ $this->put($this->namedtag); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleBlockEntityData($this); } diff --git a/src/pocketmine/network/protocol/BlockEventPacket.php b/src/pocketmine/network/mcpe/protocol/BlockEventPacket.php similarity index 84% rename from src/pocketmine/network/protocol/BlockEventPacket.php rename to src/pocketmine/network/mcpe/protocol/BlockEventPacket.php index da3ff64e8..bae6ae7ae 100644 --- a/src/pocketmine/network/protocol/BlockEventPacket.php +++ b/src/pocketmine/network/mcpe/protocol/BlockEventPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class BlockEventPacket extends DataPacket{ - const NETWORK_ID = Info::BLOCK_EVENT_PACKET; + const NETWORK_ID = ProtocolInfo::BLOCK_EVENT_PACKET; public $x; public $y; @@ -46,7 +46,7 @@ class BlockEventPacket extends DataPacket{ $this->putVarInt($this->case2); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleBlockEvent($this); } diff --git a/src/pocketmine/network/protocol/ChangeDimensionPacket.php b/src/pocketmine/network/mcpe/protocol/ChangeDimensionPacket.php similarity index 84% rename from src/pocketmine/network/protocol/ChangeDimensionPacket.php rename to src/pocketmine/network/mcpe/protocol/ChangeDimensionPacket.php index da422c0a4..93f85494d 100644 --- a/src/pocketmine/network/protocol/ChangeDimensionPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ChangeDimensionPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class ChangeDimensionPacket extends DataPacket{ - const NETWORK_ID = Info::CHANGE_DIMENSION_PACKET; + const NETWORK_ID = ProtocolInfo::CHANGE_DIMENSION_PACKET; const DIMENSION_OVERWORLD = 0; const DIMENSION_NETHER = 1; @@ -49,7 +49,7 @@ class ChangeDimensionPacket extends DataPacket{ $this->putBool($this->unknown); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleChangeDimension($this); } diff --git a/src/pocketmine/network/protocol/ChunkRadiusUpdatedPacket.php b/src/pocketmine/network/mcpe/protocol/ChunkRadiusUpdatedPacket.php similarity index 82% rename from src/pocketmine/network/protocol/ChunkRadiusUpdatedPacket.php rename to src/pocketmine/network/mcpe/protocol/ChunkRadiusUpdatedPacket.php index 029de4d60..9c6b6dc7c 100644 --- a/src/pocketmine/network/protocol/ChunkRadiusUpdatedPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ChunkRadiusUpdatedPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class ChunkRadiusUpdatedPacket extends DataPacket{ - const NETWORK_ID = Info::CHUNK_RADIUS_UPDATED_PACKET; + const NETWORK_ID = ProtocolInfo::CHUNK_RADIUS_UPDATED_PACKET; public $radius; @@ -39,7 +39,7 @@ class ChunkRadiusUpdatedPacket extends DataPacket{ $this->putVarInt($this->radius); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleChunkRadiusUpdated($this); } diff --git a/src/pocketmine/network/protocol/CommandStepPacket.php b/src/pocketmine/network/mcpe/protocol/CommandStepPacket.php similarity index 89% rename from src/pocketmine/network/protocol/CommandStepPacket.php rename to src/pocketmine/network/mcpe/protocol/CommandStepPacket.php index 6d76dbc8d..1678fc431 100644 --- a/src/pocketmine/network/protocol/CommandStepPacket.php +++ b/src/pocketmine/network/mcpe/protocol/CommandStepPacket.php @@ -19,14 +19,14 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class CommandStepPacket extends DataPacket{ - const NETWORK_ID = Info::COMMAND_STEP_PACKET; + const NETWORK_ID = ProtocolInfo::COMMAND_STEP_PACKET; /** * unknown (string) @@ -67,7 +67,7 @@ class CommandStepPacket extends DataPacket{ } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleCommandStep($this); } diff --git a/src/pocketmine/network/protocol/ContainerClosePacket.php b/src/pocketmine/network/mcpe/protocol/ContainerClosePacket.php similarity index 82% rename from src/pocketmine/network/protocol/ContainerClosePacket.php rename to src/pocketmine/network/mcpe/protocol/ContainerClosePacket.php index 9af31d553..c566152fd 100644 --- a/src/pocketmine/network/protocol/ContainerClosePacket.php +++ b/src/pocketmine/network/mcpe/protocol/ContainerClosePacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class ContainerClosePacket extends DataPacket{ - const NETWORK_ID = Info::CONTAINER_CLOSE_PACKET; + const NETWORK_ID = ProtocolInfo::CONTAINER_CLOSE_PACKET; public $windowid; @@ -40,7 +40,7 @@ class ContainerClosePacket extends DataPacket{ $this->putByte($this->windowid); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleContainerClose($this); } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/ContainerOpenPacket.php b/src/pocketmine/network/mcpe/protocol/ContainerOpenPacket.php similarity index 85% rename from src/pocketmine/network/protocol/ContainerOpenPacket.php rename to src/pocketmine/network/mcpe/protocol/ContainerOpenPacket.php index 5d9ebc730..ee6356d2f 100644 --- a/src/pocketmine/network/protocol/ContainerOpenPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ContainerOpenPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class ContainerOpenPacket extends DataPacket{ - const NETWORK_ID = Info::CONTAINER_OPEN_PACKET; + const NETWORK_ID = ProtocolInfo::CONTAINER_OPEN_PACKET; public $windowid; public $type; @@ -50,7 +50,7 @@ class ContainerOpenPacket extends DataPacket{ $this->putEntityId($this->entityId); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleContainerOpen($this); } diff --git a/src/pocketmine/network/protocol/ContainerSetContentPacket.php b/src/pocketmine/network/mcpe/protocol/ContainerSetContentPacket.php similarity index 90% rename from src/pocketmine/network/protocol/ContainerSetContentPacket.php rename to src/pocketmine/network/mcpe/protocol/ContainerSetContentPacket.php index d105d3862..ade1394d4 100644 --- a/src/pocketmine/network/protocol/ContainerSetContentPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ContainerSetContentPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class ContainerSetContentPacket extends DataPacket{ - const NETWORK_ID = Info::CONTAINER_SET_CONTENT_PACKET; + const NETWORK_ID = ProtocolInfo::CONTAINER_SET_CONTENT_PACKET; const SPECIAL_INVENTORY = 0; const SPECIAL_ARMOR = 0x78; @@ -75,7 +75,7 @@ class ContainerSetContentPacket extends DataPacket{ } } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleContainerSetContent($this); } diff --git a/src/pocketmine/network/protocol/ContainerSetDataPacket.php b/src/pocketmine/network/mcpe/protocol/ContainerSetDataPacket.php similarity index 83% rename from src/pocketmine/network/protocol/ContainerSetDataPacket.php rename to src/pocketmine/network/mcpe/protocol/ContainerSetDataPacket.php index 235fec96d..a8faaeab4 100644 --- a/src/pocketmine/network/protocol/ContainerSetDataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ContainerSetDataPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class ContainerSetDataPacket extends DataPacket{ - const NETWORK_ID = Info::CONTAINER_SET_DATA_PACKET; + const NETWORK_ID = ProtocolInfo::CONTAINER_SET_DATA_PACKET; public $windowid; public $property; @@ -44,7 +44,7 @@ class ContainerSetDataPacket extends DataPacket{ $this->putVarInt($this->value); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleContainerSetData($this); } diff --git a/src/pocketmine/network/protocol/ContainerSetSlotPacket.php b/src/pocketmine/network/mcpe/protocol/ContainerSetSlotPacket.php similarity index 86% rename from src/pocketmine/network/protocol/ContainerSetSlotPacket.php rename to src/pocketmine/network/mcpe/protocol/ContainerSetSlotPacket.php index f91da7d9d..d364c3bb0 100644 --- a/src/pocketmine/network/protocol/ContainerSetSlotPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ContainerSetSlotPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include use pocketmine\item\Item; -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class ContainerSetSlotPacket extends DataPacket{ - const NETWORK_ID = Info::CONTAINER_SET_SLOT_PACKET; + const NETWORK_ID = ProtocolInfo::CONTAINER_SET_SLOT_PACKET; public $windowid; public $slot; @@ -53,7 +53,7 @@ class ContainerSetSlotPacket extends DataPacket{ $this->putByte($this->unknown); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleContainerSetSlot($this); } diff --git a/src/pocketmine/network/protocol/CraftingDataPacket.php b/src/pocketmine/network/mcpe/protocol/CraftingDataPacket.php similarity index 95% rename from src/pocketmine/network/protocol/CraftingDataPacket.php rename to src/pocketmine/network/mcpe/protocol/CraftingDataPacket.php index 601aae635..f183510c6 100644 --- a/src/pocketmine/network/protocol/CraftingDataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/CraftingDataPacket.php @@ -19,21 +19,20 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include use pocketmine\inventory\FurnaceRecipe; -use pocketmine\inventory\MultiRecipe; use pocketmine\inventory\ShapedRecipe; use pocketmine\inventory\ShapelessRecipe; use pocketmine\item\Item; -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; use pocketmine\utils\BinaryStream; class CraftingDataPacket extends DataPacket{ - const NETWORK_ID = Info::CRAFTING_DATA_PACKET; + const NETWORK_ID = ProtocolInfo::CRAFTING_DATA_PACKET; const ENTRY_SHAPELESS = 0; const ENTRY_SHAPED = 1; @@ -199,7 +198,7 @@ class CraftingDataPacket extends DataPacket{ $this->putBool($this->cleanRecipes); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleCraftingData($this); } diff --git a/src/pocketmine/network/protocol/CraftingEventPacket.php b/src/pocketmine/network/mcpe/protocol/CraftingEventPacket.php similarity index 87% rename from src/pocketmine/network/protocol/CraftingEventPacket.php rename to src/pocketmine/network/mcpe/protocol/CraftingEventPacket.php index 4db2e113c..e45d42410 100644 --- a/src/pocketmine/network/protocol/CraftingEventPacket.php +++ b/src/pocketmine/network/mcpe/protocol/CraftingEventPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include use pocketmine\item\Item; -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class CraftingEventPacket extends DataPacket{ - const NETWORK_ID = Info::CRAFTING_EVENT_PACKET; + const NETWORK_ID = ProtocolInfo::CRAFTING_EVENT_PACKET; public $windowId; public $type; @@ -63,7 +63,7 @@ class CraftingEventPacket extends DataPacket{ } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleCraftingEvent($this); } diff --git a/src/pocketmine/network/protocol/DataPacket.php b/src/pocketmine/network/mcpe/protocol/DataPacket.php similarity index 96% rename from src/pocketmine/network/protocol/DataPacket.php rename to src/pocketmine/network/mcpe/protocol/DataPacket.php index 7f0890de6..7404f3a76 100644 --- a/src/pocketmine/network/protocol/DataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/DataPacket.php @@ -19,13 +19,13 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include use pocketmine\entity\Entity; use pocketmine\item\Item; -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; use pocketmine\utils\BinaryStream; use pocketmine\utils\Utils; @@ -44,7 +44,7 @@ abstract class DataPacket extends BinaryStream{ abstract public function decode(); - abstract public function handle(PocketEditionNetworkSession $session) : bool; + abstract public function handle(NetworkSession $session) : bool; public function reset(){ $this->buffer = chr($this::NETWORK_ID); diff --git a/src/pocketmine/network/protocol/DisconnectPacket.php b/src/pocketmine/network/mcpe/protocol/DisconnectPacket.php similarity index 84% rename from src/pocketmine/network/protocol/DisconnectPacket.php rename to src/pocketmine/network/mcpe/protocol/DisconnectPacket.php index 5a9531c0b..94fcc6d39 100644 --- a/src/pocketmine/network/protocol/DisconnectPacket.php +++ b/src/pocketmine/network/mcpe/protocol/DisconnectPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class DisconnectPacket extends DataPacket{ - const NETWORK_ID = Info::DISCONNECT_PACKET; + const NETWORK_ID = ProtocolInfo::DISCONNECT_PACKET; public $hideDisconnectionScreen = false; public $message; @@ -43,7 +43,7 @@ class DisconnectPacket extends DataPacket{ $this->putString($this->message); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleDisconnect($this); } diff --git a/src/pocketmine/network/protocol/DropItemPacket.php b/src/pocketmine/network/mcpe/protocol/DropItemPacket.php similarity index 82% rename from src/pocketmine/network/protocol/DropItemPacket.php rename to src/pocketmine/network/mcpe/protocol/DropItemPacket.php index ff4e48606..98fff9df9 100644 --- a/src/pocketmine/network/protocol/DropItemPacket.php +++ b/src/pocketmine/network/mcpe/protocol/DropItemPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class DropItemPacket extends DataPacket{ - const NETWORK_ID = Info::DROP_ITEM_PACKET; + const NETWORK_ID = ProtocolInfo::DROP_ITEM_PACKET; public $type; public $item; @@ -41,7 +41,7 @@ class DropItemPacket extends DataPacket{ } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleDropItem($this); } diff --git a/src/pocketmine/network/protocol/EntityEventPacket.php b/src/pocketmine/network/mcpe/protocol/EntityEventPacket.php similarity index 88% rename from src/pocketmine/network/protocol/EntityEventPacket.php rename to src/pocketmine/network/mcpe/protocol/EntityEventPacket.php index 68f31a1aa..388aab8b9 100644 --- a/src/pocketmine/network/protocol/EntityEventPacket.php +++ b/src/pocketmine/network/mcpe/protocol/EntityEventPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class EntityEventPacket extends DataPacket{ - const NETWORK_ID = Info::ENTITY_EVENT_PACKET; + const NETWORK_ID = ProtocolInfo::ENTITY_EVENT_PACKET; const HURT_ANIMATION = 2; const DEATH_ANIMATION = 3; @@ -64,7 +64,7 @@ class EntityEventPacket extends DataPacket{ $this->putVarInt($this->unknown); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleEntityEvent($this); } diff --git a/src/pocketmine/network/protocol/ExplodePacket.php b/src/pocketmine/network/mcpe/protocol/ExplodePacket.php similarity index 86% rename from src/pocketmine/network/protocol/ExplodePacket.php rename to src/pocketmine/network/mcpe/protocol/ExplodePacket.php index 46906ef26..6892308cc 100644 --- a/src/pocketmine/network/protocol/ExplodePacket.php +++ b/src/pocketmine/network/mcpe/protocol/ExplodePacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class ExplodePacket extends DataPacket{ - const NETWORK_ID = Info::EXPLODE_PACKET; + const NETWORK_ID = ProtocolInfo::EXPLODE_PACKET; public $x; public $y; @@ -56,7 +56,7 @@ class ExplodePacket extends DataPacket{ } } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleExplode($this); } diff --git a/src/pocketmine/network/protocol/FullChunkDataPacket.php b/src/pocketmine/network/mcpe/protocol/FullChunkDataPacket.php similarity index 83% rename from src/pocketmine/network/protocol/FullChunkDataPacket.php rename to src/pocketmine/network/mcpe/protocol/FullChunkDataPacket.php index 171719c82..6610492b6 100644 --- a/src/pocketmine/network/protocol/FullChunkDataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/FullChunkDataPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class FullChunkDataPacket extends DataPacket{ - const NETWORK_ID = Info::FULL_CHUNK_DATA_PACKET; + const NETWORK_ID = ProtocolInfo::FULL_CHUNK_DATA_PACKET; public $chunkX; public $chunkZ; @@ -44,7 +44,7 @@ class FullChunkDataPacket extends DataPacket{ $this->putString($this->data); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleFullChunkData($this); } diff --git a/src/pocketmine/network/protocol/HurtArmorPacket.php b/src/pocketmine/network/mcpe/protocol/HurtArmorPacket.php similarity index 82% rename from src/pocketmine/network/protocol/HurtArmorPacket.php rename to src/pocketmine/network/mcpe/protocol/HurtArmorPacket.php index 5c6265935..644c0bf82 100644 --- a/src/pocketmine/network/protocol/HurtArmorPacket.php +++ b/src/pocketmine/network/mcpe/protocol/HurtArmorPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class HurtArmorPacket extends DataPacket{ - const NETWORK_ID = Info::HURT_ARMOR_PACKET; + const NETWORK_ID = ProtocolInfo::HURT_ARMOR_PACKET; public $health; @@ -40,7 +40,7 @@ class HurtArmorPacket extends DataPacket{ $this->putVarInt($this->health); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleHurtArmor($this); } diff --git a/src/pocketmine/network/protocol/InteractPacket.php b/src/pocketmine/network/mcpe/protocol/InteractPacket.php similarity index 85% rename from src/pocketmine/network/protocol/InteractPacket.php rename to src/pocketmine/network/mcpe/protocol/InteractPacket.php index 4200e9ee6..08c026112 100644 --- a/src/pocketmine/network/protocol/InteractPacket.php +++ b/src/pocketmine/network/mcpe/protocol/InteractPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class InteractPacket extends DataPacket{ - const NETWORK_ID = Info::INTERACT_PACKET; + const NETWORK_ID = ProtocolInfo::INTERACT_PACKET; const ACTION_RIGHT_CLICK = 1; const ACTION_LEFT_CLICK = 2; @@ -48,7 +48,7 @@ class InteractPacket extends DataPacket{ $this->putEntityId($this->target); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleInteract($this); } diff --git a/src/pocketmine/network/protocol/InventoryActionPacket.php b/src/pocketmine/network/mcpe/protocol/InventoryActionPacket.php similarity index 82% rename from src/pocketmine/network/protocol/InventoryActionPacket.php rename to src/pocketmine/network/mcpe/protocol/InventoryActionPacket.php index 86cb3db3a..ac13818f7 100644 --- a/src/pocketmine/network/protocol/InventoryActionPacket.php +++ b/src/pocketmine/network/mcpe/protocol/InventoryActionPacket.php @@ -19,14 +19,14 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class InventoryActionPacket extends DataPacket{ - const NETWORK_ID = Info::INVENTORY_ACTION_PACKET; + const NETWORK_ID = ProtocolInfo::INVENTORY_ACTION_PACKET; public $unknown; public $item; @@ -40,7 +40,7 @@ class InventoryActionPacket extends DataPacket{ $this->putSlot($this->item); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleInventoryAction($this); } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/ItemFrameDropItemPacket.php b/src/pocketmine/network/mcpe/protocol/ItemFrameDropItemPacket.php similarity index 82% rename from src/pocketmine/network/protocol/ItemFrameDropItemPacket.php rename to src/pocketmine/network/mcpe/protocol/ItemFrameDropItemPacket.php index 4dc3bb8ba..e9cca9b7e 100644 --- a/src/pocketmine/network/protocol/ItemFrameDropItemPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ItemFrameDropItemPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class ItemFrameDropItemPacket extends DataPacket{ - const NETWORK_ID = Info::ITEM_FRAME_DROP_ITEM_PACKET; + const NETWORK_ID = ProtocolInfo::ITEM_FRAME_DROP_ITEM_PACKET; public $x; public $y; @@ -41,7 +41,7 @@ class ItemFrameDropItemPacket extends DataPacket{ } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleItemFrameDropItem($this); } diff --git a/src/pocketmine/network/protocol/LevelEventPacket.php b/src/pocketmine/network/mcpe/protocol/LevelEventPacket.php similarity index 93% rename from src/pocketmine/network/protocol/LevelEventPacket.php rename to src/pocketmine/network/mcpe/protocol/LevelEventPacket.php index 0ff2677ee..a044a9954 100644 --- a/src/pocketmine/network/protocol/LevelEventPacket.php +++ b/src/pocketmine/network/mcpe/protocol/LevelEventPacket.php @@ -19,14 +19,14 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class LevelEventPacket extends DataPacket{ - const NETWORK_ID = Info::LEVEL_EVENT_PACKET; + const NETWORK_ID = ProtocolInfo::LEVEL_EVENT_PACKET; const EVENT_SOUND_CLICK = 1000; const EVENT_SOUND_CLICK_FAIL = 1001; @@ -109,7 +109,7 @@ class LevelEventPacket extends DataPacket{ $this->putVarInt($this->data); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleLevelEvent($this); } diff --git a/src/pocketmine/network/protocol/LevelSoundEventPacket.php b/src/pocketmine/network/mcpe/protocol/LevelSoundEventPacket.php similarity index 95% rename from src/pocketmine/network/protocol/LevelSoundEventPacket.php rename to src/pocketmine/network/mcpe/protocol/LevelSoundEventPacket.php index 357a8913f..f55d936fa 100644 --- a/src/pocketmine/network/protocol/LevelSoundEventPacket.php +++ b/src/pocketmine/network/mcpe/protocol/LevelSoundEventPacket.php @@ -19,14 +19,14 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class LevelSoundEventPacket extends DataPacket{ - const NETWORK_ID = Info::LEVEL_SOUND_EVENT_PACKET; + const NETWORK_ID = ProtocolInfo::LEVEL_SOUND_EVENT_PACKET; const SOUND_ITEM_USE_ON = 0; const SOUND_HIT = 1; @@ -149,7 +149,7 @@ class LevelSoundEventPacket extends DataPacket{ $this->putBool($this->unknownBool2); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleLevelSoundEvent($this); } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/LoginPacket.php b/src/pocketmine/network/mcpe/protocol/LoginPacket.php similarity index 90% rename from src/pocketmine/network/protocol/LoginPacket.php rename to src/pocketmine/network/mcpe/protocol/LoginPacket.php index dfd1d0fef..462388d4a 100644 --- a/src/pocketmine/network/protocol/LoginPacket.php +++ b/src/pocketmine/network/mcpe/protocol/LoginPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class LoginPacket extends DataPacket{ - const NETWORK_ID = Info::LOGIN_PACKET; + const NETWORK_ID = ProtocolInfo::LOGIN_PACKET; const EDITION_POCKET = 0; @@ -47,7 +47,7 @@ class LoginPacket extends DataPacket{ public function decode(){ $this->protocol = $this->getInt(); - if($this->protocol !== Info::CURRENT_PROTOCOL){ + if($this->protocol !== ProtocolInfo::CURRENT_PROTOCOL){ $this->buffer = null; return; //Do not attempt to decode for non-accepted protocols } @@ -96,7 +96,7 @@ class LoginPacket extends DataPacket{ return json_decode(base64_decode($payloadB64), true); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleLogin($this); } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/MobArmorEquipmentPacket.php b/src/pocketmine/network/mcpe/protocol/MobArmorEquipmentPacket.php similarity index 86% rename from src/pocketmine/network/protocol/MobArmorEquipmentPacket.php rename to src/pocketmine/network/mcpe/protocol/MobArmorEquipmentPacket.php index 0f5c8bf75..8464ad9c4 100644 --- a/src/pocketmine/network/protocol/MobArmorEquipmentPacket.php +++ b/src/pocketmine/network/mcpe/protocol/MobArmorEquipmentPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class MobArmorEquipmentPacket extends DataPacket{ - const NETWORK_ID = Info::MOB_ARMOR_EQUIPMENT_PACKET; + const NETWORK_ID = ProtocolInfo::MOB_ARMOR_EQUIPMENT_PACKET; public $eid; public $slots = []; @@ -49,7 +49,7 @@ class MobArmorEquipmentPacket extends DataPacket{ $this->putSlot($this->slots[3]); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleMobArmorEquipment($this); } diff --git a/src/pocketmine/network/protocol/MobEffectPacket.php b/src/pocketmine/network/mcpe/protocol/MobEffectPacket.php similarity index 86% rename from src/pocketmine/network/protocol/MobEffectPacket.php rename to src/pocketmine/network/mcpe/protocol/MobEffectPacket.php index 266af8daa..512a25d3d 100644 --- a/src/pocketmine/network/protocol/MobEffectPacket.php +++ b/src/pocketmine/network/mcpe/protocol/MobEffectPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class MobEffectPacket extends DataPacket{ - const NETWORK_ID = Info::MOB_EFFECT_PACKET; + const NETWORK_ID = ProtocolInfo::MOB_EFFECT_PACKET; const EVENT_ADD = 1; const EVENT_MODIFY = 2; @@ -54,7 +54,7 @@ class MobEffectPacket extends DataPacket{ $this->putVarInt($this->duration); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleMobEffect($this); } diff --git a/src/pocketmine/network/protocol/MobEquipmentPacket.php b/src/pocketmine/network/mcpe/protocol/MobEquipmentPacket.php similarity index 87% rename from src/pocketmine/network/protocol/MobEquipmentPacket.php rename to src/pocketmine/network/mcpe/protocol/MobEquipmentPacket.php index c43241760..7091181e5 100644 --- a/src/pocketmine/network/protocol/MobEquipmentPacket.php +++ b/src/pocketmine/network/mcpe/protocol/MobEquipmentPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class MobEquipmentPacket extends DataPacket{ - const NETWORK_ID = Info::MOB_EQUIPMENT_PACKET; + const NETWORK_ID = ProtocolInfo::MOB_EQUIPMENT_PACKET; public $eid; public $item; @@ -52,7 +52,7 @@ class MobEquipmentPacket extends DataPacket{ $this->putByte($this->unknownByte); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleMobEquipment($this); } diff --git a/src/pocketmine/network/protocol/MoveEntityPacket.php b/src/pocketmine/network/mcpe/protocol/MoveEntityPacket.php similarity index 87% rename from src/pocketmine/network/protocol/MoveEntityPacket.php rename to src/pocketmine/network/mcpe/protocol/MoveEntityPacket.php index b04f9881d..1f7d0e9ff 100644 --- a/src/pocketmine/network/protocol/MoveEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/MoveEntityPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class MoveEntityPacket extends DataPacket{ - const NETWORK_ID = Info::MOVE_ENTITY_PACKET; + const NETWORK_ID = ProtocolInfo::MOVE_ENTITY_PACKET; public $eid; public $x; @@ -54,7 +54,7 @@ class MoveEntityPacket extends DataPacket{ $this->putByte($this->headYaw / (360.0 / 256)); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleMoveEntity($this); } diff --git a/src/pocketmine/network/protocol/MovePlayerPacket.php b/src/pocketmine/network/mcpe/protocol/MovePlayerPacket.php similarity index 89% rename from src/pocketmine/network/protocol/MovePlayerPacket.php rename to src/pocketmine/network/mcpe/protocol/MovePlayerPacket.php index ad3e3ce33..608dbd94b 100644 --- a/src/pocketmine/network/protocol/MovePlayerPacket.php +++ b/src/pocketmine/network/mcpe/protocol/MovePlayerPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class MovePlayerPacket extends DataPacket{ - const NETWORK_ID = Info::MOVE_PLAYER_PACKET; + const NETWORK_ID = ProtocolInfo::MOVE_PLAYER_PACKET; const MODE_NORMAL = 0; const MODE_RESET = 1; @@ -64,7 +64,7 @@ class MovePlayerPacket extends DataPacket{ $this->putBool($this->onGround); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleMovePlayer($this); } diff --git a/src/pocketmine/network/protocol/PlayStatusPacket.php b/src/pocketmine/network/mcpe/protocol/PlayStatusPacket.php similarity index 84% rename from src/pocketmine/network/protocol/PlayStatusPacket.php rename to src/pocketmine/network/mcpe/protocol/PlayStatusPacket.php index 0a4dee85f..47ac4e574 100644 --- a/src/pocketmine/network/protocol/PlayStatusPacket.php +++ b/src/pocketmine/network/mcpe/protocol/PlayStatusPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class PlayStatusPacket extends DataPacket{ - const NETWORK_ID = Info::PLAY_STATUS_PACKET; + const NETWORK_ID = ProtocolInfo::PLAY_STATUS_PACKET; const LOGIN_SUCCESS = 0; const LOGIN_FAILED_CLIENT = 1; @@ -47,7 +47,7 @@ class PlayStatusPacket extends DataPacket{ $this->putInt($this->status); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handlePlayStatus($this); } diff --git a/src/pocketmine/network/protocol/PlayerActionPacket.php b/src/pocketmine/network/mcpe/protocol/PlayerActionPacket.php similarity index 89% rename from src/pocketmine/network/protocol/PlayerActionPacket.php rename to src/pocketmine/network/mcpe/protocol/PlayerActionPacket.php index bc15bddda..741d5a035 100644 --- a/src/pocketmine/network/protocol/PlayerActionPacket.php +++ b/src/pocketmine/network/mcpe/protocol/PlayerActionPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class PlayerActionPacket extends DataPacket{ - const NETWORK_ID = Info::PLAYER_ACTION_PACKET; + const NETWORK_ID = ProtocolInfo::PLAYER_ACTION_PACKET; const ACTION_START_BREAK = 0; const ACTION_ABORT_BREAK = 1; @@ -69,7 +69,7 @@ class PlayerActionPacket extends DataPacket{ $this->putVarInt($this->face); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handlePlayerAction($this); } diff --git a/src/pocketmine/network/protocol/PlayerFallPacket.php b/src/pocketmine/network/mcpe/protocol/PlayerFallPacket.php similarity index 82% rename from src/pocketmine/network/protocol/PlayerFallPacket.php rename to src/pocketmine/network/mcpe/protocol/PlayerFallPacket.php index fd6d324b6..d254f21ed 100644 --- a/src/pocketmine/network/protocol/PlayerFallPacket.php +++ b/src/pocketmine/network/mcpe/protocol/PlayerFallPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class PlayerFallPacket extends DataPacket{ - const NETWORK_ID = Info::PLAYER_FALL_PACKET; + const NETWORK_ID = ProtocolInfo::PLAYER_FALL_PACKET; public $fallDistance; @@ -39,7 +39,7 @@ class PlayerFallPacket extends DataPacket{ } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handlePlayerFall($this); } } diff --git a/src/pocketmine/network/protocol/PlayerInputPacket.php b/src/pocketmine/network/mcpe/protocol/PlayerInputPacket.php similarity index 84% rename from src/pocketmine/network/protocol/PlayerInputPacket.php rename to src/pocketmine/network/mcpe/protocol/PlayerInputPacket.php index df746b253..f80d636c4 100644 --- a/src/pocketmine/network/protocol/PlayerInputPacket.php +++ b/src/pocketmine/network/mcpe/protocol/PlayerInputPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class PlayerInputPacket extends DataPacket{ - const NETWORK_ID = Info::PLAYER_INPUT_PACKET; + const NETWORK_ID = ProtocolInfo::PLAYER_INPUT_PACKET; public $motionX; public $motionY; @@ -45,7 +45,7 @@ class PlayerInputPacket extends DataPacket{ } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handlePlayerInput($this); } diff --git a/src/pocketmine/network/protocol/PlayerListPacket.php b/src/pocketmine/network/mcpe/protocol/PlayerListPacket.php similarity index 87% rename from src/pocketmine/network/protocol/PlayerListPacket.php rename to src/pocketmine/network/mcpe/protocol/PlayerListPacket.php index eb0cbf49e..bca812beb 100644 --- a/src/pocketmine/network/protocol/PlayerListPacket.php +++ b/src/pocketmine/network/mcpe/protocol/PlayerListPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class PlayerListPacket extends DataPacket{ - const NETWORK_ID = Info::PLAYER_LIST_PACKET; + const NETWORK_ID = ProtocolInfo::PLAYER_LIST_PACKET; const TYPE_ADD = 0; const TYPE_REMOVE = 1; @@ -63,7 +63,7 @@ class PlayerListPacket extends DataPacket{ } } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handlePlayerList($this); } diff --git a/src/pocketmine/network/protocol/Info.php b/src/pocketmine/network/mcpe/protocol/ProtocolInfo.php similarity index 98% rename from src/pocketmine/network/protocol/Info.php rename to src/pocketmine/network/mcpe/protocol/ProtocolInfo.php index 644191ae9..5ef62ca06 100644 --- a/src/pocketmine/network/protocol/Info.php +++ b/src/pocketmine/network/mcpe/protocol/ProtocolInfo.php @@ -22,10 +22,10 @@ /** * Minecraft: PE multiplayer protocol implementation */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; -interface Info{ +interface ProtocolInfo{ /** * Actual Minecraft: PE protocol version diff --git a/src/pocketmine/network/protocol/RemoveBlockPacket.php b/src/pocketmine/network/mcpe/protocol/RemoveBlockPacket.php similarity index 82% rename from src/pocketmine/network/protocol/RemoveBlockPacket.php rename to src/pocketmine/network/mcpe/protocol/RemoveBlockPacket.php index f9b7281a1..d9312cb1a 100644 --- a/src/pocketmine/network/protocol/RemoveBlockPacket.php +++ b/src/pocketmine/network/mcpe/protocol/RemoveBlockPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class RemoveBlockPacket extends DataPacket{ - const NETWORK_ID = Info::REMOVE_BLOCK_PACKET; + const NETWORK_ID = ProtocolInfo::REMOVE_BLOCK_PACKET; public $x; public $y; @@ -41,7 +41,7 @@ class RemoveBlockPacket extends DataPacket{ } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleRemoveBlock($this); } diff --git a/src/pocketmine/network/protocol/RemoveEntityPacket.php b/src/pocketmine/network/mcpe/protocol/RemoveEntityPacket.php similarity index 82% rename from src/pocketmine/network/protocol/RemoveEntityPacket.php rename to src/pocketmine/network/mcpe/protocol/RemoveEntityPacket.php index 250a15e89..8ec65467e 100644 --- a/src/pocketmine/network/protocol/RemoveEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/RemoveEntityPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class RemoveEntityPacket extends DataPacket{ - const NETWORK_ID = Info::REMOVE_ENTITY_PACKET; + const NETWORK_ID = ProtocolInfo::REMOVE_ENTITY_PACKET; public $eid; @@ -40,7 +40,7 @@ class RemoveEntityPacket extends DataPacket{ $this->putEntityId($this->eid); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleRemoveEntity($this); } diff --git a/src/pocketmine/network/protocol/ReplaceItemInSlotPacket.php b/src/pocketmine/network/mcpe/protocol/ReplaceItemInSlotPacket.php similarity index 81% rename from src/pocketmine/network/protocol/ReplaceItemInSlotPacket.php rename to src/pocketmine/network/mcpe/protocol/ReplaceItemInSlotPacket.php index af0ac6d51..1a2c9317b 100644 --- a/src/pocketmine/network/protocol/ReplaceItemInSlotPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ReplaceItemInSlotPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class ReplaceItemInSlotPacket extends DataPacket{ - const NETWORK_ID = Info::REPLACE_ITEM_IN_SLOT_PACKET; + const NETWORK_ID = ProtocolInfo::REPLACE_ITEM_IN_SLOT_PACKET; public $item; @@ -40,7 +40,7 @@ class ReplaceItemInSlotPacket extends DataPacket{ $this->putSlot($this->item); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleReplaceItemInSlot($this); } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/RequestChunkRadiusPacket.php b/src/pocketmine/network/mcpe/protocol/RequestChunkRadiusPacket.php similarity index 81% rename from src/pocketmine/network/protocol/RequestChunkRadiusPacket.php rename to src/pocketmine/network/mcpe/protocol/RequestChunkRadiusPacket.php index 35d728010..5a3d1bbe6 100644 --- a/src/pocketmine/network/protocol/RequestChunkRadiusPacket.php +++ b/src/pocketmine/network/mcpe/protocol/RequestChunkRadiusPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class RequestChunkRadiusPacket extends DataPacket{ - const NETWORK_ID = Info::REQUEST_CHUNK_RADIUS_PACKET; + const NETWORK_ID = ProtocolInfo::REQUEST_CHUNK_RADIUS_PACKET; public $radius; @@ -39,7 +39,7 @@ class RequestChunkRadiusPacket extends DataPacket{ } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleRequestChunkRadius($this); } diff --git a/src/pocketmine/network/protocol/ResourcePackClientResponsePacket.php b/src/pocketmine/network/mcpe/protocol/ResourcePackClientResponsePacket.php similarity index 86% rename from src/pocketmine/network/protocol/ResourcePackClientResponsePacket.php rename to src/pocketmine/network/mcpe/protocol/ResourcePackClientResponsePacket.php index d3dfad043..2aa8b14ac 100644 --- a/src/pocketmine/network/protocol/ResourcePackClientResponsePacket.php +++ b/src/pocketmine/network/mcpe/protocol/ResourcePackClientResponsePacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class ResourcePackClientResponsePacket extends DataPacket{ - const NETWORK_ID = Info::RESOURCE_PACK_CLIENT_RESPONSE_PACKET; + const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_CLIENT_RESPONSE_PACKET; const STATUS_REFUSED = 1; const STATUS_SEND_PACKS = 2; @@ -54,7 +54,7 @@ class ResourcePackClientResponsePacket extends DataPacket{ } } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleResourcePackClientResponse($this); } diff --git a/src/pocketmine/network/protocol/ResourcePackStackPacket.php b/src/pocketmine/network/mcpe/protocol/ResourcePackStackPacket.php similarity index 88% rename from src/pocketmine/network/protocol/ResourcePackStackPacket.php rename to src/pocketmine/network/mcpe/protocol/ResourcePackStackPacket.php index 9965a6b77..d2ab98c2e 100644 --- a/src/pocketmine/network/protocol/ResourcePackStackPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ResourcePackStackPacket.php @@ -20,16 +20,16 @@ */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; use pocketmine\resourcepacks\ResourcePackInfoEntry; class ResourcePackStackPacket extends DataPacket{ - const NETWORK_ID = Info::RESOURCE_PACK_STACK_PACKET; + const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_STACK_PACKET; public $mustAccept = false; @@ -41,7 +41,7 @@ class ResourcePackStackPacket extends DataPacket{ public function decode(){ $this->mustAccept = $this->getBool(); $behaviorPackCount = $this->getLShort(); - while($behaviorPackCountCount-- > 0){ + while($behaviorPackCount-- > 0){ $packId = $this->getString(); $version = $this->getString(); $this->behaviorPackStack[] = new ResourcePackInfoEntry($packId, $version); @@ -72,7 +72,7 @@ class ResourcePackStackPacket extends DataPacket{ } } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleResourcePackStack($this); } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/ResourcePacksInfoPacket.php b/src/pocketmine/network/mcpe/protocol/ResourcePacksInfoPacket.php similarity index 91% rename from src/pocketmine/network/protocol/ResourcePacksInfoPacket.php rename to src/pocketmine/network/mcpe/protocol/ResourcePacksInfoPacket.php index e9f247627..8f03c1136 100644 --- a/src/pocketmine/network/protocol/ResourcePacksInfoPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ResourcePacksInfoPacket.php @@ -19,16 +19,16 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; use pocketmine\resourcepacks\ResourcePackInfoEntry; class ResourcePacksInfoPacket extends DataPacket{ - const NETWORK_ID = Info::RESOURCE_PACKS_INFO_PACKET; + const NETWORK_ID = ProtocolInfo::RESOURCE_PACKS_INFO_PACKET; public $mustAccept = false; //if true, forces client to use selected resource packs /** @var ResourcePackInfoEntry[] */ @@ -73,7 +73,7 @@ class ResourcePacksInfoPacket extends DataPacket{ } } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleResourcePacksInfo($this); } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/RespawnPacket.php b/src/pocketmine/network/mcpe/protocol/RespawnPacket.php similarity index 84% rename from src/pocketmine/network/protocol/RespawnPacket.php rename to src/pocketmine/network/mcpe/protocol/RespawnPacket.php index d6da04814..1af41d7e8 100644 --- a/src/pocketmine/network/protocol/RespawnPacket.php +++ b/src/pocketmine/network/mcpe/protocol/RespawnPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class RespawnPacket extends DataPacket{ - const NETWORK_ID = Info::RESPAWN_PACKET; + const NETWORK_ID = ProtocolInfo::RESPAWN_PACKET; public $x; public $y; @@ -46,7 +46,7 @@ class RespawnPacket extends DataPacket{ $this->putLFloat($this->z); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleRespawn($this); } diff --git a/src/pocketmine/network/protocol/RiderJumpPacket.php b/src/pocketmine/network/mcpe/protocol/RiderJumpPacket.php similarity index 83% rename from src/pocketmine/network/protocol/RiderJumpPacket.php rename to src/pocketmine/network/mcpe/protocol/RiderJumpPacket.php index 120bb14b7..f13917fc8 100644 --- a/src/pocketmine/network/protocol/RiderJumpPacket.php +++ b/src/pocketmine/network/mcpe/protocol/RiderJumpPacket.php @@ -20,15 +20,15 @@ */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class RiderJumpPacket extends DataPacket{ - const NETWORK_ID = Info::RIDER_JUMP_PACKET; + const NETWORK_ID = ProtocolInfo::RIDER_JUMP_PACKET; public $unknown; @@ -41,7 +41,7 @@ class RiderJumpPacket extends DataPacket{ $this->putVarInt($this->unknown); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleRiderJump($this); } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/SetCommandsEnabledPacket.php b/src/pocketmine/network/mcpe/protocol/SetCommandsEnabledPacket.php similarity index 82% rename from src/pocketmine/network/protocol/SetCommandsEnabledPacket.php rename to src/pocketmine/network/mcpe/protocol/SetCommandsEnabledPacket.php index 6bf0762cb..7c7529bcb 100644 --- a/src/pocketmine/network/protocol/SetCommandsEnabledPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetCommandsEnabledPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class SetCommandsEnabledPacket extends DataPacket{ - const NETWORK_ID = Info::SET_COMMANDS_ENABLED_PACKET; + const NETWORK_ID = ProtocolInfo::SET_COMMANDS_ENABLED_PACKET; public $enabled; @@ -40,7 +40,7 @@ class SetCommandsEnabledPacket extends DataPacket{ $this->putBool($this->enabled); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleSetCommandsEnabled($this); } diff --git a/src/pocketmine/network/protocol/SetDifficultyPacket.php b/src/pocketmine/network/mcpe/protocol/SetDifficultyPacket.php similarity index 83% rename from src/pocketmine/network/protocol/SetDifficultyPacket.php rename to src/pocketmine/network/mcpe/protocol/SetDifficultyPacket.php index 8d89d33c8..700a37d22 100644 --- a/src/pocketmine/network/protocol/SetDifficultyPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetDifficultyPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class SetDifficultyPacket extends DataPacket{ - const NETWORK_ID = Info::SET_DIFFICULTY_PACKET; + const NETWORK_ID = ProtocolInfo::SET_DIFFICULTY_PACKET; public $difficulty; @@ -40,7 +40,7 @@ class SetDifficultyPacket extends DataPacket{ $this->putUnsignedVarInt($this->difficulty); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleSetDifficulty($this); } diff --git a/src/pocketmine/network/protocol/SetEntityDataPacket.php b/src/pocketmine/network/mcpe/protocol/SetEntityDataPacket.php similarity index 83% rename from src/pocketmine/network/protocol/SetEntityDataPacket.php rename to src/pocketmine/network/mcpe/protocol/SetEntityDataPacket.php index 99fbb572d..705eaec10 100644 --- a/src/pocketmine/network/protocol/SetEntityDataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetEntityDataPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class SetEntityDataPacket extends DataPacket{ - const NETWORK_ID = Info::SET_ENTITY_DATA_PACKET; + const NETWORK_ID = ProtocolInfo::SET_ENTITY_DATA_PACKET; public $eid; public $metadata; @@ -42,7 +42,7 @@ class SetEntityDataPacket extends DataPacket{ $this->putEntityMetadata($this->metadata); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleSetEntityData($this); } } diff --git a/src/pocketmine/network/protocol/SetEntityLinkPacket.php b/src/pocketmine/network/mcpe/protocol/SetEntityLinkPacket.php similarity index 83% rename from src/pocketmine/network/protocol/SetEntityLinkPacket.php rename to src/pocketmine/network/mcpe/protocol/SetEntityLinkPacket.php index fff314e19..288faf95c 100644 --- a/src/pocketmine/network/protocol/SetEntityLinkPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetEntityLinkPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class SetEntityLinkPacket extends DataPacket{ - const NETWORK_ID = Info::SET_ENTITY_LINK_PACKET; + const NETWORK_ID = ProtocolInfo::SET_ENTITY_LINK_PACKET; public $from; public $to; @@ -44,7 +44,7 @@ class SetEntityLinkPacket extends DataPacket{ $this->putByte($this->type); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleSetEntityLink($this); } diff --git a/src/pocketmine/network/protocol/SetEntityMotionPacket.php b/src/pocketmine/network/mcpe/protocol/SetEntityMotionPacket.php similarity index 83% rename from src/pocketmine/network/protocol/SetEntityMotionPacket.php rename to src/pocketmine/network/mcpe/protocol/SetEntityMotionPacket.php index 529fbde53..3b7f2d51e 100644 --- a/src/pocketmine/network/protocol/SetEntityMotionPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetEntityMotionPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class SetEntityMotionPacket extends DataPacket{ - const NETWORK_ID = Info::SET_ENTITY_MOTION_PACKET; + const NETWORK_ID = ProtocolInfo::SET_ENTITY_MOTION_PACKET; public $eid; public $motionX; @@ -44,7 +44,7 @@ class SetEntityMotionPacket extends DataPacket{ $this->putVector3f($this->motionX, $this->motionY, $this->motionZ); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleSetEntityMotion($this); } diff --git a/src/pocketmine/network/protocol/SetHealthPacket.php b/src/pocketmine/network/mcpe/protocol/SetHealthPacket.php similarity index 82% rename from src/pocketmine/network/protocol/SetHealthPacket.php rename to src/pocketmine/network/mcpe/protocol/SetHealthPacket.php index e9efa13fc..cc3d1b582 100644 --- a/src/pocketmine/network/protocol/SetHealthPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetHealthPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class SetHealthPacket extends DataPacket{ - const NETWORK_ID = Info::SET_HEALTH_PACKET; + const NETWORK_ID = ProtocolInfo::SET_HEALTH_PACKET; public $health; @@ -40,7 +40,7 @@ class SetHealthPacket extends DataPacket{ $this->putVarInt($this->health); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleSetHealth($this); } diff --git a/src/pocketmine/network/protocol/SetPlayerGameTypePacket.php b/src/pocketmine/network/mcpe/protocol/SetPlayerGameTypePacket.php similarity index 82% rename from src/pocketmine/network/protocol/SetPlayerGameTypePacket.php rename to src/pocketmine/network/mcpe/protocol/SetPlayerGameTypePacket.php index 31d633ab8..66373af8f 100644 --- a/src/pocketmine/network/protocol/SetPlayerGameTypePacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetPlayerGameTypePacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class SetPlayerGameTypePacket extends DataPacket{ - const NETWORK_ID = Info::SET_PLAYER_GAME_TYPE_PACKET; + const NETWORK_ID = ProtocolInfo::SET_PLAYER_GAME_TYPE_PACKET; public $gamemode; @@ -40,7 +40,7 @@ class SetPlayerGameTypePacket extends DataPacket{ $this->putVarInt($this->gamemode); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleSetPlayerGameType($this); } diff --git a/src/pocketmine/network/protocol/SetSpawnPositionPacket.php b/src/pocketmine/network/mcpe/protocol/SetSpawnPositionPacket.php similarity index 84% rename from src/pocketmine/network/protocol/SetSpawnPositionPacket.php rename to src/pocketmine/network/mcpe/protocol/SetSpawnPositionPacket.php index 1669674f7..086f68ee8 100644 --- a/src/pocketmine/network/protocol/SetSpawnPositionPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetSpawnPositionPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class SetSpawnPositionPacket extends DataPacket{ - const NETWORK_ID = Info::SET_SPAWN_POSITION_PACKET; + const NETWORK_ID = ProtocolInfo::SET_SPAWN_POSITION_PACKET; public $unknown; public $x; @@ -46,7 +46,7 @@ class SetSpawnPositionPacket extends DataPacket{ $this->putBool($this->unknownBool); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleSetSpawnPosition($this); } diff --git a/src/pocketmine/network/protocol/SetTimePacket.php b/src/pocketmine/network/mcpe/protocol/SetTimePacket.php similarity index 83% rename from src/pocketmine/network/protocol/SetTimePacket.php rename to src/pocketmine/network/mcpe/protocol/SetTimePacket.php index c3d78152c..1aa00412c 100644 --- a/src/pocketmine/network/protocol/SetTimePacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetTimePacket.php @@ -19,14 +19,14 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class SetTimePacket extends DataPacket{ - const NETWORK_ID = Info::SET_TIME_PACKET; + const NETWORK_ID = ProtocolInfo::SET_TIME_PACKET; public $time; public $started = true; @@ -41,7 +41,7 @@ class SetTimePacket extends DataPacket{ $this->putBool($this->started); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleSetTime($this); } diff --git a/src/pocketmine/network/protocol/ShowCreditsPacket.php b/src/pocketmine/network/mcpe/protocol/ShowCreditsPacket.php similarity index 84% rename from src/pocketmine/network/protocol/ShowCreditsPacket.php rename to src/pocketmine/network/mcpe/protocol/ShowCreditsPacket.php index 6b5dddaad..ed82bc0e7 100644 --- a/src/pocketmine/network/protocol/ShowCreditsPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ShowCreditsPacket.php @@ -20,15 +20,15 @@ */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class ShowCreditsPacket extends DataPacket{ - const NETWORK_ID = Info::SHOW_CREDITS_PACKET; + const NETWORK_ID = ProtocolInfo::SHOW_CREDITS_PACKET; const STATUS_START_CREDITS = 0; const STATUS_END_CREDITS = 1; @@ -47,7 +47,7 @@ class ShowCreditsPacket extends DataPacket{ $this->putVarInt($this->status); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleShowCredits($this); } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/SpawnExperienceOrbPacket.php b/src/pocketmine/network/mcpe/protocol/SpawnExperienceOrbPacket.php similarity index 83% rename from src/pocketmine/network/protocol/SpawnExperienceOrbPacket.php rename to src/pocketmine/network/mcpe/protocol/SpawnExperienceOrbPacket.php index afc7b8dc2..a29fc4bd9 100644 --- a/src/pocketmine/network/protocol/SpawnExperienceOrbPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SpawnExperienceOrbPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class SpawnExperienceOrbPacket extends DataPacket{ - const NETWORK_ID = Info::SPAWN_EXPERIENCE_ORB_PACKET; + const NETWORK_ID = ProtocolInfo::SPAWN_EXPERIENCE_ORB_PACKET; public $x; public $y; @@ -44,7 +44,7 @@ class SpawnExperienceOrbPacket extends DataPacket{ $this->putVarInt($this->amount); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleSpawnExperienceOrb($this); } } \ No newline at end of file diff --git a/src/pocketmine/network/protocol/StartGamePacket.php b/src/pocketmine/network/mcpe/protocol/StartGamePacket.php similarity index 92% rename from src/pocketmine/network/protocol/StartGamePacket.php rename to src/pocketmine/network/mcpe/protocol/StartGamePacket.php index 6dccecd7e..25d85314b 100644 --- a/src/pocketmine/network/protocol/StartGamePacket.php +++ b/src/pocketmine/network/mcpe/protocol/StartGamePacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class StartGamePacket extends DataPacket{ - const NETWORK_ID = Info::START_GAME_PACKET; + const NETWORK_ID = ProtocolInfo::START_GAME_PACKET; public $entityUniqueId; public $entityRuntimeId; @@ -80,7 +80,7 @@ class StartGamePacket extends DataPacket{ $this->putString($this->worldName); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleStartGame($this); } diff --git a/src/pocketmine/network/protocol/TakeItemEntityPacket.php b/src/pocketmine/network/mcpe/protocol/TakeItemEntityPacket.php similarity index 82% rename from src/pocketmine/network/protocol/TakeItemEntityPacket.php rename to src/pocketmine/network/mcpe/protocol/TakeItemEntityPacket.php index dead24ad9..80d446b6e 100644 --- a/src/pocketmine/network/protocol/TakeItemEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/TakeItemEntityPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class TakeItemEntityPacket extends DataPacket{ - const NETWORK_ID = Info::TAKE_ITEM_ENTITY_PACKET; + const NETWORK_ID = ProtocolInfo::TAKE_ITEM_ENTITY_PACKET; public $target; public $eid; @@ -42,7 +42,7 @@ class TakeItemEntityPacket extends DataPacket{ $this->putEntityId($this->eid); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleTakeItemEntity($this); } } diff --git a/src/pocketmine/network/protocol/TextPacket.php b/src/pocketmine/network/mcpe/protocol/TextPacket.php similarity index 91% rename from src/pocketmine/network/protocol/TextPacket.php rename to src/pocketmine/network/mcpe/protocol/TextPacket.php index 850fd18cd..f0c4d39d6 100644 --- a/src/pocketmine/network/protocol/TextPacket.php +++ b/src/pocketmine/network/mcpe/protocol/TextPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class TextPacket extends DataPacket{ - const NETWORK_ID = Info::TEXT_PACKET; + const NETWORK_ID = ProtocolInfo::TEXT_PACKET; const TYPE_RAW = 0; const TYPE_CHAT = 1; @@ -89,7 +89,7 @@ class TextPacket extends DataPacket{ } } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleText($this); } diff --git a/src/pocketmine/network/protocol/TransferPacket.php b/src/pocketmine/network/mcpe/protocol/TransferPacket.php similarity index 83% rename from src/pocketmine/network/protocol/TransferPacket.php rename to src/pocketmine/network/mcpe/protocol/TransferPacket.php index 0292b74ba..1e6da8000 100644 --- a/src/pocketmine/network/protocol/TransferPacket.php +++ b/src/pocketmine/network/mcpe/protocol/TransferPacket.php @@ -19,14 +19,14 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class TransferPacket extends DataPacket{ - const NETWORK_ID = Info::TRANSFER_PACKET; + const NETWORK_ID = ProtocolInfo::TRANSFER_PACKET; public $address; public $port = 19132; @@ -41,7 +41,7 @@ class TransferPacket extends DataPacket{ $this->putLShort($this->port); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleTransfer($this); } diff --git a/src/pocketmine/network/protocol/UpdateAttributesPacket.php b/src/pocketmine/network/mcpe/protocol/UpdateAttributesPacket.php similarity index 86% rename from src/pocketmine/network/protocol/UpdateAttributesPacket.php rename to src/pocketmine/network/mcpe/protocol/UpdateAttributesPacket.php index f91282803..d3da0bb78 100644 --- a/src/pocketmine/network/protocol/UpdateAttributesPacket.php +++ b/src/pocketmine/network/mcpe/protocol/UpdateAttributesPacket.php @@ -19,16 +19,16 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include use pocketmine\entity\Attribute; -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class UpdateAttributesPacket extends DataPacket{ - const NETWORK_ID = Info::UPDATE_ATTRIBUTES_PACKET; + const NETWORK_ID = ProtocolInfo::UPDATE_ATTRIBUTES_PACKET; public $entityId; @@ -52,7 +52,7 @@ class UpdateAttributesPacket extends DataPacket{ } } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleUpdateAttributes($this); } diff --git a/src/pocketmine/network/protocol/UpdateBlockPacket.php b/src/pocketmine/network/mcpe/protocol/UpdateBlockPacket.php similarity index 87% rename from src/pocketmine/network/protocol/UpdateBlockPacket.php rename to src/pocketmine/network/mcpe/protocol/UpdateBlockPacket.php index 6e557085b..2a29ba5d6 100644 --- a/src/pocketmine/network/protocol/UpdateBlockPacket.php +++ b/src/pocketmine/network/mcpe/protocol/UpdateBlockPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class UpdateBlockPacket extends DataPacket{ - const NETWORK_ID = Info::UPDATE_BLOCK_PACKET; + const NETWORK_ID = ProtocolInfo::UPDATE_BLOCK_PACKET; const FLAG_NONE = 0b0000; const FLAG_NEIGHBORS = 0b0001; @@ -56,7 +56,7 @@ class UpdateBlockPacket extends DataPacket{ $this->putUnsignedVarInt(($this->flags << 4) | $this->blockData); } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleUpdateBlock($this); } diff --git a/src/pocketmine/network/protocol/UseItemPacket.php b/src/pocketmine/network/mcpe/protocol/UseItemPacket.php similarity index 87% rename from src/pocketmine/network/protocol/UseItemPacket.php rename to src/pocketmine/network/mcpe/protocol/UseItemPacket.php index 0aab03f2d..0a2b726bb 100644 --- a/src/pocketmine/network/protocol/UseItemPacket.php +++ b/src/pocketmine/network/mcpe/protocol/UseItemPacket.php @@ -19,15 +19,15 @@ * */ -namespace pocketmine\network\protocol; +namespace pocketmine\network\mcpe\protocol; #include -use pocketmine\network\PocketEditionNetworkSession; +use pocketmine\network\mcpe\NetworkSession; class UseItemPacket extends DataPacket{ - const NETWORK_ID = Info::USE_ITEM_PACKET; + const NETWORK_ID = ProtocolInfo::USE_ITEM_PACKET; public $x; public $y; @@ -57,7 +57,7 @@ class UseItemPacket extends DataPacket{ } - public function handle(PocketEditionNetworkSession $session) : bool{ + public function handle(NetworkSession $session) : bool{ return $session->handleUseItem($this); } diff --git a/src/pocketmine/scheduler/SendUsageTask.php b/src/pocketmine/scheduler/SendUsageTask.php index bd7d3003d..688ed7432 100644 --- a/src/pocketmine/scheduler/SendUsageTask.php +++ b/src/pocketmine/scheduler/SendUsageTask.php @@ -21,7 +21,7 @@ namespace pocketmine\scheduler; -use pocketmine\network\protocol\Info; +use pocketmine\network\mcpe\protocol\ProtocolInfo; use pocketmine\Server; use pocketmine\utils\Utils; use pocketmine\utils\UUID; @@ -58,7 +58,7 @@ class SendUsageTask extends AsyncTask{ "build" => $version->getBuild(), "api" => $server->getApiVersion(), "minecraftVersion" => $server->getVersion(), - "protocol" => Info::CURRENT_PROTOCOL + "protocol" => ProtocolInfo::CURRENT_PROTOCOL ]; $data["system"] = [ diff --git a/src/pocketmine/tile/Furnace.php b/src/pocketmine/tile/Furnace.php index b97b95adb..d0c3e0806 100644 --- a/src/pocketmine/tile/Furnace.php +++ b/src/pocketmine/tile/Furnace.php @@ -35,7 +35,7 @@ use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\ListTag; use pocketmine\nbt\tag\ShortTag; use pocketmine\nbt\tag\StringTag; -use pocketmine\network\protocol\ContainerSetDataPacket; +use pocketmine\network\mcpe\protocol\ContainerSetDataPacket; class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{ /** @var FurnaceInventory */ diff --git a/src/pocketmine/tile/Spawnable.php b/src/pocketmine/tile/Spawnable.php index 07f0ffaa4..33048b00f 100644 --- a/src/pocketmine/tile/Spawnable.php +++ b/src/pocketmine/tile/Spawnable.php @@ -24,7 +24,7 @@ namespace pocketmine\tile; use pocketmine\level\Level; use pocketmine\nbt\NBT; use pocketmine\nbt\tag\CompoundTag; -use pocketmine\network\protocol\BlockEntityDataPacket; +use pocketmine\network\mcpe\protocol\BlockEntityDataPacket; use pocketmine\Player; abstract class Spawnable extends Tile{ From ea0f291cb5b6e2ac188e1f4f5f12a530f9468301 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 27 Feb 2017 11:09:49 +0000 Subject: [PATCH 06/96] Added class method DataPacket->canBeBatched() --- src/pocketmine/network/mcpe/RakLibInterface.php | 2 +- src/pocketmine/network/mcpe/protocol/BatchPacket.php | 4 ++++ src/pocketmine/network/mcpe/protocol/DataPacket.php | 4 ++++ src/pocketmine/network/mcpe/protocol/LoginPacket.php | 4 ++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/network/mcpe/RakLibInterface.php b/src/pocketmine/network/mcpe/RakLibInterface.php index b723c8acb..8045f36b1 100644 --- a/src/pocketmine/network/mcpe/RakLibInterface.php +++ b/src/pocketmine/network/mcpe/RakLibInterface.php @@ -211,7 +211,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{ $pk = $packet->__encapsulatedPacket; } - if(!$immediate and !$needACK and $packet::NETWORK_ID !== ProtocolInfo::BATCH_PACKET + if(!$immediate and !$needACK and $packet->canBeBatched() and Network::$BATCH_THRESHOLD >= 0 and strlen($packet->buffer) >= Network::$BATCH_THRESHOLD){ $this->server->batchPackets([$player], [$packet], true); diff --git a/src/pocketmine/network/mcpe/protocol/BatchPacket.php b/src/pocketmine/network/mcpe/protocol/BatchPacket.php index 6eb101479..4f952548e 100644 --- a/src/pocketmine/network/mcpe/protocol/BatchPacket.php +++ b/src/pocketmine/network/mcpe/protocol/BatchPacket.php @@ -31,6 +31,10 @@ class BatchPacket extends DataPacket{ public $payload; + public function canBeBatched() : bool{ + return false; + } + public function decode(){ $this->payload = $this->getString(); } diff --git a/src/pocketmine/network/mcpe/protocol/DataPacket.php b/src/pocketmine/network/mcpe/protocol/DataPacket.php index 7404f3a76..f06fc6ff7 100644 --- a/src/pocketmine/network/mcpe/protocol/DataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/DataPacket.php @@ -40,6 +40,10 @@ abstract class DataPacket extends BinaryStream{ return $this::NETWORK_ID; } + public function canBeBatched() : bool{ + return true; + } + abstract public function encode(); abstract public function decode(); diff --git a/src/pocketmine/network/mcpe/protocol/LoginPacket.php b/src/pocketmine/network/mcpe/protocol/LoginPacket.php index 462388d4a..e1f732e1a 100644 --- a/src/pocketmine/network/mcpe/protocol/LoginPacket.php +++ b/src/pocketmine/network/mcpe/protocol/LoginPacket.php @@ -44,6 +44,10 @@ class LoginPacket extends DataPacket{ public $clientData = []; + public function canBeBatched() : bool{ + return false; + } + public function decode(){ $this->protocol = $this->getInt(); From 564b50ea33fafc3c12b27496845d3625ac54849b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 27 Feb 2017 12:10:52 +0000 Subject: [PATCH 07/96] Added API methods for validating usernames and skins --- src/pocketmine/Player.php | 45 +++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 1efdb7790..d294567dd 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -199,6 +199,28 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade const SURVIVAL_SLOTS = 36; const CREATIVE_SLOTS = 112; + /** + * Checks a supplied username and checks it is valid. + * @param string $name + * + * @return bool + */ + public static function isValidUserName(string $name) : bool{ + $lname = strtolower($name); + $len = strlen($name); + return $lname !== "rcon" and $lname !== "console" and $len >= 1 and $len <= 16 and preg_match("[^A-Za-z0-9_]", $name) === 0; + } + + /** + * Checks the length of a supplied skin bitmap and returns whether the length is valid. + * @param string $skin + * + * @return bool + */ + public static function isValidSkin(string $skin) : bool{ + return strlen($skin) === 64 * 64 * 4 or strlen($skin) === 64 * 32 * 4; + } + /** @var SourceInterface */ protected $interface; @@ -1916,31 +1938,12 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->uuid = UUID::fromString($packet->clientUUID); $this->rawUUID = $this->uuid->toBinary(); - $valid = true; - $len = strlen($packet->username); - if($len > 16 or $len < 3){ - $valid = false; - } - for($i = 0; $i < $len and $valid; ++$i){ - $c = ord($packet->username{$i}); - if(($c >= ord("a") and $c <= ord("z")) or - ($c >= ord("A") and $c <= ord("Z")) or - ($c >= ord("0") and $c <= ord("9")) or $c === ord("_") - ){ - continue; - } - - $valid = false; - break; - } - - if(!$valid or $this->iusername === "rcon" or $this->iusername === "console"){ + if(!Player::isValidUserName($packet->username)){ $this->close("", "disconnectionScreen.invalidName"); - return true; } - if(strlen($packet->skin) !== 64 * 32 * 4 and strlen($packet->skin) !== 64 * 64 * 4){ + if(!Player::isValidSkin($packet->skin)){ $this->close("", "disconnectionScreen.invalidSkin"); return true; } From d0faf3df917d2d4cab54878a9ac8604c36de6927 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 27 Feb 2017 13:06:27 +0000 Subject: [PATCH 08/96] Added S2C and C2S handshake packet classes and stub handlers TODO: implement encryption Add boilerplate reset() for C2S packet encode This crap really needs fixing --- src/pocketmine/Player.php | 10 ++++ src/pocketmine/network/Network.php | 4 ++ .../network/mcpe/NetworkSession.php | 6 ++- .../ClientToServerHandshakePacket.php | 44 +++++++++++++++++ .../ServerToClientHandshakePacket.php | 49 +++++++++++++++++++ 5 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 src/pocketmine/network/mcpe/protocol/ClientToServerHandshakePacket.php create mode 100644 src/pocketmine/network/mcpe/protocol/ServerToClientHandshakePacket.php diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index d294567dd..8a4536dc3 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -116,6 +116,7 @@ use pocketmine\network\mcpe\protocol\BlockEntityDataPacket; use pocketmine\network\mcpe\protocol\BlockEventPacket; use pocketmine\network\mcpe\protocol\ChangeDimensionPacket; use pocketmine\network\mcpe\protocol\ChunkRadiusUpdatedPacket; +use pocketmine\network\mcpe\protocol\ClientToServerHandshakePacket; use pocketmine\network\mcpe\protocol\CommandStepPacket; use pocketmine\network\mcpe\protocol\ContainerClosePacket; use pocketmine\network\mcpe\protocol\ContainerOpenPacket; @@ -157,6 +158,7 @@ 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\ServerToClientHandshakePacket; use pocketmine\network\mcpe\protocol\SetCommandsEnabledPacket; use pocketmine\network\mcpe\protocol\SetDifficultyPacket; use pocketmine\network\mcpe\protocol\SetEntityDataPacket; @@ -1966,6 +1968,14 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade 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; } diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index f29cc153b..8dff1ebd4 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -38,6 +38,7 @@ use pocketmine\network\mcpe\protocol\BlockEntityDataPacket; use pocketmine\network\mcpe\protocol\BlockEventPacket; use pocketmine\network\mcpe\protocol\ChangeDimensionPacket; use pocketmine\network\mcpe\protocol\ChunkRadiusUpdatedPacket; +use pocketmine\network\mcpe\protocol\ClientToServerHandshakePacket; use pocketmine\network\mcpe\protocol\CommandStepPacket; use pocketmine\network\mcpe\protocol\ContainerClosePacket; use pocketmine\network\mcpe\protocol\ContainerOpenPacket; @@ -77,6 +78,7 @@ use pocketmine\network\mcpe\protocol\ResourcePackClientResponsePacket; use pocketmine\network\mcpe\protocol\ResourcePacksInfoPacket; use pocketmine\network\mcpe\protocol\RespawnPacket; use pocketmine\network\mcpe\protocol\RiderJumpPacket; +use pocketmine\network\mcpe\protocol\ServerToClientHandshakePacket; use pocketmine\network\mcpe\protocol\SetCommandsEnabledPacket; use pocketmine\network\mcpe\protocol\SetDifficultyPacket; use pocketmine\network\mcpe\protocol\SetEntityDataPacket; @@ -321,6 +323,7 @@ class Network{ $this->registerPacket(ProtocolInfo::BLOCK_EVENT_PACKET, BlockEventPacket::class); $this->registerPacket(ProtocolInfo::CHANGE_DIMENSION_PACKET, ChangeDimensionPacket::class); $this->registerPacket(ProtocolInfo::CHUNK_RADIUS_UPDATED_PACKET, ChunkRadiusUpdatedPacket::class); + $this->registerPacket(ProtocolInfo::CLIENT_TO_SERVER_HANDSHAKE_PACKET, ClientToServerHandshakePacket::class); $this->registerPacket(ProtocolInfo::COMMAND_STEP_PACKET, CommandStepPacket::class); $this->registerPacket(ProtocolInfo::CONTAINER_CLOSE_PACKET, ContainerClosePacket::class); $this->registerPacket(ProtocolInfo::CONTAINER_OPEN_PACKET, ContainerOpenPacket::class); @@ -358,6 +361,7 @@ class Network{ $this->registerPacket(ProtocolInfo::RESOURCE_PACKS_INFO_PACKET, ResourcePacksInfoPacket::class); $this->registerPacket(ProtocolInfo::RESPAWN_PACKET, RespawnPacket::class); $this->registerPacket(ProtocolInfo::RIDER_JUMP_PACKET, RiderJumpPacket::class); + $this->registerPacket(ProtocolInfo::SERVER_TO_CLIENT_HANDSHAKE_PACKET, ServerToClientHandshakePacket::class); $this->registerPacket(ProtocolInfo::SET_COMMANDS_ENABLED_PACKET, SetCommandsEnabledPacket::class); $this->registerPacket(ProtocolInfo::SET_DIFFICULTY_PACKET, SetDifficultyPacket::class); $this->registerPacket(ProtocolInfo::SET_ENTITY_DATA_PACKET, SetEntityDataPacket::class); diff --git a/src/pocketmine/network/mcpe/NetworkSession.php b/src/pocketmine/network/mcpe/NetworkSession.php index bb86fe2d8..89b91b488 100644 --- a/src/pocketmine/network/mcpe/NetworkSession.php +++ b/src/pocketmine/network/mcpe/NetworkSession.php @@ -37,6 +37,7 @@ use pocketmine\network\mcpe\protocol\BlockEntityDataPacket; use pocketmine\network\mcpe\protocol\BlockEventPacket; use pocketmine\network\mcpe\protocol\ChangeDimensionPacket; use pocketmine\network\mcpe\protocol\ChunkRadiusUpdatedPacket; +use pocketmine\network\mcpe\protocol\ClientToServerHandshakePacket; use pocketmine\network\mcpe\protocol\CommandStepPacket; use pocketmine\network\mcpe\protocol\ContainerClosePacket; use pocketmine\network\mcpe\protocol\ContainerOpenPacket; @@ -76,6 +77,7 @@ 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\ServerToClientHandshakePacket; use pocketmine\network\mcpe\protocol\SetCommandsEnabledPacket; use pocketmine\network\mcpe\protocol\SetDifficultyPacket; use pocketmine\network\mcpe\protocol\SetEntityDataPacket; @@ -101,9 +103,9 @@ interface NetworkSession{ public function handlePlayStatus(PlayStatusPacket $packet) : bool; - //public function handleServerToClientHandshake(ServerToClientHandshakePacket $packet) : bool; //TODO + public function handleServerToClientHandshake(ServerToClientHandshakePacket $packet) : bool; - //public function handleClientToServerHandshake(ClientToServerHandshakePacket $packet) : bool; //TODO + public function handleClientToServerHandshake(ClientToServerHandshakePacket $packet) : bool; public function handleDisconnect(DisconnectPacket $packet) : bool; diff --git a/src/pocketmine/network/mcpe/protocol/ClientToServerHandshakePacket.php b/src/pocketmine/network/mcpe/protocol/ClientToServerHandshakePacket.php new file mode 100644 index 000000000..dcb1d7a49 --- /dev/null +++ b/src/pocketmine/network/mcpe/protocol/ClientToServerHandshakePacket.php @@ -0,0 +1,44 @@ + + + +use pocketmine\network\mcpe\NetworkSession; + +class ClientToServerHandshakePacket extends DataPacket{ + const NETWORK_ID = ProtocolInfo::CLIENT_TO_SERVER_HANDSHAKE_PACKET; + + public function decode(){ + //No payload + } + + public function encode(){ + $this->reset(); + //No payload + } + + public function handle(NetworkSession $session) : bool{ + return $session->handleClientToServerHandshake($this); + } +} diff --git a/src/pocketmine/network/mcpe/protocol/ServerToClientHandshakePacket.php b/src/pocketmine/network/mcpe/protocol/ServerToClientHandshakePacket.php new file mode 100644 index 000000000..5ef9583f1 --- /dev/null +++ b/src/pocketmine/network/mcpe/protocol/ServerToClientHandshakePacket.php @@ -0,0 +1,49 @@ + + + +use pocketmine\network\mcpe\NetworkSession; + +class ServerToClientHandshakePacket extends DataPacket{ + const NETWORK_ID = ProtocolInfo::SERVER_TO_CLIENT_HANDSHAKE_PACKET; + + public $publicKey; + public $serverToken; + + public function decode(){ + $this->publicKey = $this->getString(); + $this->serverToken = $this->getString(); + } + + public function encode(){ + $this->reset(); + $this->putString($this->publicKey); + $this->putString($this->serverToken); + } + + public function handle(NetworkSession $session) : bool{ + return $session->handleServerToClientHandshake($this); + } +} \ No newline at end of file From 5aed0fb0d5960b42f08ccd9d63cf78050a80b3da Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 27 Feb 2017 13:22:29 +0000 Subject: [PATCH 09/96] Remove redundant TODO comment --- .../mcpe/protocol/ResourcePackClientResponsePacket.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/network/mcpe/protocol/ResourcePackClientResponsePacket.php b/src/pocketmine/network/mcpe/protocol/ResourcePackClientResponsePacket.php index 2aa8b14ac..78ced44fb 100644 --- a/src/pocketmine/network/mcpe/protocol/ResourcePackClientResponsePacket.php +++ b/src/pocketmine/network/mcpe/protocol/ResourcePackClientResponsePacket.php @@ -34,7 +34,7 @@ class ResourcePackClientResponsePacket extends DataPacket{ const STATUS_HAVE_ALL_PACKS = 3; const STATUS_COMPLETED = 4; - public $status; //TODO: add constants for status types + public $status; public $packIds = []; public function decode(){ @@ -58,4 +58,4 @@ class ResourcePackClientResponsePacket extends DataPacket{ return $session->handleResourcePackClientResponse($this); } -} \ No newline at end of file +} From e008a3cd5e5a127d627e2e56fa4162396ae35734 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 27 Feb 2017 16:51:02 +0000 Subject: [PATCH 10/96] Added handling for unknown packets --- src/pocketmine/Player.php | 12 +++-- src/pocketmine/network/Network.php | 7 +-- .../network/mcpe/NetworkSession.php | 3 ++ .../network/mcpe/protocol/UnknownPacket.php | 53 +++++++++++++++++++ 4 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 src/pocketmine/network/mcpe/protocol/UnknownPacket.php diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 8a4536dc3..eb6f5a4f7 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -174,6 +174,7 @@ use pocketmine\network\mcpe\protocol\StartGamePacket; use pocketmine\network\mcpe\protocol\TakeItemEntityPacket; use pocketmine\network\mcpe\protocol\TextPacket; use pocketmine\network\mcpe\protocol\TransferPacket; +use pocketmine\network\mcpe\protocol\UnknownPacket; use pocketmine\network\mcpe\protocol\UpdateAttributesPacket; use pocketmine\network\mcpe\protocol\UpdateBlockPacket; use pocketmine\network\mcpe\protocol\UseItemPacket; @@ -3258,12 +3259,13 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return false; } + public function handleUnknown(UnknownPacket $packet) : bool{ + $this->server->getLogger()->debug("Received unknown packet from " . $this->getName() . ": 0x" . bin2hex($packet->payload)); + return true; + } + /** - * Handles a Minecraft packet - * TODO: Separate all of this in handlers - * - * WARNING: Do not use this, it's only for internal use. - * Changes to this function won't be recorded on the version. + * TODO: get rid of these remains, fix DataPacketReceiveEvent, fix timings * * @param DataPacket $packet */ diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index 8dff1ebd4..18fac5c8b 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -94,6 +94,7 @@ use pocketmine\network\mcpe\protocol\StartGamePacket; use pocketmine\network\mcpe\protocol\TakeItemEntityPacket; use pocketmine\network\mcpe\protocol\TextPacket; use pocketmine\network\mcpe\protocol\TransferPacket; +use pocketmine\network\mcpe\protocol\UnknownPacket; use pocketmine\network\mcpe\protocol\UpdateBlockPacket; use pocketmine\network\mcpe\protocol\UseItemPacket; use pocketmine\Player; @@ -245,8 +246,8 @@ class Network{ $buf = $stream->getString(); if(($pk = $this->getPacket(ord($buf{0}))) !== null){ - if($pk::NETWORK_ID === ProtocolInfo::BATCH_PACKET){ - throw new \InvalidStateException("Invalid BatchPacket inside BatchPacket"); + if(!$pk->canBeBatched()){ + throw new \InvalidStateException("Received invalid " . get_class($pk) . " inside BatchPacket"); } $pk->setBuffer($buf, 1); @@ -279,7 +280,7 @@ class Network{ if($class !== null){ return clone $class; } - return null; + return new UnknownPacket(); } diff --git a/src/pocketmine/network/mcpe/NetworkSession.php b/src/pocketmine/network/mcpe/NetworkSession.php index 89b91b488..887666563 100644 --- a/src/pocketmine/network/mcpe/NetworkSession.php +++ b/src/pocketmine/network/mcpe/NetworkSession.php @@ -93,6 +93,7 @@ use pocketmine\network\mcpe\protocol\StartGamePacket; use pocketmine\network\mcpe\protocol\TakeItemEntityPacket; use pocketmine\network\mcpe\protocol\TextPacket; use pocketmine\network\mcpe\protocol\TransferPacket; +use pocketmine\network\mcpe\protocol\UnknownPacket; use pocketmine\network\mcpe\protocol\UpdateAttributesPacket; use pocketmine\network\mcpe\protocol\UpdateBlockPacket; use pocketmine\network\mcpe\protocol\UseItemPacket; @@ -262,4 +263,6 @@ interface NetworkSession{ //public function handleResourcePackChunkRequest(ResourcePackChunkRequestPacket $packet) : bool; //TODO public function handleTransfer(TransferPacket $packet) : bool; + + public function handleUnknown(UnknownPacket $packet) : bool; } \ No newline at end of file diff --git a/src/pocketmine/network/mcpe/protocol/UnknownPacket.php b/src/pocketmine/network/mcpe/protocol/UnknownPacket.php new file mode 100644 index 000000000..87034a35e --- /dev/null +++ b/src/pocketmine/network/mcpe/protocol/UnknownPacket.php @@ -0,0 +1,53 @@ +payload ?? "") > 0){ + return ord($this->payload{0}); + } + return self::NETWORK_ID; + } + + public function decode(){ + $this->offset -= 1; //Rewind one byte so we can read the PID + $this->payload = $this->get(true); + } + + public function encode(){ + //Do not reset the buffer, this class does not have a valid NETWORK_ID constant. + $this->put($this->payload); + } + + public function handle(NetworkSession $session) : bool{ + return $session->handleUnknown($this); + } +} \ No newline at end of file From 667602931904ac37fcbf74cbf1d092afcfe0667a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 27 Feb 2017 19:23:43 +0000 Subject: [PATCH 11/96] Improved some handlers, added detection for no-clip --- src/pocketmine/Player.php | 27 +++++++++++++++++++++------ src/pocketmine/lang/locale | 2 +- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index eb6f5a4f7..d0bccc860 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2414,8 +2414,13 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } } break; + case InteractPacket::ACTION_RIGHT_CLICK: + case InteractPacket::ACTION_LEAVE_VEHICLE: + case InteractPacket::ACTION_MOUSEOVER: + break; //TODO: handle these default: - return false; //TODO: handle other actions + $this->server->getLogger()->debug("Unhandled/unknown interaction type " . $packet->action . "received from ". $this->getName()); + break; } return true; @@ -2733,8 +2738,12 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->setSneaking(false); } return true; + case PlayerActionPacket::ACTION_START_GLIDE: + case PlayerActionPacket::ACTION_STOP_GLIDE: + break; //TODO default: - assert(false, "Unhandled player action " . $packet->action . " from " . $this->getName()); + $this->server->getLogger()->debug("Unhandled/unknown player action type " . $packet->action . " from " . $this->getName()); + break; } $this->startAction = -1; @@ -3106,7 +3115,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade public function handleAdventureSettings(AdventureSettingsPacket $packet) : bool{ if($packet->isFlying and !$this->allowFlight and !$this->server->getAllowFlight()){ - $this->kick("Flying is not enabled on this server"); + $this->kick($this->server->getLanguage()->translateString("kick.reason.cheat", ["%ability.flight"])); return true; }elseif($packet->isFlying !== $this->isFlying()){ $this->server->getPluginManager()->callEvent($ev = new PlayerToggleFlightEvent($this, $packet->isFlying)); @@ -3115,10 +3124,16 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade }else{ $this->flying = $ev->isFlying(); } - return true; - }else{ - return false; } + + if($packet->noClip and !$this->allowMovementCheats and !$this->isSpectator()){ + $this->kick($this->server->getLanguage()->translateString("kick.reason.cheat", ["%ability.noclip"])); + return true; + } + + //TODO: check other changes + + return true; } public function handleBlockEntityData(BlockEntityDataPacket $packet) : bool{ diff --git a/src/pocketmine/lang/locale b/src/pocketmine/lang/locale index 3499fe4a6..55e8fbae3 160000 --- a/src/pocketmine/lang/locale +++ b/src/pocketmine/lang/locale @@ -1 +1 @@ -Subproject commit 3499fe4a6a1973cc965396f184eb01c52de79aa4 +Subproject commit 55e8fbae371c8a48f6dd58333903a302ca2371f4 From 425686755b88ed598643d5bbad8668da3c797b29 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 28 Feb 2017 11:51:00 +0000 Subject: [PATCH 12/96] Added basic resource-pack response handling, fixed sounds, broadcast sounds received from client There are still a lot of sounds which do not work, these are supposed to be sent by the server and will be fixed at a later date. --- src/pocketmine/Player.php | 76 +++++++++---------- .../network/mcpe/protocol/LoginPacket.php | 2 +- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index d0bccc860..486b7bc9c 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -897,9 +897,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $pk->z = $pos->z; $this->dataPacket($pk); - $pk = new PlayStatusPacket(); - $pk->status = PlayStatusPacket::PLAYER_SPAWN; - $this->dataPacket($pk); + $this->sendPlayStatus(PlayStatusPacket::PLAYER_SPAWN); $this->server->getPluginManager()->callEvent($ev = new PlayerJoinEvent($this, new TranslationContainer(TextFormat::YELLOW . "%multiplayer.player.joined", [ @@ -1721,29 +1719,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return ($dot1 - $dot) >= -$maxDiff; } - public function onPlayerPreLogin(){ - //TODO: implement auth - $this->tryAuthenticate(); - } - public function tryAuthenticate(){ - $pk = new PlayStatusPacket(); - $pk->status = PlayStatusPacket::LOGIN_SUCCESS; - $this->dataPacket($pk); - //TODO: implement authentication after it is available - $this->authenticateCallback(true); - } - - public function authenticateCallback($valid){ - - //TODO add more stuff after authentication is available - if(!$valid){ - $this->close("", "disconnectionScreen.invalidSession"); - return; - } - - $this->processLogin(); - } protected function processLogin(){ if(!$this->server->isWhitelisted(strtolower($this->getName()))){ @@ -1837,8 +1813,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->inventory->setHeldItemSlot($this->inventory->getHotbarSlotIndex(0)); } - $this->dataPacket(new ResourcePacksInfoPacket()); - if(!$this->hasValidSpawnPosition() and isset($this->namedtag->SpawnLevel) and ($level = $this->server->getLevelByName($this->namedtag["SpawnLevel"])) instanceof Level){ $this->spawnPosition = new WeakPosition($this->namedtag["SpawnX"], $this->namedtag["SpawnY"], $this->namedtag["SpawnZ"], $level); } @@ -1920,16 +1894,10 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade if($packet->protocol !== ProtocolInfo::CURRENT_PROTOCOL){ if($packet->protocol < ProtocolInfo::CURRENT_PROTOCOL){ $message = "disconnectionScreen.outdatedClient"; - - $pk = new PlayStatusPacket(); - $pk->status = PlayStatusPacket::LOGIN_FAILED_CLIENT; - $this->directDataPacket($pk); + $this->sendPlayStatus(PlayStatusPacket::LOGIN_FAILED_CLIENT, true); }else{ $message = "disconnectionScreen.outdatedServer"; - - $pk = new PlayStatusPacket(); - $pk->status = PlayStatusPacket::LOGIN_FAILED_SERVER; - $this->directDataPacket($pk); + $this->sendPlayStatus(PlayStatusPacket::LOGIN_FAILED_SERVER, true); } $this->close("", $message, false); @@ -1960,7 +1928,12 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return true; } - $this->onPlayerPreLogin(); + //TODO: add JWT verification, add encryption + + $this->sendPlayStatus(PlayStatusPacket::LOGIN_SUCCESS); + + $pk = new ResourcePacksInfoPacket(); + $this->dataPacket($pk); //TODO: add resource packs stuff return true; } @@ -1969,6 +1942,16 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return false; } + public function sendPlayStatus(int $status, bool $immediate = false){ + $pk = new PlayStatusPacket(); + $pk->status = $status; + if($immediate){ + $this->directDataPacket($pk); + }else{ + $this->dataPacket($pk); + } + } + public function handleServerToClientHandshake(ServerToClientHandshakePacket $packet) : bool{ return false; } @@ -1995,7 +1978,22 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } public function handleResourcePackClientResponse(ResourcePackClientResponsePacket $packet) : bool{ - // TODO: Implement resource packs + switch($packet->status){ + case ResourcePackClientResponsePacket::STATUS_REFUSED: + $this->close("", "must accept resource packs to join", true); + break; + case ResourcePackClientResponsePacket::STATUS_SEND_PACKS: + //TODO + break; + case ResourcePackClientResponsePacket::STATUS_HAVE_ALL_PACKS: + $pk = new ResourcePackStackPacket(); + $this->dataPacket($pk); //TODO: send resource stack + break; + case ResourcePackClientResponsePacket::STATUS_COMPLETED: + $this->processLogin(); + break; + } + return true; } @@ -2169,7 +2167,9 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } public function handleLevelSoundEvent(LevelSoundEventPacket $packet) : bool{ - return false; + //TODO: add events so plugins can change this + $this->getLevel()->addChunkPacket($this->chunk->getX(), $this->chunk->getZ(), $packet); + return true; } public function handleLevelEvent(LevelEventPacket $packet) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/LoginPacket.php b/src/pocketmine/network/mcpe/protocol/LoginPacket.php index e1f732e1a..ace691911 100644 --- a/src/pocketmine/network/mcpe/protocol/LoginPacket.php +++ b/src/pocketmine/network/mcpe/protocol/LoginPacket.php @@ -40,7 +40,7 @@ class LoginPacket extends DataPacket{ public $serverAddress; public $skinId; - public $skin = null; + public $skin = ""; public $clientData = []; From 55598ba703445cc1a1597cff9473b1b348d6492a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 2 Mar 2017 14:42:38 +0000 Subject: [PATCH 13/96] Moaaaar resource packets --- src/pocketmine/Player.php | 16 +++++ src/pocketmine/network/Network.php | 6 ++ .../network/mcpe/NetworkSession.php | 9 ++- .../protocol/ResourcePackChunkDataPacket.php | 56 +++++++++++++++++ .../ResourcePackChunkRequestPacket.php | 50 ++++++++++++++++ .../protocol/ResourcePackDataInfoPacket.php | 60 +++++++++++++++++++ 6 files changed, 194 insertions(+), 3 deletions(-) create mode 100644 src/pocketmine/network/mcpe/protocol/ResourcePackChunkDataPacket.php create mode 100644 src/pocketmine/network/mcpe/protocol/ResourcePackChunkRequestPacket.php create mode 100644 src/pocketmine/network/mcpe/protocol/ResourcePackDataInfoPacket.php diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 486b7bc9c..9f14466e9 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -153,7 +153,10 @@ use pocketmine\network\mcpe\protocol\RemoveBlockPacket; use pocketmine\network\mcpe\protocol\RemoveEntityPacket; use pocketmine\network\mcpe\protocol\ReplaceItemInSlotPacket; 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; @@ -182,6 +185,7 @@ use pocketmine\network\SourceInterface; use pocketmine\permission\PermissibleBase; use pocketmine\permission\PermissionAttachment; use pocketmine\plugin\Plugin; +use pocketmine\resourcepacks\ResourcePackInfoEntry; use pocketmine\tile\ItemFrame; use pocketmine\tile\Spawnable; use pocketmine\utils\TextFormat; @@ -3270,6 +3274,18 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return true; } + public function handleResourcePackDataInfo(ResourcePackDataInfoPacket $packet) : bool{ + return false; + } + + public function handleResourcePackChunkData(ResourcePackChunkDataPacket $packet) : bool{ + return false; + } + + public function handleResourcePackChunkRequest(ResourcePackChunkRequestPacket $packet) : bool{ + return false; + } + public function handleTransfer(TransferPacket $packet) : bool{ return false; } diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index 18fac5c8b..3eed90c6c 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -74,7 +74,10 @@ use pocketmine\network\mcpe\protocol\RemoveBlockPacket; use pocketmine\network\mcpe\protocol\RemoveEntityPacket; use pocketmine\network\mcpe\protocol\ReplaceItemInSlotPacket; 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\RespawnPacket; use pocketmine\network\mcpe\protocol\RiderJumpPacket; @@ -358,7 +361,10 @@ class Network{ $this->registerPacket(ProtocolInfo::REMOVE_ENTITY_PACKET, RemoveEntityPacket::class); $this->registerPacket(ProtocolInfo::REPLACE_ITEM_IN_SLOT_PACKET, ReplaceItemInSlotPacket::class); $this->registerPacket(ProtocolInfo::REQUEST_CHUNK_RADIUS_PACKET, RequestChunkRadiusPacket::class); + $this->registerPacket(ProtocolInfo::RESOURCE_PACK_CHUNK_DATA_PACKET, ResourcePackChunkDataPacket::class); + $this->registerPacket(ProtocolInfo::RESOURCE_PACK_CHUNK_REQUEST_PACKET, ResourcePackChunkRequestPacket::class); $this->registerPacket(ProtocolInfo::RESOURCE_PACK_CLIENT_RESPONSE_PACKET, ResourcePackClientResponsePacket::class); + $this->registerPacket(ProtocolInfo::RESOURCE_PACK_DATA_INFO_PACKET, ResourcePackDataInfoPacket::class); $this->registerPacket(ProtocolInfo::RESOURCE_PACKS_INFO_PACKET, ResourcePacksInfoPacket::class); $this->registerPacket(ProtocolInfo::RESPAWN_PACKET, RespawnPacket::class); $this->registerPacket(ProtocolInfo::RIDER_JUMP_PACKET, RiderJumpPacket::class); diff --git a/src/pocketmine/network/mcpe/NetworkSession.php b/src/pocketmine/network/mcpe/NetworkSession.php index 887666563..e655269f5 100644 --- a/src/pocketmine/network/mcpe/NetworkSession.php +++ b/src/pocketmine/network/mcpe/NetworkSession.php @@ -72,7 +72,10 @@ use pocketmine\network\mcpe\protocol\RemoveBlockPacket; use pocketmine\network\mcpe\protocol\RemoveEntityPacket; use pocketmine\network\mcpe\protocol\ReplaceItemInSlotPacket; 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; @@ -256,11 +259,11 @@ interface NetworkSession{ public function handleCommandStep(CommandStepPacket $packet) : bool; - //public function handleResourcePackDataInfo(ResourcePackDataInfoPacket $packet) : bool; //TODO + public function handleResourcePackDataInfo(ResourcePackDataInfoPacket $packet) : bool; - //public function handleResourcePackChunkData(ResourcePackChunkDataPacket $packet) : bool; //TODO + public function handleResourcePackChunkData(ResourcePackChunkDataPacket $packet) : bool; - //public function handleResourcePackChunkRequest(ResourcePackChunkRequestPacket $packet) : bool; //TODO + public function handleResourcePackChunkRequest(ResourcePackChunkRequestPacket $packet) : bool; public function handleTransfer(TransferPacket $packet) : bool; diff --git a/src/pocketmine/network/mcpe/protocol/ResourcePackChunkDataPacket.php b/src/pocketmine/network/mcpe/protocol/ResourcePackChunkDataPacket.php new file mode 100644 index 000000000..1d455d448 --- /dev/null +++ b/src/pocketmine/network/mcpe/protocol/ResourcePackChunkDataPacket.php @@ -0,0 +1,56 @@ + + + +use pocketmine\network\mcpe\NetworkSession; + +class ResourcePackChunkDataPacket extends DataPacket{ + const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_CHUNK_DATA_PACKET; + + public $packId; + public $unknown1; + public $unknown2; + public $data; + + public function decode(){ + $this->packId = $this->getString(); + $this->unknown1 = $this->getLInt(); + $this->unknown2 = $this->getLLong(); + $this->data = $this->get($this->getLInt()); + } + + public function encode(){ + $this->putString($this->packId); + $this->putLInt($this->unknown1); + $this->putLLong($this->unknown2); + $this->putLInt(strlen($this->data)); + $this->put($this->data); + } + + public function handle(NetworkSession $session) : bool{ + $session->handleResourcePackChunkData($this); + } +} \ No newline at end of file diff --git a/src/pocketmine/network/mcpe/protocol/ResourcePackChunkRequestPacket.php b/src/pocketmine/network/mcpe/protocol/ResourcePackChunkRequestPacket.php new file mode 100644 index 000000000..1ae1eac3a --- /dev/null +++ b/src/pocketmine/network/mcpe/protocol/ResourcePackChunkRequestPacket.php @@ -0,0 +1,50 @@ + + + +use pocketmine\network\mcpe\NetworkSession; + +class ResourcePackChunkRequestPacket extends DataPacket{ + const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_CHUNK_REQUEST_PACKET; + + public $packId; + public $unknown; + + public function decode(){ + $this->packId = $this->getString(); + $this->unknown = $this->getLInt(); + } + + public function encode(){ + $this->reset(); + $this->putString($this->packId); + $this->putLInt($this->unknown); + } + + public function handle(NetworkSession $session) : bool{ + $session->handleResourcePackChunkRequest($this); + } +} \ No newline at end of file diff --git a/src/pocketmine/network/mcpe/protocol/ResourcePackDataInfoPacket.php b/src/pocketmine/network/mcpe/protocol/ResourcePackDataInfoPacket.php new file mode 100644 index 000000000..c7afce108 --- /dev/null +++ b/src/pocketmine/network/mcpe/protocol/ResourcePackDataInfoPacket.php @@ -0,0 +1,60 @@ + + + +use pocketmine\network\mcpe\NetworkSession; + +class ResourcePackDataInfoPacket extends DataPacket{ + const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_DATA_INFO_PACKET; + + public $packId; + public $int1; + public $int2; + public $packSize; + public $unknown; + + public function decode(){ + $this->packId = $this->getString(); + $this->int1 = $this->getLInt(); + $this->int2 = $this->getLInt(); + $this->packSize = $this->getLLong(); + $this->unknown = $this->getString(); + } + + public function encode(){ + $this->reset(); + $this->putString($this->packId); + $this->putLInt($this->int1); + $this->putLInt($this->int2); + $this->putLLong($this->packSize); + $this->putString($this->unknown); + } + + public function handle(NetworkSession $session) : bool{ + $session->handleResourcePackDataInfo($this); + } + +} \ No newline at end of file From 9b47aed0abdeb0feb1d575356c77225a61074844 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 2 Mar 2017 19:24:21 +0000 Subject: [PATCH 14/96] Added MapInfoRequestPacket --- src/pocketmine/Player.php | 5 ++ src/pocketmine/network/Network.php | 2 + .../network/mcpe/NetworkSession.php | 3 +- .../mcpe/protocol/MapInfoRequestPacket.php | 47 +++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/pocketmine/network/mcpe/protocol/MapInfoRequestPacket.php diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 9f14466e9..d623805ce 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -132,6 +132,7 @@ use pocketmine\network\mcpe\protocol\EntityEventPacket; use pocketmine\network\mcpe\protocol\ExplodePacket; use pocketmine\network\mcpe\protocol\FullChunkDataPacket; use pocketmine\network\mcpe\protocol\HurtArmorPacket; +use pocketmine\network\mcpe\protocol\MapInfoRequestPacket; use pocketmine\network\mcpe\protocol\ProtocolInfo; use pocketmine\network\mcpe\protocol\InteractPacket; use pocketmine\network\mcpe\protocol\InventoryActionPacket; @@ -3203,6 +3204,10 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return false; //TODO } + public function handleMapInfoRequest(MapInfoRequestPacket $packet) : bool{ + return false; //TODO + } + public function handleRequestChunkRadius(RequestChunkRadiusPacket $packet) : bool{ $this->setViewDistance($packet->radius); diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index 3eed90c6c..663d7de36 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -54,6 +54,7 @@ use pocketmine\network\mcpe\protocol\EntityEventPacket; use pocketmine\network\mcpe\protocol\ExplodePacket; use pocketmine\network\mcpe\protocol\FullChunkDataPacket; use pocketmine\network\mcpe\protocol\HurtArmorPacket; +use pocketmine\network\mcpe\protocol\MapInfoRequestPacket; use pocketmine\network\mcpe\protocol\ProtocolInfo; use pocketmine\network\mcpe\protocol\InteractPacket; use pocketmine\network\mcpe\protocol\InventoryActionPacket; @@ -348,6 +349,7 @@ class Network{ $this->registerPacket(ProtocolInfo::LEVEL_EVENT_PACKET, LevelEventPacket::class); $this->registerPacket(ProtocolInfo::LEVEL_SOUND_EVENT_PACKET, LevelSoundEventPacket::class); $this->registerPacket(ProtocolInfo::LOGIN_PACKET, LoginPacket::class); + $this->registerPacket(ProtocolInfo::MAP_INFO_REQUEST_PACKET, MapInfoRequestPacket::class); $this->registerPacket(ProtocolInfo::MOB_ARMOR_EQUIPMENT_PACKET, MobArmorEquipmentPacket::class); $this->registerPacket(ProtocolInfo::MOB_EQUIPMENT_PACKET, MobEquipmentPacket::class); $this->registerPacket(ProtocolInfo::MOVE_ENTITY_PACKET, MoveEntityPacket::class); diff --git a/src/pocketmine/network/mcpe/NetworkSession.php b/src/pocketmine/network/mcpe/NetworkSession.php index e655269f5..62b12647e 100644 --- a/src/pocketmine/network/mcpe/NetworkSession.php +++ b/src/pocketmine/network/mcpe/NetworkSession.php @@ -58,6 +58,7 @@ use pocketmine\network\mcpe\protocol\ItemFrameDropItemPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; use pocketmine\network\mcpe\protocol\LoginPacket; +use pocketmine\network\mcpe\protocol\MapInfoRequestPacket; use pocketmine\network\mcpe\protocol\MobArmorEquipmentPacket; use pocketmine\network\mcpe\protocol\MobEffectPacket; use pocketmine\network\mcpe\protocol\MobEquipmentPacket; @@ -235,7 +236,7 @@ interface NetworkSession{ //public function handleClientboundMapItemData(ClientboundMapItemDataPacket $packet) : bool; //TODO - //public function handleMapInfoRequest(MapInfoRequestPacket $packet) : bool; //TODO + public function handleMapInfoRequest(MapInfoRequestPacket $packet) : bool; //TODO public function handleRequestChunkRadius(RequestChunkRadiusPacket $packet) : bool; diff --git a/src/pocketmine/network/mcpe/protocol/MapInfoRequestPacket.php b/src/pocketmine/network/mcpe/protocol/MapInfoRequestPacket.php new file mode 100644 index 000000000..98b65a970 --- /dev/null +++ b/src/pocketmine/network/mcpe/protocol/MapInfoRequestPacket.php @@ -0,0 +1,47 @@ + + + +use pocketmine\network\mcpe\NetworkSession; + +class MapInfoRequestPacket extends DataPacket{ + const NETWORK_ID = ProtocolInfo::MAP_INFO_REQUEST_PACKET; + + public $mapId; + + public function decode(){ + $this->mapId = $this->getVarInt(); //signed var-long, actually entity ID (needs fixing) + } + + public function encode(){ + $this->reset(); + $this->putVarInt($this->mapId); + } + + public function handle(NetworkSession $session) : bool{ + return $session->handleMapInfoRequest($this); + } +} \ No newline at end of file From d823ff18d8f091286149f2a42969046b7c501365 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 2 Mar 2017 20:41:12 +0000 Subject: [PATCH 15/96] Bump API version to 3.0.0-ALPHA5 (not finalized) --- src/pocketmine/PocketMine.php | 2 +- tests/plugins/PocketMine-DevTools | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 12aa25c3a..2d9dc1997 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -74,7 +74,7 @@ namespace pocketmine { use raklib\RakLib; const VERSION = "1.6.2dev"; - const API_VERSION = "3.0.0-ALPHA4"; + const API_VERSION = "3.0.0-ALPHA5"; const CODENAME = "Unleashed"; /* diff --git a/tests/plugins/PocketMine-DevTools b/tests/plugins/PocketMine-DevTools index db894896e..dc4e7c35f 160000 --- a/tests/plugins/PocketMine-DevTools +++ b/tests/plugins/PocketMine-DevTools @@ -1 +1 @@ -Subproject commit db894896ee4932a86f8655ca9f8cabef726787b3 +Subproject commit dc4e7c35f287419e3af2352db3f9ed80bddb7bcd From 005c2419e96088728494b7f4431437e1501c4168 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 3 Mar 2017 17:33:30 +0000 Subject: [PATCH 16/96] Fixed batched packets being encoded twice --- src/pocketmine/network/mcpe/RakLibInterface.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pocketmine/network/mcpe/RakLibInterface.php b/src/pocketmine/network/mcpe/RakLibInterface.php index 8045f36b1..e113174b8 100644 --- a/src/pocketmine/network/mcpe/RakLibInterface.php +++ b/src/pocketmine/network/mcpe/RakLibInterface.php @@ -200,6 +200,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{ $pk = null; if(!$packet->isEncoded){ $packet->encode(); + $packet->isEncoded = true; }elseif(!$needACK){ if(!isset($packet->__encapsulatedPacket)){ $packet->__encapsulatedPacket = new CachedEncapsulatedPacket; From 9e92a350e3d2789cd8bb684712f2fa431233f30c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 3 Mar 2017 19:54:50 +0000 Subject: [PATCH 17/96] ClientboundMapItemDataPacket --- src/pocketmine/Player.php | 10 +- src/pocketmine/network/Network.php | 2 + .../network/mcpe/NetworkSession.php | 3 +- .../protocol/ClientboundMapItemDataPacket.php | 149 +++++++++++++++++ src/pocketmine/utils/Color.php | 158 ++++++++++++++++++ 5 files changed, 318 insertions(+), 4 deletions(-) create mode 100644 src/pocketmine/network/mcpe/protocol/ClientboundMapItemDataPacket.php create mode 100644 src/pocketmine/utils/Color.php diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index d623805ce..5c0ac0a95 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -116,6 +116,7 @@ use pocketmine\network\mcpe\protocol\BlockEntityDataPacket; use pocketmine\network\mcpe\protocol\BlockEventPacket; 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\CommandStepPacket; use pocketmine\network\mcpe\protocol\ContainerClosePacket; @@ -132,14 +133,13 @@ use pocketmine\network\mcpe\protocol\EntityEventPacket; use pocketmine\network\mcpe\protocol\ExplodePacket; use pocketmine\network\mcpe\protocol\FullChunkDataPacket; use pocketmine\network\mcpe\protocol\HurtArmorPacket; -use pocketmine\network\mcpe\protocol\MapInfoRequestPacket; -use pocketmine\network\mcpe\protocol\ProtocolInfo; use pocketmine\network\mcpe\protocol\InteractPacket; use pocketmine\network\mcpe\protocol\InventoryActionPacket; use pocketmine\network\mcpe\protocol\ItemFrameDropItemPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; use pocketmine\network\mcpe\protocol\LoginPacket; +use pocketmine\network\mcpe\protocol\MapInfoRequestPacket; use pocketmine\network\mcpe\protocol\MobArmorEquipmentPacket; use pocketmine\network\mcpe\protocol\MobEffectPacket; use pocketmine\network\mcpe\protocol\MobEquipmentPacket; @@ -150,6 +150,7 @@ use pocketmine\network\mcpe\protocol\PlayerFallPacket; use pocketmine\network\mcpe\protocol\PlayerInputPacket; use pocketmine\network\mcpe\protocol\PlayerListPacket; use pocketmine\network\mcpe\protocol\PlayStatusPacket; +use pocketmine\network\mcpe\protocol\ProtocolInfo; use pocketmine\network\mcpe\protocol\RemoveBlockPacket; use pocketmine\network\mcpe\protocol\RemoveEntityPacket; use pocketmine\network\mcpe\protocol\ReplaceItemInSlotPacket; @@ -186,7 +187,6 @@ use pocketmine\network\SourceInterface; use pocketmine\permission\PermissibleBase; use pocketmine\permission\PermissionAttachment; use pocketmine\plugin\Plugin; -use pocketmine\resourcepacks\ResourcePackInfoEntry; use pocketmine\tile\ItemFrame; use pocketmine\tile\Spawnable; use pocketmine\utils\TextFormat; @@ -3204,6 +3204,10 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return false; //TODO } + public function handleClientboundMapItemData(ClientboundMapItemDataPacket $packet) : bool{ + return false; + } + public function handleMapInfoRequest(MapInfoRequestPacket $packet) : bool{ return false; //TODO } diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index 663d7de36..4f5dda94a 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -38,6 +38,7 @@ use pocketmine\network\mcpe\protocol\BlockEntityDataPacket; use pocketmine\network\mcpe\protocol\BlockEventPacket; 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\CommandStepPacket; use pocketmine\network\mcpe\protocol\ContainerClosePacket; @@ -328,6 +329,7 @@ class Network{ $this->registerPacket(ProtocolInfo::BLOCK_EVENT_PACKET, BlockEventPacket::class); $this->registerPacket(ProtocolInfo::CHANGE_DIMENSION_PACKET, ChangeDimensionPacket::class); $this->registerPacket(ProtocolInfo::CHUNK_RADIUS_UPDATED_PACKET, ChunkRadiusUpdatedPacket::class); + $this->registerPacket(ProtocolInfo::CLIENTBOUND_MAP_ITEM_DATA_PACKET, ClientboundMapItemDataPacket::class); $this->registerPacket(ProtocolInfo::CLIENT_TO_SERVER_HANDSHAKE_PACKET, ClientToServerHandshakePacket::class); $this->registerPacket(ProtocolInfo::COMMAND_STEP_PACKET, CommandStepPacket::class); $this->registerPacket(ProtocolInfo::CONTAINER_CLOSE_PACKET, ContainerClosePacket::class); diff --git a/src/pocketmine/network/mcpe/NetworkSession.php b/src/pocketmine/network/mcpe/NetworkSession.php index 62b12647e..62786b8f2 100644 --- a/src/pocketmine/network/mcpe/NetworkSession.php +++ b/src/pocketmine/network/mcpe/NetworkSession.php @@ -37,6 +37,7 @@ use pocketmine\network\mcpe\protocol\BlockEntityDataPacket; use pocketmine\network\mcpe\protocol\BlockEventPacket; 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\CommandStepPacket; use pocketmine\network\mcpe\protocol\ContainerClosePacket; @@ -234,7 +235,7 @@ interface NetworkSession{ public function handleSpawnExperienceOrb(SpawnExperienceOrbPacket $packet) : bool; - //public function handleClientboundMapItemData(ClientboundMapItemDataPacket $packet) : bool; //TODO + public function handleClientboundMapItemData(ClientboundMapItemDataPacket $packet) : bool; public function handleMapInfoRequest(MapInfoRequestPacket $packet) : bool; //TODO diff --git a/src/pocketmine/network/mcpe/protocol/ClientboundMapItemDataPacket.php b/src/pocketmine/network/mcpe/protocol/ClientboundMapItemDataPacket.php new file mode 100644 index 000000000..86f28fae8 --- /dev/null +++ b/src/pocketmine/network/mcpe/protocol/ClientboundMapItemDataPacket.php @@ -0,0 +1,149 @@ + + + +use pocketmine\network\mcpe\NetworkSession; +use pocketmine\utils\Color; + +class ClientboundMapItemDataPacket extends DataPacket{ + const NETWORK_ID = ProtocolInfo::CLIENTBOUND_MAP_ITEM_DATA_PACKET; + + const BITFLAG_TEXTURE_UPDATE = 0x02; + const BITFLAG_DECORATION_UPDATE = 0x04; + + public $mapId; + public $type; + + public $eids = []; + public $scale; + public $decorations = []; + + public $width; + public $height; + public $xOffset = 0; + public $yOffset = 0; + /** @var Color[][] */ + public $colors = []; + + public function decode(){ + $this->mapId = $this->getVarInt(); + $this->type = $this->getUnsignedVarInt(); + + if(($this->type & 0x08) !== 0){ + $count = $this->getUnsignedVarInt(); + for($i = 0; $i < $count; ++$i){ + $this->eids[] = $this->getVarInt(); //entity unique ID, signed var-int + } + } + + if(($this->type & (self::BITFLAG_DECORATION_UPDATE | self::BITFLAG_TEXTURE_UPDATE)) !== 0){ //Decoration bitflag or colour bitflag + $this->scale = $this->getByte(); + } + + if(($this->type & self::BITFLAG_DECORATION_UPDATE) !== 0){ + $count = $this->getUnsignedVarInt(); + for($i = 0; $i < $count; ++$i){ + $weird = $this->getVarInt(); + $this->decorations[$i]["rot"] = $weird & 0x0f; + $this->decorations[$i]["img"] = $weird >> 4; + + $this->decorations[$i]["xOffset"] = $this->getByte(); + $this->decorations[$i]["yOffset"] = $this->getByte(); + $this->decorations[$i]["label"] = $this->getString(); + + $this->decorations[$i]["color"] = Color::fromARGB($this->getLInt()); //already BE, don't need to reverse it again + } + } + + if(($this->type & self::BITFLAG_TEXTURE_UPDATE) !== 0){ + $this->width = $this->getVarInt(); + $this->height = $this->getVarInt(); + $this->xOffset = $this->getVarInt(); + $this->yOffset = $this->getVarInt(); + for($y = 0; $y < $this->height; ++$y){ + for($x = 0; $x < $this->width; ++$x){ + $this->colors[$y][$x] = Color::fromABGR($this->getUnsignedVarInt()); + } + } + } + } + + public function encode(){ + $this->reset(); + $this->putVarInt($this->mapId); //entity unique ID, signed var-int + + $type = 0; + if(($eidsCount = count($this->eids)) > 0){ + $type |= 0x08; + } + if(($decorationCount = count($this->decorations)) > 0){ + $type |= self::BITFLAG_DECORATION_UPDATE; + } + if(count($this->colors) > 0){ + $type |= self::BITFLAG_TEXTURE_UPDATE; + } + + $this->putUnsignedVarInt($type); + + if(($type & 0x08) !== 0){ //TODO: find out what these are for + $this->putUnsignedVarInt($eidsCount); + foreach($this->eids as $eid){ + $this->putVarInt($eid); + } + } + + if(($type & (self::BITFLAG_TEXTURE_UPDATE | self::BITFLAG_DECORATION_UPDATE)) !== 0){ + $this->putByte($this->scale); + } + + if(($type & self::BITFLAG_DECORATION_UPDATE) !== 0){ + $this->putUnsignedVarInt($decorationCount); + foreach($this->decorations as $decoration){ + $this->putVarInt(($decoration["rot"] & 0x0f) | ($decoration["img"] << 4)); + $this->putByte($decoration["xOffset"]); + $this->putByte($decoration["yOffset"]); + $this->putString($decoration["label"]); + $this->putLInt($decoration["color"]->toARGB()); + } + } + + if(($type & self::BITFLAG_TEXTURE_UPDATE) !== 0){ + $this->putVarInt($this->width); + $this->putVarInt($this->height); + $this->putVarInt($this->xOffset); + $this->putVarInt($this->yOffset); + for($y = 0; $y < $this->height; ++$y){ + for($x = 0; $x < $this->width; ++$x){ + $this->putUnsignedVarInt($this->colors[$y][$x]->toABGR()); + } + } + } + } + + public function handle(NetworkSession $session) : bool{ + $session->handleClientboundMapItemData($this); + } +} \ No newline at end of file diff --git a/src/pocketmine/utils/Color.php b/src/pocketmine/utils/Color.php new file mode 100644 index 000000000..6913e7a92 --- /dev/null +++ b/src/pocketmine/utils/Color.php @@ -0,0 +1,158 @@ +r = $r & 0xff; + $this->g = $g & 0xff; + $this->b = $b & 0xff; + $this->a = $a & 0xff; + } + + /** + * Returns the alpha (transparency) value of this colour. + * @return int + */ + public function getA() : int{ + return $this->a; + } + + /** + * Sets the alpha (opacity) value of this colour, lower = more transparent + * @param int $a + */ + public function setA(int $a){ + $this->a = $a & 0xff; + } + + /** + * Retuns the red value of this colour. + * @return int + */ + public function getR() : int{ + return $this->r; + } + + /** + * Sets the red value of this colour. + * @param int $r + */ + public function setR(int $r){ + $this->r = $r & 0xff; + } + + /** + * Returns the green value of this colour. + * @return int + */ + public function getG() : int{ + return $this->g; + } + + /** + * Sets the green value of this colour. + * @param int $g + */ + public function setG(int $g){ + $this->g = $g & 0xff; + } + + /** + * Returns the blue value of this colour. + * @return int + */ + public function getB() : int{ + return $this->b; + } + + /** + * Sets the blue value of this colour. + * @param int $b + */ + public function setB(int $b){ + $this->b = $b & 0xff; + } + + /** + * Returns a Color from the supplied RGB colour code (24-bit) + * @param int $code + * + * @return Color + */ + public static function fromRGB(int $code){ + return new Color(($code >> 16) & 0xff, ($code >> 8) & 0xff, $code & 0xff); + } + + /** + * Returns a Color from the supplied ARGB colour code (32-bit) + * + * @param int $code + * + * @return Color + */ + public static function fromARGB(int $code){ + return new Color(($code >> 16) & 0xff, ($code >> 8) & 0xff, $code & 0xff, ($code >> 24) & 0xff); + } + + /** + * Returns an ARGB 32-bit colour value. + * @return int + */ + public function toARGB() : int{ + return ($this->a << 24) | ($this->r << 16) | ($this->g << 8) | $this->b; + } + + /** + * Returns a little-endian ARGB 32-bit colour value. + * @return int + */ + public function toBGRA() : int{ + return ($this->b << 24) | ($this->g << 16) | ($this->r << 8) | $this->a; + } + + /** + * Returns an RGBA 32-bit colour value. + * @return int + */ + public function toRGBA() : int{ + return ($this->r << 24) | ($this->g << 16) | ($this->b << 8) | $this->a; + } + + /** + * Returns a little-endian RGBA colour value. + * @return int + */ + public function toABGR() : int{ + return ($this->a << 24) | ($this->b << 16) | ($this->g << 8) | $this->r; + } + + public static function fromABGR(int $code){ + return new Color($code & 0xff, ($code >> 8) & 0xff, ($code >> 16) & 0xff, ($code >> 24) & 0xff); + } +} \ No newline at end of file From adb7df212c7b3a3b0707ae4d898412ef38868af5 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 8 Mar 2017 18:31:24 +0000 Subject: [PATCH 18/96] Let the parent caller catch this so we get encapsulated packet hexdumps --- src/pocketmine/network/Network.php | 56 +++++++++++++----------------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index 4f5dda94a..3a548ee50 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -232,44 +232,36 @@ class Network{ } public function processBatch(BatchPacket $packet, Player $p){ - try{ - if(strlen($packet->payload) === 0){ - //prevent zlib_decode errors for incorrectly-decoded packets - throw new \InvalidArgumentException("BatchPacket payload is empty or packet decode error"); - } + if(strlen($packet->payload) === 0){ + //prevent zlib_decode errors for incorrectly-decoded packets + throw new \InvalidArgumentException("BatchPacket payload is empty or packet decode error"); + } - $str = zlib_decode($packet->payload, 1024 * 1024 * 64); //Max 64MB - $len = strlen($str); + $str = zlib_decode($packet->payload, 1024 * 1024 * 64); //Max 64MB + $len = strlen($str); - if($len === 0){ - throw new \InvalidStateException("Decoded BatchPacket payload is empty"); - } + if($len === 0){ + throw new \InvalidStateException("Decoded BatchPacket payload is empty"); + } - $stream = new BinaryStream($str); + $stream = new BinaryStream($str); - while($stream->offset < $len){ - $buf = $stream->getString(); + while($stream->offset < $len){ + $buf = $stream->getString(); - if(($pk = $this->getPacket(ord($buf{0}))) !== null){ - if(!$pk->canBeBatched()){ - throw new \InvalidStateException("Received invalid " . get_class($pk) . " inside BatchPacket"); - } - - $pk->setBuffer($buf, 1); - - $pk->decode(); - assert($pk->feof(), "Still " . strlen(substr($pk->buffer, $pk->offset)) . " bytes unread in " . get_class($pk)); - if(!$pk->handle($p)){ - $logger = $this->server->getLogger(); - $logger->debug("Unhandled " . get_class($pk) . " received from " . $p->getName()); - } + if(($pk = $this->getPacket(ord($buf{0}))) !== null){ + if(!$pk->canBeBatched()){ + throw new \InvalidStateException("Received invalid " . get_class($pk) . " inside BatchPacket"); + } + + $pk->setBuffer($buf, 1); + + $pk->decode(); + assert($pk->feof(), "Still " . strlen(substr($pk->buffer, $pk->offset)) . " bytes unread in " . get_class($pk)); + if(!$pk->handle($p)){ + $logger = $this->server->getLogger(); + $logger->debug("Unhandled " . get_class($pk) . " received from " . $p->getName()); } - } - }catch(\Throwable $e){ - if(\pocketmine\DEBUG > 1){ - $logger = $this->server->getLogger(); - $logger->debug("BatchPacket " . " 0x" . bin2hex($packet->payload)); - $logger->logException($e); } } } From 3a044f0154d004c31d6ebbfd59d85eaa986296c4 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 8 Mar 2017 13:20:10 +0000 Subject: [PATCH 19/96] Added methods for VarLong, limited Binary::readVarInt() to 5-byte numbers --- src/pocketmine/utils/Binary.php | 254 ++++++++++++++++++++++++++++++-- 1 file changed, 243 insertions(+), 11 deletions(-) diff --git a/src/pocketmine/utils/Binary.php b/src/pocketmine/utils/Binary.php index 7899e5383..668c6ed6f 100644 --- a/src/pocketmine/utils/Binary.php +++ b/src/pocketmine/utils/Binary.php @@ -336,8 +336,15 @@ class Binary{ return strrev(self::writeLong($value)); } - //TODO: proper varlong support + + /** + * Reads a 32-bit zigzag-encoded variable-length integer from the supplied stream. + * + * @param \pocketmine\nbt\NBT|BinaryStream $stream + * + * @return int + */ public static function readVarInt($stream){ $shift = PHP_INT_SIZE === 8 ? 63 : 31; $raw = self::readUnsignedVarInt($stream); @@ -345,25 +352,250 @@ class Binary{ return $temp ^ ($raw & (1 << $shift)); } + /** + * Reads a 32-bit variable-length unsigned integer from the supplied stream. + * + * @param \pocketmine\nbt\NBT|BinaryStream $stream + * + * @return int + */ public static function readUnsignedVarInt($stream){ $value = 0; - $i = 0; - do{ - if($i > 63){ - throw new \InvalidArgumentException("Varint did not terminate after 10 bytes!"); - } - $value |= ((($b = $stream->getByte()) & 0x7f) << $i); - $i += 7; - }while($b & 0x80); + for($i = 0; $i <= 35; $i += 7){ + $b = $stream->getByte(); + $value |= (($b & 0x7f) << $i); - return $value; + if(($b & 0x80) === 0){ + return $value; + } + } + + throw new \InvalidArgumentException("VarInt did not terminate after 5 bytes!"); } + /** + * Writes a 32-bit integer as a zigzag-encoded variable-length integer. + * + * @param int $v + * + * @return string + */ public static function writeVarInt($v){ return self::writeUnsignedVarInt(($v << 1) ^ ($v >> (PHP_INT_SIZE === 8 ? 63 : 31))); } + /** + * Writes a 32-bit unsigned integer as a variable-length integer. + * @param int $value + * + * @return string up to 5 bytes + */ public static function writeUnsignedVarInt($value){ + $buf = ""; + for($i = 0; $i < 5; ++$i){ + if(($value >> 7) !== 0){ + $buf .= chr($value | 0x80); //Let chr() take the last byte of this, it's faster than adding another & 0x7f. + }else{ + $buf .= chr($value & 0x7f); + return $buf; + } + + $value = (($value >> 7) & (PHP_INT_MAX >> 6)); //PHP really needs a logical right-shift operator + } + + throw new \InvalidArgumentException("Value too large to be encoded as a VarInt"); + } + + + + /** + * Reads a 64-bit zigzag-encoded variable-length integer from the supplied stream. + * @param \pocketmine\nbt\NBT|BinaryStream $stream + * + * @return int + */ + public static function readVarLong($stream){ + if(PHP_INT_SIZE === 8){ + return self::readVarLong_64($stream); + }else{ + return self::readVarLong_32($stream); + } + } + + /** + * Legacy BC Math zigzag VarLong reader. Will work on 32-bit or 64-bit, but will be slower than the regular 64-bit method. + * @param \pocketmine\nbt\NBT|BinaryStream $stream + * + * @return string + */ + public static function readVarLong_32($stream){ + /** @var string $raw */ + $raw = self::readUnsignedVarLong_32($stream); + $result = bcdiv($raw, "2"); + if(bcmod($raw, "2") === "1"){ + $result = bcsub(bcmul($result, "-1"), "1"); + } + + return $result; + } + + /** + * 64-bit zizgag VarLong reader. + * @param \pocketmine\nbt\NBT|BinaryStream $stream + * + * @return int + */ + public static function readVarLong_64($stream){ + $raw = self::readUnsignedVarLong_64($stream); + $temp = ((($raw << 63) >> 63) ^ $raw) >> 1; + return $temp ^ ($raw & (1 << 63)); + } + + /** + * Reads an unsigned VarLong from the supplied stream. + * @param \pocketmine\nbt\NBT|BinaryStream $stream + * + * @return int|string + */ + public static function readUnsignedVarLong($stream){ + if(PHP_INT_SIZE === 8){ + return self::readUnsignedVarLong_64($stream); + }else{ + return self::readUnsignedVarLong_32($stream); + } + } + + /** + * Legacy BC Math unsigned VarLong reader. + * @param \pocketmine\nbt\NBT|BinaryStream $stream + * + * @return string + */ + public static function readUnsignedVarLong_32($stream){ + $value = "0"; + for($i = 0; $i <= 63; $i += 7){ + $b = $stream->getByte(); + $value = bcadd($value, bcmul($b & 0x7f, bcpow("2", "$i"))); + var_dump($value); + + if(($b & 0x80) === 0){ + return $value; + } + } + + throw new \InvalidArgumentException("VarLong did not terminate after 10 bytes!"); + } + + /** + * 64-bit unsigned VarLong reader. + * @param \pocketmine\nbt\NBT|BinaryStream $stream + * + * @return int + */ + public static function readUnsignedVarLong_64($stream){ + $value = 0; + for($i = 0; $i <= 63; $i += 7){ + $b = $stream->getByte(); + $value |= (($b & 0x7f) << $i); + var_dump($value); + + if(($b & 0x80) === 0){ + return $value; + } + } + + throw new \InvalidArgumentException("VarLong did not terminate after 10 bytes!"); + } + + + + /** + * Writes a 64-bit integer as a variable-length long. + * @param int|string $v + * + * @return string up to 10 bytes + */ + public static function writeVarLong($v){ + if(PHP_INT_SIZE === 8){ + return self::writeVarLong_64($v); + }else{ + return self::writeVarLong_32($v); + } + } + + /** + * Legacy BC Math zigzag VarLong encoder. + * @param string $v + * + * @return string + */ + public static function writeVarLong_32($v){ + $v = bcmod(bcmul($v, "2"), "18446744073709551616"); + if(bccomp($v, "0") == -1){ + $v = bcsub(bcmul($v, "-1"), "1"); + } + + return self::writeUnsignedVarLong_32($v); + } + + /** + * 64-bit VarLong encoder. + * @param int $v + * + * @return string + */ + public static function writeVarLong_64($v){ + return self::writeUnsignedVarLong_64(($v << 1) ^ ($v >> 63)); + } + + /** + * Writes a 64-bit integer as a variable-length long + * @param int|string $v + * + * @return string up to 10 bytes + */ + public static function writeUnsignedVarLong($v){ + if(PHP_INT_SIZE === 8){ + return self::writeUnsignedVarLong_64($v); + }else{ + return self::writeUnsignedVarLong_32($v); + } + } + + /** + * Legacy BC Math unsigned VarLong encoder. + * @param string $value + * + * @return string + */ + public static function writeUnsignedVarLong_32($value){ + $buf = ""; + + if(bccomp($value, "0") == -1){ + $value = bcadd($value, "18446744073709551616"); + } + + for($i = 0; $i < 10; ++$i){ + $byte = (int) bcmod($value, "128"); + $value = bcdiv($value, "128"); + if($value !== "0"){ + $buf .= chr($byte | 0x80); + }else{ + $buf .= chr($byte); + return $buf; + } + } + + throw new \InvalidArgumentException("Value too large to be encoded as a VarLong"); + } + + /** + * 64-bit unsigned VarLong encoder. + * @param int $value + * + * @return string + */ + public static function writeUnsignedVarLong_64($value){ $buf = ""; for($i = 0; $i < 10; ++$i){ if(($value >> 7) !== 0){ @@ -376,6 +608,6 @@ class Binary{ $value = (($value >> 7) & (PHP_INT_MAX >> 6)); //PHP really needs a logical right-shift operator } - throw new \InvalidArgumentException("Value too large to be encoded as a varint"); + throw new \InvalidArgumentException("Value too large to be encoded as a VarLong"); } } From 295d9bc80b8b2ff1c4a163d617db69709162b60a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 8 Mar 2017 19:34:12 +0000 Subject: [PATCH 20/96] Cleaned up muddled varint/varlong mess, added separate methods for entity unique and runtime ids, moved some MCPE-protocol-specific methods out of BinaryStream --- .../network/mcpe/protocol/AddEntityPacket.php | 8 +- .../mcpe/protocol/AddHangingEntityPacket.php | 6 +- .../mcpe/protocol/AddItemEntityPacket.php | 4 +- .../mcpe/protocol/AddPaintingPacket.php | 6 +- .../network/mcpe/protocol/AddPlayerPacket.php | 4 +- .../network/mcpe/protocol/AnimatePacket.php | 4 +- .../mcpe/protocol/BlockEntityDataPacket.php | 4 +- .../mcpe/protocol/BlockEventPacket.php | 2 +- .../mcpe/protocol/CommandStepPacket.php | 21 +---- .../mcpe/protocol/ContainerOpenPacket.php | 4 +- .../network/mcpe/protocol/DataPacket.php | 84 ++++++++++++++++++- .../mcpe/protocol/EntityEventPacket.php | 4 +- .../network/mcpe/protocol/ExplodePacket.php | 2 +- .../network/mcpe/protocol/InteractPacket.php | 4 +- .../mcpe/protocol/ItemFrameDropItemPacket.php | 2 +- .../mcpe/protocol/MobArmorEquipmentPacket.php | 4 +- .../network/mcpe/protocol/MobEffectPacket.php | 2 +- .../mcpe/protocol/MobEquipmentPacket.php | 4 +- .../mcpe/protocol/MoveEntityPacket.php | 4 +- .../mcpe/protocol/MovePlayerPacket.php | 4 +- .../mcpe/protocol/PlayerActionPacket.php | 8 +- .../mcpe/protocol/PlayerListPacket.php | 2 +- .../mcpe/protocol/RemoveBlockPacket.php | 2 +- .../mcpe/protocol/RemoveEntityPacket.php | 2 +- .../mcpe/protocol/SetEntityDataPacket.php | 2 +- .../mcpe/protocol/SetEntityLinkPacket.php | 4 +- .../mcpe/protocol/SetEntityMotionPacket.php | 2 +- .../mcpe/protocol/SetSpawnPositionPacket.php | 2 +- .../mcpe/protocol/ShowCreditsPacket.php | 4 +- .../network/mcpe/protocol/StartGamePacket.php | 6 +- .../mcpe/protocol/TakeItemEntityPacket.php | 4 +- .../mcpe/protocol/UpdateAttributesPacket.php | 2 +- .../mcpe/protocol/UpdateBlockPacket.php | 2 +- .../network/mcpe/protocol/UseItemPacket.php | 2 +- src/pocketmine/utils/Binary.php | 4 +- src/pocketmine/utils/BinaryStream.php | 62 +++++++------- 36 files changed, 177 insertions(+), 110 deletions(-) diff --git a/src/pocketmine/network/mcpe/protocol/AddEntityPacket.php b/src/pocketmine/network/mcpe/protocol/AddEntityPacket.php index cbb5a974c..84f69f379 100644 --- a/src/pocketmine/network/mcpe/protocol/AddEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddEntityPacket.php @@ -50,8 +50,8 @@ class AddEntityPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putEntityId($this->eid); //EntityUniqueID - TODO: verify this - $this->putEntityId($this->eid); + $this->putEntityUniqueId($this->eid); + $this->putEntityRuntimeId($this->eid); $this->putUnsignedVarInt($this->type); $this->putVector3f($this->x, $this->y, $this->z); $this->putVector3f($this->speedX, $this->speedY, $this->speedZ); @@ -67,8 +67,8 @@ class AddEntityPacket extends DataPacket{ $this->putEntityMetadata($this->metadata); $this->putUnsignedVarInt(count($this->links)); foreach($this->links as $link){ - $this->putEntityId($link[0]); - $this->putEntityId($link[1]); + $this->putEntityUniqueId($link[0]); + $this->putEntityUniqueId($link[1]); $this->putByte($link[2]); } } diff --git a/src/pocketmine/network/mcpe/protocol/AddHangingEntityPacket.php b/src/pocketmine/network/mcpe/protocol/AddHangingEntityPacket.php index 4550e9823..5d2d4310e 100644 --- a/src/pocketmine/network/mcpe/protocol/AddHangingEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddHangingEntityPacket.php @@ -41,9 +41,9 @@ class AddHangingEntityPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putEntityId($this->entityUniqueId); - $this->putEntityId($this->entityRuntimeId); - $this->putBlockCoords($this->x, $this->y, $this->z); + $this->putEntityUniqueId($this->entityUniqueId); + $this->putEntityRuntimeId($this->entityRuntimeId); + $this->putBlockPosition($this->x, $this->y, $this->z); $this->putVarInt($this->unknown); } diff --git a/src/pocketmine/network/mcpe/protocol/AddItemEntityPacket.php b/src/pocketmine/network/mcpe/protocol/AddItemEntityPacket.php index f1fd7930e..48d7f0130 100644 --- a/src/pocketmine/network/mcpe/protocol/AddItemEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddItemEntityPacket.php @@ -44,8 +44,8 @@ class AddItemEntityPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putEntityId($this->eid); //EntityUniqueID - $this->putEntityId($this->eid); //EntityRuntimeID + $this->putEntityUniqueId($this->eid); + $this->putEntityRuntimeId($this->eid); $this->putSlot($this->item); $this->putVector3f($this->x, $this->y, $this->z); $this->putVector3f($this->speedX, $this->speedY, $this->speedZ); diff --git a/src/pocketmine/network/mcpe/protocol/AddPaintingPacket.php b/src/pocketmine/network/mcpe/protocol/AddPaintingPacket.php index c2af0e398..9ae5b2988 100644 --- a/src/pocketmine/network/mcpe/protocol/AddPaintingPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddPaintingPacket.php @@ -42,9 +42,9 @@ class AddPaintingPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putEntityId($this->eid); //EntityUniqueID - $this->putEntityId($this->eid); //EntityRuntimeID - $this->putBlockCoords($this->x, $this->y, $this->z); + $this->putEntityUniqueId($this->eid); + $this->putEntityRuntimeId($this->eid); + $this->putBlockPosition($this->x, $this->y, $this->z); $this->putVarInt($this->direction); $this->putString($this->title); } diff --git a/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php b/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php index aad154a7d..b64c3b428 100644 --- a/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AddPlayerPacket.php @@ -51,8 +51,8 @@ class AddPlayerPacket extends DataPacket{ $this->reset(); $this->putUUID($this->uuid); $this->putString($this->username); - $this->putEntityId($this->eid); //EntityUniqueID - $this->putEntityId($this->eid); //EntityRuntimeID + $this->putEntityUniqueId($this->eid); + $this->putEntityRuntimeId($this->eid); $this->putVector3f($this->x, $this->y, $this->z); $this->putVector3f($this->speedX, $this->speedY, $this->speedZ); $this->putLFloat($this->pitch); diff --git a/src/pocketmine/network/mcpe/protocol/AnimatePacket.php b/src/pocketmine/network/mcpe/protocol/AnimatePacket.php index ecd0e64de..fba81c904 100644 --- a/src/pocketmine/network/mcpe/protocol/AnimatePacket.php +++ b/src/pocketmine/network/mcpe/protocol/AnimatePacket.php @@ -34,13 +34,13 @@ class AnimatePacket extends DataPacket{ public function decode(){ $this->action = $this->getVarInt(); - $this->eid = $this->getEntityId(); + $this->eid = $this->getEntityRuntimeId(); } public function encode(){ $this->reset(); $this->putVarInt($this->action); - $this->putEntityId($this->eid); + $this->putEntityRuntimeId($this->eid); } public function handle(NetworkSession $session) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/BlockEntityDataPacket.php b/src/pocketmine/network/mcpe/protocol/BlockEntityDataPacket.php index 9a5eeea48..cc1fbc52d 100644 --- a/src/pocketmine/network/mcpe/protocol/BlockEntityDataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/BlockEntityDataPacket.php @@ -35,13 +35,13 @@ class BlockEntityDataPacket extends DataPacket{ public $namedtag; public function decode(){ - $this->getBlockCoords($this->x, $this->y, $this->z); + $this->getBlockPosition($this->x, $this->y, $this->z); $this->namedtag = $this->get(true); } public function encode(){ $this->reset(); - $this->putBlockCoords($this->x, $this->y, $this->z); + $this->putBlockPosition($this->x, $this->y, $this->z); $this->put($this->namedtag); } diff --git a/src/pocketmine/network/mcpe/protocol/BlockEventPacket.php b/src/pocketmine/network/mcpe/protocol/BlockEventPacket.php index bae6ae7ae..ba0667a4a 100644 --- a/src/pocketmine/network/mcpe/protocol/BlockEventPacket.php +++ b/src/pocketmine/network/mcpe/protocol/BlockEventPacket.php @@ -41,7 +41,7 @@ class BlockEventPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putBlockCoords($this->x, $this->y, $this->z); + $this->putBlockPosition($this->x, $this->y, $this->z); $this->putVarInt($this->case1); $this->putVarInt($this->case2); } diff --git a/src/pocketmine/network/mcpe/protocol/CommandStepPacket.php b/src/pocketmine/network/mcpe/protocol/CommandStepPacket.php index 1678fc431..26ccf3233 100644 --- a/src/pocketmine/network/mcpe/protocol/CommandStepPacket.php +++ b/src/pocketmine/network/mcpe/protocol/CommandStepPacket.php @@ -28,25 +28,13 @@ use pocketmine\network\mcpe\NetworkSession; class CommandStepPacket extends DataPacket{ const NETWORK_ID = ProtocolInfo::COMMAND_STEP_PACKET; - /** - * unknown (string) - * unknown (string) - * unknown (uvarint) - * unknown (uvarint) - * unknown (bool) - * unknown (uvarint64) - * unknown (string) - * unknown (string) - * https://gist.github.com/dktapps/8285b93af4ca38e0104bfeb9a6c87afd - */ - public $command; public $overload; public $uvarint1; public $uvarint2; public $bool; public $uvarint64; - public $args; //JSON formatted command arguments + public $args; public $string4; public function decode(){ @@ -55,12 +43,11 @@ class CommandStepPacket extends DataPacket{ $this->uvarint1 = $this->getUnsignedVarInt(); $this->uvarint2 = $this->getUnsignedVarInt(); $this->bool = (bool) $this->getByte(); - $this->uvarint64 = $this->getUnsignedVarInt(); //TODO: varint64 + $this->uvarint64 = $this->getUnsignedVarLong(); $this->args = json_decode($this->getString()); $this->string4 = $this->getString(); - while(!$this->feof()){ - $this->getByte(); //prevent assertion errors. TODO: find out why there are always 3 extra bytes at the end of this packet. - } + + $this->get(true); //TODO: read command origin data } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/ContainerOpenPacket.php b/src/pocketmine/network/mcpe/protocol/ContainerOpenPacket.php index ee6356d2f..698c9d058 100644 --- a/src/pocketmine/network/mcpe/protocol/ContainerOpenPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ContainerOpenPacket.php @@ -46,8 +46,8 @@ class ContainerOpenPacket extends DataPacket{ $this->putByte($this->windowid); $this->putByte($this->type); $this->putVarInt($this->slots); - $this->putBlockCoords($this->x, $this->y, $this->z); - $this->putEntityId($this->entityId); + $this->putBlockPosition($this->x, $this->y, $this->z); + $this->putEntityUniqueId($this->entityId); } public function handle(NetworkSession $session) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/DataPacket.php b/src/pocketmine/network/mcpe/protocol/DataPacket.php index f06fc6ff7..d08193289 100644 --- a/src/pocketmine/network/mcpe/protocol/DataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/DataPacket.php @@ -122,7 +122,7 @@ abstract class DataPacket extends BinaryStream{ $value[2] = $this->getVarInt(); //z break; case Entity::DATA_TYPE_LONG: - $value = $this->getVarInt(); //TODO: varint64 proper support + $value = $this->getVarLong(); break; case Entity::DATA_TYPE_VECTOR3F: $value = [0.0, 0.0, 0.0]; @@ -178,7 +178,7 @@ abstract class DataPacket extends BinaryStream{ $this->putVarInt($d[1][2]); //z break; case Entity::DATA_TYPE_LONG: - $this->putVarInt($d[1]); //TODO: varint64 support + $this->putVarLong($d[1]); break; case Entity::DATA_TYPE_VECTOR3F: //TODO: change this implementation (use objects) @@ -186,4 +186,84 @@ abstract class DataPacket extends BinaryStream{ } } } + + /** + * Reads and returns an EntityUniqueID + * @return int|string + */ + public function getEntityUniqueId(){ + return $this->getVarLong(); + } + + /** + * Writes an EntityUniqueID + * @param int|string $eid + */ + public function putEntityUniqueId($eid){ + $this->putVarLong($eid); + } + + /** + * Reads and returns an EntityRuntimeID + * @return int|string + */ + public function getEntityRuntimeId(){ + return $this->getUnsignedVarLong(); + } + + /** + * Writes an EntityUniqueID + * @param int|string $eid + */ + public function putEntityRuntimeId($eid){ + $this->putUnsignedVarLong($eid); + } + + /** + * Writes an block position with unsigned Y coordinate. + * @param int $x + * @param int $y 0-255 + * @param int $z + */ + public function getBlockPosition(&$x, &$y, &$z){ + $x = $this->getVarInt(); + $y = $this->getUnsignedVarInt(); + $z = $this->getVarInt(); + } + + /** + * Reads a block position with unsigned Y coordinate. + * @param int &$x + * @param int &$y + * @param int &$z + */ + public function putBlockPosition($x, $y, $z){ + $this->putVarInt($x); + $this->putUnsignedVarInt($y); + $this->putVarInt($z); + } + + /** + * Reads a floating-point vector3 rounded to 4dp. + * @param float $x + * @param float $y + * @param float $z + */ + public function getVector3f(&$x, &$y, &$z){ + $x = $this->getLFloat(4); + $y = $this->getLFloat(4); + $z = $this->getLFloat(4); + } + + /** + * Writes a floating-point vector3 + * @param float $x + * @param float $y + * @param float $z + */ + public function putVector3f($x, $y, $z){ + $this->putLFloat($x); + $this->putLFloat($y); + $this->putLFloat($z); + } } diff --git a/src/pocketmine/network/mcpe/protocol/EntityEventPacket.php b/src/pocketmine/network/mcpe/protocol/EntityEventPacket.php index 388aab8b9..da6357aa7 100644 --- a/src/pocketmine/network/mcpe/protocol/EntityEventPacket.php +++ b/src/pocketmine/network/mcpe/protocol/EntityEventPacket.php @@ -52,14 +52,14 @@ class EntityEventPacket extends DataPacket{ public $unknown; public function decode(){ - $this->eid = $this->getEntityId(); + $this->eid = $this->getEntityRuntimeId(); $this->event = $this->getByte(); $this->unknown = $this->getVarInt(); } public function encode(){ $this->reset(); - $this->putEntityId($this->eid); + $this->putEntityRuntimeId($this->eid); $this->putByte($this->event); $this->putVarInt($this->unknown); } diff --git a/src/pocketmine/network/mcpe/protocol/ExplodePacket.php b/src/pocketmine/network/mcpe/protocol/ExplodePacket.php index 6892308cc..c298e6351 100644 --- a/src/pocketmine/network/mcpe/protocol/ExplodePacket.php +++ b/src/pocketmine/network/mcpe/protocol/ExplodePacket.php @@ -51,7 +51,7 @@ class ExplodePacket extends DataPacket{ $this->putUnsignedVarInt(count($this->records)); if(count($this->records) > 0){ foreach($this->records as $record){ - $this->putBlockCoords($record->x, $record->y, $record->z); + $this->putBlockPosition($record->x, $record->y, $record->z); } } } diff --git a/src/pocketmine/network/mcpe/protocol/InteractPacket.php b/src/pocketmine/network/mcpe/protocol/InteractPacket.php index 08c026112..604342505 100644 --- a/src/pocketmine/network/mcpe/protocol/InteractPacket.php +++ b/src/pocketmine/network/mcpe/protocol/InteractPacket.php @@ -39,13 +39,13 @@ class InteractPacket extends DataPacket{ public function decode(){ $this->action = $this->getByte(); - $this->target = $this->getEntityId(); + $this->target = $this->getEntityRuntimeId(); } public function encode(){ $this->reset(); $this->putByte($this->action); - $this->putEntityId($this->target); + $this->putEntityRuntimeId($this->target); } public function handle(NetworkSession $session) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/ItemFrameDropItemPacket.php b/src/pocketmine/network/mcpe/protocol/ItemFrameDropItemPacket.php index e9cca9b7e..9a101c420 100644 --- a/src/pocketmine/network/mcpe/protocol/ItemFrameDropItemPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ItemFrameDropItemPacket.php @@ -34,7 +34,7 @@ class ItemFrameDropItemPacket extends DataPacket{ public $z; public function decode(){ - $this->getBlockCoords($this->x, $this->y, $this->z); + $this->getBlockPosition($this->x, $this->y, $this->z); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/MobArmorEquipmentPacket.php b/src/pocketmine/network/mcpe/protocol/MobArmorEquipmentPacket.php index 8464ad9c4..63cf63587 100644 --- a/src/pocketmine/network/mcpe/protocol/MobArmorEquipmentPacket.php +++ b/src/pocketmine/network/mcpe/protocol/MobArmorEquipmentPacket.php @@ -33,7 +33,7 @@ class MobArmorEquipmentPacket extends DataPacket{ public $slots = []; public function decode(){ - $this->eid = $this->getEntityId(); + $this->eid = $this->getEntityRuntimeId(); $this->slots[0] = $this->getSlot(); $this->slots[1] = $this->getSlot(); $this->slots[2] = $this->getSlot(); @@ -42,7 +42,7 @@ class MobArmorEquipmentPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putEntityId($this->eid); + $this->putEntityRuntimeId($this->eid); $this->putSlot($this->slots[0]); $this->putSlot($this->slots[1]); $this->putSlot($this->slots[2]); diff --git a/src/pocketmine/network/mcpe/protocol/MobEffectPacket.php b/src/pocketmine/network/mcpe/protocol/MobEffectPacket.php index 512a25d3d..be64a6c25 100644 --- a/src/pocketmine/network/mcpe/protocol/MobEffectPacket.php +++ b/src/pocketmine/network/mcpe/protocol/MobEffectPacket.php @@ -46,7 +46,7 @@ class MobEffectPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putEntityId($this->eid); + $this->putEntityRuntimeId($this->eid); $this->putByte($this->eventId); $this->putVarInt($this->effectId); $this->putVarInt($this->amplifier); diff --git a/src/pocketmine/network/mcpe/protocol/MobEquipmentPacket.php b/src/pocketmine/network/mcpe/protocol/MobEquipmentPacket.php index 7091181e5..2299b4072 100644 --- a/src/pocketmine/network/mcpe/protocol/MobEquipmentPacket.php +++ b/src/pocketmine/network/mcpe/protocol/MobEquipmentPacket.php @@ -36,7 +36,7 @@ class MobEquipmentPacket extends DataPacket{ public $unknownByte; public function decode(){ - $this->eid = $this->getEntityId(); //EntityRuntimeID + $this->eid = $this->getEntityRuntimeId(); $this->item = $this->getSlot(); $this->slot = $this->getByte(); $this->selectedSlot = $this->getByte(); @@ -45,7 +45,7 @@ class MobEquipmentPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putEntityId($this->eid); //EntityRuntimeID + $this->putEntityRuntimeId($this->eid); $this->putSlot($this->item); $this->putByte($this->slot); $this->putByte($this->selectedSlot); diff --git a/src/pocketmine/network/mcpe/protocol/MoveEntityPacket.php b/src/pocketmine/network/mcpe/protocol/MoveEntityPacket.php index 1f7d0e9ff..fbda02c9e 100644 --- a/src/pocketmine/network/mcpe/protocol/MoveEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/MoveEntityPacket.php @@ -38,7 +38,7 @@ class MoveEntityPacket extends DataPacket{ public $pitch; public function decode(){ - $this->eid = $this->getEntityId(); + $this->eid = $this->getEntityRuntimeId(); $this->getVector3f($this->x, $this->y, $this->z); $this->pitch = $this->getByte() * (360.0 / 256); $this->yaw = $this->getByte() * (360.0 / 256); @@ -47,7 +47,7 @@ class MoveEntityPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putEntityId($this->eid); + $this->putEntityRuntimeId($this->eid); $this->putVector3f($this->x, $this->y, $this->z); $this->putByte($this->pitch / (360.0 / 256)); $this->putByte($this->yaw / (360.0 / 256)); diff --git a/src/pocketmine/network/mcpe/protocol/MovePlayerPacket.php b/src/pocketmine/network/mcpe/protocol/MovePlayerPacket.php index 608dbd94b..24a5644e6 100644 --- a/src/pocketmine/network/mcpe/protocol/MovePlayerPacket.php +++ b/src/pocketmine/network/mcpe/protocol/MovePlayerPacket.php @@ -44,7 +44,7 @@ class MovePlayerPacket extends DataPacket{ public $onGround; public function decode(){ - $this->eid = $this->getEntityId(); //EntityRuntimeID + $this->eid = $this->getEntityRuntimeId(); $this->getVector3f($this->x, $this->y, $this->z); $this->pitch = $this->getLFloat(); $this->yaw = $this->getLFloat(); @@ -55,7 +55,7 @@ class MovePlayerPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putEntityId($this->eid); //EntityRuntimeID + $this->putEntityRuntimeId($this->eid); $this->putVector3f($this->x, $this->y, $this->z); $this->putLFloat($this->pitch); $this->putLFloat($this->yaw); diff --git a/src/pocketmine/network/mcpe/protocol/PlayerActionPacket.php b/src/pocketmine/network/mcpe/protocol/PlayerActionPacket.php index 741d5a035..6d04ec3d5 100644 --- a/src/pocketmine/network/mcpe/protocol/PlayerActionPacket.php +++ b/src/pocketmine/network/mcpe/protocol/PlayerActionPacket.php @@ -55,17 +55,17 @@ class PlayerActionPacket extends DataPacket{ public $face; public function decode(){ - $this->eid = $this->getEntityId(); + $this->eid = $this->getEntityRuntimeId(); $this->action = $this->getVarInt(); - $this->getBlockCoords($this->x, $this->y, $this->z); + $this->getBlockPosition($this->x, $this->y, $this->z); $this->face = $this->getVarInt(); } public function encode(){ $this->reset(); - $this->putEntityId($this->eid); + $this->putEntityRuntimeId($this->eid); $this->putVarInt($this->action); - $this->putBlockCoords($this->x, $this->y, $this->z); + $this->putBlockPosition($this->x, $this->y, $this->z); $this->putVarInt($this->face); } diff --git a/src/pocketmine/network/mcpe/protocol/PlayerListPacket.php b/src/pocketmine/network/mcpe/protocol/PlayerListPacket.php index bca812beb..07e95483f 100644 --- a/src/pocketmine/network/mcpe/protocol/PlayerListPacket.php +++ b/src/pocketmine/network/mcpe/protocol/PlayerListPacket.php @@ -53,7 +53,7 @@ class PlayerListPacket extends DataPacket{ foreach($this->entries as $d){ if($this->type === self::TYPE_ADD){ $this->putUUID($d[0]); - $this->putEntityId($d[1]); + $this->putEntityUniqueId($d[1]); $this->putString($d[2]); $this->putString($d[3]); $this->putString($d[4]); diff --git a/src/pocketmine/network/mcpe/protocol/RemoveBlockPacket.php b/src/pocketmine/network/mcpe/protocol/RemoveBlockPacket.php index d9312cb1a..65025be1e 100644 --- a/src/pocketmine/network/mcpe/protocol/RemoveBlockPacket.php +++ b/src/pocketmine/network/mcpe/protocol/RemoveBlockPacket.php @@ -34,7 +34,7 @@ class RemoveBlockPacket extends DataPacket{ public $z; public function decode(){ - $this->getBlockCoords($this->x, $this->y, $this->z); + $this->getBlockPosition($this->x, $this->y, $this->z); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/RemoveEntityPacket.php b/src/pocketmine/network/mcpe/protocol/RemoveEntityPacket.php index 8ec65467e..a75da9742 100644 --- a/src/pocketmine/network/mcpe/protocol/RemoveEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/RemoveEntityPacket.php @@ -37,7 +37,7 @@ class RemoveEntityPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putEntityId($this->eid); + $this->putEntityUniqueId($this->eid); } public function handle(NetworkSession $session) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/SetEntityDataPacket.php b/src/pocketmine/network/mcpe/protocol/SetEntityDataPacket.php index 705eaec10..25b5437b5 100644 --- a/src/pocketmine/network/mcpe/protocol/SetEntityDataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetEntityDataPacket.php @@ -38,7 +38,7 @@ class SetEntityDataPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putEntityId($this->eid); + $this->putEntityRuntimeId($this->eid); $this->putEntityMetadata($this->metadata); } diff --git a/src/pocketmine/network/mcpe/protocol/SetEntityLinkPacket.php b/src/pocketmine/network/mcpe/protocol/SetEntityLinkPacket.php index 288faf95c..486df6b17 100644 --- a/src/pocketmine/network/mcpe/protocol/SetEntityLinkPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetEntityLinkPacket.php @@ -39,8 +39,8 @@ class SetEntityLinkPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putEntityId($this->from); - $this->putEntityId($this->to); + $this->putEntityUniqueId($this->from); + $this->putEntityUniqueId($this->to); $this->putByte($this->type); } diff --git a/src/pocketmine/network/mcpe/protocol/SetEntityMotionPacket.php b/src/pocketmine/network/mcpe/protocol/SetEntityMotionPacket.php index 3b7f2d51e..ec66b3953 100644 --- a/src/pocketmine/network/mcpe/protocol/SetEntityMotionPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetEntityMotionPacket.php @@ -40,7 +40,7 @@ class SetEntityMotionPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putEntityId($this->eid); + $this->putEntityRuntimeId($this->eid); $this->putVector3f($this->motionX, $this->motionY, $this->motionZ); } diff --git a/src/pocketmine/network/mcpe/protocol/SetSpawnPositionPacket.php b/src/pocketmine/network/mcpe/protocol/SetSpawnPositionPacket.php index 086f68ee8..0c1acd0bc 100644 --- a/src/pocketmine/network/mcpe/protocol/SetSpawnPositionPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SetSpawnPositionPacket.php @@ -42,7 +42,7 @@ class SetSpawnPositionPacket extends DataPacket{ public function encode(){ $this->reset(); $this->putVarInt($this->unknown); - $this->putBlockCoords($this->x, $this->y, $this->z); + $this->putBlockPosition($this->x, $this->y, $this->z); $this->putBool($this->unknownBool); } diff --git a/src/pocketmine/network/mcpe/protocol/ShowCreditsPacket.php b/src/pocketmine/network/mcpe/protocol/ShowCreditsPacket.php index ed82bc0e7..03b888b0e 100644 --- a/src/pocketmine/network/mcpe/protocol/ShowCreditsPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ShowCreditsPacket.php @@ -37,13 +37,13 @@ class ShowCreditsPacket extends DataPacket{ public $status; public function decode(){ - $this->playerEid = $this->getEntityId(); + $this->playerEid = $this->getEntityRuntimeId(); $this->status = $this->getVarInt(); } public function encode(){ $this->reset(); - $this->putEntityId($this->playerEid); + $this->putEntityRuntimeId($this->playerEid); $this->putVarInt($this->status); } diff --git a/src/pocketmine/network/mcpe/protocol/StartGamePacket.php b/src/pocketmine/network/mcpe/protocol/StartGamePacket.php index 25d85314b..0c43a515b 100644 --- a/src/pocketmine/network/mcpe/protocol/StartGamePacket.php +++ b/src/pocketmine/network/mcpe/protocol/StartGamePacket.php @@ -58,8 +58,8 @@ class StartGamePacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putEntityId($this->entityUniqueId); //EntityUniqueID - $this->putEntityId($this->entityRuntimeId); //EntityRuntimeID + $this->putEntityUniqueId($this->entityUniqueId); //EntityUniqueID + $this->putEntityRuntimeId($this->entityRuntimeId); //EntityRuntimeID $this->putVector3f($this->x, $this->y, $this->z); $this->putLFloat(0); //TODO: find out what these are (yaw/pitch?) $this->putLFloat(0); @@ -68,7 +68,7 @@ class StartGamePacket extends DataPacket{ $this->putVarInt($this->generator); $this->putVarInt($this->gamemode); $this->putVarInt($this->difficulty); - $this->putBlockCoords($this->spawnX, $this->spawnY, $this->spawnZ); + $this->putBlockPosition($this->spawnX, $this->spawnY, $this->spawnZ); $this->putBool($this->hasAchievementsDisabled); $this->putVarInt($this->dayCycleStopTime); $this->putBool($this->eduMode); diff --git a/src/pocketmine/network/mcpe/protocol/TakeItemEntityPacket.php b/src/pocketmine/network/mcpe/protocol/TakeItemEntityPacket.php index 80d446b6e..d4b4b4fc1 100644 --- a/src/pocketmine/network/mcpe/protocol/TakeItemEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/TakeItemEntityPacket.php @@ -38,8 +38,8 @@ class TakeItemEntityPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putEntityId($this->target); - $this->putEntityId($this->eid); + $this->putEntityRuntimeId($this->target); + $this->putEntityRuntimeId($this->eid); } public function handle(NetworkSession $session) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/UpdateAttributesPacket.php b/src/pocketmine/network/mcpe/protocol/UpdateAttributesPacket.php index d3da0bb78..9f369579f 100644 --- a/src/pocketmine/network/mcpe/protocol/UpdateAttributesPacket.php +++ b/src/pocketmine/network/mcpe/protocol/UpdateAttributesPacket.php @@ -41,7 +41,7 @@ class UpdateAttributesPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putEntityId($this->entityId); + $this->putEntityRuntimeId($this->entityId); $this->putUnsignedVarInt(count($this->entries)); foreach($this->entries as $entry){ $this->putLFloat($entry->getMinValue()); diff --git a/src/pocketmine/network/mcpe/protocol/UpdateBlockPacket.php b/src/pocketmine/network/mcpe/protocol/UpdateBlockPacket.php index 2a29ba5d6..b7ac09198 100644 --- a/src/pocketmine/network/mcpe/protocol/UpdateBlockPacket.php +++ b/src/pocketmine/network/mcpe/protocol/UpdateBlockPacket.php @@ -51,7 +51,7 @@ class UpdateBlockPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putBlockCoords($this->x, $this->y, $this->z); + $this->putBlockPosition($this->x, $this->y, $this->z); $this->putUnsignedVarInt($this->blockId); $this->putUnsignedVarInt(($this->flags << 4) | $this->blockData); } diff --git a/src/pocketmine/network/mcpe/protocol/UseItemPacket.php b/src/pocketmine/network/mcpe/protocol/UseItemPacket.php index 0a2b726bb..505123d02 100644 --- a/src/pocketmine/network/mcpe/protocol/UseItemPacket.php +++ b/src/pocketmine/network/mcpe/protocol/UseItemPacket.php @@ -44,7 +44,7 @@ class UseItemPacket extends DataPacket{ public $slot; public function decode(){ - $this->getBlockCoords($this->x, $this->y, $this->z); + $this->getBlockPosition($this->x, $this->y, $this->z); $this->blockId = $this->getUnsignedVarInt(); $this->face = $this->getVarInt(); $this->getVector3f($this->fx, $this->fy, $this->fz); diff --git a/src/pocketmine/utils/Binary.php b/src/pocketmine/utils/Binary.php index 668c6ed6f..efbc26b13 100644 --- a/src/pocketmine/utils/Binary.php +++ b/src/pocketmine/utils/Binary.php @@ -412,7 +412,7 @@ class Binary{ * Reads a 64-bit zigzag-encoded variable-length integer from the supplied stream. * @param \pocketmine\nbt\NBT|BinaryStream $stream * - * @return int + * @return int|string */ public static function readVarLong($stream){ if(PHP_INT_SIZE === 8){ @@ -476,7 +476,6 @@ class Binary{ for($i = 0; $i <= 63; $i += 7){ $b = $stream->getByte(); $value = bcadd($value, bcmul($b & 0x7f, bcpow("2", "$i"))); - var_dump($value); if(($b & 0x80) === 0){ return $value; @@ -497,7 +496,6 @@ class Binary{ for($i = 0; $i <= 63; $i += 7){ $b = $stream->getByte(); $value |= (($b & 0x7f) << $i); - var_dump($value); if(($b & 0x80) === 0){ return $value; diff --git a/src/pocketmine/utils/BinaryStream.php b/src/pocketmine/utils/BinaryStream.php index 506a162f0..156ce4523 100644 --- a/src/pocketmine/utils/BinaryStream.php +++ b/src/pocketmine/utils/BinaryStream.php @@ -233,66 +233,68 @@ class BinaryStream extends \stdClass{ $this->put($v); } - //TODO: varint64 - /** - * Reads an unsigned varint32 from the stream. + * Reads a 32-bit variable-length unsigned integer from the buffer and returns it. + * @return int */ public function getUnsignedVarInt(){ return Binary::readUnsignedVarInt($this); } /** - * Writes an unsigned varint32 to the stream. + * Writes a 32-bit variable-length unsigned integer to the end of the buffer. + * @param int $v */ public function putUnsignedVarInt($v){ $this->put(Binary::writeUnsignedVarInt($v)); } /** - * Reads a signed varint32 from the stream. + * Reads a 32-bit zigzag-encoded variable-length integer from the buffer and returns it. + * @return int */ public function getVarInt(){ return Binary::readVarInt($this); } /** - * Writes a signed varint32 to the stream. + * Writes a 32-bit zigzag-encoded variable-length integer to the end of the buffer. + * @param int $v */ public function putVarInt($v){ $this->put(Binary::writeVarInt($v)); } - public function getEntityId(){ - return $this->getVarInt(); + /** + * Reads a 64-bit variable-length integer from the buffer and returns it. + * @return int|string int, or the string representation of an int64 on 32-bit platforms + */ + public function getUnsignedVarLong(){ + return Binary::readUnsignedVarLong($this); } - public function putEntityId($v){ - $this->putVarInt($v); + /** + * Writes a 64-bit variable-length integer to the end of the buffer. + * @param int|string $v int, or the string representation of an int64 on 32-bit platforms + */ + public function putUnsignedVarLong($v){ + $this->buffer .= Binary::writeUnsignedVarLong($v); } - public function getBlockCoords(&$x, &$y, &$z){ - $x = $this->getVarInt(); - $y = $this->getUnsignedVarInt(); - $z = $this->getVarInt(); + /** + * Reads a 64-bit zigzag-encoded variable-length integer from the buffer and returns it. + * @return int|string int, or the string representation of an int64 on 32-bit platforms + */ + public function getVarLong(){ + return Binary::readVarLong($this); } - public function putBlockCoords($x, $y, $z){ - $this->putVarInt($x); - $this->putUnsignedVarInt($y); - $this->putVarInt($z); - } - - public function getVector3f(&$x, &$y, &$z){ - $x = $this->getLFloat(4); - $y = $this->getLFloat(4); - $z = $this->getLFloat(4); - } - - public function putVector3f($x, $y, $z){ - $this->putLFloat($x); - $this->putLFloat($y); - $this->putLFloat($z); + /** + * Writes a 64-bit zigzag-encoded variable-length integer to the end of the buffer. + * @param int|string $v int, or the string representation of an int64 on 32-bit platforms + */ + public function putVarLong($v){ + $this->buffer .= Binary::writeVarLong($v); } public function feof(){ From 9311b4f24838bbd843abfbb6805d8dcb730b4cf1 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 8 Mar 2017 19:51:07 +0000 Subject: [PATCH 21/96] Remove unneeded comments --- src/pocketmine/network/mcpe/protocol/StartGamePacket.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/network/mcpe/protocol/StartGamePacket.php b/src/pocketmine/network/mcpe/protocol/StartGamePacket.php index 0c43a515b..6e534f96e 100644 --- a/src/pocketmine/network/mcpe/protocol/StartGamePacket.php +++ b/src/pocketmine/network/mcpe/protocol/StartGamePacket.php @@ -58,8 +58,8 @@ class StartGamePacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putEntityUniqueId($this->entityUniqueId); //EntityUniqueID - $this->putEntityRuntimeId($this->entityRuntimeId); //EntityRuntimeID + $this->putEntityUniqueId($this->entityUniqueId); + $this->putEntityRuntimeId($this->entityRuntimeId); $this->putVector3f($this->x, $this->y, $this->z); $this->putLFloat(0); //TODO: find out what these are (yaw/pitch?) $this->putLFloat(0); From a19996a7cfcbe46e718d948e4bcbc322e134c749 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 8 Mar 2017 19:59:16 +0000 Subject: [PATCH 22/96] Added deprecation warning for 32-bit --- src/pocketmine/PocketMine.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 2d9dc1997..67a495e21 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -453,6 +453,10 @@ namespace pocketmine { exit(1); //Exit with error } + if(PHP_INT_SIZE < 8){ + $logger->warning("Running PocketMine-MP with 32-bit systems/PHP is deprecated. Support for 32-bit may be dropped in the future."); + } + $gitHash = str_repeat("00", 20); if(file_exists(\pocketmine\PATH . ".git/HEAD")){ //Found Git information! $ref = trim(file_get_contents(\pocketmine\PATH . ".git/HEAD")); From 94d78ca554b61be187e40e0ce6c441734f5b34ce Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 8 Mar 2017 20:38:11 +0000 Subject: [PATCH 23/96] Added missing returns --- .../network/mcpe/protocol/ClientboundMapItemDataPacket.php | 2 +- .../network/mcpe/protocol/ResourcePackChunkDataPacket.php | 2 +- .../network/mcpe/protocol/ResourcePackChunkRequestPacket.php | 2 +- .../network/mcpe/protocol/ResourcePackDataInfoPacket.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pocketmine/network/mcpe/protocol/ClientboundMapItemDataPacket.php b/src/pocketmine/network/mcpe/protocol/ClientboundMapItemDataPacket.php index 86f28fae8..d1a94d9a8 100644 --- a/src/pocketmine/network/mcpe/protocol/ClientboundMapItemDataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ClientboundMapItemDataPacket.php @@ -144,6 +144,6 @@ class ClientboundMapItemDataPacket extends DataPacket{ } public function handle(NetworkSession $session) : bool{ - $session->handleClientboundMapItemData($this); + return $session->handleClientboundMapItemData($this); } } \ No newline at end of file diff --git a/src/pocketmine/network/mcpe/protocol/ResourcePackChunkDataPacket.php b/src/pocketmine/network/mcpe/protocol/ResourcePackChunkDataPacket.php index 1d455d448..c897ce7fa 100644 --- a/src/pocketmine/network/mcpe/protocol/ResourcePackChunkDataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ResourcePackChunkDataPacket.php @@ -51,6 +51,6 @@ class ResourcePackChunkDataPacket extends DataPacket{ } public function handle(NetworkSession $session) : bool{ - $session->handleResourcePackChunkData($this); + return $session->handleResourcePackChunkData($this); } } \ No newline at end of file diff --git a/src/pocketmine/network/mcpe/protocol/ResourcePackChunkRequestPacket.php b/src/pocketmine/network/mcpe/protocol/ResourcePackChunkRequestPacket.php index 1ae1eac3a..f572971a4 100644 --- a/src/pocketmine/network/mcpe/protocol/ResourcePackChunkRequestPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ResourcePackChunkRequestPacket.php @@ -45,6 +45,6 @@ class ResourcePackChunkRequestPacket extends DataPacket{ } public function handle(NetworkSession $session) : bool{ - $session->handleResourcePackChunkRequest($this); + return $session->handleResourcePackChunkRequest($this); } } \ No newline at end of file diff --git a/src/pocketmine/network/mcpe/protocol/ResourcePackDataInfoPacket.php b/src/pocketmine/network/mcpe/protocol/ResourcePackDataInfoPacket.php index c7afce108..c371b546e 100644 --- a/src/pocketmine/network/mcpe/protocol/ResourcePackDataInfoPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ResourcePackDataInfoPacket.php @@ -54,7 +54,7 @@ class ResourcePackDataInfoPacket extends DataPacket{ } public function handle(NetworkSession $session) : bool{ - $session->handleResourcePackDataInfo($this); + return $session->handleResourcePackDataInfo($this); } } \ No newline at end of file From f8c2eb8c3a2e18ce4e0f6842edb0dcc9c00d4550 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 9 Mar 2017 12:23:24 +0000 Subject: [PATCH 24/96] Fixed signed VarInt encoding on 64-bit systems Numbers represented as hex or binary with the 32nd bit set, for example 0xffffffff, were not considered as signed on 64-bit. --- src/pocketmine/utils/Binary.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/utils/Binary.php b/src/pocketmine/utils/Binary.php index efbc26b13..e2ab3737d 100644 --- a/src/pocketmine/utils/Binary.php +++ b/src/pocketmine/utils/Binary.php @@ -381,7 +381,10 @@ class Binary{ * @return string */ public static function writeVarInt($v){ - return self::writeUnsignedVarInt(($v << 1) ^ ($v >> (PHP_INT_SIZE === 8 ? 63 : 31))); + if(PHP_INT_SIZE === 8){ + $v = ($v << 32 >> 32); + } + return self::writeUnsignedVarInt(($v << 1) ^ ($v >> 31)); } /** From c052ee5847c732bc16fe8ed392e313ccf7a48870 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 9 Mar 2017 12:26:24 +0000 Subject: [PATCH 25/96] Set alpha value to 0xff, fixed potion bubbles, close #407 TODO: implement transparency --- src/pocketmine/entity/Entity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 010d846de..804d75176 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -505,7 +505,7 @@ abstract class Entity extends Location implements Metadatable{ $g = ($color[1] / $count) & 0xff; $b = ($color[2] / $count) & 0xff; - $this->setDataProperty(Entity::DATA_POTION_COLOR, Entity::DATA_TYPE_INT, ($r << 16) + ($g << 8) + $b); + $this->setDataProperty(Entity::DATA_POTION_COLOR, Entity::DATA_TYPE_INT, 0xff000000 | ($r << 16) | ($g << 8) | $b); $this->setDataProperty(Entity::DATA_POTION_AMBIENT, Entity::DATA_TYPE_BYTE, $ambient ? 1 : 0); }else{ $this->setDataProperty(Entity::DATA_POTION_COLOR, Entity::DATA_TYPE_INT, 0); From d41bdfc31c4875dccec0d572d747acde8bc232de Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 10 Mar 2017 20:00:31 +0000 Subject: [PATCH 26/96] Added resource packs support --- .gitignore | 1 + src/pocketmine/Player.php | 45 +++++- src/pocketmine/PocketMine.php | 5 + src/pocketmine/Server.php | 17 ++- .../protocol/ResourcePackChunkDataPacket.php | 13 +- .../ResourcePackChunkRequestPacket.php | 6 +- .../protocol/ResourcePackDataInfoPacket.php | 24 ++-- .../mcpe/protocol/ResourcePackStackPacket.php | 13 +- .../mcpe/protocol/ResourcePacksInfoPacket.php | 13 +- src/pocketmine/resourcepacks/ResourcePack.php | 39 ++++++ .../resourcepacks/ResourcePackManager.php | 129 ++++++++++++++++++ .../resourcepacks/ZippedResourcePack.php | 105 ++++++++++++++ 12 files changed, 370 insertions(+), 40 deletions(-) create mode 100644 src/pocketmine/resourcepacks/ResourcePack.php create mode 100644 src/pocketmine/resourcepacks/ResourcePackManager.php create mode 100644 src/pocketmine/resourcepacks/ZippedResourcePack.php diff --git a/.gitignore b/.gitignore index b08db6710..17d9ae8d1 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ timings/* server.properties /pocketmine.yml memoryDump_*/* +resource_packs/ # Common IDEs .idea/ diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 75e1ad3c8..2448ff2da 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -189,6 +189,7 @@ use pocketmine\network\SourceInterface; use pocketmine\permission\PermissibleBase; use pocketmine\permission\PermissionAttachment; use pocketmine\plugin\Plugin; +use pocketmine\resourcepacks\ResourcePack; use pocketmine\tile\ItemFrame; use pocketmine\tile\Spawnable; use pocketmine\utils\TextFormat; @@ -1934,7 +1935,10 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->sendPlayStatus(PlayStatusPacket::LOGIN_SUCCESS); $pk = new ResourcePacksInfoPacket(); - $this->dataPacket($pk); //TODO: add resource packs stuff + $manager = $this->server->getResourceManager(); + $pk->resourcePackEntries = $manager->getResourceStack(); + $pk->mustAccept = $manager->resourcePacksRequired(); + $this->dataPacket($pk); return true; } @@ -1984,11 +1988,31 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->close("", "must accept resource packs to join", true); break; case ResourcePackClientResponsePacket::STATUS_SEND_PACKS: - //TODO + $manager = $this->server->getResourceManager(); + 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); //TODO: add strings to lang files + break; + } + + $pk = new ResourcePackDataInfoPacket(); + $pk->packId = $pack->getPackId(); + $pk->maxChunkSize = 1048576; //1MB + $pk->chunkCount = $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(); - $this->dataPacket($pk); //TODO: send resource stack + $manager = $this->server->getResourceManager(); + $pk->resourcePackStack = $manager->getResourceStack(); + $pk->mustAccept = $manager->resourcePacksRequired(); + $this->dataPacket($pk); break; case ResourcePackClientResponsePacket::STATUS_COMPLETED: $this->processLogin(); @@ -3292,7 +3316,20 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } public function handleResourcePackChunkRequest(ResourcePackChunkRequestPacket $packet) : bool{ - return false; + $manager = $this->server->getResourceManager(); + $pack = $manager->getPackById($packet->packId); + if(!($pack instanceof ResourcePack)){ + $this->close("", "disconnectionScreen.resourcePack", true); + return true; + } + + $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 handleTransfer(TransferPacket $packet) : bool{ diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 67a495e21..3e69e6d9d 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -446,6 +446,11 @@ namespace pocketmine { ++$errors; } + if(!extension_loaded("openssl")){ + $logger->critical("Unable to find the OpenSSL extension."); + ++$errors; + } + if($errors > 0){ $logger->critical("Please use the installer provided on the homepage, or recompile PHP again."); $logger->shutdown(); diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 4474cdaef..e5be618de 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -90,6 +90,7 @@ use pocketmine\plugin\Plugin; use pocketmine\plugin\PluginLoadOrder; use pocketmine\plugin\PluginManager; use pocketmine\plugin\ScriptPluginLoader; +use pocketmine\resourcepacks\ResourcePackManager; use pocketmine\scheduler\FileWriteTask; use pocketmine\scheduler\SendUsageTask; use pocketmine\scheduler\ServerScheduler; @@ -176,6 +177,9 @@ class Server{ /** @var CraftingManager */ private $craftingManager; + /** @var ResourcePackManager */ + private $resourceManager; + /** @var ConsoleCommandSender */ private $consoleSender; @@ -594,6 +598,13 @@ class Server{ return $this->craftingManager; } + /** + * @return ResourcePackManager + */ + public function getResourceManager() : ResourcePackManager{ + return $this->resourceManager; + } + /** * @return ServerScheduler */ @@ -1510,6 +1521,8 @@ class Server{ Attribute::init(); $this->craftingManager = new CraftingManager(); + $this->resourceManager = new ResourcePackManager($this, \pocketmine\PATH . "resource_packs" . DIRECTORY_SEPARATOR); + $this->pluginManager = new PluginManager($this, $this->commandMap); $this->pluginManager->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this->consoleSender); $this->pluginManager->setUseTimings($this->getProperty("settings.enable-profiling", false)); @@ -2165,9 +2178,7 @@ class Server{ private function checkTickUpdates($currentTick, $tickTime){ foreach($this->players as $p){ - if(!$p->loggedIn and ($tickTime - $p->creationTime) >= 10){ - $p->close("", "Login timeout"); - }elseif($this->alwaysTickPlayers){ + if($this->alwaysTickPlayers){ $p->onUpdate($currentTick); } } diff --git a/src/pocketmine/network/mcpe/protocol/ResourcePackChunkDataPacket.php b/src/pocketmine/network/mcpe/protocol/ResourcePackChunkDataPacket.php index c897ce7fa..9612449db 100644 --- a/src/pocketmine/network/mcpe/protocol/ResourcePackChunkDataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ResourcePackChunkDataPacket.php @@ -31,21 +31,22 @@ class ResourcePackChunkDataPacket extends DataPacket{ const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_CHUNK_DATA_PACKET; public $packId; - public $unknown1; - public $unknown2; + public $chunkIndex; + public $progress; public $data; public function decode(){ $this->packId = $this->getString(); - $this->unknown1 = $this->getLInt(); - $this->unknown2 = $this->getLLong(); + $this->chunkIndex = $this->getLInt(); + $this->progress = $this->getLLong(); $this->data = $this->get($this->getLInt()); } public function encode(){ + $this->reset(); $this->putString($this->packId); - $this->putLInt($this->unknown1); - $this->putLLong($this->unknown2); + $this->putLInt($this->chunkIndex); + $this->putLLong($this->progress); $this->putLInt(strlen($this->data)); $this->put($this->data); } diff --git a/src/pocketmine/network/mcpe/protocol/ResourcePackChunkRequestPacket.php b/src/pocketmine/network/mcpe/protocol/ResourcePackChunkRequestPacket.php index f572971a4..d9b89bcef 100644 --- a/src/pocketmine/network/mcpe/protocol/ResourcePackChunkRequestPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ResourcePackChunkRequestPacket.php @@ -31,17 +31,17 @@ class ResourcePackChunkRequestPacket extends DataPacket{ const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_CHUNK_REQUEST_PACKET; public $packId; - public $unknown; + public $chunkIndex; public function decode(){ $this->packId = $this->getString(); - $this->unknown = $this->getLInt(); + $this->chunkIndex = $this->getLInt(); } public function encode(){ $this->reset(); $this->putString($this->packId); - $this->putLInt($this->unknown); + $this->putLInt($this->chunkIndex); } public function handle(NetworkSession $session) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/ResourcePackDataInfoPacket.php b/src/pocketmine/network/mcpe/protocol/ResourcePackDataInfoPacket.php index c371b546e..c8970f55e 100644 --- a/src/pocketmine/network/mcpe/protocol/ResourcePackDataInfoPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ResourcePackDataInfoPacket.php @@ -31,26 +31,26 @@ class ResourcePackDataInfoPacket extends DataPacket{ const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_DATA_INFO_PACKET; public $packId; - public $int1; - public $int2; - public $packSize; - public $unknown; + public $maxChunkSize; + public $chunkCount; + public $compressedPackSize; + public $sha256; public function decode(){ $this->packId = $this->getString(); - $this->int1 = $this->getLInt(); - $this->int2 = $this->getLInt(); - $this->packSize = $this->getLLong(); - $this->unknown = $this->getString(); + $this->maxChunkSize = $this->getLInt(); + $this->chunkCount = $this->getLInt(); + $this->compressedPackSize = $this->getLLong(); + $this->sha256 = $this->getString(); } public function encode(){ $this->reset(); $this->putString($this->packId); - $this->putLInt($this->int1); - $this->putLInt($this->int2); - $this->putLLong($this->packSize); - $this->putString($this->unknown); + $this->putLInt($this->maxChunkSize); + $this->putLInt($this->chunkCount); + $this->putLLong($this->compressedPackSize); + $this->putString($this->sha256); } public function handle(NetworkSession $session) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/ResourcePackStackPacket.php b/src/pocketmine/network/mcpe/protocol/ResourcePackStackPacket.php index d2ab98c2e..32633a7fb 100644 --- a/src/pocketmine/network/mcpe/protocol/ResourcePackStackPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ResourcePackStackPacket.php @@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\NetworkSession; +use pocketmine\resourcepacks\ResourcePack; use pocketmine\resourcepacks\ResourcePackInfoEntry; class ResourcePackStackPacket extends DataPacket{ @@ -33,13 +34,13 @@ class ResourcePackStackPacket extends DataPacket{ public $mustAccept = false; - /** @var ResourcePackInfoEntry[] */ + /** @var ResourcePack[] */ public $behaviorPackStack = []; - /** @var ResourcePackInfoEntry[] */ + /** @var ResourcePack[] */ public $resourcePackStack = []; public function decode(){ - $this->mustAccept = $this->getBool(); + /*$this->mustAccept = $this->getBool(); $behaviorPackCount = $this->getLShort(); while($behaviorPackCount-- > 0){ $packId = $this->getString(); @@ -52,7 +53,7 @@ class ResourcePackStackPacket extends DataPacket{ $packId = $this->getString(); $version = $this->getString(); $this->resourcePackStack[] = new ResourcePackInfoEntry($packId, $version); - } + }*/ } public function encode(){ @@ -62,13 +63,13 @@ class ResourcePackStackPacket extends DataPacket{ $this->putLShort(count($this->behaviorPackStack)); foreach($this->behaviorPackStack as $entry){ $this->putString($entry->getPackId()); - $this->putString($entry->getVersion()); + $this->putString($entry->getPackVersion()); } $this->putLShort(count($this->resourcePackStack)); foreach($this->resourcePackStack as $entry){ $this->putString($entry->getPackId()); - $this->putString($entry->getVersion()); + $this->putString($entry->getPackVersion()); } } diff --git a/src/pocketmine/network/mcpe/protocol/ResourcePacksInfoPacket.php b/src/pocketmine/network/mcpe/protocol/ResourcePacksInfoPacket.php index 8f03c1136..3b07fe359 100644 --- a/src/pocketmine/network/mcpe/protocol/ResourcePacksInfoPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ResourcePacksInfoPacket.php @@ -25,19 +25,20 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\NetworkSession; +use pocketmine\resourcepacks\ResourcePack; use pocketmine\resourcepacks\ResourcePackInfoEntry; class ResourcePacksInfoPacket extends DataPacket{ const NETWORK_ID = ProtocolInfo::RESOURCE_PACKS_INFO_PACKET; public $mustAccept = false; //if true, forces client to use selected resource packs - /** @var ResourcePackInfoEntry[] */ + /** @var ResourcePack[] */ public $behaviorPackEntries = []; - /** @var ResourcePackInfoEntry[] */ + /** @var ResourcePack[] */ public $resourcePackEntries = []; public function decode(){ - $this->mustAccept = $this->getBool(); + /*$this->mustAccept = $this->getBool(); $behaviorPackCount = $this->getLShort(); while($behaviorPackCount-- > 0){ $id = $this->getString(); @@ -52,7 +53,7 @@ class ResourcePacksInfoPacket extends DataPacket{ $version = $this->getString(); $size = $this->getLLong(); $this->resourcePackEntries[] = new ResourcePackInfoEntry($id, $version, $size); - } + }*/ } public function encode(){ @@ -62,13 +63,13 @@ class ResourcePacksInfoPacket extends DataPacket{ $this->putLShort(count($this->behaviorPackEntries)); foreach($this->behaviorPackEntries as $entry){ $this->putString($entry->getPackId()); - $this->putString($entry->getVersion()); + $this->putString($entry->getPackVersion()); $this->putLLong($entry->getPackSize()); } $this->putLShort(count($this->resourcePackEntries)); foreach($this->resourcePackEntries as $entry){ $this->putString($entry->getPackId()); - $this->putString($entry->getVersion()); + $this->putString($entry->getPackVersion()); $this->putLLong($entry->getPackSize()); } } diff --git a/src/pocketmine/resourcepacks/ResourcePack.php b/src/pocketmine/resourcepacks/ResourcePack.php new file mode 100644 index 000000000..fd7962896 --- /dev/null +++ b/src/pocketmine/resourcepacks/ResourcePack.php @@ -0,0 +1,39 @@ +server = $server; + $this->path = $path; + + if(!file_exists($this->path)){ + $this->server->getLogger()->debug("Resource packs path $path does not exist, creating directory"); + mkdir($this->path); + }elseif(!is_dir($this->path)){ + throw new \InvalidArgumentException("Resource packs path $path exists and is not a directory"); + } + + $this->resourcePacksConfig = new Config($this->path . "resource_packs.yml", Config::YAML, []); + + if(count($this->resourcePacksConfig->getAll()) === 0){ + $this->resourcePacksConfig->set("force_resources", false); + $this->resourcePacksConfig->set("resource_stack", []); + $this->resourcePacksConfig->save(); + } + + $this->serverForceResources = (bool) $this->resourcePacksConfig->get("force_resources", false); + + $this->server->getLogger()->info("Loading resource packs..."); + + foreach($this->resourcePacksConfig->get("resource_stack", []) as $pos => $pack){ + try{ + $packPath = $this->path . DIRECTORY_SEPARATOR . $pack; + if(file_exists($packPath)){ + $newPack = null; + //Detect the type of resource pack. + if(is_dir($packPath)){ + $this->server->getLogger()->warning("Skipped resource entry $pack due to directory resource packs currently unsupported"); + }else{ + $info = new \SplFileInfo($packPath); + switch($info->getExtension()){ + case "zip": + $newPack = new ZippedResourcePack($packPath); + break; + default: + $this->server->getLogger()->warning("Skipped resource entry $pack due to format not recognized"); + break; + } + } + + if($newPack instanceof ResourcePack){ + $this->resourcePacks[] = $newPack; + $this->uuidList[$newPack->getPackId()] = $newPack; + } + }else{ + $this->server->getLogger()->warning("Skipped resource entry $pack due to file or directory not found"); + } + }catch(\Throwable $e){ + $this->server->getLogger()->logException($e); + } + } + + $this->server->getLogger()->debug("Successfully loaded " . count($this->resourcePacks) . " resource packs"); + } + + /** + * @return bool + */ + public function resourcePacksRequired() : bool{ + return $this->serverForceResources; + } + + /** + * @return ResourcePack[] + */ + public function getResourceStack() : array{ + return $this->resourcePacks; + } + + /** + * @param string $id + * + * @return ResourcePack|null + */ + public function getPackById(string $id){ + return $this->uuidList[$id] ?? null; + } +} \ No newline at end of file diff --git a/src/pocketmine/resourcepacks/ZippedResourcePack.php b/src/pocketmine/resourcepacks/ZippedResourcePack.php new file mode 100644 index 000000000..40977d5d2 --- /dev/null +++ b/src/pocketmine/resourcepacks/ZippedResourcePack.php @@ -0,0 +1,105 @@ +format_version) or !isset($manifest->header) or !isset($manifest->modules)){ + return false; + } + + //Right now we don't care about anything else, only the stuff we're sending to clients. + //TODO: add more manifest validation + return + isset($manifest->header->description) and + isset($manifest->header->name) and + isset($manifest->header->uuid) and + isset($manifest->header->version) and + count($manifest->header->version) === 3; + } + + /** @var string */ + protected $path; + + /** @var \stdClass */ + protected $manifest; + + /** @var string */ + protected $sha256 = null; + + + public function __construct(string $zipPath){ + $this->path = $zipPath; + + if(!file_exists($zipPath)){ + throw new \InvalidArgumentException("Could not open resource pack $zipPath: file not found"); + } + + $archive = new \ZipArchive(); + if(($openResult = $archive->open($zipPath)) !== true){ + throw new \InvalidStateException("Encountered ZipArchive error code $openResult while trying to open $zipPath"); + } + + if(($manifestData = $archive->getFromName("manifest.json")) === false){ + throw new \InvalidStateException("Could not load resource pack from $zipPath: manifest.json not found"); + } + + $archive->close(); + + $manifest = json_decode($manifestData); + if(!self::verifyManifest($manifest)){ + throw new \InvalidStateException("Could not load resource pack from $zipPath: manifest.json is invalid or incomplete"); + } + + $this->manifest = $manifest; + } + + public function getPackName() : string{ + return $this->manifest->header->name; + } + + public function getPackVersion() : string{ + return implode(".", $this->manifest->header->version); + } + + public function getPackId() : string{ + return $this->manifest->header->uuid; + } + + public function getPackSize() : int{ + return filesize($this->path); + } + + public function getSha256(bool $cached = true) : string{ + if($this->sha256 === null or !$cached){ + $this->sha256 = openssl_digest(file_get_contents($this->path), "sha256", true); + } + return $this->sha256; + } + + public function getPackChunk(int $start, int $length) : string{ + return substr(file_get_contents($this->path), $start, $length); + } +} \ No newline at end of file From 2cb98c48c26d9669a5f95979015181b9d0ea645e Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 10 Mar 2017 21:51:05 +0000 Subject: [PATCH 27/96] Improved dependency checking --- src/pocketmine/PocketMine.php | 37 ++++++++++++++--------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 3e69e6d9d..9a0269657 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -398,11 +398,6 @@ namespace pocketmine { ++$errors; } - if(!extension_loaded("sockets")){ - $logger->critical("Unable to find the Socket extension."); - ++$errors; - } - $pthreads_version = phpversion("pthreads"); if(substr_count($pthreads_version, ".") < 2){ $pthreads_version = "0.$pthreads_version"; @@ -431,24 +426,22 @@ namespace pocketmine { "); } - if(!extension_loaded("curl")){ - $logger->critical("Unable to find the cURL extension."); - ++$errors; - } + $extensions = [ + "curl" => "cURL", + "json" => "JSON", + "mbstring" => "Multibyte String", + "yaml" => "YAML", + "openssl" => "OpenSSL", + "sockets" => "Sockets", + "zip" => "Zip", + "zlib" => "Zlib" + ]; - if(!extension_loaded("yaml")){ - $logger->critical("Unable to find the YAML extension."); - ++$errors; - } - - if(!extension_loaded("zlib")){ - $logger->critical("Unable to find the Zlib extension."); - ++$errors; - } - - if(!extension_loaded("openssl")){ - $logger->critical("Unable to find the OpenSSL extension."); - ++$errors; + foreach($extensions as $ext => $name){ + if(!extension_loaded($ext)){ + $logger->critical("Unable to find the $name ($ext) extension."); + ++$errors; + } } if($errors > 0){ From e1fb4a44e91b6a516f501963a0e4449a508be026 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 11 Mar 2017 10:59:02 +0000 Subject: [PATCH 28/96] Updated PocketMine-Language submodule --- src/pocketmine/Player.php | 2 +- src/pocketmine/lang/locale | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 2448ff2da..42b21d623 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1993,7 +1993,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $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); //TODO: add strings to lang files + $this->close("", "disconnectionScreen.resourcePack", true); break; } diff --git a/src/pocketmine/lang/locale b/src/pocketmine/lang/locale index 7ac7004e2..8d56e216b 160000 --- a/src/pocketmine/lang/locale +++ b/src/pocketmine/lang/locale @@ -1 +1 @@ -Subproject commit 7ac7004e2dde7d3e424aef2514f1eb8b98192ea9 +Subproject commit 8d56e216be03710208800ba31aa3b63612742623 From ed765a2c9bddd7d8ee60735b6df86628c5140e2b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 11 Mar 2017 11:19:14 +0000 Subject: [PATCH 29/96] Added debug messages for resource requests with invalid pack IDs --- src/pocketmine/Player.php | 3 +++ src/pocketmine/resourcepacks/ResourcePackManager.php | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 42b21d623..28d0b8317 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1994,6 +1994,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade 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())); break; } @@ -3320,6 +3321,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $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 " . $uuid . ", available packs: " . implode(", ", $manager->getPackIdList())); + return true; } diff --git a/src/pocketmine/resourcepacks/ResourcePackManager.php b/src/pocketmine/resourcepacks/ResourcePackManager.php index 7ec44bed0..97ab8130e 100644 --- a/src/pocketmine/resourcepacks/ResourcePackManager.php +++ b/src/pocketmine/resourcepacks/ResourcePackManager.php @@ -126,4 +126,11 @@ class ResourcePackManager{ public function getPackById(string $id){ return $this->uuidList[$id] ?? null; } + + /** + * @return string[] + */ + public function getPackIdList() : array{ + return array_keys($this->uuidList); + } } \ No newline at end of file From 91a92b4e57b4da07d3fcbdb280197f878466c8b4 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 11 Mar 2017 11:40:07 +0000 Subject: [PATCH 30/96] Use a pre-created resource packs config with comments to explain how to use it --- src/pocketmine/resourcepacks/ResourcePackManager.php | 10 ++++------ src/pocketmine/resources/resource_packs.yml | 12 ++++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 src/pocketmine/resources/resource_packs.yml diff --git a/src/pocketmine/resourcepacks/ResourcePackManager.php b/src/pocketmine/resourcepacks/ResourcePackManager.php index 97ab8130e..ed47ecb57 100644 --- a/src/pocketmine/resourcepacks/ResourcePackManager.php +++ b/src/pocketmine/resourcepacks/ResourcePackManager.php @@ -57,14 +57,12 @@ class ResourcePackManager{ throw new \InvalidArgumentException("Resource packs path $path exists and is not a directory"); } - $this->resourcePacksConfig = new Config($this->path . "resource_packs.yml", Config::YAML, []); - - if(count($this->resourcePacksConfig->getAll()) === 0){ - $this->resourcePacksConfig->set("force_resources", false); - $this->resourcePacksConfig->set("resource_stack", []); - $this->resourcePacksConfig->save(); + if(!file_exists($this->path . "resource_packs.yml")){ + file_put_contents($this->path . "resource_packs.yml", file_get_contents($this->server->getFilePath() . "src/pocketmine/resources/resource_packs.yml")); } + $this->resourcePacksConfig = new Config($this->path . "resource_packs.yml", Config::YAML, []); + $this->serverForceResources = (bool) $this->resourcePacksConfig->get("force_resources", false); $this->server->getLogger()->info("Loading resource packs..."); diff --git a/src/pocketmine/resources/resource_packs.yml b/src/pocketmine/resources/resource_packs.yml new file mode 100644 index 000000000..331760e97 --- /dev/null +++ b/src/pocketmine/resources/resource_packs.yml @@ -0,0 +1,12 @@ +#This configuration file controls global resources used on your PocketMine-MP server. + +#Choose whether players must use your chosen resource packs to join the server. +#NOTE: This will do nothing if there are no resource packs in the stack below. +force_resources: false +resource_stack: + #Resource packs here are applied from bottom to top. This means that resources in higher packs will override those in lower packs. + #Entries here must indicate the filename of the resource pack. + #Example + # - natural.zip + # - vanilla.zip + #If you want to force clients to use vanilla resources, you must place a vanilla resource pack in your resources folder and add it to the stack here. \ No newline at end of file From 004880548c6d59db811bee479b700b4b1ae999ee Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 11 Mar 2017 12:13:55 +0000 Subject: [PATCH 31/96] Autogenerated data for 1.0.5.0 --- .../network/mcpe/protocol/ProtocolInfo.php | 110 +++++++++--------- 1 file changed, 58 insertions(+), 52 deletions(-) diff --git a/src/pocketmine/network/mcpe/protocol/ProtocolInfo.php b/src/pocketmine/network/mcpe/protocol/ProtocolInfo.php index b3bbb780c..3a5fa1114 100644 --- a/src/pocketmine/network/mcpe/protocol/ProtocolInfo.php +++ b/src/pocketmine/network/mcpe/protocol/ProtocolInfo.php @@ -16,6 +16,7 @@ * @author PocketMine Team * @link http://www.pocketmine.net/ * + * This file is generated automatically, do not edit it manually. * */ @@ -30,9 +31,9 @@ interface ProtocolInfo{ /** * Actual Minecraft: PE protocol version */ - const CURRENT_PROTOCOL = 102; - const MINECRAFT_VERSION = "v1.0.4.11"; - const MINECRAFT_VERSION_NETWORK = "1.0.4.11"; + const CURRENT_PROTOCOL = 105; + const MINECRAFT_VERSION = "v1.0.5.0 beta"; + const MINECRAFT_VERSION_NETWORK = "1.0.5.0"; const LOGIN_PACKET = 0x01; const PLAY_STATUS_PACKET = 0x02; @@ -68,54 +69,59 @@ interface ProtocolInfo{ const MOB_EQUIPMENT_PACKET = 0x20; const MOB_ARMOR_EQUIPMENT_PACKET = 0x21; const INTERACT_PACKET = 0x22; - const USE_ITEM_PACKET = 0x23; - const PLAYER_ACTION_PACKET = 0x24; - const PLAYER_FALL_PACKET = 0x25; - const HURT_ARMOR_PACKET = 0x26; - const SET_ENTITY_DATA_PACKET = 0x27; - const SET_ENTITY_MOTION_PACKET = 0x28; - const SET_ENTITY_LINK_PACKET = 0x29; - const SET_HEALTH_PACKET = 0x2a; - const SET_SPAWN_POSITION_PACKET = 0x2b; - const ANIMATE_PACKET = 0x2c; - const RESPAWN_PACKET = 0x2d; - const DROP_ITEM_PACKET = 0x2e; - const INVENTORY_ACTION_PACKET = 0x2f; - const CONTAINER_OPEN_PACKET = 0x30; - const CONTAINER_CLOSE_PACKET = 0x31; - const CONTAINER_SET_SLOT_PACKET = 0x32; - const CONTAINER_SET_DATA_PACKET = 0x33; - const CONTAINER_SET_CONTENT_PACKET = 0x34; - const CRAFTING_DATA_PACKET = 0x35; - const CRAFTING_EVENT_PACKET = 0x36; - const ADVENTURE_SETTINGS_PACKET = 0x37; - const BLOCK_ENTITY_DATA_PACKET = 0x38; - const PLAYER_INPUT_PACKET = 0x39; - const FULL_CHUNK_DATA_PACKET = 0x3a; - const SET_COMMANDS_ENABLED_PACKET = 0x3b; - const SET_DIFFICULTY_PACKET = 0x3c; - const CHANGE_DIMENSION_PACKET = 0x3d; - const SET_PLAYER_GAME_TYPE_PACKET = 0x3e; - const PLAYER_LIST_PACKET = 0x3f; - const EVENT_PACKET = 0x40; //TelemetryEventPacket - const SPAWN_EXPERIENCE_ORB_PACKET = 0x41; - const CLIENTBOUND_MAP_ITEM_DATA_PACKET = 0x42; //MapItemDataPacket - const MAP_INFO_REQUEST_PACKET = 0x43; - const REQUEST_CHUNK_RADIUS_PACKET = 0x44; - const CHUNK_RADIUS_UPDATED_PACKET = 0x45; - const ITEM_FRAME_DROP_ITEM_PACKET = 0x46; - const REPLACE_ITEM_IN_SLOT_PACKET = 0x47; //ReplaceSelectedItemPacket - const GAME_RULES_CHANGED_PACKET = 0x48; - const CAMERA_PACKET = 0x49; - const ADD_ITEM_PACKET = 0x4a; - const BOSS_EVENT_PACKET = 0x4b; - const SHOW_CREDITS_PACKET = 0x4c; - const AVAILABLE_COMMANDS_PACKET = 0x4d; - const COMMAND_STEP_PACKET = 0x4e; - const UPDATE_TRADE_PACKET = 0x4f; - const RESOURCE_PACK_DATA_INFO_PACKET = 0x50; - const RESOURCE_PACK_CHUNK_DATA_PACKET = 0x51; - const RESOURCE_PACK_CHUNK_REQUEST_PACKET = 0x52; - const TRANSFER_PACKET = 0x53; + const BLOCK_PICK_REQUEST_PACKET = 0x23; + const USE_ITEM_PACKET = 0x24; + const PLAYER_ACTION_PACKET = 0x25; + const PLAYER_FALL_PACKET = 0x26; + const HURT_ARMOR_PACKET = 0x27; + const SET_ENTITY_DATA_PACKET = 0x28; + const SET_ENTITY_MOTION_PACKET = 0x29; + const SET_ENTITY_LINK_PACKET = 0x2a; + const SET_HEALTH_PACKET = 0x2b; + const SET_SPAWN_POSITION_PACKET = 0x2c; + const ANIMATE_PACKET = 0x2d; + const RESPAWN_PACKET = 0x2e; + const DROP_ITEM_PACKET = 0x2f; + const INVENTORY_ACTION_PACKET = 0x30; + const CONTAINER_OPEN_PACKET = 0x31; + const CONTAINER_CLOSE_PACKET = 0x32; + const CONTAINER_SET_SLOT_PACKET = 0x33; + const CONTAINER_SET_DATA_PACKET = 0x34; + const CONTAINER_SET_CONTENT_PACKET = 0x35; + const CRAFTING_DATA_PACKET = 0x36; + const CRAFTING_EVENT_PACKET = 0x37; + const ADVENTURE_SETTINGS_PACKET = 0x38; + const BLOCK_ENTITY_DATA_PACKET = 0x39; + const PLAYER_INPUT_PACKET = 0x3a; + const FULL_CHUNK_DATA_PACKET = 0x3b; + const SET_COMMANDS_ENABLED_PACKET = 0x3c; + const SET_DIFFICULTY_PACKET = 0x3d; + const CHANGE_DIMENSION_PACKET = 0x3e; + const SET_PLAYER_GAME_TYPE_PACKET = 0x3f; + const PLAYER_LIST_PACKET = 0x40; + const EVENT_PACKET = 0x41; //TelemetryEventPacket + const SPAWN_EXPERIENCE_ORB_PACKET = 0x42; + const CLIENTBOUND_MAP_ITEM_DATA_PACKET = 0x43; //MapItemDataPacket + const MAP_INFO_REQUEST_PACKET = 0x44; + const REQUEST_CHUNK_RADIUS_PACKET = 0x45; + const CHUNK_RADIUS_UPDATED_PACKET = 0x46; + const ITEM_FRAME_DROP_ITEM_PACKET = 0x47; + const REPLACE_ITEM_IN_SLOT_PACKET = 0x48; //ReplaceSelectedItemPacket + const GAME_RULES_CHANGED_PACKET = 0x49; + const CAMERA_PACKET = 0x4a; + const ADD_ITEM_PACKET = 0x4b; + const BOSS_EVENT_PACKET = 0x4c; + const SHOW_CREDITS_PACKET = 0x4d; + const AVAILABLE_COMMANDS_PACKET = 0x4e; + const COMMAND_STEP_PACKET = 0x4f; + const COMMAND_BLOCK_UPDATE_PACKET = 0x50; + const UPDATE_TRADE_PACKET = 0x51; + const RESOURCE_PACK_DATA_INFO_PACKET = 0x52; + const RESOURCE_PACK_CHUNK_DATA_PACKET = 0x53; + const RESOURCE_PACK_CHUNK_REQUEST_PACKET = 0x54; + const TRANSFER_PACKET = 0x55; + const PLAY_SOUND_PACKET = 0x56; + const STOP_SOUND_PACKET = 0x57; + const SET_TITLE_PACKET = 0x58; } From 6f1b12b021ab4cc6d5eee6c44d0d559e4f79db66 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 11 Mar 2017 19:54:03 +0000 Subject: [PATCH 32/96] Added new 1.0.5 packets --- src/pocketmine/Player.php | 25 +++++ src/pocketmine/network/Network.php | 10 ++ .../network/mcpe/NetworkSession.php | 15 +++ .../mcpe/protocol/BlockPickRequestPacket.php | 52 +++++++++++ .../protocol/CommandBlockUpdatePacket.php | 92 +++++++++++++++++++ .../network/mcpe/protocol/DataPacket.php | 42 ++++++--- .../network/mcpe/protocol/PlaySoundPacket.php | 58 ++++++++++++ .../network/mcpe/protocol/SetTitlePacket.php | 66 +++++++++++++ .../network/mcpe/protocol/StopSoundPacket.php | 50 ++++++++++ 9 files changed, 399 insertions(+), 11 deletions(-) create mode 100644 src/pocketmine/network/mcpe/protocol/BlockPickRequestPacket.php create mode 100644 src/pocketmine/network/mcpe/protocol/CommandBlockUpdatePacket.php create mode 100644 src/pocketmine/network/mcpe/protocol/PlaySoundPacket.php create mode 100644 src/pocketmine/network/mcpe/protocol/SetTitlePacket.php create mode 100644 src/pocketmine/network/mcpe/protocol/StopSoundPacket.php diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 28d0b8317..ef44d72e6 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -115,10 +115,12 @@ use pocketmine\network\mcpe\protocol\AvailableCommandsPacket; use pocketmine\network\mcpe\protocol\BatchPacket; use pocketmine\network\mcpe\protocol\BlockEntityDataPacket; use pocketmine\network\mcpe\protocol\BlockEventPacket; +use pocketmine\network\mcpe\protocol\BlockPickRequestPacket; 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\CommandStepPacket; use pocketmine\network\mcpe\protocol\ContainerClosePacket; use pocketmine\network\mcpe\protocol\ContainerOpenPacket; @@ -150,6 +152,7 @@ use pocketmine\network\mcpe\protocol\PlayerActionPacket; use pocketmine\network\mcpe\protocol\PlayerFallPacket; use pocketmine\network\mcpe\protocol\PlayerInputPacket; use pocketmine\network\mcpe\protocol\PlayerListPacket; +use pocketmine\network\mcpe\protocol\PlaySoundPacket; use pocketmine\network\mcpe\protocol\PlayStatusPacket; use pocketmine\network\mcpe\protocol\ProtocolInfo; use pocketmine\network\mcpe\protocol\RemoveBlockPacket; @@ -174,9 +177,11 @@ use pocketmine\network\mcpe\protocol\SetHealthPacket; use pocketmine\network\mcpe\protocol\SetPlayerGameTypePacket; 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\SpawnExperienceOrbPacket; use pocketmine\network\mcpe\protocol\StartGamePacket; +use pocketmine\network\mcpe\protocol\StopSoundPacket; use pocketmine\network\mcpe\protocol\TakeItemEntityPacket; use pocketmine\network\mcpe\protocol\TextPacket; use pocketmine\network\mcpe\protocol\TransferPacket; @@ -2452,6 +2457,10 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return true; } + public function handleBlockPickRequest(BlockPickRequestPacket $packet) : bool{ + return false; //TODO + } + public function handleUseItem(UseItemPacket $packet) : bool{ if($this->spawned === false or !$this->isAlive()){ return true; @@ -3304,6 +3313,10 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return true; } + public function handleCommandBlockUpdate(CommandBlockUpdatePacket $packet) : bool{ + return false; //TODO + } + public function handleUpdateTrade(UpdateTradePacket $packet) : bool{ return false; } @@ -3339,6 +3352,18 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade 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 handleUnknown(UnknownPacket $packet) : bool{ $this->server->getLogger()->debug("Received unknown packet from " . $this->getName() . ": 0x" . bin2hex($packet->payload)); return true; diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index 49e00b370..abe41caba 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -36,10 +36,12 @@ use pocketmine\network\mcpe\protocol\AvailableCommandsPacket; use pocketmine\network\mcpe\protocol\BatchPacket; use pocketmine\network\mcpe\protocol\BlockEntityDataPacket; use pocketmine\network\mcpe\protocol\BlockEventPacket; +use pocketmine\network\mcpe\protocol\BlockPickRequestPacket; 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\CommandStepPacket; use pocketmine\network\mcpe\protocol\ContainerClosePacket; use pocketmine\network\mcpe\protocol\ContainerOpenPacket; @@ -56,6 +58,7 @@ use pocketmine\network\mcpe\protocol\ExplodePacket; use pocketmine\network\mcpe\protocol\FullChunkDataPacket; use pocketmine\network\mcpe\protocol\HurtArmorPacket; use pocketmine\network\mcpe\protocol\MapInfoRequestPacket; +use pocketmine\network\mcpe\protocol\PlaySoundPacket; use pocketmine\network\mcpe\protocol\ProtocolInfo; use pocketmine\network\mcpe\protocol\InteractPacket; use pocketmine\network\mcpe\protocol\InventoryActionPacket; @@ -93,9 +96,11 @@ use pocketmine\network\mcpe\protocol\SetHealthPacket; use pocketmine\network\mcpe\protocol\SetPlayerGameTypePacket; 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\SpawnExperienceOrbPacket; use pocketmine\network\mcpe\protocol\StartGamePacket; +use pocketmine\network\mcpe\protocol\StopSoundPacket; use pocketmine\network\mcpe\protocol\TakeItemEntityPacket; use pocketmine\network\mcpe\protocol\TextPacket; use pocketmine\network\mcpe\protocol\TransferPacket; @@ -320,10 +325,12 @@ class Network{ $this->registerPacket(ProtocolInfo::BATCH_PACKET, BatchPacket::class); $this->registerPacket(ProtocolInfo::BLOCK_ENTITY_DATA_PACKET, BlockEntityDataPacket::class); $this->registerPacket(ProtocolInfo::BLOCK_EVENT_PACKET, BlockEventPacket::class); + $this->registerPacket(ProtocolInfo::BLOCK_PICK_REQUEST_PACKET, BlockPickRequestPacket::class); $this->registerPacket(ProtocolInfo::CHANGE_DIMENSION_PACKET, ChangeDimensionPacket::class); $this->registerPacket(ProtocolInfo::CHUNK_RADIUS_UPDATED_PACKET, ChunkRadiusUpdatedPacket::class); $this->registerPacket(ProtocolInfo::CLIENTBOUND_MAP_ITEM_DATA_PACKET, ClientboundMapItemDataPacket::class); $this->registerPacket(ProtocolInfo::CLIENT_TO_SERVER_HANDSHAKE_PACKET, ClientToServerHandshakePacket::class); + $this->registerPacket(ProtocolInfo::COMMAND_BLOCK_UPDATE_PACKET, CommandBlockUpdatePacket::class); $this->registerPacket(ProtocolInfo::COMMAND_STEP_PACKET, CommandStepPacket::class); $this->registerPacket(ProtocolInfo::CONTAINER_CLOSE_PACKET, ContainerClosePacket::class); $this->registerPacket(ProtocolInfo::CONTAINER_OPEN_PACKET, ContainerOpenPacket::class); @@ -353,6 +360,7 @@ class Network{ $this->registerPacket(ProtocolInfo::PLAYER_FALL_PACKET, PlayerFallPacket::class); $this->registerPacket(ProtocolInfo::PLAYER_INPUT_PACKET, PlayerInputPacket::class); $this->registerPacket(ProtocolInfo::PLAYER_LIST_PACKET, PlayerListPacket::class); + $this->registerPacket(ProtocolInfo::PLAY_SOUND_PACKET, PlaySoundPacket::class); $this->registerPacket(ProtocolInfo::PLAY_STATUS_PACKET, PlayStatusPacket::class); $this->registerPacket(ProtocolInfo::REMOVE_BLOCK_PACKET, RemoveBlockPacket::class); $this->registerPacket(ProtocolInfo::REMOVE_ENTITY_PACKET, RemoveEntityPacket::class); @@ -375,9 +383,11 @@ class Network{ $this->registerPacket(ProtocolInfo::SET_PLAYER_GAME_TYPE_PACKET, SetPlayerGameTypePacket::class); $this->registerPacket(ProtocolInfo::SET_SPAWN_POSITION_PACKET, SetSpawnPositionPacket::class); $this->registerPacket(ProtocolInfo::SET_TIME_PACKET, SetTimePacket::class); + $this->registerPacket(ProtocolInfo::SET_TITLE_PACKET, SetTitlePacket::class); $this->registerPacket(ProtocolInfo::SHOW_CREDITS_PACKET, ShowCreditsPacket::class); $this->registerPacket(ProtocolInfo::SPAWN_EXPERIENCE_ORB_PACKET, SpawnExperienceOrbPacket::class); $this->registerPacket(ProtocolInfo::START_GAME_PACKET, StartGamePacket::class); + $this->registerPacket(ProtocolInfo::STOP_SOUND_PACKET, StopSoundPacket::class); $this->registerPacket(ProtocolInfo::TAKE_ITEM_ENTITY_PACKET, TakeItemEntityPacket::class); $this->registerPacket(ProtocolInfo::TEXT_PACKET, TextPacket::class); $this->registerPacket(ProtocolInfo::TRANSFER_PACKET, TransferPacket::class); diff --git a/src/pocketmine/network/mcpe/NetworkSession.php b/src/pocketmine/network/mcpe/NetworkSession.php index ae790ae9e..a0c0ecfc3 100644 --- a/src/pocketmine/network/mcpe/NetworkSession.php +++ b/src/pocketmine/network/mcpe/NetworkSession.php @@ -35,10 +35,12 @@ use pocketmine\network\mcpe\protocol\AvailableCommandsPacket; use pocketmine\network\mcpe\protocol\BatchPacket; use pocketmine\network\mcpe\protocol\BlockEntityDataPacket; use pocketmine\network\mcpe\protocol\BlockEventPacket; +use pocketmine\network\mcpe\protocol\BlockPickRequestPacket; 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\CommandStepPacket; use pocketmine\network\mcpe\protocol\ContainerClosePacket; use pocketmine\network\mcpe\protocol\ContainerOpenPacket; @@ -69,6 +71,7 @@ use pocketmine\network\mcpe\protocol\PlayerActionPacket; use pocketmine\network\mcpe\protocol\PlayerFallPacket; use pocketmine\network\mcpe\protocol\PlayerInputPacket; use pocketmine\network\mcpe\protocol\PlayerListPacket; +use pocketmine\network\mcpe\protocol\PlaySoundPacket; use pocketmine\network\mcpe\protocol\PlayStatusPacket; use pocketmine\network\mcpe\protocol\RemoveBlockPacket; use pocketmine\network\mcpe\protocol\RemoveEntityPacket; @@ -92,9 +95,11 @@ use pocketmine\network\mcpe\protocol\SetHealthPacket; use pocketmine\network\mcpe\protocol\SetPlayerGameTypePacket; 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\SpawnExperienceOrbPacket; use pocketmine\network\mcpe\protocol\StartGamePacket; +use pocketmine\network\mcpe\protocol\StopSoundPacket; use pocketmine\network\mcpe\protocol\TakeItemEntityPacket; use pocketmine\network\mcpe\protocol\TextPacket; use pocketmine\network\mcpe\protocol\TransferPacket; @@ -174,6 +179,8 @@ interface NetworkSession{ public function handleInteract(InteractPacket $packet) : bool; + public function handleBlockPickRequest(BlockPickRequestPacket $packet) : bool; + public function handleUseItem(UseItemPacket $packet) : bool; public function handlePlayerAction(PlayerActionPacket $packet) : bool; @@ -262,6 +269,8 @@ interface NetworkSession{ public function handleCommandStep(CommandStepPacket $packet) : bool; + public function handleCommandBlockUpdate(CommandBlockUpdatePacket $packet) : bool; + public function handleUpdateTrade(UpdateTradePacket $packet) : bool; public function handleResourcePackDataInfo(ResourcePackDataInfoPacket $packet) : bool; @@ -272,5 +281,11 @@ interface NetworkSession{ public function handleTransfer(TransferPacket $packet) : bool; + public function handlePlaySound(PlaySoundPacket $packet) : bool; + + public function handleStopSound(StopSoundPacket $packet) : bool; + + public function handleSetTitle(SetTitlePacket $packet) : bool; + public function handleUnknown(UnknownPacket $packet) : bool; } \ No newline at end of file diff --git a/src/pocketmine/network/mcpe/protocol/BlockPickRequestPacket.php b/src/pocketmine/network/mcpe/protocol/BlockPickRequestPacket.php new file mode 100644 index 000000000..89ff5180f --- /dev/null +++ b/src/pocketmine/network/mcpe/protocol/BlockPickRequestPacket.php @@ -0,0 +1,52 @@ + + + +use pocketmine\network\mcpe\NetworkSession; + +class BlockPickRequestPacket extends DataPacket{ + const NETWORK_ID = ProtocolInfo::BLOCK_PICK_REQUEST_PACKET; + + public $tileX; + public $tileY; + public $tileZ; + public $hotbarSlot; + + public function decode(){ + $this->getSignedBlockPosition($this->tileX, $this->tileY, $this->tileZ); + $this->hotbarSlot = $this->getByte(); + } + + public function encode(){ + $this->reset(); + $this->putSignedBlockPosition($this->tileX, $this->tileY, $this->tileZ); + $this->putByte($this->hotbarSlot); + } + + public function handle(NetworkSession $session) : bool{ + return $session->handleBlockPickRequest($this); + } +} \ No newline at end of file diff --git a/src/pocketmine/network/mcpe/protocol/CommandBlockUpdatePacket.php b/src/pocketmine/network/mcpe/protocol/CommandBlockUpdatePacket.php new file mode 100644 index 000000000..f99720e5f --- /dev/null +++ b/src/pocketmine/network/mcpe/protocol/CommandBlockUpdatePacket.php @@ -0,0 +1,92 @@ + + + +use pocketmine\network\mcpe\NetworkSession; + +class CommandBlockUpdatePacket extends DataPacket{ + const NETWORK_ID = ProtocolInfo::COMMAND_BLOCK_UPDATE_PACKET; + + public $isCommandBlockUpdate; + + public $x; + public $y; + public $z; + public $commandBlockMode; + public $isRedstoneMode; + public $isConditional; + + public $eid; + + public $command; + public $lastOutput; + public $name; + + public $shouldTrackOutput; + + public function decode(){ + $this->isCommandBlockUpdate = $this->getBool(); + + if($this->isCommandBlockUpdate){ + $this->getBlockPosition($this->x, $this->y, $this->z); + $this->commandBlockMode = $this->getUnsignedVarInt(); + $this->isRedstoneMode = $this->getBool(); + $this->isConditional = $this->getBool(); + }else{ + $this->eid = $this->getEntityRuntimeId(); + } + + $this->command = $this->getString(); + $this->lastOutput = $this->getString(); + $this->name = $this->getString(); + + $this->shouldTrackOutput = $this->getBool(); + } + + public function encode(){ + $this->reset(); + $this->putBool($this->isCommandBlockUpdate); + + if($this->isCommandBlockUpdate){ + $this->putBlockPosition($this->x, $this->y, $this->z); + $this->putUnsignedVarInt($this->commandBlockMode); + $this->putBool($this->isRedstoneMode); + $this->putBool($this->isConditional); + }else{ + $this->putEntityRuntimeId($this->eid); + } + + $this->putString($this->command); + $this->putString($this->lastOutput); + $this->putString($this->name); + + $this->putBool($this->shouldTrackOutput); + } + + public function handle(NetworkSession $session) : bool{ + return $session->handleCommandBlockUpdate($this); + } +} \ No newline at end of file diff --git a/src/pocketmine/network/mcpe/protocol/DataPacket.php b/src/pocketmine/network/mcpe/protocol/DataPacket.php index d08193289..18f006290 100644 --- a/src/pocketmine/network/mcpe/protocol/DataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/DataPacket.php @@ -116,17 +116,15 @@ abstract class DataPacket extends BinaryStream{ $value[2] = $item->getDamage(); break; case Entity::DATA_TYPE_POS: - $value = []; - $value[0] = $this->getVarInt(); //x - $value[1] = $this->getVarInt(); //y (SIGNED) - $value[2] = $this->getVarInt(); //z + $value = [0, 0, 0]; + $this->getSignedBlockPosition(...$value); break; case Entity::DATA_TYPE_LONG: $value = $this->getVarLong(); break; case Entity::DATA_TYPE_VECTOR3F: $value = [0.0, 0.0, 0.0]; - $this->getVector3f($value[0], $value[1], $value[2]); + $this->getVector3f(...$value); break; default: $value = []; @@ -173,16 +171,14 @@ abstract class DataPacket extends BinaryStream{ break; case Entity::DATA_TYPE_POS: //TODO: change this implementation (use objects) - $this->putVarInt($d[1][0]); //x - $this->putVarInt($d[1][1]); //y (SIGNED) - $this->putVarInt($d[1][2]); //z + $this->putSignedBlockPosition(...$d[1]); break; case Entity::DATA_TYPE_LONG: $this->putVarLong($d[1]); break; case Entity::DATA_TYPE_VECTOR3F: //TODO: change this implementation (use objects) - $this->putVector3f($d[1][0], $d[1][1], $d[1][2]); //x, y, z + $this->putVector3f(...$d[1]); //x, y, z } } } @@ -220,7 +216,7 @@ abstract class DataPacket extends BinaryStream{ } /** - * Writes an block position with unsigned Y coordinate. + * Reads an block position with unsigned Y coordinate. * @param int $x * @param int $y 0-255 * @param int $z @@ -232,7 +228,7 @@ abstract class DataPacket extends BinaryStream{ } /** - * Reads a block position with unsigned Y coordinate. + * Writes a block position with unsigned Y coordinate. * @param int &$x * @param int &$y * @param int &$z @@ -243,6 +239,30 @@ abstract class DataPacket extends BinaryStream{ $this->putVarInt($z); } + /** + * Reads a block position with a signed Y coordinate. + * @param int &$x + * @param int &$y + * @param int &$z + */ + public function getSignedBlockPosition(&$x, &$y, &$z){ + $x = $this->getVarInt(); + $y = $this->getVarInt(); + $z = $this->getVarInt(); + } + + /** + * Writes a block position with a signed Y coordinate. + * @param int $x + * @param int $y + * @param int $z + */ + public function putSignedBlockPosition($x, $y, $z){ + $this->putVarInt($x); + $this->putVarInt($y); + $this->putVarInt($z); + } + /** * Reads a floating-point vector3 rounded to 4dp. * @param float $x diff --git a/src/pocketmine/network/mcpe/protocol/PlaySoundPacket.php b/src/pocketmine/network/mcpe/protocol/PlaySoundPacket.php new file mode 100644 index 000000000..ba40a6a82 --- /dev/null +++ b/src/pocketmine/network/mcpe/protocol/PlaySoundPacket.php @@ -0,0 +1,58 @@ + + + +use pocketmine\network\mcpe\NetworkSession; + +class PlaySoundPacket extends DataPacket{ + const NETWORK_ID = ProtocolInfo::PLAY_SOUND_PACKET; + + public $string1; + public $x; + public $y; + public $z; + public $float1; + public $float2; + + public function decode(){ + $this->string1 = $this->getString(); + $this->getBlockPosition($this->x, $this->y, $this->z); + $this->float1 = $this->getLFloat(); + $this->float2 = $this->getLFloat(); + } + + public function encode(){ + $this->reset(); + $this->putString($this->string1); + $this->putBlockPosition($this->x, $this->y, $this->z); + $this->putLFloat($this->float1); + $this->putLFloat($this->float2); + } + + public function handle(NetworkSession $session) : bool{ + return $session->handlePlaySound($this); + } +} \ No newline at end of file diff --git a/src/pocketmine/network/mcpe/protocol/SetTitlePacket.php b/src/pocketmine/network/mcpe/protocol/SetTitlePacket.php new file mode 100644 index 000000000..3ecf312d4 --- /dev/null +++ b/src/pocketmine/network/mcpe/protocol/SetTitlePacket.php @@ -0,0 +1,66 @@ + + + +use pocketmine\network\mcpe\NetworkSession; + +class SetTitlePacket extends DataPacket{ + const NETWORK_ID = ProtocolInfo::SET_TITLE_PACKET; + + const TYPE_CLEAR_TITLE = 0; + const TYPE_RESET_TITLE = 1; + const TYPE_SET_TITLE = 2; + const TYPE_SET_SUBTITLE = 3; + const TYPE_SET_ACTIONBAR_MESSAGE = 4; + const TYPE_SET_ANIMATION_TIMES = 5; + + public $type; + public $text; + public $fadeInTime; + public $stayTime; + public $fadeOutTime; + + public function decode(){ + $this->type = $this->getVarInt(); + $this->text = $this->getString(); + $this->fadeInTime = $this->getVarInt(); + $this->stayTime = $this->getVarInt(); + $this->fadeOutTime = $this->getVarInt(); + } + + public function encode(){ + $this->reset(); + $this->putVarInt($this->type); + $this->putString($this->text); + $this->putVarInt($this->fadeInTime); + $this->putVarInt($this->stayTime); + $this->putVarInt($this->fadeOutTime); + } + + public function handle(NetworkSession $session) : bool{ + return $session->handleSetTitle($this); + } +} \ No newline at end of file diff --git a/src/pocketmine/network/mcpe/protocol/StopSoundPacket.php b/src/pocketmine/network/mcpe/protocol/StopSoundPacket.php new file mode 100644 index 000000000..a339f9121 --- /dev/null +++ b/src/pocketmine/network/mcpe/protocol/StopSoundPacket.php @@ -0,0 +1,50 @@ + + + +use pocketmine\network\mcpe\NetworkSession; + +class StopSoundPacket extends DataPacket{ + const NETWORK_ID = ProtocolInfo::STOP_SOUND_PACKET; + + public $string1; + public $stopAll; + + public function decode(){ + $this->string1 = $this->getString(); + $this->stopAll = $this->getBool(); + } + + public function encode(){ + $this->reset(); + $this->putString($this->string1); + $this->putBool($this->stopAll); + } + + public function handle(NetworkSession $session) : bool{ + return $session->handleStopSound($this); + } +} \ No newline at end of file From f58ee2028e6f1a0eb7bf8b5a89e0ceef7c619c54 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 12 Mar 2017 19:52:57 +0000 Subject: [PATCH 33/96] Moved effects stuff to json --- src/pocketmine/entity/Effect.php | 44 ++++----- src/pocketmine/lang/locale | 2 +- src/pocketmine/resources/effects.json | 131 ++++++++++++++++++++++++++ 3 files changed, 149 insertions(+), 28 deletions(-) create mode 100644 src/pocketmine/resources/effects.json diff --git a/src/pocketmine/entity/Effect.php b/src/pocketmine/entity/Effect.php index 9e95cd20b..f55c4b1de 100644 --- a/src/pocketmine/entity/Effect.php +++ b/src/pocketmine/entity/Effect.php @@ -28,6 +28,7 @@ use pocketmine\event\entity\EntityRegainHealthEvent; use pocketmine\event\player\PlayerExhaustEvent; use pocketmine\network\mcpe\protocol\MobEffectPacket; use pocketmine\Player; +use pocketmine\utils\Config; class Effect{ const SPEED = 1; @@ -58,34 +59,23 @@ class Effect{ const SATURATION = 23; /** @var Effect[] */ - protected static $effects; + protected static $effects = []; public static function init(){ - self::$effects = new \SplFixedArray(256); + $config = new Config(\pocketmine\PATH . "src/pocketmine/resources/effects.json", Config::JSON, []); - self::$effects[Effect::SPEED] = new Effect(Effect::SPEED, "%potion.moveSpeed", 124, 175, 198); - self::$effects[Effect::SLOWNESS] = new Effect(Effect::SLOWNESS, "%potion.moveSlowdown", 90, 108, 129, true); - self::$effects[Effect::SWIFTNESS] = new Effect(Effect::SWIFTNESS, "%potion.digSpeed", 217, 192, 67); - self::$effects[Effect::FATIGUE] = new Effect(Effect::FATIGUE, "%potion.digSlowDown", 74, 66, 23, true); - self::$effects[Effect::STRENGTH] = new Effect(Effect::STRENGTH, "%potion.damageBoost", 147, 36, 35); - //self::$effects[Effect::HEALING] = new InstantEffect(Effect::HEALING, "%potion.heal", 248, 36, 35); - //self::$effects[Effect::HARMING] = new InstantEffect(Effect::HARMING, "%potion.harm", 67, 10, 9, true); - self::$effects[Effect::JUMP] = new Effect(Effect::JUMP, "%potion.jump", 34, 255, 76); - self::$effects[Effect::NAUSEA] = new Effect(Effect::NAUSEA, "%potion.confusion", 85, 29, 74, true); - self::$effects[Effect::REGENERATION] = new Effect(Effect::REGENERATION, "%potion.regeneration", 205, 92, 171); - self::$effects[Effect::DAMAGE_RESISTANCE] = new Effect(Effect::DAMAGE_RESISTANCE, "%potion.resistance", 153, 69, 58); - self::$effects[Effect::FIRE_RESISTANCE] = new Effect(Effect::FIRE_RESISTANCE, "%potion.fireResistance", 228, 154, 58); - self::$effects[Effect::WATER_BREATHING] = new Effect(Effect::WATER_BREATHING, "%potion.waterBreathing", 46, 82, 153); - self::$effects[Effect::INVISIBILITY] = new Effect(Effect::INVISIBILITY, "%potion.invisibility", 127, 131, 146); - self::$effects[Effect::BLINDNESS] = new Effect(Effect::BLINDNESS, "%potion.blindness", 191, 192, 192); - self::$effects[Effect::NIGHT_VISION] = new Effect(Effect::NIGHT_VISION, "%potion.nightVision", 0, 0, 139); - self::$effects[Effect::HUNGER] = new Effect(Effect::HUNGER, "%potion.hunger", 46, 139, 87); - self::$effects[Effect::WEAKNESS] = new Effect(Effect::WEAKNESS, "%potion.weakness", 72, 77, 72, true); - self::$effects[Effect::POISON] = new Effect(Effect::POISON, "%potion.poison", 78, 147, 49, true); - self::$effects[Effect::WITHER] = new Effect(Effect::WITHER, "%potion.wither", 53, 42, 39, true); - self::$effects[Effect::HEALTH_BOOST] = new Effect(Effect::HEALTH_BOOST, "%potion.healthBoost", 248, 125, 35); - self::$effects[Effect::ABSORPTION] = new Effect(Effect::ABSORPTION, "%potion.absorption", 36, 107, 251); - self::$effects[Effect::SATURATION] = new Effect(Effect::SATURATION, "%potion.saturation", 255, 0, 255); + foreach($config->getAll() as $name => $data){ + $color = hexdec($data["color"]); + $r = ($color >> 16) & 0xff; + $g = ($color >> 8) & 0xff; + $b = $color & 0xff; + self::registerEffect($name, new Effect($data["id"], "%" . $data["name"], $r, $g, $b, $data["isBad"] ?? false)); + } + } + + public static function registerEffect(string $internalName, Effect $effect){ + self::$effects[$effect->getId()] = $effect; + self::$effects[$internalName] = $effect; } /** @@ -101,8 +91,8 @@ class Effect{ } public static function getEffectByName($name){ - if(defined(Effect::class . "::" . strtoupper($name))){ - return self::getEffect(constant(Effect::class . "::" . strtoupper($name))); + if(isset(self::$effects[$name])){ + return clone self::$effects[$name]; } return null; } diff --git a/src/pocketmine/lang/locale b/src/pocketmine/lang/locale index 8d56e216b..a1c4d8f11 160000 --- a/src/pocketmine/lang/locale +++ b/src/pocketmine/lang/locale @@ -1 +1 @@ -Subproject commit 8d56e216be03710208800ba31aa3b63612742623 +Subproject commit a1c4d8f117f27b7da42a9db644e3c252c1fc033a diff --git a/src/pocketmine/resources/effects.json b/src/pocketmine/resources/effects.json new file mode 100644 index 000000000..b750536dd --- /dev/null +++ b/src/pocketmine/resources/effects.json @@ -0,0 +1,131 @@ +{ + "speed": { + "id": 1, + "color": "7cafc6", + "name": "potion.moveSpeed" + }, + "slowness": { + "id": 2, + "color": "5a6c81", + "name": "potion.moveSlowdown", + "isBad": true + }, + "haste": { + "id": 3, + "color": "d9c043", + "name": "potion.digSpeed" + }, + "mining_fatigue": { + "id": 4, + "color": "4a4217", + "name": "potion.digSlowDown", + "isBad": true + }, + "strength": { + "id": 5, + "color": "932423", + "name": "potion.damageBoost" + }, + "instant_health": { + "id": 6, + "color": "f82423", + "name": "potion.heal" + }, + "instant_damage": { + "id": 7, + "color": "430a09", + "name": "potion.harm", + "isBad": true + }, + "jump_boost": { + "id": 8, + "color": "22ff4c", + "name": "potion.jump" + }, + "nausea": { + "id": 9, + "color": "551d4a", + "name": "potion.confusion", + "isBad": true + }, + "regeneration": { + "id": 10, + "color": "cd5cab", + "name": "potion.regeneration" + }, + "resistance": { + "id": 11, + "color": "99453a", + "name": "potion.resistance" + }, + "fire_resistance": { + "id": 12, + "color": "e49a3a", + "name": "potion.fireResistance" + }, + "water_breathing": { + "id": 13, + "color": "2e5299", + "name": "potion.waterBreathing" + }, + "invisibility": { + "id": 14, + "color": "7f8392", + "name": "potion.invisibility" + }, + "blindness": { + "id": 15, + "color": "1f1f23", + "name": "potion.blindness", + "isBad": true + }, + "night_vision": { + "id": 16, + "color": "1f1fa1", + "name": "potion.nightVision" + }, + "hunger": { + "id": 17, + "color": "587653", + "name": "potion.hunger", + "isBad": true + }, + "weakness": { + "id": 18, + "color": "484d48", + "name": "potion.weakness", + "isBad": true + }, + "poison": { + "id": 19, + "color": "4e9331", + "name": "potion.poison", + "isBad": true + }, + "wither": { + "id": 20, + "color": "352a27", + "name": "potion.wither", + "isBad": true + }, + "health_boost": { + "id": 21, + "color": "f87d23", + "name": "potion.healthBoost" + }, + "absorption": { + "id": 22, + "color": "2552a5", + "name": "potion.absorption" + }, + "saturation": { + "id": 23, + "color": "f82423", + "name": "potion.saturation" + }, + "levitation": { + "id": 24, + "color": "ceffff", + "name": "potion.levitation" + } +} \ No newline at end of file From 955dc38be4b99f72ca188d7038b6519be937b7cb Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 12 Mar 2017 20:06:39 +0000 Subject: [PATCH 34/96] Fixed botch-job implementation of Health Boost, will now actually work and not crash the server --- src/pocketmine/entity/Effect.php | 83 ++++++++++++++++++++------------ src/pocketmine/entity/Entity.php | 6 +-- src/pocketmine/entity/Living.php | 4 ++ 3 files changed, 58 insertions(+), 35 deletions(-) diff --git a/src/pocketmine/entity/Effect.php b/src/pocketmine/entity/Effect.php index f55c4b1de..ccbe3d109 100644 --- a/src/pocketmine/entity/Effect.php +++ b/src/pocketmine/entity/Effect.php @@ -263,27 +263,42 @@ class Effect{ $entity->dataPacket($pk); } - if($this->id === Effect::INVISIBILITY){ - $entity->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, true); - $entity->setNameTagVisible(false); - }elseif($this->id === Effect::SPEED){ - $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); - if($ev->willModify() and $oldEffect !== null){ - $speed = $attr->getValue() / (1 + 0.2 * $oldEffect->getAmplifier()); - }else{ - $speed = $attr->getValue(); - } - $speed *= (1 + 0.2 * $this->amplifier); - $attr->setValue($speed); - }elseif($this->id === Effect::SLOWNESS){ - $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); - if($ev->willModify() and $oldEffect !== null){ - $speed = $attr->getValue() / (1 - 0.15 * $oldEffect->getAmplifier()); - }else{ - $speed = $attr->getValue(); - } - $speed *= (1 - 0.15 * $this->amplifier); - $attr->setValue($speed, true); + switch($this->id){ + case Effect::INVISIBILITY: + $entity->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, true); + $entity->setNameTagVisible(false); + break; + case Effect::SPEED: + $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); + if($ev->willModify() and $oldEffect !== null){ + $speed = $attr->getValue() / (1 + 0.2 * $oldEffect->getAmplifier()); + }else{ + $speed = $attr->getValue(); + } + $speed *= (1 + 0.2 * $this->amplifier); + $attr->setValue($speed); + break; + case Effect::SLOWNESS: + $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); + if($ev->willModify() and $oldEffect !== null){ + $speed = $attr->getValue() / (1 - 0.15 * $oldEffect->getAmplifier()); + }else{ + $speed = $attr->getValue(); + } + $speed *= (1 - 0.15 * $this->amplifier); + $attr->setValue($speed, true); + break; + case Effect::HEALTH_BOOST: + $attr = $entity->getAttributeMap()->getAttribute(Attribute::HEALTH); + if($ev->willModify() and $oldEffect !== null){ + $max = $attr->getMaxValue() - (4 * ($this->amplifier + 1)); + }else{ + $max = $attr->getMaxValue(); + } + + $max += (4 * ($this->amplifier + 1)); + $attr->setMaxValue($max); + break; } } @@ -301,15 +316,23 @@ class Effect{ $entity->dataPacket($pk); } - if($this->id === Effect::INVISIBILITY){ - $entity->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, false); - $entity->setNameTagVisible(true); - }elseif($this->id === Effect::SPEED){ - $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); - $attr->setValue($attr->getValue() / (1 + 0.2 * $this->amplifier)); - }elseif($this->id === Effect::SLOWNESS){ - $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); - $attr->setValue($attr->getValue() / (1 - 0.15 * $this->amplifier)); + switch($this->id){ + case Effect::INVISIBILITY: + $entity->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, false); + $entity->setNameTagVisible(true); + break; + case Effect::SPEED: + $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); + $attr->setValue($attr->getValue() / (1 + 0.2 * $this->amplifier)); + break; + case Effect::SLOWNESS: + $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); + $attr->setValue($attr->getValue() / (1 - 0.15 * $this->amplifier)); + break; + case Effect::HEALTH_BOOST: + $attr = $entity->getAttributeMap()->getAttribute(Attribute::HEALTH); + $attr->setMaxValue($attr->getMaxValue() - (4 * ($this->amplifier + 1))); + break; } } } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index e3edaccd8..3c09d906d 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -484,10 +484,6 @@ abstract class Entity extends Location implements Metadatable{ $this->effects[$effect->getId()] = $effect; $this->recalculateEffectColor(); - - if($effect->getId() === Effect::HEALTH_BOOST){ - $this->setHealth($this->getHealth() + 4 * ($effect->getAmplifier() + 1)); - } } protected function recalculateEffectColor(){ @@ -811,7 +807,7 @@ abstract class Entity extends Location implements Metadatable{ * @return int */ public function getMaxHealth(){ - return $this->maxHealth + ($this->hasEffect(Effect::HEALTH_BOOST) ? 4 * ($this->getEffect(Effect::HEALTH_BOOST)->getAmplifier() + 1) : 0); + return $this->maxHealth; } /** diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index e9b8d2429..b8510434f 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -77,6 +77,10 @@ abstract class Living extends Entity implements Damageable{ } } + public function getMaxHealth(){ + return $this->attributeMap->getAttribute(Attribute::HEALTH)->getMaxValue(); + } + public function setMaxHealth($amount){ $this->attributeMap->getAttribute(Attribute::HEALTH)->setMaxValue($amount); } From 78278a0b9343116975588b86278a6dc250409317 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 12 Mar 2017 20:15:21 +0000 Subject: [PATCH 35/96] Fixed a mistake in old effect handling --- src/pocketmine/entity/Effect.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/entity/Effect.php b/src/pocketmine/entity/Effect.php index ccbe3d109..f901245fb 100644 --- a/src/pocketmine/entity/Effect.php +++ b/src/pocketmine/entity/Effect.php @@ -291,7 +291,7 @@ class Effect{ case Effect::HEALTH_BOOST: $attr = $entity->getAttributeMap()->getAttribute(Attribute::HEALTH); if($ev->willModify() and $oldEffect !== null){ - $max = $attr->getMaxValue() - (4 * ($this->amplifier + 1)); + $max = $attr->getMaxValue() - (4 * ($oldEffect->getAmplifier() + 1)); }else{ $max = $attr->getMaxValue(); } From 565335f29e4e09381989650d6c8bafba299e3c22 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 12 Mar 2017 14:24:49 -0400 Subject: [PATCH 36/96] Revert "TODO: REVERT - Added a workaround for client text duplication" This reverts commit 52748fcf64830453967fab4b43d6e823aeb37ecf. --- src/pocketmine/Player.php | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index c1a15661b..8abf3b25b 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1681,15 +1681,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->timings->stopTiming(); - //TODO: remove this workaround (broken client MCPE 1.0.0) - if(count($this->messageQueue) > 0){ - $pk = new TextPacket(); - $pk->type = TextPacket::TYPE_RAW; - $pk->message = implode("\n", $this->messageQueue); - $this->dataPacket($pk); - $this->messageQueue = []; - } - return true; } @@ -3404,9 +3395,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return false; } - /** @var string[] */ - private $messageQueue = []; - /** * Sends a direct chat message to a player * @@ -3421,14 +3409,10 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $message = $message->getText(); } - //TODO: Remove this workaround (broken client MCPE 1.0.0) - $this->messageQueue[] = $this->server->getLanguage()->translateString($message); - /* $pk = new TextPacket(); $pk->type = TextPacket::TYPE_RAW; $pk->message = $this->server->getLanguage()->translateString($message); $this->dataPacket($pk); - */ } public function sendTranslation($message, array $parameters = []){ From bb85308b01dc826ede29e19f8eedbbebc929172e Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 13 Mar 2017 09:46:39 +0000 Subject: [PATCH 37/96] Fix undefined variable --- src/pocketmine/Player.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 61c7f979e..39df6e115 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -3274,7 +3274,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $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 " . $uuid . ", available packs: " . implode(", ", $manager->getPackIdList())); + $this->server->getLogger()->debug("Got a resource pack chunk request for unknown pack with UUID " . $packet->packId . ", available packs: " . implode(", ", $manager->getPackIdList())); return true; } From e7dbda922a5e8eb4a2f7e5529c6965febdbaac8b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 13 Mar 2017 10:44:23 +0000 Subject: [PATCH 38/96] Rename some CommandBlockUpdatePacket fields --- .../mcpe/protocol/CommandBlockUpdatePacket.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/pocketmine/network/mcpe/protocol/CommandBlockUpdatePacket.php b/src/pocketmine/network/mcpe/protocol/CommandBlockUpdatePacket.php index f99720e5f..cba3f9ad0 100644 --- a/src/pocketmine/network/mcpe/protocol/CommandBlockUpdatePacket.php +++ b/src/pocketmine/network/mcpe/protocol/CommandBlockUpdatePacket.php @@ -30,7 +30,7 @@ use pocketmine\network\mcpe\NetworkSession; class CommandBlockUpdatePacket extends DataPacket{ const NETWORK_ID = ProtocolInfo::COMMAND_BLOCK_UPDATE_PACKET; - public $isCommandBlockUpdate; + public $isBlock; public $x; public $y; @@ -39,7 +39,7 @@ class CommandBlockUpdatePacket extends DataPacket{ public $isRedstoneMode; public $isConditional; - public $eid; + public $minecartEid; public $command; public $lastOutput; @@ -48,15 +48,16 @@ class CommandBlockUpdatePacket extends DataPacket{ public $shouldTrackOutput; public function decode(){ - $this->isCommandBlockUpdate = $this->getBool(); + $this->isBlock = $this->getBool(); - if($this->isCommandBlockUpdate){ + if($this->isBlock){ $this->getBlockPosition($this->x, $this->y, $this->z); $this->commandBlockMode = $this->getUnsignedVarInt(); $this->isRedstoneMode = $this->getBool(); $this->isConditional = $this->getBool(); }else{ - $this->eid = $this->getEntityRuntimeId(); + //Minecart with command block + $this->minecartEid = $this->getEntityRuntimeId(); } $this->command = $this->getString(); @@ -68,15 +69,15 @@ class CommandBlockUpdatePacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putBool($this->isCommandBlockUpdate); + $this->putBool($this->isBlock); - if($this->isCommandBlockUpdate){ + if($this->isBlock){ $this->putBlockPosition($this->x, $this->y, $this->z); $this->putUnsignedVarInt($this->commandBlockMode); $this->putBool($this->isRedstoneMode); $this->putBool($this->isConditional); }else{ - $this->putEntityRuntimeId($this->eid); + $this->putEntityRuntimeId($this->minecartEid); } $this->putString($this->command); From 9e341f74d867accf075bd234f791bc1c8cb43d91 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 13 Mar 2017 11:27:44 +0000 Subject: [PATCH 39/96] Added new window types and found some UpdateTradePacket fields --- .../network/mcpe/protocol/UpdateTradePacket.php | 13 +++++++------ .../mcpe/protocol/types/InventoryNetworkIds.php | 5 +++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/pocketmine/network/mcpe/protocol/UpdateTradePacket.php b/src/pocketmine/network/mcpe/protocol/UpdateTradePacket.php index 8b13bb4c1..319a34e76 100644 --- a/src/pocketmine/network/mcpe/protocol/UpdateTradePacket.php +++ b/src/pocketmine/network/mcpe/protocol/UpdateTradePacket.php @@ -26,13 +26,14 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\protocol\types\InventoryNetworkIds; class UpdateTradePacket extends DataPacket{ const NETWORK_ID = ProtocolInfo::UPDATE_TRADE_PACKET; //TODO: find fields - public $byte1; - public $byte2; + public $windowId; + public $windowType = InventoryNetworkIds::TRADING; //Mojang hardcoded this -_- public $varint1; public $varint2; public $isWilling; @@ -42,8 +43,8 @@ class UpdateTradePacket extends DataPacket{ public $offers; public function decode(){ - $this->byte1 = $this->getByte(); - $this->byte2 = $this->getByte(); + $this->windowId = $this->getByte(); + $this->windowType = $this->getByte(); $this->varint1 = $this->getVarInt(); $this->varint2 = $this->getVarInt(); $this->isWilling = $this->getBool(); @@ -55,8 +56,8 @@ class UpdateTradePacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putByte($this->byte1); - $this->putByte($this->byte2); + $this->putByte($this->windowId); + $this->putByte($this->windowType); $this->putVarInt($this->varint1); $this->putVarInt($this->varint2); $this->putBool($this->isWilling); diff --git a/src/pocketmine/network/mcpe/protocol/types/InventoryNetworkIds.php b/src/pocketmine/network/mcpe/protocol/types/InventoryNetworkIds.php index 671010b02..be64b880c 100644 --- a/src/pocketmine/network/mcpe/protocol/types/InventoryNetworkIds.php +++ b/src/pocketmine/network/mcpe/protocol/types/InventoryNetworkIds.php @@ -39,4 +39,9 @@ interface InventoryNetworkIds{ const MINECART_CHEST = 10; const MINECART_HOPPER = 11; const HORSE = 12; + const BEACON = 13; + const STRUCTURE_EDITOR = 14; + const TRADING = 15; + const COMMAND_BLOCK = 16; + } \ No newline at end of file From c344caaf78bf834ef3cfed1ffde95d5797ea725f Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 13 Mar 2017 11:30:40 +0000 Subject: [PATCH 40/96] Refactor InventoryNetworkIds as WindowTypes --- src/pocketmine/inventory/InventoryType.php | 20 +++++++++---------- .../mcpe/protocol/UpdateTradePacket.php | 4 ++-- ...nventoryNetworkIds.php => WindowTypes.php} | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) rename src/pocketmine/network/mcpe/protocol/types/{InventoryNetworkIds.php => WindowTypes.php} (97%) diff --git a/src/pocketmine/inventory/InventoryType.php b/src/pocketmine/inventory/InventoryType.php index 86d1a3ddd..4b97db2e9 100644 --- a/src/pocketmine/inventory/InventoryType.php +++ b/src/pocketmine/inventory/InventoryType.php @@ -21,7 +21,7 @@ namespace pocketmine\inventory; -use pocketmine\network\mcpe\protocol\types\InventoryNetworkIds; +use pocketmine\network\mcpe\protocol\types\WindowTypes; /** * Saves all the information regarding default inventory sizes and types @@ -63,15 +63,15 @@ class InventoryType{ //TODO: move network stuff out of here //TODO: move inventory data to json static::$default = [ - static::CHEST => new InventoryType(27, "Chest", InventoryNetworkIds::CONTAINER), - static::DOUBLE_CHEST => new InventoryType(27 + 27, "Double Chest", InventoryNetworkIds::CONTAINER), - static::PLAYER => new InventoryType(36 + 4, "Player", InventoryNetworkIds::INVENTORY), //36 CONTAINER, 4 ARMOR - static::CRAFTING => new InventoryType(5, "Crafting", InventoryNetworkIds::INVENTORY), //yes, the use of INVENTORY is intended! 4 CRAFTING slots, 1 RESULT - static::WORKBENCH => new InventoryType(10, "Crafting", InventoryNetworkIds::WORKBENCH), //9 CRAFTING slots, 1 RESULT - static::FURNACE => new InventoryType(3, "Furnace", InventoryNetworkIds::FURNACE), //2 INPUT, 1 OUTPUT - static::ENCHANT_TABLE => new InventoryType(2, "Enchant", InventoryNetworkIds::ENCHANTMENT), //1 INPUT/OUTPUT, 1 LAPIS - static::BREWING_STAND => new InventoryType(4, "Brewing", InventoryNetworkIds::BREWING_STAND), //1 INPUT, 3 POTION - static::ANVIL => new InventoryType(3, "Anvil", InventoryNetworkIds::ANVIL) //2 INPUT, 1 OUTP + static::CHEST => new InventoryType(27, "Chest", WindowTypes::CONTAINER), + static::DOUBLE_CHEST => new InventoryType(27 + 27, "Double Chest", WindowTypes::CONTAINER), + static::PLAYER => new InventoryType(36 + 4, "Player", WindowTypes::INVENTORY), //36 CONTAINER, 4 ARMOR + static::CRAFTING => new InventoryType(5, "Crafting", WindowTypes::INVENTORY), //yes, the use of INVENTORY is intended! 4 CRAFTING slots, 1 RESULT + static::WORKBENCH => new InventoryType(10, "Crafting", WindowTypes::WORKBENCH), //9 CRAFTING slots, 1 RESULT + static::FURNACE => new InventoryType(3, "Furnace", WindowTypes::FURNACE), //2 INPUT, 1 OUTPUT + static::ENCHANT_TABLE => new InventoryType(2, "Enchant", WindowTypes::ENCHANTMENT), //1 INPUT/OUTPUT, 1 LAPIS + static::BREWING_STAND => new InventoryType(4, "Brewing", WindowTypes::BREWING_STAND), //1 INPUT, 3 POTION + static::ANVIL => new InventoryType(3, "Anvil", WindowTypes::ANVIL) //2 INPUT, 1 OUTP ]; } diff --git a/src/pocketmine/network/mcpe/protocol/UpdateTradePacket.php b/src/pocketmine/network/mcpe/protocol/UpdateTradePacket.php index 319a34e76..6a8f76e2e 100644 --- a/src/pocketmine/network/mcpe/protocol/UpdateTradePacket.php +++ b/src/pocketmine/network/mcpe/protocol/UpdateTradePacket.php @@ -26,14 +26,14 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\NetworkSession; -use pocketmine\network\mcpe\protocol\types\InventoryNetworkIds; +use pocketmine\network\mcpe\protocol\types\WindowTypes; class UpdateTradePacket extends DataPacket{ const NETWORK_ID = ProtocolInfo::UPDATE_TRADE_PACKET; //TODO: find fields public $windowId; - public $windowType = InventoryNetworkIds::TRADING; //Mojang hardcoded this -_- + public $windowType = WindowTypes::TRADING; //Mojang hardcoded this -_- public $varint1; public $varint2; public $isWilling; diff --git a/src/pocketmine/network/mcpe/protocol/types/InventoryNetworkIds.php b/src/pocketmine/network/mcpe/protocol/types/WindowTypes.php similarity index 97% rename from src/pocketmine/network/mcpe/protocol/types/InventoryNetworkIds.php rename to src/pocketmine/network/mcpe/protocol/types/WindowTypes.php index be64b880c..667b69674 100644 --- a/src/pocketmine/network/mcpe/protocol/types/InventoryNetworkIds.php +++ b/src/pocketmine/network/mcpe/protocol/types/WindowTypes.php @@ -23,7 +23,7 @@ namespace pocketmine\network\mcpe\protocol\types; -interface InventoryNetworkIds{ +interface WindowTypes{ const INVENTORY = -1; const CONTAINER = 0; From 3c709b1d3e50cbfc521ed8191aeb388521e50676 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 13 Mar 2017 15:52:00 +0000 Subject: [PATCH 41/96] Return false on unhandled/unknown resource pack client response status --- src/pocketmine/Player.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 8abf3b25b..61ecff1fe 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2006,6 +2006,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade case ResourcePackClientResponsePacket::STATUS_COMPLETED: $this->processLogin(); break; + default: + return false; } return true; From b7b73aab23c3fc0a40f7eb9439e23ff9c664225b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 15 Mar 2017 19:22:43 +0000 Subject: [PATCH 42/96] Fixed username regex failing, close #427 --- src/pocketmine/Player.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 39df6e115..340588f6e 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -216,7 +216,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade public static function isValidUserName(string $name) : bool{ $lname = strtolower($name); $len = strlen($name); - return $lname !== "rcon" and $lname !== "console" and $len >= 1 and $len <= 16 and preg_match("[^A-Za-z0-9_]", $name) === 0; + return $lname !== "rcon" and $lname !== "console" and $len >= 1 and $len <= 16 and preg_match("/[^A-Za-z0-9_]/", $name) === 0; } /** From 51a20470f6a1baf5659133ac2d55daf57ef9add5 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 18 Mar 2017 15:03:41 +0000 Subject: [PATCH 43/96] Switch back to the old chunk-packet method since MoveEntityPacket and SetEntityMotionPacket no longer have lists --- src/pocketmine/level/Level.php | 55 ++++++++++------------------------ 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index e16d13ad8..4441058ce 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -134,9 +134,6 @@ class Level implements ChunkManager, Metadatable{ /** @var Tile[] */ private $tiles = []; - private $motionToSend = []; - private $moveToSend = []; - /** @var Player[] */ private $players = []; @@ -723,35 +720,6 @@ class Level implements ChunkManager, Metadatable{ $this->checkSleep(); } - foreach($this->moveToSend as $index => $entry){ - Level::getXZ($index, $chunkX, $chunkZ); - foreach($entry as $e){ - $pk = new MoveEntityPacket(); - $pk->eid = $e[0]; - $pk->x = $e[1]; - $pk->y = $e[2]; - $pk->z = $e[3]; - $pk->yaw = $e[4]; - $pk->headYaw = $e[5]; - $pk->pitch = $e[6]; - $this->addChunkPacket($chunkX, $chunkZ, $pk); - } - } - $this->moveToSend = []; - - foreach($this->motionToSend as $index => $entry){ - Level::getXZ($index, $chunkX, $chunkZ); - foreach($entry as $entity){ - $pk = new SetEntityMotionPacket(); - $pk->eid = $entity[0]; - $pk->motionX = $entity[1]; - $pk->motionY = $entity[2]; - $pk->motionZ = $entity[3]; - $this->addChunkPacket($chunkX, $chunkZ, $pk); - } - } - $this->motionToSend = []; - foreach($this->chunkPackets as $index => $entries){ Level::getXZ($index, $chunkX, $chunkZ); $chunkPlayers = $this->getChunkPlayers($chunkX, $chunkZ); @@ -2827,16 +2795,23 @@ class Level implements ChunkManager, Metadatable{ } public function addEntityMotion(int $chunkX, int $chunkZ, int $entityId, float $x, float $y, float $z){ - if(!isset($this->motionToSend[$index = Level::chunkHash($chunkX, $chunkZ)])){ - $this->motionToSend[$index] = []; - } - $this->motionToSend[$index][$entityId] = [$entityId, $x, $y, $z]; + $pk = new SetEntityMotionPacket(); + $pk->eid = $entityId; + $pk->motionX = $x; + $pk->motionY = $y; + $pk->motionZ = $z; + $this->addChunkPacket($chunkX, $chunkZ, $pk); } public function addEntityMovement(int $chunkX, int $chunkZ, int $entityId, float $x, float $y, float $z, float $yaw, float $pitch, $headYaw = null){ - if(!isset($this->moveToSend[$index = Level::chunkHash($chunkX, $chunkZ)])){ - $this->moveToSend[$index] = []; - } - $this->moveToSend[$index][$entityId] = [$entityId, $x, $y, $z, $yaw, $headYaw === null ? $yaw : $headYaw, $pitch]; + $pk = new MoveEntityPacket(); + $pk->eid = $entityId; + $pk->x = $x; + $pk->y = $y; + $pk->z = $z; + $pk->yaw = $yaw; + $pk->pitch = $pitch; + $pk->headYaw = $headYaw ?? $yaw; + $this->addChunkPacket($chunkX, $chunkZ, $pk); } } From cc0b4d888ea6736f495d5b221eb5999aa4000911 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 18 Mar 2017 15:49:48 +0000 Subject: [PATCH 44/96] Use a resource for reading resource packs from disk --- .../resourcepacks/ZippedResourcePack.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/resourcepacks/ZippedResourcePack.php b/src/pocketmine/resourcepacks/ZippedResourcePack.php index 40977d5d2..f65506bbe 100644 --- a/src/pocketmine/resourcepacks/ZippedResourcePack.php +++ b/src/pocketmine/resourcepacks/ZippedResourcePack.php @@ -49,6 +49,9 @@ class ZippedResourcePack implements ResourcePack{ /** @var string */ protected $sha256 = null; + /** @var resource */ + protected $fileResource; + public function __construct(string $zipPath){ $this->path = $zipPath; @@ -74,6 +77,12 @@ class ZippedResourcePack implements ResourcePack{ } $this->manifest = $manifest; + + $this->fileResource = fopen($zipPath, "rb"); + } + + public function __destruct(){ + fclose($this->fileResource); } public function getPackName() : string{ @@ -100,6 +109,10 @@ class ZippedResourcePack implements ResourcePack{ } public function getPackChunk(int $start, int $length) : string{ - return substr(file_get_contents($this->path), $start, $length); + fseek($this->fileResource, $start); + if(feof($this->fileResource)){ + throw new \RuntimeException("Requested a resource pack chunk with invalid start offset"); + } + return fread($this->fileResource, $length); } } \ No newline at end of file From 0d37d0d896e8f11ff76aebc3d621c8afd16a01e6 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 18 Mar 2017 16:07:03 +0000 Subject: [PATCH 45/96] Added some documentation to resource packs namespace --- src/pocketmine/resourcepacks/ResourcePack.php | 31 +++++++++++++++++++ .../resourcepacks/ResourcePackManager.php | 10 +++++- .../resourcepacks/ZippedResourcePack.php | 12 +++++-- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/resourcepacks/ResourcePack.php b/src/pocketmine/resourcepacks/ResourcePack.php index fd7962896..d4eeeb0e6 100644 --- a/src/pocketmine/resourcepacks/ResourcePack.php +++ b/src/pocketmine/resourcepacks/ResourcePack.php @@ -25,15 +25,46 @@ namespace pocketmine\resourcepacks; interface ResourcePack{ + /** + * Returns the human-readable name of the resource pack + * @return string + */ public function getPackName() : string; + /** + * Returns the pack's UUID as a human-readable string + * @return string + */ public function getPackId() : string; + /** + * Returns the size of the pack on disk in bytes. + * @return int + */ public function getPackSize() : int; + /** + * Returns a version number for the pack in the format major.minor.patch + * @return string + */ public function getPackVersion() : string; + /** + * Returns the raw SHA256 sum of the compressed resource pack zip. This is used by clients to validate pack downloads. + * @return string byte-array length 32 bytes + */ public function getSha256() : string; + /** + * Returns a chunk of the resource pack zip as a byte-array for sending to clients. + * + * Note that resource packs must **always** be in zip archive format for sending. + * A folder resource loader may need to perform on-the-fly compression for this purpose. + * + * @param int $start Offset to start reading the chunk from + * @param int $length Maximum length of data to return. + * + * @return string byte-array + */ public function getPackChunk(int $start, int $length) : string; } \ No newline at end of file diff --git a/src/pocketmine/resourcepacks/ResourcePackManager.php b/src/pocketmine/resourcepacks/ResourcePackManager.php index ed47ecb57..125c31ce0 100644 --- a/src/pocketmine/resourcepacks/ResourcePackManager.php +++ b/src/pocketmine/resourcepacks/ResourcePackManager.php @@ -46,6 +46,10 @@ class ResourcePackManager{ /** @var ResourcePack[] */ private $uuidList = []; + /** + * @param Server $server + * @param string $path Path to resource-packs directory. + */ public function __construct(Server $server, string $path){ $this->server = $server; $this->path = $path; @@ -103,6 +107,7 @@ class ResourcePackManager{ } /** + * Returns whether players must accept resource packs in order to join. * @return bool */ public function resourcePacksRequired() : bool{ @@ -110,6 +115,7 @@ class ResourcePackManager{ } /** + * Returns an array of resource packs in use, sorted in order of priority. * @return ResourcePack[] */ public function getResourceStack() : array{ @@ -117,8 +123,9 @@ class ResourcePackManager{ } /** - * @param string $id + * Returns the resource pack matching the specified UUID string, or null if the ID was not recognized. * + * @param string $id * @return ResourcePack|null */ public function getPackById(string $id){ @@ -126,6 +133,7 @@ class ResourcePackManager{ } /** + * Returns an array of pack IDs for packs currently in use. * @return string[] */ public function getPackIdList() : array{ diff --git a/src/pocketmine/resourcepacks/ZippedResourcePack.php b/src/pocketmine/resourcepacks/ZippedResourcePack.php index f65506bbe..1f49bd8c9 100644 --- a/src/pocketmine/resourcepacks/ZippedResourcePack.php +++ b/src/pocketmine/resourcepacks/ZippedResourcePack.php @@ -25,13 +25,19 @@ namespace pocketmine\resourcepacks; class ZippedResourcePack implements ResourcePack{ + /** + * Performs basic validation checks on a resource pack's manifest.json. + * TODO: add more manifest validation + * + * @param \stdClass $manifest + * @return bool + */ public static function verifyManifest(\stdClass $manifest){ if(!isset($manifest->format_version) or !isset($manifest->header) or !isset($manifest->modules)){ return false; } //Right now we don't care about anything else, only the stuff we're sending to clients. - //TODO: add more manifest validation return isset($manifest->header->description) and isset($manifest->header->name) and @@ -52,7 +58,9 @@ class ZippedResourcePack implements ResourcePack{ /** @var resource */ protected $fileResource; - + /** + * @param string $zipPath Path to the resource pack zip + */ public function __construct(string $zipPath){ $this->path = $zipPath; From 8a28021b4468433a21fab392ce22c04957ed324b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 18 Mar 2017 21:46:02 +0000 Subject: [PATCH 46/96] Use hash_file instead of OpenSSL for resource pack hashing Epic facepalm. I totally forgot this function existed. >_< --- src/pocketmine/PocketMine.php | 1 - src/pocketmine/resourcepacks/ZippedResourcePack.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 9a0269657..9e6d42fac 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -431,7 +431,6 @@ namespace pocketmine { "json" => "JSON", "mbstring" => "Multibyte String", "yaml" => "YAML", - "openssl" => "OpenSSL", "sockets" => "Sockets", "zip" => "Zip", "zlib" => "Zlib" diff --git a/src/pocketmine/resourcepacks/ZippedResourcePack.php b/src/pocketmine/resourcepacks/ZippedResourcePack.php index 1f49bd8c9..80af52660 100644 --- a/src/pocketmine/resourcepacks/ZippedResourcePack.php +++ b/src/pocketmine/resourcepacks/ZippedResourcePack.php @@ -111,7 +111,7 @@ class ZippedResourcePack implements ResourcePack{ public function getSha256(bool $cached = true) : string{ if($this->sha256 === null or !$cached){ - $this->sha256 = openssl_digest(file_get_contents($this->path), "sha256", true); + $this->sha256 = hash_file("sha256", $this->path, true); } return $this->sha256; } From be449b610627c49d511509b1d6a18f2beaf0bdf6 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 19 Mar 2017 10:32:38 +0000 Subject: [PATCH 47/96] Removed useless condition from RemoveBlockPacket handler --- src/pocketmine/Player.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index ac7ccfd3c..057caeee1 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2135,12 +2135,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $vector = new Vector3($packet->x, $packet->y, $packet->z); - if($this->isCreative()){ - $item = $this->inventory->getItemInHand(); - }else{ - $item = $this->inventory->getItemInHand(); - } - + $item = $this->inventory->getItemInHand(); $oldItem = clone $item; if($this->canInteract($vector->add(0.5, 0.5, 0.5), $this->isCreative() ? 13 : 6) and $this->level->useBreakOn($vector, $item, $this, true)){ From 9c350dbe47c2461a284b8a97947d904b0ee92667 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 19 Mar 2017 21:50:09 +0000 Subject: [PATCH 48/96] Fixed DataPacketReceiveEvent, fixed packet receive timings, gave Player->handleDataPacket() a new use --- src/pocketmine/Player.php | 10 +++------ src/pocketmine/network/Network.php | 21 +++++++++++++------ .../network/mcpe/RakLibInterface.php | 5 +---- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 057caeee1..b93234287 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -3291,7 +3291,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } /** - * TODO: get rid of these remains, fix DataPacketReceiveEvent, fix timings + * Called when a packet is received from the client. This method will call DataPacketReceiveEvent. * * @param DataPacket $packet */ @@ -3300,18 +3300,14 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return; } - $timings = Timings::getReceiveDataPacketTimings($packet); - $timings->startTiming(); $this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this, $packet)); - if($ev->isCancelled()){ - $timings->stopTiming(); - return; + if(!$ev->isCancelled() and !$packet->handle($this)){ + $this->server->getLogger()->debug("Unhandled " . get_class($packet) . " received from " . $this->getName()); } - $timings->stopTiming(); } diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index 49e00b370..d7dfc7a3a 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -232,10 +232,22 @@ class Network{ return $this->server; } + /** + * Decodes a batch packet and does handling for it. + * + * TODO: Move this out of here + * + * @param BatchPacket $packet + * @param Player $player + * + * @throws \InvalidArgumentException|\InvalidStateException + */ public function processBatch(BatchPacket $packet, Player $p){ - if(strlen($packet->payload) === 0){ - //prevent zlib_decode errors for incorrectly-decoded packets + $rawLen = strlen($packet->payload); + if($rawLen === 0){ throw new \InvalidArgumentException("BatchPacket payload is empty or packet decode error"); + }elseif($rawLen < 3){ + throw new \InvalidArgumentException("Not enough bytes, expected zlib header"); } $str = zlib_decode($packet->payload, 1024 * 1024 * 64); //Max 64MB @@ -259,10 +271,7 @@ class Network{ $pk->decode(); assert($pk->feof(), "Still " . strlen(substr($pk->buffer, $pk->offset)) . " bytes unread in " . get_class($pk)); - if(!$pk->handle($p)){ - $logger = $this->server->getLogger(); - $logger->debug("Unhandled " . get_class($pk) . " received from " . $p->getName()); - } + $p->handleDataPacket($pk); } } } diff --git a/src/pocketmine/network/mcpe/RakLibInterface.php b/src/pocketmine/network/mcpe/RakLibInterface.php index e113174b8..9a5b12275 100644 --- a/src/pocketmine/network/mcpe/RakLibInterface.php +++ b/src/pocketmine/network/mcpe/RakLibInterface.php @@ -135,10 +135,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{ if($pk !== null){ $pk->decode(); assert($pk->feof(), "Still " . strlen(substr($pk->buffer, $pk->offset)) . " bytes unread!"); - if(!$pk->handle($this->players[$identifier])){ - $logger = $this->server->getLogger(); - $logger->debug("Unhandled " . get_class($pk) . " received from " . $this->players[$identifier]->getName()); - } + $this->players[$identifier]->handleDataPacket($pk); } } }catch(\Throwable $e){ From 4638ccbb68c398b72a6807a81c1b2a3369df07f3 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 19 Mar 2017 21:58:12 +0000 Subject: [PATCH 49/96] Remove this workaround (client bug fixed in 1.0.5 beta) --- src/pocketmine/Player.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index ce1823c3c..0fa8cda49 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2092,10 +2092,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade public function handleMovePlayer(MovePlayerPacket $packet) : bool{ $newPos = new Vector3($packet->x, $packet->y - $this->getEyeHeight(), $packet->z); - if($newPos->distanceSquared($this) == 0 and ($packet->yaw % 360) === $this->yaw and ($packet->pitch % 360) === $this->pitch){ //player hasn't moved, just client spamming packets - return true; - } - $revert = false; if(!$this->isAlive() or $this->spawned !== true){ $revert = true; From 6ba4a8fe5c5e719fc8236050fde8874b6ef7e5bc Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 20 Mar 2017 10:20:54 +0000 Subject: [PATCH 50/96] Moved batch packet handling into BatchPacket->handle(), fixed data packet receive timings to include MCPE packet decode time --- src/pocketmine/Player.php | 9 ++-- src/pocketmine/network/Network.php | 52 ++----------------- .../network/mcpe/NetworkSession.php | 12 +++-- .../network/mcpe/RakLibInterface.php | 6 +-- .../network/mcpe/protocol/BatchPacket.php | 27 +++++++++- 5 files changed, 42 insertions(+), 64 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index b93234287..1e6c9474f 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -112,7 +112,6 @@ 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\BatchPacket; use pocketmine\network\mcpe\protocol\BlockEntityDataPacket; use pocketmine\network\mcpe\protocol\BlockEventPacket; use pocketmine\network\mcpe\protocol\ChangeDimensionPacket; @@ -1959,11 +1958,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return false; } - public function handleBatch(BatchPacket $packet) : bool{ - $this->server->getNetwork()->processBatch($packet, $this); - return true; - } - public function handleResourcePacksInfo(ResourcePacksInfoPacket $packet) : bool{ return false; } @@ -3303,6 +3297,9 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $timings = Timings::getReceiveDataPacketTimings($packet); $timings->startTiming(); + $packet->decode(); + assert($packet->feof(), "Still " . strlen(substr($packet->buffer, $packet->offset)) . " bytes unread in " . get_class($packet)); + $this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this, $packet)); if(!$ev->isCancelled() and !$packet->handle($this)){ $this->server->getLogger()->debug("Unhandled " . get_class($packet) . " received from " . $this->getName()); diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index d7dfc7a3a..1a16800a3 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -55,16 +55,15 @@ use pocketmine\network\mcpe\protocol\EntityEventPacket; use pocketmine\network\mcpe\protocol\ExplodePacket; use pocketmine\network\mcpe\protocol\FullChunkDataPacket; use pocketmine\network\mcpe\protocol\HurtArmorPacket; -use pocketmine\network\mcpe\protocol\MapInfoRequestPacket; -use pocketmine\network\mcpe\protocol\ProtocolInfo; use pocketmine\network\mcpe\protocol\InteractPacket; use pocketmine\network\mcpe\protocol\InventoryActionPacket; use pocketmine\network\mcpe\protocol\ItemFrameDropItemPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; use pocketmine\network\mcpe\protocol\LoginPacket; -use pocketmine\network\mcpe\protocol\MobEquipmentPacket; +use pocketmine\network\mcpe\protocol\MapInfoRequestPacket; use pocketmine\network\mcpe\protocol\MobArmorEquipmentPacket; +use pocketmine\network\mcpe\protocol\MobEquipmentPacket; use pocketmine\network\mcpe\protocol\MoveEntityPacket; use pocketmine\network\mcpe\protocol\MovePlayerPacket; use pocketmine\network\mcpe\protocol\PlayerActionPacket; @@ -72,6 +71,7 @@ use pocketmine\network\mcpe\protocol\PlayerFallPacket; use pocketmine\network\mcpe\protocol\PlayerInputPacket; use pocketmine\network\mcpe\protocol\PlayerListPacket; use pocketmine\network\mcpe\protocol\PlayStatusPacket; +use pocketmine\network\mcpe\protocol\ProtocolInfo; use pocketmine\network\mcpe\protocol\RemoveBlockPacket; use pocketmine\network\mcpe\protocol\RemoveEntityPacket; use pocketmine\network\mcpe\protocol\ReplaceItemInSlotPacket; @@ -103,9 +103,7 @@ use pocketmine\network\mcpe\protocol\UnknownPacket; use pocketmine\network\mcpe\protocol\UpdateBlockPacket; use pocketmine\network\mcpe\protocol\UpdateTradePacket; use pocketmine\network\mcpe\protocol\UseItemPacket; -use pocketmine\Player; use pocketmine\Server; -use pocketmine\utils\BinaryStream; class Network{ @@ -232,50 +230,6 @@ class Network{ return $this->server; } - /** - * Decodes a batch packet and does handling for it. - * - * TODO: Move this out of here - * - * @param BatchPacket $packet - * @param Player $player - * - * @throws \InvalidArgumentException|\InvalidStateException - */ - public function processBatch(BatchPacket $packet, Player $p){ - $rawLen = strlen($packet->payload); - if($rawLen === 0){ - throw new \InvalidArgumentException("BatchPacket payload is empty or packet decode error"); - }elseif($rawLen < 3){ - throw new \InvalidArgumentException("Not enough bytes, expected zlib header"); - } - - $str = zlib_decode($packet->payload, 1024 * 1024 * 64); //Max 64MB - $len = strlen($str); - - if($len === 0){ - throw new \InvalidStateException("Decoded BatchPacket payload is empty"); - } - - $stream = new BinaryStream($str); - - while($stream->offset < $len){ - $buf = $stream->getString(); - - if(($pk = $this->getPacket(ord($buf{0}))) !== null){ - if(!$pk->canBeBatched()){ - throw new \InvalidStateException("Received invalid " . get_class($pk) . " inside BatchPacket"); - } - - $pk->setBuffer($buf, 1); - - $pk->decode(); - assert($pk->feof(), "Still " . strlen(substr($pk->buffer, $pk->offset)) . " bytes unread in " . get_class($pk)); - $p->handleDataPacket($pk); - } - } - } - /** * @param $id * diff --git a/src/pocketmine/network/mcpe/NetworkSession.php b/src/pocketmine/network/mcpe/NetworkSession.php index ae790ae9e..66d19d063 100644 --- a/src/pocketmine/network/mcpe/NetworkSession.php +++ b/src/pocketmine/network/mcpe/NetworkSession.php @@ -32,7 +32,6 @@ 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\BatchPacket; use pocketmine\network\mcpe\protocol\BlockEntityDataPacket; use pocketmine\network\mcpe\protocol\BlockEventPacket; use pocketmine\network\mcpe\protocol\ChangeDimensionPacket; @@ -47,6 +46,7 @@ use pocketmine\network\mcpe\protocol\ContainerSetDataPacket; use pocketmine\network\mcpe\protocol\ContainerSetSlotPacket; use pocketmine\network\mcpe\protocol\CraftingDataPacket; use pocketmine\network\mcpe\protocol\CraftingEventPacket; +use pocketmine\network\mcpe\protocol\DataPacket; use pocketmine\network\mcpe\protocol\DisconnectPacket; use pocketmine\network\mcpe\protocol\DropItemPacket; use pocketmine\network\mcpe\protocol\EntityEventPacket; @@ -103,9 +103,17 @@ use pocketmine\network\mcpe\protocol\UpdateAttributesPacket; use pocketmine\network\mcpe\protocol\UpdateBlockPacket; use pocketmine\network\mcpe\protocol\UpdateTradePacket; use pocketmine\network\mcpe\protocol\UseItemPacket; +use pocketmine\Server; interface NetworkSession{ + /** + * @return Server + */ + public function getServer(); + + public function handleDataPacket(DataPacket $pk); + public function handleLogin(LoginPacket $packet) : bool; public function handlePlayStatus(PlayStatusPacket $packet) : bool; @@ -116,8 +124,6 @@ interface NetworkSession{ public function handleDisconnect(DisconnectPacket $packet) : bool; - public function handleBatch(BatchPacket $packet) : bool; - public function handleResourcePacksInfo(ResourcePacksInfoPacket $packet) : bool; public function handleResourcePackStack(ResourcePackStackPacket $packet) : bool; diff --git a/src/pocketmine/network/mcpe/RakLibInterface.php b/src/pocketmine/network/mcpe/RakLibInterface.php index 9a5b12275..a613d8a41 100644 --- a/src/pocketmine/network/mcpe/RakLibInterface.php +++ b/src/pocketmine/network/mcpe/RakLibInterface.php @@ -132,11 +132,7 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{ try{ if($packet->buffer !== ""){ $pk = $this->getPacket($packet->buffer); - if($pk !== null){ - $pk->decode(); - assert($pk->feof(), "Still " . strlen(substr($pk->buffer, $pk->offset)) . " bytes unread!"); - $this->players[$identifier]->handleDataPacket($pk); - } + $this->players[$identifier]->handleDataPacket($pk); } }catch(\Throwable $e){ if(\pocketmine\DEBUG > 1 and isset($pk)){ diff --git a/src/pocketmine/network/mcpe/protocol/BatchPacket.php b/src/pocketmine/network/mcpe/protocol/BatchPacket.php index 4f952548e..2257655a0 100644 --- a/src/pocketmine/network/mcpe/protocol/BatchPacket.php +++ b/src/pocketmine/network/mcpe/protocol/BatchPacket.php @@ -45,7 +45,32 @@ class BatchPacket extends DataPacket{ } public function handle(NetworkSession $session) : bool{ - return $session->handleBatch($this); + if(strlen($this->payload) < 2){ + throw new \InvalidStateException("Not enough bytes in payload, expected zlib header"); + } + + $str = zlib_decode($this->payload, 1024 * 1024 * 64); //Max 64MB + $len = strlen($str); + + if($len === 0){ + throw new \InvalidStateException("Decoded BatchPacket payload is empty"); + } + + $this->setBuffer($str, 0); + + $network = $session->getServer()->getNetwork(); + while(!$this->feof()){ + $buf = $this->getString(); + $pk = $network->getPacket(ord($buf{0})); + if(!$pk->canBeBatched()){ + throw new \InvalidArgumentException("Received invalid " . get_class($pk) . " inside BatchPacket"); + } + + $pk->setBuffer($buf, 1); + $session->handleDataPacket($pk); + } + + return true; } } \ No newline at end of file From 284c18d40102e91c35108d28473f30256be3b8c2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 20 Mar 2017 10:58:43 +0000 Subject: [PATCH 51/96] Added debug for mismatched item equipment tool damage packets sent in the wrong order? This could be bad for performance since the entire inventory is resent every time this issue crops up. --- src/pocketmine/Player.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 1e6c9474f..b0c448d95 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2237,6 +2237,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $item = $this->inventory->getItem($packet->inventorySlot); if(!$item->equals($packet->item)){ + $this->server->getLogger()->debug("Tried to equip " . $packet->item . " but have " . $item . " in target slot"); $this->inventory->sendContents($this); return false; } From 0e64d4bbc222fedf28109affb3b50a5b1ca0854f Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 20 Mar 2017 12:21:02 +0000 Subject: [PATCH 52/96] Given Player->iusername a use, added Player->getLowerCaseName() Micro optimizations by not repeatedly lowercasing names when searching --- src/pocketmine/Player.php | 7 +++++++ src/pocketmine/Server.php | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index b0c448d95..324404d0f 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -3571,6 +3571,13 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return $this->username; } + /** + * @return string + */ + public function getLowerCaseName() : string{ + return $this->iusername; + } + public function kill(){ if(!$this->spawned){ return; diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 3bf61a76f..1ab35324c 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -817,7 +817,7 @@ class Server{ public function getPlayerExact($name){ $name = strtolower($name); foreach($this->getOnlinePlayers() as $player){ - if(strtolower($player->getName()) === $name){ + if($player->getLowerCaseName() === $name){ return $player; } } @@ -834,7 +834,7 @@ class Server{ $partialName = strtolower($partialName); $matchedPlayers = []; foreach($this->getOnlinePlayers() as $player){ - if(strtolower($player->getName()) === $partialName){ + if($player->getLowerCaseName() === $partialName){ $matchedPlayers = [$player]; break; }elseif(stripos($player->getName(), $partialName) !== false){ From 6a03f8d434b04d200115c504cf6338f30f87385c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 20 Mar 2017 13:20:34 +0000 Subject: [PATCH 53/96] Fixed server creating resource packs directory inside itself when running from a phar Once again, epic facepalm @dktapps --- src/pocketmine/Server.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 1ab35324c..9f0db3dbc 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -1546,7 +1546,7 @@ class Server{ Attribute::init(); $this->craftingManager = new CraftingManager(); - $this->resourceManager = new ResourcePackManager($this, \pocketmine\PATH . "resource_packs" . DIRECTORY_SEPARATOR); + $this->resourceManager = new ResourcePackManager($this, $this->getDataPath() . "resource_packs" . DIRECTORY_SEPARATOR); $this->pluginManager = new PluginManager($this, $this->commandMap); $this->pluginManager->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this->consoleSender); From 2d927db264bf62c926823401e653ffe3a2926bfe Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 21 Mar 2017 11:38:08 +0000 Subject: [PATCH 54/96] Implemented Instant Health and Instant Damage effects --- .../command/defaults/EffectCommand.php | 10 +- src/pocketmine/entity/Effect.php | 162 +++++++++++++++++- src/pocketmine/entity/Entity.php | 2 +- src/pocketmine/entity/InstantEffect.php | 26 --- src/pocketmine/resources/effects.json | 8 +- 5 files changed, 163 insertions(+), 45 deletions(-) delete mode 100644 src/pocketmine/entity/InstantEffect.php diff --git a/src/pocketmine/command/defaults/EffectCommand.php b/src/pocketmine/command/defaults/EffectCommand.php index ba30dc112..76e761b38 100644 --- a/src/pocketmine/command/defaults/EffectCommand.php +++ b/src/pocketmine/command/defaults/EffectCommand.php @@ -23,7 +23,6 @@ namespace pocketmine\command\defaults; use pocketmine\command\CommandSender; use pocketmine\entity\Effect; -use pocketmine\entity\InstantEffect; use pocketmine\event\TranslationContainer; use pocketmine\utils\TextFormat; @@ -80,12 +79,9 @@ class EffectCommand extends VanillaCommand{ $amplification = 0; if(count($args) >= 3){ - $duration = (int) $args[2]; - if(!($effect instanceof InstantEffect)){ - $duration *= 20; - } - }elseif($effect instanceof InstantEffect){ - $duration = 1; + $duration = ((int) $args[2]) * 20; //ticks + }else{ + $duration = $effect->getDefaultDuration(); } if(count($args) >= 4){ diff --git a/src/pocketmine/entity/Effect.php b/src/pocketmine/entity/Effect.php index f901245fb..a867bda37 100644 --- a/src/pocketmine/entity/Effect.php +++ b/src/pocketmine/entity/Effect.php @@ -33,13 +33,11 @@ use pocketmine\utils\Config; class Effect{ const SPEED = 1; const SLOWNESS = 2; - const HASTE = 3; - const SWIFTNESS = 3; - const FATIGUE = 4; - const MINING_FATIGUE = 4; + const HASTE = 3, SWIFTNESS = 3; + const FATIGUE = 4, MINING_FATIGUE = 4; const STRENGTH = 5; -// TODO: const HEALING = 6; -// TODO: const HARMING = 7; + const INSTANT_HEALTH = 6, HEALING = 6; + const INSTANT_DAMAGE = 7, HARMING = 7; const JUMP = 8; const NAUSEA = 9; const CONFUSION = 9; @@ -69,7 +67,16 @@ class Effect{ $r = ($color >> 16) & 0xff; $g = ($color >> 8) & 0xff; $b = $color & 0xff; - self::registerEffect($name, new Effect($data["id"], "%" . $data["name"], $r, $g, $b, $data["isBad"] ?? false)); + self::registerEffect($name, new Effect( + $data["id"], + "%" . $data["name"], + $r, + $g, + $b, + $data["isBad"] ?? false, + $data["default_duration"] ?? 300 * 20, + $data["has_bubbles"] ?? true + )); } } @@ -81,7 +88,7 @@ class Effect{ /** * @param int $id * - * @return $this + * @return Effect|null */ public static function getEffect($id){ if(isset(self::$effects[$id])){ @@ -90,6 +97,11 @@ class Effect{ return null; } + /** + * @param string $name + * + * @return Effect|null + */ public static function getEffectByName($name){ if(isset(self::$effects[$name])){ return clone self::$effects[$name]; @@ -114,40 +126,106 @@ class Effect{ protected $bad; - public function __construct($id, $name, $r, $g, $b, $isBad = false){ + protected $defaultDuration = 300 * 20; + + protected $hasBubbles = true; + + /** + * @param int $id Effect ID as per Minecraft PE + * @param string $name Translation key used for effect name + * @param int $r 0-255, red balance of potion particle colour + * @param int $g 0-255, green balance of potion particle colour + * @param int $b 0-255, blue balance of potion particle colour + * @param bool $isBad Whether the effect is harmful + * @param int $defaultDuration Duration in ticks the effect will last for by default if applied without a duration. + * @param bool $hasBubbles Whether the effect has potion bubbles. Some do not (e.g. Instant Damage has its own particles instead of bubbles) + */ + public function __construct($id, $name, $r, $g, $b, $isBad = false, int $defaultDuration = 300 * 20, bool $hasBubbles = true){ $this->id = $id; $this->name = $name; $this->bad = (bool) $isBad; $this->setColor($r, $g, $b); + $this->defaultDuration = $defaultDuration; + $this->duration = $defaultDuration; + $this->hasBubbles = $hasBubbles; } + /** + * Returns the translation key used to translate this effect's name. + * @return string + */ public function getName(){ return $this->name; } + /** + * Returns the effect ID as per Minecraft PE + * @return int + */ public function getId(){ return $this->id; } + /** + * Sets the duration in ticks of the effect. + * @param $ticks + * + * @return $this + */ public function setDuration($ticks){ $this->duration = $ticks; return $this; } + /** + * Returns the duration remaining of the effect in ticks. + * @return int + */ public function getDuration(){ return $this->duration; } + /** + * Returns the default duration this effect will apply for if a duration is not specified. + * @return int + */ + public function getDefaultDuration() : int{ + return $this->defaultDuration; + } + + /** + * Returns whether this effect will give the subject potion bubbles. + * @return bool + */ + public function hasBubbles() : bool{ + return $this->hasBubbles; + } + + /** + * Returns whether this effect will produce some visible effect, such as bubbles or particles. + * NOTE: Do not confuse this with {@link Effect#hasBubbles}. For example, Instant Damage does not have bubbles, but still produces visible effects (particles). + * + * @return bool + */ public function isVisible(){ return $this->show; } + /** + * Changes the visibility of the effect. + * @param bool $bool + * + * @return $this + */ public function setVisible($bool){ $this->show = (bool) $bool; return $this; } /** + * Returns the amplifier of this effect. + * TODO: fix mess of amplifier used instead of level for effect calculation. + * * @return int */ public function getAmplifier(){ @@ -164,19 +242,40 @@ class Effect{ return $this; } + /** + * Returns whether the effect is ambient. + * @return bool + */ public function isAmbient(){ return $this->ambient; } + /** + * Sets the ambiency of this effect. + * @param bool $ambient + * + * @return $this + */ public function setAmbient($ambient = true){ $this->ambient = (bool) $ambient; return $this; } + /** + * Returns whether this effect is harmful. + * TODO: implement inverse effect results for undead mobs + * + * @return bool + */ public function isBad(){ return $this->bad; } + /** + * Returns whether the effect will do something on the current tick. + * + * @return bool + */ public function canTick(){ switch($this->id){ case Effect::POISON: @@ -202,10 +301,19 @@ class Effect{ return ($this->duration % $interval) === 0; } return true; + case Effect::INSTANT_DAMAGE: + case Effect::INSTANT_HEALTH: + //If forced to last longer than 1 tick, these apply every tick. + return true; } return false; } + /** + * Applies effect results to an entity. + * + * @param Entity $entity + */ public function applyEffect(Entity $entity){ switch($this->id){ case Effect::POISON: @@ -231,17 +339,48 @@ class Effect{ if($entity instanceof Human){ $entity->exhaust(0.5 * $this->amplifier, PlayerExhaustEvent::CAUSE_POTION); } + break; + case Effect::INSTANT_HEALTH: + //TODO: add particles (witch spell) + if($entity->getHealth() < $entity->getMaxHealth()){ + $amount = 2 * (2 ** (($this->amplifier + 1) % 32)); + $entity->heal($amount, new EntityRegainHealthEvent($entity, $amount, EntityRegainHealthEvent::CAUSE_MAGIC)); + } + break; + case Effect::INSTANT_DAMAGE: + //TODO: add particles (witch spell) + $amount = 2 * (2 ** (($this->amplifier + 1) % 32)); + $entity->attack($amount, new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, $amount)); + break; } } + /** + * Returns an RGB color array of this effect's color. + * @return array + */ public function getColor(){ return [$this->color >> 16, ($this->color >> 8) & 0xff, $this->color & 0xff]; } + /** + * Sets the color of this effect. + * + * @param int $r + * @param int $g + * @param int $b + */ public function setColor($r, $g, $b){ $this->color = (($r & 0xff) << 16) + (($g & 0xff) << 8) + ($b & 0xff); } + /** + * Adds this effect to the Entity, performing effect overriding as specified. + * + * @param Entity $entity + * @param bool $modify + * @param Effect|null $oldEffect + */ public function add(Entity $entity, $modify = false, Effect $oldEffect = null){ $entity->getLevel()->getServer()->getPluginManager()->callEvent($ev = new EntityEffectAddEvent($entity, $this, $modify, $oldEffect)); if($ev->isCancelled()){ @@ -302,6 +441,11 @@ class Effect{ } } + /** + * Removes the effect from the entity, resetting any changed values back to their original defaults. + * + * @param Entity $entity + */ public function remove(Entity $entity){ $entity->getLevel()->getServer()->getPluginManager()->callEvent($ev = new EntityEffectRemoveEvent($entity, $this)); if($ev->isCancelled()){ diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index ba1c916a5..1af903d89 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -492,7 +492,7 @@ abstract class Entity extends Location implements Metadatable{ $count = 0; $ambient = true; foreach($this->effects as $effect){ - if($effect->isVisible()){ + if($effect->isVisible() and $effect->hasBubbles()){ $c = $effect->getColor(); $color[0] += $c[0] * ($effect->getAmplifier() + 1); $color[1] += $c[1] * ($effect->getAmplifier() + 1); diff --git a/src/pocketmine/entity/InstantEffect.php b/src/pocketmine/entity/InstantEffect.php deleted file mode 100644 index 708f39bee..000000000 --- a/src/pocketmine/entity/InstantEffect.php +++ /dev/null @@ -1,26 +0,0 @@ - Date: Tue, 21 Mar 2017 11:49:18 +0000 Subject: [PATCH 55/96] Updated Effect constants, removed incorrect/misleading SWIFTNESS constant So what? I'd rather crash plugins than have them suddenly behave strangely because SWIFTNESS is now an alias for SPEED instead of HASTE. --- src/pocketmine/entity/Effect.php | 6 +++--- src/pocketmine/level/Level.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pocketmine/entity/Effect.php b/src/pocketmine/entity/Effect.php index a867bda37..cf25cced1 100644 --- a/src/pocketmine/entity/Effect.php +++ b/src/pocketmine/entity/Effect.php @@ -33,14 +33,13 @@ use pocketmine\utils\Config; class Effect{ const SPEED = 1; const SLOWNESS = 2; - const HASTE = 3, SWIFTNESS = 3; + const HASTE = 3; const FATIGUE = 4, MINING_FATIGUE = 4; const STRENGTH = 5; const INSTANT_HEALTH = 6, HEALING = 6; const INSTANT_DAMAGE = 7, HARMING = 7; const JUMP = 8; - const NAUSEA = 9; - const CONFUSION = 9; + const NAUSEA = 9, CONFUSION = 9; const REGENERATION = 10; const DAMAGE_RESISTANCE = 11; const FIRE_RESISTANCE = 12; @@ -55,6 +54,7 @@ class Effect{ const HEALTH_BOOST = 21; const ABSORPTION = 22; // TODO implement const SATURATION = 23; + const LEVITATION = 24; //TODO /** @var Effect[] */ protected static $effects = []; diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 4441058ce..50dd643b1 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1494,8 +1494,8 @@ class Level implements ChunkManager, Metadatable{ $breakTime = 0.15; } - if($player->hasEffect(Effect::SWIFTNESS)){ - $breakTime *= 1 - (0.2 * ($player->getEffect(Effect::SWIFTNESS)->getAmplifier() + 1)); + if($player->hasEffect(Effect::HASTE)){ + $breakTime *= 1 - (0.2 * ($player->getEffect(Effect::HASTE)->getAmplifier() + 1)); } if($player->hasEffect(Effect::MINING_FATIGUE)){ From 940b20c191b275b152e010ed2ce8b9eb807b43e0 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 21 Mar 2017 13:23:57 +0000 Subject: [PATCH 56/96] Implemented Absorption effect This is a little buggy due to a client-sided bug. https://bugs.mojang.com/browse/MCPE-20520 TODO: add attribute save/restore --- src/pocketmine/entity/Effect.php | 15 +++++++++++++++ src/pocketmine/entity/Entity.php | 24 +++++++++++++++++++++++- src/pocketmine/entity/Living.php | 8 ++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/entity/Effect.php b/src/pocketmine/entity/Effect.php index cf25cced1..a68cd8d55 100644 --- a/src/pocketmine/entity/Effect.php +++ b/src/pocketmine/entity/Effect.php @@ -427,6 +427,7 @@ class Effect{ $speed *= (1 - 0.15 * $this->amplifier); $attr->setValue($speed, true); break; + case Effect::HEALTH_BOOST: $attr = $entity->getAttributeMap()->getAttribute(Attribute::HEALTH); if($ev->willModify() and $oldEffect !== null){ @@ -438,6 +439,17 @@ class Effect{ $max += (4 * ($this->amplifier + 1)); $attr->setMaxValue($max); break; + case Effect::ABSORPTION: + if($ev->willModify() and $oldEffect !== null){ + $value = $entity->getAbsorption() - (4 * ($oldEffect->getAmplifier() + 1)); + }else{ + $value = $entity->getAbsorption(); + } + + $value += (4 * ($this->amplifier + 1)); + $entity->setAbsorption($value); + break; + } } @@ -477,6 +489,9 @@ class Effect{ $attr = $entity->getAttributeMap()->getAttribute(Attribute::HEALTH); $attr->setMaxValue($attr->getMaxValue() - (4 * ($this->amplifier + 1))); break; + case Effect::ABSORPTION: + $entity->setAbsorption($entity->getAbsorption() - (4 * ($this->amplifier + 1))); + break; } } } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 1af903d89..20de4cd3b 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -735,7 +735,21 @@ abstract class Entity extends Location implements Metadatable{ $this->setLastDamageCause($source); - $this->setHealth($this->getHealth() - $source->getFinalDamage()); + $damage = $source->getFinalDamage(); + + $absorption = $this->getAbsorption(); + if($absorption > 0){ + if($absorption > $damage){ + //Use absorption health before normal health. + $this->setAbsorption($absorption - $damage); + $damage = 0; + }else{ + $this->setAbsorption(0); + $damage -= $absorption; + } + } + + $this->setHealth($this->getHealth() - $damage); } /** @@ -785,6 +799,14 @@ abstract class Entity extends Location implements Metadatable{ } } + public function getAbsorption() : int{ + return 0; + } + + public function setAbsorption(int $absorption){ + + } + /** * @param EntityDamageEvent $type */ diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index f8933d39c..fbdac34e5 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -85,6 +85,14 @@ abstract class Living extends Entity implements Damageable{ $this->attributeMap->getAttribute(Attribute::HEALTH)->setMaxValue($amount); } + public function getAbsorption() : int{ + return (int) $this->attributeMap->getAttribute(Attribute::ABSORPTION)->getValue(); + } + + public function setAbsorption(int $absorption){ + $this->attributeMap->getAttribute(Attribute::ABSORPTION)->setValue($absorption); + } + public function saveNBT(){ parent::saveNBT(); $this->namedtag->Health = new ShortTag("Health", $this->getHealth()); From 9a35b4fbc869824076d3738be5f74fff136f701a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 21 Mar 2017 14:03:53 +0000 Subject: [PATCH 57/96] Removed redundant TODO comment --- src/pocketmine/entity/Effect.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/entity/Effect.php b/src/pocketmine/entity/Effect.php index a68cd8d55..49bd99525 100644 --- a/src/pocketmine/entity/Effect.php +++ b/src/pocketmine/entity/Effect.php @@ -52,7 +52,7 @@ class Effect{ const POISON = 19; const WITHER = 20; const HEALTH_BOOST = 21; - const ABSORPTION = 22; // TODO implement + const ABSORPTION = 22; const SATURATION = 23; const LEVITATION = 24; //TODO From 2fb92c1c623de12da8a1317b9cf2510d56fbc016 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 22 Mar 2017 16:10:42 +0000 Subject: [PATCH 58/96] Fixed wrong constant value for EntityEventPacket::RESPAWN --- src/pocketmine/network/mcpe/protocol/EntityEventPacket.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/network/mcpe/protocol/EntityEventPacket.php b/src/pocketmine/network/mcpe/protocol/EntityEventPacket.php index da6357aa7..d8d35edba 100644 --- a/src/pocketmine/network/mcpe/protocol/EntityEventPacket.php +++ b/src/pocketmine/network/mcpe/protocol/EntityEventPacket.php @@ -43,9 +43,10 @@ class EntityEventPacket extends DataPacket{ const FISH_HOOK_TEASE = 14; const SQUID_INK_CLOUD = 15; const AMBIENT_SOUND = 16; - const RESPAWN = 17; - //TODO add new events + const RESPAWN = 18; + + //TODO: add more events public $eid; public $event; From dda8c6cc8f04d917688d003ebe6c4b2b62cd94af Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 26 Mar 2017 13:20:46 +0100 Subject: [PATCH 59/96] Removed a condition that's been useless almost since the beginning of PocketMine This condition has been useless since before NBT was introduced to PocketMine. If there was a use for it, it should have been placed BEFORE anything attempted to read from the NBT. However, Server now handles bad data automatically now, so Server->getOfflinePlayerData() will never _not_ return a CompoundTag. Hence I've added a CompoundTag type-hint. --- src/pocketmine/Player.php | 7 +------ src/pocketmine/Server.php | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index a6aaed00e..b8d8988c6 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1751,6 +1751,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } $nbt = $this->server->getOfflinePlayerData($this->username); + $this->playedBefore = ($nbt["lastPlayed"] - $nbt["firstPlayed"]) > 1; // microtime(true) - microtime(true) may have less than one millisecond difference if(!isset($nbt->NameTag)){ $nbt->NameTag = new StringTag("NameTag", $this->username); @@ -1775,12 +1776,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->setLevel($level); } - if(!($nbt instanceof CompoundTag)){ - $this->close($this->getLeaveMessage(), "Invalid data"); - - return; - } - $this->achievements = []; /** @var ByteTag $achievement */ diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index a882b9b97..bcc61a87a 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -701,7 +701,7 @@ class Server{ * * @return CompoundTag */ - public function getOfflinePlayerData($name){ + public function getOfflinePlayerData($name) : CompoundTag{ $name = strtolower($name); $path = $this->getDataPath() . "players/"; if($this->shouldSavePlayerData()){ From 01440fb65956f49f27886d1c97e26029bc6d3e83 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 26 Mar 2017 13:40:39 +0100 Subject: [PATCH 60/96] Fixed players receiving double SetEntityMotionPackets for themselves --- src/pocketmine/Player.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index b8d8988c6..02fa5038e 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1578,12 +1578,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade if(parent::setMotion($mot)){ if($this->chunk !== null){ $this->level->addEntityMotion($this->chunk->getX(), $this->chunk->getZ(), $this->getId(), $this->motionX, $this->motionY, $this->motionZ); - $pk = new SetEntityMotionPacket(); - $pk->eid = $this->id; - $pk->motionX = $mot->x; - $pk->motionY = $mot->y; - $pk->motionZ = $mot->z; - $this->dataPacket($pk); } if($this->motionY > 0){ From 788bd6fc20426e9cbe5aa5ca4bba4e38787a8e00 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 26 Mar 2017 14:40:59 +0100 Subject: [PATCH 61/96] Fixed resource packs/login sequence fail, added basic safety restrictions for packet sending before clients are logged in close #452 --- src/pocketmine/Player.php | 64 ++++++++++++------- src/pocketmine/Server.php | 4 +- .../network/mcpe/protocol/BatchPacket.php | 4 ++ .../ClientToServerHandshakePacket.php | 4 ++ .../network/mcpe/protocol/DataPacket.php | 4 ++ .../mcpe/protocol/DisconnectPacket.php | 4 ++ .../network/mcpe/protocol/LoginPacket.php | 4 ++ .../mcpe/protocol/PlayStatusPacket.php | 4 ++ .../ServerToClientHandshakePacket.php | 4 ++ 9 files changed, 71 insertions(+), 25 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 02fa5038e..79e33f8f8 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1063,6 +1063,11 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return false; } + //Basic safety restriction. TODO: improve this + if(!$this->loggedIn and !$packet->canBeSentBeforeLogin()){ + throw new \InvalidArgumentException("Attempted to send " . get_class($packet) . " to " . $this->getName() . " too early"); + } + $timings = Timings::getSendDataPacketTimings($packet); $timings->startTiming(); @@ -1096,6 +1101,11 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return false; } + //Basic safety restriction. TODO: improve this + if(!$this->loggedIn and !$packet->canBeSentBeforeLogin()){ + throw new \InvalidArgumentException("Attempted to send " . get_class($packet) . " to " . $this->getName() . " too early"); + } + $timings = Timings::getSendDataPacketTimings($packet); $timings->startTiming(); $this->server->getPluginManager()->callEvent($ev = new DataPacketSendEvent($this, $packet)); @@ -1734,38 +1744,40 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade if($p !== $this and strtolower($p->getName()) === strtolower($this->getName())){ if($p->kick("logged in from another location") === false){ $this->close($this->getLeaveMessage(), "Logged in from another location"); + return; } }elseif($p->loggedIn and $this->getUniqueId()->equals($p->getUniqueId())){ if($p->kick("logged in from another location") === false){ $this->close($this->getLeaveMessage(), "Logged in from another location"); + return; } } } - $nbt = $this->server->getOfflinePlayerData($this->username); + $this->namedtag = $this->server->getOfflinePlayerData($this->username); - $this->playedBefore = ($nbt["lastPlayed"] - $nbt["firstPlayed"]) > 1; // microtime(true) - microtime(true) may have less than one millisecond difference - if(!isset($nbt->NameTag)){ - $nbt->NameTag = new StringTag("NameTag", $this->username); + $this->playedBefore = ($this->namedtag["lastPlayed"] - $this->namedtag["firstPlayed"]) > 1; // microtime(true) - microtime(true) may have less than one millisecond difference + if(!isset($this->namedtag->NameTag)){ + $this->namedtag->NameTag = new StringTag("NameTag", $this->username); }else{ - $nbt["NameTag"] = $this->username; + $this->namedtag["NameTag"] = $this->username; } - $this->gamemode = $nbt["playerGameType"] & 0x03; + $this->gamemode = $this->namedtag["playerGameType"] & 0x03; if($this->server->getForceGamemode()){ $this->gamemode = $this->server->getGamemode(); - $nbt->playerGameType = new IntTag("playerGameType", $this->gamemode); + $this->namedtag->playerGameType = new IntTag("playerGameType", $this->gamemode); } $this->allowFlight = (bool) ($this->gamemode & 0x01); - if(($level = $this->server->getLevelByName($nbt["Level"])) === null){ + if(($level = $this->server->getLevelByName($this->namedtag["Level"])) === null){ $this->setLevel($this->server->getDefaultLevel()); - $nbt["Level"] = $this->level->getName(); - $nbt["Pos"][0] = $this->level->getSpawnLocation()->x; - $nbt["Pos"][1] = $this->level->getSpawnLocation()->y; - $nbt["Pos"][2] = $this->level->getSpawnLocation()->z; + $this->namedtag["Level"] = $this->level->getName(); + $this->namedtag["Pos"][0] = $this->level->getSpawnLocation()->x; + $this->namedtag["Pos"][1] = $this->level->getSpawnLocation()->y; + $this->namedtag["Pos"][2] = $this->level->getSpawnLocation()->z; }else{ $this->setLevel($level); } @@ -1773,19 +1785,29 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->achievements = []; /** @var ByteTag $achievement */ - foreach($nbt->Achievements as $achievement){ + foreach($this->namedtag->Achievements as $achievement){ $this->achievements[$achievement->getName()] = $achievement->getValue() > 0 ? true : false; } - $nbt->lastPlayed = new LongTag("lastPlayed", floor(microtime(true) * 1000)); + $this->namedtag->lastPlayed = new LongTag("lastPlayed", floor(microtime(true) * 1000)); if($this->server->getAutoSave()){ - $this->server->saveOfflinePlayerData($this->username, $nbt, true); + $this->server->saveOfflinePlayerData($this->username, $this->namedtag, true); } - parent::__construct($this->level, $nbt); + $this->sendPlayStatus(PlayStatusPacket::LOGIN_SUCCESS); + $this->loggedIn = true; $this->server->addOnlinePlayer($this); + $pk = new ResourcePacksInfoPacket(); + $manager = $this->server->getResourceManager(); + $pk->resourcePackEntries = $manager->getResourceStack(); + $pk->mustAccept = $manager->resourcePacksRequired(); + $this->dataPacket($pk); + } + + protected function completeLoginSequence(){ + 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()); @@ -1910,13 +1932,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade //TODO: add JWT verification, add encryption - $this->sendPlayStatus(PlayStatusPacket::LOGIN_SUCCESS); - - $pk = new ResourcePacksInfoPacket(); - $manager = $this->server->getResourceManager(); - $pk->resourcePackEntries = $manager->getResourceStack(); - $pk->mustAccept = $manager->resourcePacksRequired(); - $this->dataPacket($pk); + $this->processLogin(); return true; } @@ -1989,7 +2005,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->dataPacket($pk); break; case ResourcePackClientResponsePacket::STATUS_COMPLETED: - $this->processLogin(); + $this->completeLoginSequence(); break; } diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index bcc61a87a..44e38e5c9 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -2207,7 +2207,9 @@ class Server{ private function checkTickUpdates($currentTick, $tickTime){ foreach($this->players as $p){ - if($this->alwaysTickPlayers){ + if(!$p->loggedIn and ($tickTime - $p->creationTime) >= 10){ + $p->close("", "Login timeout"); + }elseif($this->alwaysTickPlayers){ $p->onUpdate($currentTick); } } diff --git a/src/pocketmine/network/mcpe/protocol/BatchPacket.php b/src/pocketmine/network/mcpe/protocol/BatchPacket.php index 2257655a0..a288b24c4 100644 --- a/src/pocketmine/network/mcpe/protocol/BatchPacket.php +++ b/src/pocketmine/network/mcpe/protocol/BatchPacket.php @@ -35,6 +35,10 @@ class BatchPacket extends DataPacket{ return false; } + public function canBeSentBeforeLogin() : bool{ + return true; + } + public function decode(){ $this->payload = $this->getString(); } diff --git a/src/pocketmine/network/mcpe/protocol/ClientToServerHandshakePacket.php b/src/pocketmine/network/mcpe/protocol/ClientToServerHandshakePacket.php index dcb1d7a49..ef1aa7c33 100644 --- a/src/pocketmine/network/mcpe/protocol/ClientToServerHandshakePacket.php +++ b/src/pocketmine/network/mcpe/protocol/ClientToServerHandshakePacket.php @@ -29,6 +29,10 @@ use pocketmine\network\mcpe\NetworkSession; class ClientToServerHandshakePacket extends DataPacket{ const NETWORK_ID = ProtocolInfo::CLIENT_TO_SERVER_HANDSHAKE_PACKET; + public function canBeSentBeforeLogin() : bool{ + return true; + } + public function decode(){ //No payload } diff --git a/src/pocketmine/network/mcpe/protocol/DataPacket.php b/src/pocketmine/network/mcpe/protocol/DataPacket.php index d08193289..14855fbfb 100644 --- a/src/pocketmine/network/mcpe/protocol/DataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/DataPacket.php @@ -44,6 +44,10 @@ abstract class DataPacket extends BinaryStream{ return true; } + public function canBeSentBeforeLogin() : bool{ + return false; + } + abstract public function encode(); abstract public function decode(); diff --git a/src/pocketmine/network/mcpe/protocol/DisconnectPacket.php b/src/pocketmine/network/mcpe/protocol/DisconnectPacket.php index 94fcc6d39..627e76015 100644 --- a/src/pocketmine/network/mcpe/protocol/DisconnectPacket.php +++ b/src/pocketmine/network/mcpe/protocol/DisconnectPacket.php @@ -32,6 +32,10 @@ class DisconnectPacket extends DataPacket{ public $hideDisconnectionScreen = false; public $message; + public function canBeSentBeforeLogin() : bool{ + return true; + } + public function decode(){ $this->hideDisconnectionScreen = $this->getBool(); $this->message = $this->getString(); diff --git a/src/pocketmine/network/mcpe/protocol/LoginPacket.php b/src/pocketmine/network/mcpe/protocol/LoginPacket.php index ace691911..b8a596475 100644 --- a/src/pocketmine/network/mcpe/protocol/LoginPacket.php +++ b/src/pocketmine/network/mcpe/protocol/LoginPacket.php @@ -48,6 +48,10 @@ class LoginPacket extends DataPacket{ return false; } + public function canBeSentBeforeLogin() : bool{ + return true; + } + public function decode(){ $this->protocol = $this->getInt(); diff --git a/src/pocketmine/network/mcpe/protocol/PlayStatusPacket.php b/src/pocketmine/network/mcpe/protocol/PlayStatusPacket.php index 47ac4e574..621f6c05c 100644 --- a/src/pocketmine/network/mcpe/protocol/PlayStatusPacket.php +++ b/src/pocketmine/network/mcpe/protocol/PlayStatusPacket.php @@ -42,6 +42,10 @@ class PlayStatusPacket extends DataPacket{ } + public function canBeSentBeforeLogin() : bool{ + return true; + } + public function encode(){ $this->reset(); $this->putInt($this->status); diff --git a/src/pocketmine/network/mcpe/protocol/ServerToClientHandshakePacket.php b/src/pocketmine/network/mcpe/protocol/ServerToClientHandshakePacket.php index 5ef9583f1..ce6a236b0 100644 --- a/src/pocketmine/network/mcpe/protocol/ServerToClientHandshakePacket.php +++ b/src/pocketmine/network/mcpe/protocol/ServerToClientHandshakePacket.php @@ -32,6 +32,10 @@ class ServerToClientHandshakePacket extends DataPacket{ public $publicKey; public $serverToken; + public function canBeSentBeforeLogin() : bool{ + return true; + } + public function decode(){ $this->publicKey = $this->getString(); $this->serverToken = $this->getString(); From 3e76c3a6ddd8ec9cb25a20c96bbbaadb72e4f665 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 28 Mar 2017 18:47:51 +0100 Subject: [PATCH 62/96] Added handling for tile picking, added API for setting item lore worked almost out of the box (some W10 equipment bugs though) --- src/pocketmine/Player.php | 15 ++++++++++++++- src/pocketmine/item/Item.php | 29 +++++++++++++++++++++++++++++ src/pocketmine/tile/Tile.php | 11 +++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 371a7d787..1a32eeaca 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -196,6 +196,7 @@ use pocketmine\plugin\Plugin; use pocketmine\resourcepacks\ResourcePack; use pocketmine\tile\ItemFrame; use pocketmine\tile\Spawnable; +use pocketmine\tile\Tile; use pocketmine\utils\TextFormat; use pocketmine\utils\UUID; @@ -2388,7 +2389,19 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } public function handleBlockPickRequest(BlockPickRequestPacket $packet) : bool{ - return false; //TODO + $tile = $this->getLevel()->getTile($this->temporalVector->setComponents($packet->tileX, $packet->tileY, $packet->tileZ)); + if($tile instanceof Tile){ //TODO: check if the held item matches the target tile + $nbt = $tile->getCleanedNBT(); + if($nbt instanceof CompoundTag){ + $item = $this->inventory->getItemInHand(); + $item->setCustomBlockData($nbt); + $item->setLore(["+(DATA)"]); + $this->inventory->setItemInHand($item); + } + + return true; + } + return false; } public function handleUseItem(UseItemPacket $packet) : bool{ diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index 356466d68..7e793d55e 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -660,6 +660,35 @@ class Item implements ItemIds, \JsonSerializable{ return $this; } + public function getLore() : array{ + $tag = $this->getNamedTagEntry("display"); + if($tag instanceof CompoundTag and isset($tag->Lore) and $tag->Lore instanceof ListTag){ + $lines = []; + foreach($tag->Lore->getValue() as $line){ + $lines[] = $line->getValue(); + } + + return $lines; + } + + return []; + } + + public function setLore(array $lines){ + $tag = $this->getNamedTag(); + if(!isset($tag->display)){ + $tag->display = new CompoundTag("display", []); + } + $tag->display->Lore = new ListTag("Lore"); + $tag->display->Lore->setTagType(NBT::TAG_String); + $count = 0; + foreach($lines as $line){ + $tag->display->Lore[$count++] = new StringTag("", $line); + } + + $this->setNamedTag($tag); + } + /** * @param $name * @return Tag|null diff --git a/src/pocketmine/tile/Tile.php b/src/pocketmine/tile/Tile.php index 51c3ca9d8..6f81bbad3 100644 --- a/src/pocketmine/tile/Tile.php +++ b/src/pocketmine/tile/Tile.php @@ -148,6 +148,17 @@ abstract class Tile extends Position{ $this->namedtag->z = new IntTag("z", $this->z); } + public function getCleanedNBT(){ + $this->saveNBT(); + $tag = clone $this->namedtag; + unset($tag->x, $tag->y, $tag->z, $tag->id); + if($tag->getCount() > 0){ + return $tag; + }else{ + return null; + } + } + /** * @return \pocketmine\block\Block */ From 6b747f9272ac07e558cd31403155408795ee7571 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 29 Mar 2017 20:02:16 +0100 Subject: [PATCH 63/96] Added basic API for working with titles --- src/pocketmine/Player.php | 69 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 1a32eeaca..27b29e6e8 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -3398,6 +3398,75 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return false; } + /** + * Adds a title text to the user's screen, with an optional subtitle. + * + * @param string $title + * @param string $subtitle + * @param int $fadeIn Duration in ticks for fade-in. If -1 is given, client-sided defaults will be used. + * @param int $stay Duration in ticks to stay on screen for + * @param int $fadeOut Duration in ticks for fade-out. + */ + public function addTitle(string $title, string $subtitle = "", int $fadeIn = -1, int $stay = -1, int $fadeOut = -1){ + $this->setTitleDuration($fadeIn, $stay, $fadeOut); + $this->sendTitleText($title, SetTitlePacket::TYPE_SET_TITLE); + if($subtitle !== ""){ + $this->sendTitleText($subtitle, SetTitlePacket::TYPE_SET_SUBTITLE); + } + } + + /** + * Adds small text to the user's screen. + * + * @param string $message + */ + public function addActionBarMessage(string $message){ + $this->sendTitleText($message, SetTitlePacket::TYPE_SET_ACTIONBAR_MESSAGE); + } + + /** + * Removes the title from the client's screen. + */ + public function removeTitles(){ + $pk = new SetTitlePacket(); + $pk->type = SetTitlePacket::TYPE_CLEAR_TITLE; + $this->dataPacket($pk); + } + + /** + * Sets the title duration. + * + * @param int $fadeIn Title fade-in time in ticks. + * @param int $stay Title stay time in ticks. + * @param int $fadeOut Title fade-out time in ticks. + */ + public function setTitleDuration(int $fadeIn, int $stay, int $fadeOut){ + if($fadeIn >= 0 and $stay >= 0 and $fadeOut >= 0){ + $pk = new SetTitlePacket(); + $pk->type = SetTitlePacket::TYPE_SET_ANIMATION_TIMES; + $pk->fadeInTime = $fadeIn; + $pk->stayTime = $stay; + $pk->fadeOutTime = $fadeOut; + $this->dataPacket($pk); + } + } + + /** + * Internal function used for sending titles. + * + * @param string $title + * @param int $type + * @param int $fadeIn + * @param int $stay + * @param int $fadeOut + */ + protected function sendTitleText(string $title, int $type){ + $pk = new SetTitlePacket(); + $pk->type = $type; + $pk->text = $title; + $this->dataPacket($pk); + } + /** * Sends a direct chat message to a player * From cb059ea713cd4d28c017335d5485763025287c25 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 30 Mar 2017 12:10:59 +0100 Subject: [PATCH 64/96] fix some PhpStorm inspections --- src/pocketmine/Player.php | 3 --- src/pocketmine/entity/Entity.php | 1 + src/pocketmine/entity/Human.php | 1 - src/pocketmine/updater/AutoUpdater.php | 1 - 4 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 27b29e6e8..361068114 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -3456,9 +3456,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade * * @param string $title * @param int $type - * @param int $fadeIn - * @param int $stay - * @param int $fadeOut */ protected function sendTitleText(string $title, int $type){ $pk = new SetTitlePacket(); diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 833b5b604..9cc94f806 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -703,6 +703,7 @@ abstract class Entity extends Location implements Metadatable{ /** * @param Player $player + * @param bool $send */ public function despawnFrom(Player $player, bool $send = true){ if(isset($this->hasSpawned[$player->getLoaderId()])){ diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index e10245ab0..9dd852bfc 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -36,7 +36,6 @@ use pocketmine\nbt\tag\ListTag; use pocketmine\nbt\tag\ShortTag; use pocketmine\nbt\tag\StringTag; use pocketmine\network\mcpe\protocol\AddPlayerPacket; -use pocketmine\network\mcpe\protocol\RemoveEntityPacket; use pocketmine\Player; use pocketmine\utils\UUID; diff --git a/src/pocketmine/updater/AutoUpdater.php b/src/pocketmine/updater/AutoUpdater.php index 5d206290e..23461e4fe 100644 --- a/src/pocketmine/updater/AutoUpdater.php +++ b/src/pocketmine/updater/AutoUpdater.php @@ -24,7 +24,6 @@ namespace pocketmine\updater; use pocketmine\Player; use pocketmine\Server; use pocketmine\utils\TextFormat; -use pocketmine\utils\Utils; use pocketmine\utils\VersionString; class AutoUpdater{ From 45e5b6b04c9d229ebc771847a01c8efbe6d49a45 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 30 Mar 2017 16:29:18 +0100 Subject: [PATCH 65/96] Do not subscribe to broadcast permissions until the player spawns This is unnecessary since the player won't see any messages sent before they spawn anyway. This was also causing an occasional client-sided crash due to TextPackets being sent to players at bad times during the login sequence. --- src/pocketmine/Player.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 361068114..053dfc36c 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -902,6 +902,13 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->sendPlayStatus(PlayStatusPacket::PLAYER_SPAWN); + if($this->hasPermission(Server::BROADCAST_CHANNEL_USERS)){ + $this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_USERS, $this); + } + if($this->hasPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE)){ + $this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this); + } + $this->server->getPluginManager()->callEvent($ev = new PlayerJoinEvent($this, new TranslationContainer(TextFormat::YELLOW . "%multiplayer.player.joined", [ $this->getDisplayName() @@ -1730,13 +1737,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return; } - if($this->hasPermission(Server::BROADCAST_CHANNEL_USERS)){ - $this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_USERS, $this); - } - if($this->hasPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE)){ - $this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this); - } - foreach($this->server->getOnlinePlayers() as $p){ if($p !== $this and strtolower($p->getName()) === strtolower($this->getName())){ if($p->kick("logged in from another location") === false){ From 69ac80518c1ef7a7794f3f1c5b24a8d5f42a3151 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 30 Mar 2017 19:33:47 +0100 Subject: [PATCH 66/96] some improvements to the horrendous mess that is the handling of joining and quitting, fixed some crashes, probably caused some other crashes I can't fix this completely because it's just too much of a fucking mess. NEED to separate network stuff from Player. --- src/pocketmine/Player.php | 109 +++++++++--------- src/pocketmine/entity/Entity.php | 3 + src/pocketmine/entity/Human.php | 2 +- src/pocketmine/permission/PermissibleBase.php | 7 +- 4 files changed, 64 insertions(+), 57 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 053dfc36c..a67d3872c 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -241,6 +241,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade public $playedBefore; public $spawned = false; public $loggedIn = false; + public $joined = false; public $gamemode; public $lastBreak; @@ -945,6 +946,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $pk->z = $pos->z; $this->dataPacket($pk); } + + $this->joined = true; } protected function orderChunks(){ @@ -1971,7 +1974,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade public function handleResourcePackClientResponse(ResourcePackClientResponsePacket $packet) : bool{ switch($packet->status){ case ResourcePackClientResponsePacket::STATUS_REFUSED: - $this->close("", "must accept resource packs to join", true); + //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->getResourceManager(); @@ -3536,21 +3540,41 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade * @param bool $notify */ public final function close($message = "", $reason = "generic reason", $notify = true){ - if($this->connected and !$this->closed){ if($notify and strlen((string) $reason) > 0){ - $pk = new DisconnectPacket; + $pk = new DisconnectPacket(); $pk->message = $reason; $this->directDataPacket($pk); } $this->connected = false; - if(strlen($this->getName()) > 0){ - $this->server->getPluginManager()->callEvent($ev = new PlayerQuitEvent($this, $message, true)); - if($this->loggedIn === true and $ev->getAutoSave()){ - $this->save(); + + $this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_USERS, $this); + $this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this); + + if($this->joined){ + //TODO: add events for player data saving + $this->save(); + + $this->server->getPluginManager()->callEvent($ev = new PlayerQuitEvent($this, $message)); + if($ev->getQuitMessage() != ""){ + $this->server->broadcastMessage($ev->getQuitMessage()); } } + $this->joined = false; + + if($this->isValid()){ + foreach($this->usedChunks as $index => $d){ + Level::getXZ($index, $chunkX, $chunkZ); + $this->level->unregisterChunkLoader($this, $chunkX, $chunkZ); + foreach($this->level->getChunkEntities($chunkX, $chunkZ) as $entity){ + $entity->despawnFrom($this); + } + unset($this->usedChunks[$index]); + } + } + $this->usedChunks = []; + $this->loadQueue = []; foreach($this->server->getOnlinePlayers() as $player){ if(!$player->canSee($this)){ @@ -3562,61 +3586,40 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade foreach($this->windowIndex as $window){ $this->removeWindow($window); } - - foreach($this->usedChunks as $index => $d){ - Level::getXZ($index, $chunkX, $chunkZ); - $this->level->unregisterChunkLoader($this, $chunkX, $chunkZ); - foreach($this->level->getChunkEntities($chunkX, $chunkZ) as $entity){ - $entity->despawnFrom($this, false); - } - unset($this->usedChunks[$index]); - } + $this->windows = null; + $this->windowIndex = []; parent::close(); + $this->spawned = false; $this->interface->close($this, $notify ? $reason : ""); if($this->loggedIn){ $this->server->removeOnlinePlayer($this); } - $this->loggedIn = false; - $this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_USERS, $this); - $this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this); - - if(isset($ev) and $this->username != "" and $this->spawned !== false and $ev->getQuitMessage() != ""){ - $this->server->broadcastMessage($ev->getQuitMessage()); - } - - $this->spawned = false; $this->server->getLogger()->info($this->getServer()->getLanguage()->translateString("pocketmine.player.logOut", [ TextFormat::AQUA . $this->getName() . TextFormat::WHITE, $this->ip, $this->port, $this->getServer()->getLanguage()->translateString($reason) ])); - $this->windows = new \SplObjectStorage(); - $this->windowIndex = []; - $this->usedChunks = []; - $this->loadQueue = []; - $this->hasSpawned = []; + $this->spawnPosition = null; + + if($this->perm !== null){ + $this->perm->clearPermissions(); + $this->perm = null; + } + + if($this->inventory !== null){ + $this->inventory = null; + $this->currentTransaction = null; + } + + $this->server->removePlayer($this); } - - if($this->perm !== null){ - $this->perm->clearPermissions(); - $this->perm = null; - } - - if($this->inventory !== null){ - $this->inventory = null; - $this->currentTransaction = null; - } - - $this->chunk = null; - - $this->server->removePlayer($this); } public function __debugInfo(){ @@ -3634,7 +3637,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } parent::saveNBT(); - if($this->level instanceof Level){ + if($this->getLevel() instanceof Level){ $this->namedtag->Level = new StringTag("Level", $this->level->getFolderName()); if($this->hasValidSpawnPosition()){ $this->namedtag["SpawnLevel"] = $this->spawnPosition->getLevel()->getFolderName(); @@ -3642,17 +3645,17 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->namedtag["SpawnY"] = (int) $this->spawnPosition->y; $this->namedtag["SpawnZ"] = (int) $this->spawnPosition->z; } + } - foreach($this->achievements as $achievement => $status){ - $this->namedtag->Achievements[$achievement] = new ByteTag($achievement, $status === true ? 1 : 0); - } + foreach($this->achievements as $achievement => $status){ + $this->namedtag->Achievements[$achievement] = new ByteTag($achievement, $status === true ? 1 : 0); + } - $this->namedtag["playerGameType"] = $this->gamemode; - $this->namedtag["lastPlayed"] = new LongTag("lastPlayed", floor(microtime(true) * 1000)); + $this->namedtag["playerGameType"] = $this->gamemode; + $this->namedtag["lastPlayed"] = new LongTag("lastPlayed", floor(microtime(true) * 1000)); - if($this->username != "" and $this->namedtag instanceof CompoundTag){ - $this->server->saveOfflinePlayerData($this->username, $this->namedtag, $async); - } + if($this->username != "" and $this->namedtag instanceof CompoundTag){ + $this->server->saveOfflinePlayerData($this->username, $this->namedtag, $async); } } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 9cc94f806..fa8aea85b 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -1661,7 +1661,10 @@ abstract class Entity extends Location implements Metadatable{ if(!$this->closed){ $this->server->getPluginManager()->callEvent(new EntityDespawnEvent($this)); $this->closed = true; + $this->despawnFromAll(); + $this->hasSpawned = []; + if($this->chunk !== null){ $this->chunk->removeEntity($this); $this->chunk = null; diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index 9dd852bfc..732dd23f8 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -504,7 +504,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ public function close(){ if(!$this->closed){ - if(!($this instanceof Player) or $this->loggedIn){ + if($this->inventory !== null){ foreach($this->inventory->getViewers() as $viewer){ $viewer->removeWindow($this->inventory); } diff --git a/src/pocketmine/permission/PermissibleBase.php b/src/pocketmine/permission/PermissibleBase.php index 95acb5032..c10049a3e 100644 --- a/src/pocketmine/permission/PermissibleBase.php +++ b/src/pocketmine/permission/PermissibleBase.php @@ -188,12 +188,13 @@ class PermissibleBase implements Permissible{ } public function clearPermissions(){ + $pluginManager = Server::getInstance()->getPluginManager(); foreach(array_keys($this->permissions) as $name){ - Server::getInstance()->getPluginManager()->unsubscribeFromPermission($name, $this->parent !== null ? $this->parent : $this); + $pluginManager->unsubscribeFromPermission($name, $this->parent ?? $this); } - Server::getInstance()->getPluginManager()->unsubscribeFromDefaultPerms(false, $this->parent !== null ? $this->parent : $this); - Server::getInstance()->getPluginManager()->unsubscribeFromDefaultPerms(true, $this->parent !== null ? $this->parent : $this); + $pluginManager->unsubscribeFromDefaultPerms(false, $this->parent ?? $this); + $pluginManager->unsubscribeFromDefaultPerms(true, $this->parent ?? $this); $this->permissions = []; } From 40a6f4dee97e47b0dbbfd9ab601aa7f928b22131 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 30 Mar 2017 19:41:10 +0100 Subject: [PATCH 67/96] Elevated level close check to exception level As an assertion, this will crash on save if the level is already closed due to the provider being null. --- src/pocketmine/level/Level.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 7afb386b4..0ad2e7fbc 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -416,7 +416,9 @@ class Level implements ChunkManager, Metadatable{ } public function close(){ - assert(!$this->closed, "Tried to close a level which is already closed"); + if($this->closed){ + throw new \InvalidStateException("Tried to close a level which is already closed"); + } if($this->getAutoSave()){ $this->save(); From b5f473a3df5459620dcf1f9feef27b7e437da822 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 31 Mar 2017 13:14:05 +0100 Subject: [PATCH 68/96] Throw an exception when attempting to tick closed Levels --- src/pocketmine/level/Level.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 0ad2e7fbc..25acf601d 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -645,6 +645,9 @@ class Level implements ChunkManager, Metadatable{ * */ public function doTick(int $currentTick){ + if($this->closed){ + throw new \InvalidStateException("Attempted to tick a Level which has been closed"); + } $this->timings->doTick->startTiming(); From 7f838a8c3655ac2862be3a7a20f425f56ab9fec2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 31 Mar 2017 13:45:28 +0100 Subject: [PATCH 69/96] Fixed crashes due to adding players 'online' far too early, fixed some Player save logic --- src/pocketmine/Player.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index a67d3872c..1de47f2f7 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1797,7 +1797,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->sendPlayStatus(PlayStatusPacket::LOGIN_SUCCESS); $this->loggedIn = true; - $this->server->addOnlinePlayer($this); $pk = new ResourcePacksInfoPacket(); $manager = $this->server->getResourceManager(); @@ -1876,6 +1875,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->forceMovement = $this->teleportPosition = $this->getPosition(); + $this->server->addOnlinePlayer($this); + $this->server->onPlayerLogin($this); } @@ -3637,14 +3638,16 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } parent::saveNBT(); - if($this->getLevel() instanceof Level){ + + if($this->isValid()){ $this->namedtag->Level = new StringTag("Level", $this->level->getFolderName()); - if($this->hasValidSpawnPosition()){ - $this->namedtag["SpawnLevel"] = $this->spawnPosition->getLevel()->getFolderName(); - $this->namedtag["SpawnX"] = (int) $this->spawnPosition->x; - $this->namedtag["SpawnY"] = (int) $this->spawnPosition->y; - $this->namedtag["SpawnZ"] = (int) $this->spawnPosition->z; - } + } + + if($this->hasValidSpawnPosition()){ + $this->namedtag["SpawnLevel"] = $this->spawnPosition->getLevel()->getFolderName(); + $this->namedtag["SpawnX"] = (int) $this->spawnPosition->x; + $this->namedtag["SpawnY"] = (int) $this->spawnPosition->y; + $this->namedtag["SpawnZ"] = (int) $this->spawnPosition->z; } foreach($this->achievements as $achievement => $status){ From 87a52a4f3532a01897462030bd202d2bcd8ca5ee Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 31 Mar 2017 16:09:40 +0100 Subject: [PATCH 70/96] Fixed yet another crash when level-settings.always-tick-players is set to true --- src/pocketmine/Server.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 44e38e5c9..a022d1375 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -2209,7 +2209,7 @@ class Server{ foreach($this->players as $p){ if(!$p->loggedIn and ($tickTime - $p->creationTime) >= 10){ $p->close("", "Login timeout"); - }elseif($this->alwaysTickPlayers){ + }elseif($this->alwaysTickPlayers and $p->joined){ $p->onUpdate($currentTick); } } From 16972bf9a5121fc73dbe5e533aef54f25edb6fd0 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 31 Mar 2017 18:59:40 +0100 Subject: [PATCH 71/96] Fix issues with writing negative numbers as non-zigzag varints, close #493 --- src/pocketmine/utils/Binary.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pocketmine/utils/Binary.php b/src/pocketmine/utils/Binary.php index e2ab3737d..60099b7c4 100644 --- a/src/pocketmine/utils/Binary.php +++ b/src/pocketmine/utils/Binary.php @@ -395,6 +395,7 @@ class Binary{ */ public static function writeUnsignedVarInt($value){ $buf = ""; + $value &= 0xffffffff; for($i = 0; $i < 5; ++$i){ if(($value >> 7) !== 0){ $buf .= chr($value | 0x80); //Let chr() take the last byte of this, it's faster than adding another & 0x7f. From 845b124f89ca920d86a8a4d8c7619cf18126670c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 31 Mar 2017 20:32:55 +0100 Subject: [PATCH 72/96] Stop autosaving players who haven't joined yet, close #494 --- src/pocketmine/Server.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index a022d1375..f9c6477d5 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -2254,7 +2254,7 @@ class Server{ if($this->getAutoSave()){ Timings::$worldSaveTimer->startTiming(); foreach($this->players as $index => $player){ - if($player->isOnline()){ + if($player->joined){ $player->save(true); }elseif(!$player->isConnected()){ $this->removePlayer($player); From b24d516edaf05ef68ae2562f9b95ef219e392c8c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 1 Apr 2017 10:39:37 +0100 Subject: [PATCH 73/96] Send TransferPacket with immediate priority, should fix #497 --- src/pocketmine/Player.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 1de47f2f7..15ebddeaa 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -3362,7 +3362,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $pk = new TransferPacket(); $pk->address = $ev->getAddress(); $pk->port = $ev->getPort(); - $this->dataPacket($pk); + $this->directDataPacket($pk); $this->close("", $ev->getMessage(), false); return true; From f75cc93160a3ad8da89bc24938e1c3b6df549fa0 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 1 Apr 2017 14:08:02 +0100 Subject: [PATCH 74/96] HOW did nobody notice this?! --- src/pocketmine/network/mcpe/RakLibInterface.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/network/mcpe/RakLibInterface.php b/src/pocketmine/network/mcpe/RakLibInterface.php index a613d8a41..de31bab8c 100644 --- a/src/pocketmine/network/mcpe/RakLibInterface.php +++ b/src/pocketmine/network/mcpe/RakLibInterface.php @@ -215,8 +215,8 @@ class RakLibInterface implements ServerInstance, AdvancedSourceInterface{ if($pk === null){ $pk = new EncapsulatedPacket(); $pk->buffer = chr(0xfe) . $packet->buffer; // #blameshoghi - $packet->reliability = PacketReliability::RELIABLE_ORDERED; - $packet->orderChannel = 0; + $pk->reliability = PacketReliability::RELIABLE_ORDERED; + $pk->orderChannel = 0; if($needACK === true){ $pk->identifierACK = $this->identifiersACK[$identifier]++; From 874afc2fd21f6f9ce1ec64474c4cd4e31b75e034 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 1 Apr 2017 19:33:16 +0100 Subject: [PATCH 75/96] fixed players need to move to pick up dropped items, close #498 --- src/pocketmine/Player.php | 45 ++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 15ebddeaa..1142b3172 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1570,10 +1570,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } } - if(!$this->isSpectator()){ - $this->checkNearEntities($tickDiff); - } - $this->speed = ($to->subtract($from))->divide($tickDiff); }elseif($distanceSquared == 0){ $this->speed = new Vector3(0, 0, 0); @@ -1663,28 +1659,33 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->processMovement($tickDiff); $this->entityBaseTick($tickDiff); - if(!$this->isSpectator() and $this->speed !== null){ - if($this->onGround){ - if($this->inAirTicks !== 0){ - $this->startAirTicks = 5; - } - $this->inAirTicks = 0; - }else{ - if(!$this->allowFlight and $this->inAirTicks > 10 and !$this->isSleeping() and !$this->isImmobile()){ - $expectedVelocity = (-$this->gravity) / $this->drag - ((-$this->gravity) / $this->drag) * exp(-$this->drag * ($this->inAirTicks - $this->startAirTicks)); - $diff = ($this->speed->y - $expectedVelocity) ** 2; + if(!$this->isSpectator()){ + $this->checkNearEntities($tickDiff); - if(!$this->hasEffect(Effect::JUMP) and $diff > 0.6 and $expectedVelocity < $this->speed->y and !$this->server->getAllowFlight()){ - if($this->inAirTicks < 100){ - $this->setMotion(new Vector3(0, $expectedVelocity, 0)); - }elseif($this->kick("Flying is not enabled on this server")){ - $this->timings->stopTiming(); - return false; + if($this->speed !== null){ + if($this->onGround){ + if($this->inAirTicks !== 0){ + $this->startAirTicks = 5; + } + $this->inAirTicks = 0; + }else{ + if(!$this->allowFlight and $this->inAirTicks > 10 and !$this->isSleeping() and !$this->isImmobile()){ + $expectedVelocity = (-$this->gravity) / $this->drag - ((-$this->gravity) / $this->drag) * exp(-$this->drag * ($this->inAirTicks - $this->startAirTicks)); + $diff = ($this->speed->y - $expectedVelocity) ** 2; + + if(!$this->hasEffect(Effect::JUMP) and $diff > 0.6 and $expectedVelocity < $this->speed->y and !$this->server->getAllowFlight()){ + if($this->inAirTicks < 100){ + $this->setMotion(new Vector3(0, $expectedVelocity, 0)); + }elseif($this->kick("Flying is not enabled on this server")){ + $this->timings->stopTiming(); + + return false; + } } } - } - ++$this->inAirTicks; + ++$this->inAirTicks; + } } } } From 1c2895eb12c9ed86f4a4f908011c59d7f976f1f8 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 5 Apr 2017 21:15:58 +0100 Subject: [PATCH 76/96] Fixed absorption application logic, close #518 --- src/pocketmine/entity/Effect.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/pocketmine/entity/Effect.php b/src/pocketmine/entity/Effect.php index 49bd99525..a5327dbde 100644 --- a/src/pocketmine/entity/Effect.php +++ b/src/pocketmine/entity/Effect.php @@ -440,14 +440,10 @@ class Effect{ $attr->setMaxValue($max); break; case Effect::ABSORPTION: - if($ev->willModify() and $oldEffect !== null){ - $value = $entity->getAbsorption() - (4 * ($oldEffect->getAmplifier() + 1)); - }else{ - $value = $entity->getAbsorption(); + $new = (4 * ($this->amplifier + 1)); + if($new > $entity->getAbsorption()){ + $entity->setAbsorption($new); } - - $value += (4 * ($this->amplifier + 1)); - $entity->setAbsorption($value); break; } @@ -490,7 +486,7 @@ class Effect{ $attr->setMaxValue($attr->getMaxValue() - (4 * ($this->amplifier + 1))); break; case Effect::ABSORPTION: - $entity->setAbsorption($entity->getAbsorption() - (4 * ($this->amplifier + 1))); + $entity->setAbsorption(0); break; } } From 172d7339f906f7515811a810ca8d15e484703143 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 12 Apr 2017 11:11:26 +0100 Subject: [PATCH 77/96] Autogenerated data for 1.0.6.52 --- .../network/mcpe/protocol/ProtocolInfo.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/pocketmine/network/mcpe/protocol/ProtocolInfo.php b/src/pocketmine/network/mcpe/protocol/ProtocolInfo.php index 3a5fa1114..82cfc851a 100644 --- a/src/pocketmine/network/mcpe/protocol/ProtocolInfo.php +++ b/src/pocketmine/network/mcpe/protocol/ProtocolInfo.php @@ -31,9 +31,9 @@ interface ProtocolInfo{ /** * Actual Minecraft: PE protocol version */ - const CURRENT_PROTOCOL = 105; - const MINECRAFT_VERSION = "v1.0.5.0 beta"; - const MINECRAFT_VERSION_NETWORK = "1.0.5.0"; + const CURRENT_PROTOCOL = 106; + const MINECRAFT_VERSION = 'v1.0.6.52'; + const MINECRAFT_VERSION_NETWORK = '1.0.6.52'; const LOGIN_PACKET = 0x01; const PLAY_STATUS_PACKET = 0x02; @@ -42,7 +42,7 @@ interface ProtocolInfo{ const DISCONNECT_PACKET = 0x05; const BATCH_PACKET = 0x06; const RESOURCE_PACKS_INFO_PACKET = 0x07; - const RESOURCE_PACK_STACK_PACKET = 0x08; //ResourcePacksStackPacket + const RESOURCE_PACK_STACK_PACKET = 0x08; const RESOURCE_PACK_CLIENT_RESPONSE_PACKET = 0x09; const TEXT_PACKET = 0x0a; const SET_TIME_PACKET = 0x0b; @@ -99,14 +99,14 @@ interface ProtocolInfo{ const CHANGE_DIMENSION_PACKET = 0x3e; const SET_PLAYER_GAME_TYPE_PACKET = 0x3f; const PLAYER_LIST_PACKET = 0x40; - const EVENT_PACKET = 0x41; //TelemetryEventPacket + const EVENT_PACKET = 0x41; const SPAWN_EXPERIENCE_ORB_PACKET = 0x42; - const CLIENTBOUND_MAP_ITEM_DATA_PACKET = 0x43; //MapItemDataPacket + const CLIENTBOUND_MAP_ITEM_DATA_PACKET = 0x43; const MAP_INFO_REQUEST_PACKET = 0x44; const REQUEST_CHUNK_RADIUS_PACKET = 0x45; const CHUNK_RADIUS_UPDATED_PACKET = 0x46; const ITEM_FRAME_DROP_ITEM_PACKET = 0x47; - const REPLACE_ITEM_IN_SLOT_PACKET = 0x48; //ReplaceSelectedItemPacket + const REPLACE_ITEM_IN_SLOT_PACKET = 0x48; const GAME_RULES_CHANGED_PACKET = 0x49; const CAMERA_PACKET = 0x4a; const ADD_ITEM_PACKET = 0x4b; From f7e1939ae8951141109cc1724a071f5666a3a0a0 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 12 Apr 2017 11:16:50 +0100 Subject: [PATCH 78/96] Changed some handling of unknown packet content --- 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 c0de17903..a8bc67869 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1987,7 +1987,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade //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())); - break; + return false; } $pk = new ResourcePackDataInfoPacket(); @@ -2388,7 +2388,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade break; //TODO: handle these default: $this->server->getLogger()->debug("Unhandled/unknown interaction type " . $packet->action . "received from ". $this->getName()); - break; + return false; } return true; @@ -2727,7 +2727,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade break; //TODO default: $this->server->getLogger()->debug("Unhandled/unknown player action type " . $packet->action . " from " . $this->getName()); - break; + return false; } $this->startAction = -1; @@ -3290,7 +3290,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $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 true; + return false; } $pk = new ResourcePackChunkDataPacket(); From cb7264e0e50ea7d1be2fa310d894aab7236a6a33 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 12 Apr 2017 11:20:58 +0100 Subject: [PATCH 79/96] Hexdump unhandled packets --- src/pocketmine/Player.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index a8bc67869..d6ec77ae2 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -3341,7 +3341,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this, $packet)); if(!$ev->isCancelled() and !$packet->handle($this)){ - $this->server->getLogger()->debug("Unhandled " . get_class($packet) . " received from " . $this->getName()); + $this->server->getLogger()->debug("Unhandled " . get_class($packet) . " received from " . $this->getName() . ": 0x" . bin2hex($packet->buffer)); } $timings->stopTiming(); From 7c66af599454117421ee4295df0a0980985404fc Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 12 Apr 2017 11:53:51 +0100 Subject: [PATCH 80/96] "Fixed" resource packs TODO: new fields --- .../network/mcpe/protocol/ResourcePacksInfoPacket.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pocketmine/network/mcpe/protocol/ResourcePacksInfoPacket.php b/src/pocketmine/network/mcpe/protocol/ResourcePacksInfoPacket.php index 3b07fe359..6162056ae 100644 --- a/src/pocketmine/network/mcpe/protocol/ResourcePacksInfoPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ResourcePacksInfoPacket.php @@ -45,6 +45,7 @@ class ResourcePacksInfoPacket extends DataPacket{ $version = $this->getString(); $size = $this->getLLong(); $this->behaviorPackEntries[] = new ResourcePackInfoEntry($id, $version, $size); + $this->getString(); } $resourcePackCount = $this->getLShort(); @@ -53,6 +54,7 @@ class ResourcePacksInfoPacket extends DataPacket{ $version = $this->getString(); $size = $this->getLLong(); $this->resourcePackEntries[] = new ResourcePackInfoEntry($id, $version, $size); + $this->getString(); }*/ } @@ -65,12 +67,14 @@ class ResourcePacksInfoPacket extends DataPacket{ $this->putString($entry->getPackId()); $this->putString($entry->getPackVersion()); $this->putLLong($entry->getPackSize()); + $this->putString(""); //TODO } $this->putLShort(count($this->resourcePackEntries)); foreach($this->resourcePackEntries as $entry){ $this->putString($entry->getPackId()); $this->putString($entry->getPackVersion()); $this->putLLong($entry->getPackSize()); + $this->putString(""); //TODO } } From 319763dd935e8c1dd8da5848cfb6b0c504d45601 Mon Sep 17 00:00:00 2001 From: Muqsit Rayyan Date: Thu, 13 Apr 2017 22:32:53 +0300 Subject: [PATCH 81/96] Fix #823 Thanks to @SuperMaXAleX --- src/pocketmine/Player.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index d6ec77ae2..3d0ba7c6d 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -3415,10 +3415,10 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade */ public function addTitle(string $title, string $subtitle = "", int $fadeIn = -1, int $stay = -1, int $fadeOut = -1){ $this->setTitleDuration($fadeIn, $stay, $fadeOut); - $this->sendTitleText($title, SetTitlePacket::TYPE_SET_TITLE); if($subtitle !== ""){ $this->sendTitleText($subtitle, SetTitlePacket::TYPE_SET_SUBTITLE); } + $this->sendTitleText($title, SetTitlePacket::TYPE_SET_TITLE); } /** From 4ab8233fe0487014e27737352433647ec906d407 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 14 Apr 2017 15:27:32 +0100 Subject: [PATCH 82/96] Fixed shooting bow while sprinting, close #827 --- src/pocketmine/Player.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 3d0ba7c6d..7898f764e 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2694,7 +2694,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade }else{ $this->setSprinting(true); } - break; + return true; case PlayerActionPacket::ACTION_STOP_SPRINT: $ev = new PlayerToggleSprintEvent($this, false); $this->server->getPluginManager()->callEvent($ev); @@ -2703,7 +2703,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade }else{ $this->setSprinting(false); } - break; + return true; case PlayerActionPacket::ACTION_START_SNEAK: $ev = new PlayerToggleSneakEvent($this, true); $this->server->getPluginManager()->callEvent($ev); From f2159c5948bf93f75c86ffda9a0394f68ccb8b56 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 14 Apr 2017 15:30:37 +0100 Subject: [PATCH 83/96] Fixed unlit furnaces glowing in the dark, close #508 Whether Furnace extending BurningFurnace actually makes logical sense is a different question, but that cna be resolved any other time. --- src/pocketmine/block/Furnace.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pocketmine/block/Furnace.php b/src/pocketmine/block/Furnace.php index a013b3ab4..44281446f 100644 --- a/src/pocketmine/block/Furnace.php +++ b/src/pocketmine/block/Furnace.php @@ -29,4 +29,8 @@ class Furnace extends BurningFurnace{ public function getName(){ return "Furnace"; } + + public function getLightLevel(){ + return 0; + } } \ No newline at end of file From 8a775e0c456908a645d8e9bf77a43cb8a3d30f12 Mon Sep 17 00:00:00 2001 From: Muqsit Rayyan Date: Sat, 15 Apr 2017 12:02:00 +0300 Subject: [PATCH 84/96] Fix PopSound giving failed click sound. (#829) --- src/pocketmine/level/sound/PopSound.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/level/sound/PopSound.php b/src/pocketmine/level/sound/PopSound.php index 5d2862588..b291e56fd 100644 --- a/src/pocketmine/level/sound/PopSound.php +++ b/src/pocketmine/level/sound/PopSound.php @@ -26,6 +26,6 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket; class PopSound extends GenericSound{ public function __construct(Vector3 $pos, $pitch = 0){ - parent::__construct($pos, LevelEventPacket::EVENT_SOUND_CLICK_FAIL, $pitch); + parent::__construct($pos, LevelEventPacket::EVENT_SOUND_POP, $pitch); } } From eefa8abaf218f1dad0976fb2ba3b62390365d311 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 18 Apr 2017 14:45:33 +0100 Subject: [PATCH 85/96] Throw exceptions if something attempts to add a closed Tile or Entity to a chunk --- src/pocketmine/level/format/Chunk.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/pocketmine/level/format/Chunk.php b/src/pocketmine/level/format/Chunk.php index 9f47296cf..00db9a89c 100644 --- a/src/pocketmine/level/format/Chunk.php +++ b/src/pocketmine/level/format/Chunk.php @@ -568,6 +568,9 @@ class Chunk{ * @param Entity $entity */ public function addEntity(Entity $entity){ + if($entity->closed){ + throw new \InvalidArgumentException("Attempted to add a garbage closed Entity to a chunk"); + } $this->entities[$entity->getId()] = $entity; if(!($entity instanceof Player) and $this->isInit){ $this->hasChanged = true; @@ -588,6 +591,9 @@ class Chunk{ * @param Tile $tile */ public function addTile(Tile $tile){ + if($tile->closed){ + throw new \InvalidArgumentException("Attempted to add a garbage closed Tile to a chunk"); + } $this->tiles[$tile->getId()] = $tile; if(isset($this->tileList[$index = (($tile->x & 0x0f) << 12) | (($tile->z & 0x0f) << 8) | ($tile->y & 0xff)]) and $this->tileList[$index] !== $tile){ $this->tileList[$index]->close(); From d2efcee115e9edac8c200a9169edfba656ad2c8c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 18 Apr 2017 14:47:42 +0100 Subject: [PATCH 86/96] Fixed tiles and entities being closed when replacing chunks, should fix #490 --- src/pocketmine/level/Level.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 8e480d712..44e27894b 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -2228,18 +2228,20 @@ class Level implements ChunkManager, Metadatable{ $oldEntities = $oldChunk !== null ? $oldChunk->getEntities() : []; $oldTiles = $oldChunk !== null ? $oldChunk->getTiles() : []; - $this->provider->setChunk($chunkX, $chunkZ, $chunk); - $this->chunks[$index] = $chunk; - foreach($oldEntities as $entity){ $chunk->addEntity($entity); + $oldChunk->removeEntity($entity); $entity->chunk = $chunk; } foreach($oldTiles as $tile){ $chunk->addTile($tile); + $oldChunk->removeTile($tile); $tile->chunk = $chunk; } + + $this->provider->setChunk($chunkX, $chunkZ, $chunk); + $this->chunks[$index] = $chunk; } unset($this->chunkCache[$index]); From 207056fb9de4d27ff4303fd37ee755461f641b9c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 3 Apr 2017 12:37:12 +0100 Subject: [PATCH 87/96] Fixed adventure mode being useless --- src/pocketmine/level/Level.php | 74 +++++++++++++++++----------------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 44e27894b..37b272d49 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1570,6 +1570,25 @@ class Level implements ChunkManager, Metadatable{ $ev->setCancelled(); } } + + if($player->isAdventure(true) and !$ev->isCancelled()){ + $tag = $item->getNamedTagEntry("CanDestroy"); + $canBreak = false; + if($tag instanceof ListTag){ + foreach($tag as $v){ + if($v instanceof StringTag){ + $entry = Item::fromString($v->getValue()); + if($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()){ + $canBreak = true; + break; + } + } + } + } + + $ev->setCancelled(!$canBreak); + } + $this->server->getPluginManager()->callEvent($ev); if($ev->isCancelled()){ return false; @@ -1615,24 +1634,6 @@ class Level implements ChunkManager, Metadatable{ } } - $tag = $item->getNamedTagEntry("CanDestroy"); - if($tag instanceof ListTag){ - $canBreak = false; - foreach($tag as $v){ - if($v instanceof StringTag){ - $entry = Item::fromString($v->getValue()); - if($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()){ - $canBreak = true; - break; - } - } - } - - if(!$canBreak){ - return false; - } - } - if($createParticles){ $this->addParticle(new DestroyBlockParticle($target->add(0.5, 0.5, 0.5), $target)); } @@ -1707,6 +1708,25 @@ class Level implements ChunkManager, Metadatable{ $ev->setCancelled(); } } + + if($player->isAdventure(true) and !$ev->isCancelled()){ + $canPlace = false; + $tag = $item->getNamedTagEntry("CanPlaceOn"); + if($tag instanceof ListTag){ + foreach($tag as $v){ + if($v instanceof StringTag){ + $entry = Item::fromString($v->getValue()); + if($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()){ + $canPlace = true; + break; + } + } + } + } + + $ev->setCancelled(!$canPlace); + } + $this->server->getPluginManager()->callEvent($ev); if(!$ev->isCancelled()){ $target->onUpdate(self::BLOCK_UPDATE_TOUCH); @@ -1769,24 +1789,6 @@ class Level implements ChunkManager, Metadatable{ } } - $tag = $item->getNamedTagEntry("CanPlaceOn"); - if($tag instanceof ListTag){ - $canPlace = false; - foreach($tag as $v){ - if($v instanceof StringTag){ - $entry = Item::fromString($v->getValue()); - if($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()){ - $canPlace = true; - break; - } - } - } - - if(!$canPlace){ - return false; - } - } - if($player !== null){ $ev = new BlockPlaceEvent($player, $hand, $block, $target, $item); From 86de0bddd912466b21badf57b80999a24754e7f2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 18 Apr 2017 20:01:51 +0100 Subject: [PATCH 88/96] World should only be completely immutable if we're in spectator mode Fixes being unable to break any blocks at all in adventure mode --- src/pocketmine/Player.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 7898f764e..d9f30ecbd 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1319,7 +1319,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade public function sendSettings(){ $pk = new AdventureSettingsPacket(); $pk->flags = 0; - $pk->worldImmutable = $this->isAdventure(); + $pk->worldImmutable = $this->isSpectator(); $pk->autoJump = $this->autoJump; $pk->allowFlight = $this->allowFlight; $pk->noClip = $this->isSpectator(); From 547a09c8d4bb7c034e66377a9252b367e8122234 Mon Sep 17 00:00:00 2001 From: Muqsit Rayyan Date: Thu, 20 Apr 2017 22:39:09 +0300 Subject: [PATCH 89/96] Fix "Creating default object from empty value" (#858) while setting lore to items. --- src/pocketmine/item/Item.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index 7cc94878c..b116db7a6 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -685,7 +685,7 @@ class Item implements ItemIds, \JsonSerializable{ } public function setLore(array $lines){ - $tag = $this->getNamedTag(); + $tag = $this->getNamedTag() ?? new CompoundTag("", []); if(!isset($tag->display)){ $tag->display = new CompoundTag("display", []); } From a356e363402af7f042bd76d15da7e72be2d37bf7 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 21 Apr 2017 13:22:09 +0100 Subject: [PATCH 90/96] Autogenerated data for 1.0.7.0 Did they actually _change_ anything or just trying to keep it on par with the game version? >_< --- src/pocketmine/network/mcpe/protocol/ProtocolInfo.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/network/mcpe/protocol/ProtocolInfo.php b/src/pocketmine/network/mcpe/protocol/ProtocolInfo.php index 82cfc851a..e789512ff 100644 --- a/src/pocketmine/network/mcpe/protocol/ProtocolInfo.php +++ b/src/pocketmine/network/mcpe/protocol/ProtocolInfo.php @@ -31,9 +31,9 @@ interface ProtocolInfo{ /** * Actual Minecraft: PE protocol version */ - const CURRENT_PROTOCOL = 106; - const MINECRAFT_VERSION = 'v1.0.6.52'; - const MINECRAFT_VERSION_NETWORK = '1.0.6.52'; + const CURRENT_PROTOCOL = 107; + const MINECRAFT_VERSION = 'v1.0.7.0'; + const MINECRAFT_VERSION_NETWORK = '1.0.7.0'; const LOGIN_PACKET = 0x01; const PLAY_STATUS_PACKET = 0x02; From e7406ba0969b55d583568ab82607ccdeb96a19ac Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 21 Apr 2017 14:42:19 +0100 Subject: [PATCH 91/96] Fixed squid health attribute errors --- src/pocketmine/entity/Entity.php | 3 +-- src/pocketmine/entity/Living.php | 2 +- src/pocketmine/entity/Squid.php | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index e7e924e76..9f9ff3a65 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -339,6 +339,7 @@ abstract class Entity extends Location implements Metadatable{ $this->invulnerable = $this->namedtag["Invulnerable"] > 0 ? true : false; $this->attributeMap = new AttributeMap(); + $this->addAttributes(); $this->chunk->addEntity($this); $this->level->addEntity($this); @@ -642,8 +643,6 @@ abstract class Entity extends Location implements Metadatable{ $this->scheduleUpdate(); - $this->addAttributes(); - if(isset($this->namedtag->ActiveEffects)){ foreach($this->namedtag->ActiveEffects->getValue() as $e){ $amplifier = $e["Amplifier"] & 0xff; //0-255 only diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index fbdac34e5..7a0a93e91 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -68,7 +68,7 @@ abstract class Living extends Entity implements Damageable{ public function setHealth($amount){ $wasAlive = $this->isAlive(); parent::setHealth($amount); - $this->attributeMap->getAttribute(Attribute::HEALTH)->setValue($this->getHealth()); + $this->attributeMap->getAttribute(Attribute::HEALTH)->setValue($this->getHealth(), true); if($this->isAlive() and !$wasAlive){ $pk = new EntityEventPacket(); $pk->eid = $this->getId(); diff --git a/src/pocketmine/entity/Squid.php b/src/pocketmine/entity/Squid.php index becc8cfc2..50a398360 100644 --- a/src/pocketmine/entity/Squid.php +++ b/src/pocketmine/entity/Squid.php @@ -43,8 +43,8 @@ class Squid extends WaterAnimal implements Ageable{ private $switchDirectionTicker = 0; public function initEntity(){ + $this->setMaxHealth(10); parent::initEntity(); - $this->setMaxHealth(5); } public function getName(){ From 00a226921c6a982491c029d7dcc16d4beaae855a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 21 Apr 2017 18:51:26 +0100 Subject: [PATCH 92/96] Fixed server crash when taking damage after being killed when having Health Boost effect --- src/pocketmine/Player.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index d9f30ecbd..4763c0113 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2672,9 +2672,9 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->deadTicks = 0; $this->noDamageTicks = 60; + $this->removeAllEffects(); $this->setHealth($this->getMaxHealth()); - $this->removeAllEffects(); $this->sendData($this); $this->sendSettings(); From 22049423383c0f671056ae3b1a1738b4edeec1cb Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 3 Apr 2017 13:12:33 +0100 Subject: [PATCH 93/96] Fixed the half-done hunger implementation, fixed lots of bugs related to hunger - Fixed starvation doesn't deal any damage at all (Human->getFood() returns a float, not an int, === 0 won't work so great) - Added exhaustion for sprinting, walking, jumping and sprint-jumping as per MCPE (these use MCPE values, and yes MCPE does walking exhaustion!) - Fixed attributes don't get reset after player death - Added food and hunger regeneration in peaceful difficulty - Added API methods Living->jump() (motion isn't updated yet, so this won't actually do much if plugins try to use it) and Living->getJumpVelocity() TODO: implement exhaustion for swimming --- src/pocketmine/Player.php | 35 +++++++++---- src/pocketmine/entity/Attribute.php | 4 ++ src/pocketmine/entity/AttributeMap.php | 3 ++ src/pocketmine/entity/Human.php | 49 ++++++++++++------- src/pocketmine/entity/Living.php | 23 +++++++++ .../event/player/PlayerExhaustEvent.php | 18 +++++-- 6 files changed, 101 insertions(+), 31 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 4763c0113..ad6f7b3ed 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1566,6 +1566,15 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->teleport($ev->getTo()); }else{ $this->level->addEntityMovement($this->x >> 4, $this->z >> 4, $this->getId(), $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch, $this->yaw); + + $distance = $from->distance($to); + + //TODO: check swimming (adds 0.015 exhaustion in MCPE) + if($this->isSprinting()){ + $this->exhaust(0.1 * $distance, PlayerExhaustEvent::CAUSE_SPRINTING); + }else{ + $this->exhaust(0.01 * $distance, PlayerExhaustEvent::CAUSE_WALKING); + } } } } @@ -2675,6 +2684,10 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->removeAllEffects(); $this->setHealth($this->getMaxHealth()); + foreach($this->attributeMap->getAll() as $attr){ + $attr->resetToDefault(); + } + $this->sendData($this); $this->sendSettings(); @@ -2685,6 +2698,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->scheduleUpdate(); break; case PlayerActionPacket::ACTION_JUMP: + $this->jump(); return true; case PlayerActionPacket::ACTION_START_SPRINT: $ev = new PlayerToggleSprintEvent($this, true); @@ -3684,6 +3698,17 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return; } + parent::kill(); + + $pk = new RespawnPacket(); + $pos = $this->getSpawn(); + $pk->x = $pos->x; + $pk->y = $pos->y; + $pk->z = $pos->z; + $this->dataPacket($pk); + } + + protected function callDeathEvent(){ $message = "death.attack.generic"; $params = [ @@ -3793,10 +3818,9 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade break; default: + break; } - Entity::kill(); - $this->server->getPluginManager()->callEvent($ev = new PlayerDeathEvent($this, $this->getDrops(), new TranslationContainer($message, $params))); if(!$ev->getKeepInventory()){ @@ -3814,13 +3838,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade if($ev->getDeathMessage() != ""){ $this->server->broadcast($ev->getDeathMessage(), Server::BROADCAST_CHANNEL_USERS); } - - $pk = new RespawnPacket(); - $pos = $this->getSpawn(); - $pk->x = $pos->x; - $pk->y = $pos->y; - $pk->z = $pos->z; - $this->dataPacket($pk); } public function attack($damage, EntityDamageEvent $source){ diff --git a/src/pocketmine/entity/Attribute.php b/src/pocketmine/entity/Attribute.php index be5a6cfae..c48534c63 100644 --- a/src/pocketmine/entity/Attribute.php +++ b/src/pocketmine/entity/Attribute.php @@ -165,6 +165,10 @@ class Attribute{ return $this; } + public function resetToDefault(){ + $this->setValue($this->getDefaultValue()); + } + public function getValue(){ return $this->currentValue; } diff --git a/src/pocketmine/entity/AttributeMap.php b/src/pocketmine/entity/AttributeMap.php index cdf821c52..b74492f08 100644 --- a/src/pocketmine/entity/AttributeMap.php +++ b/src/pocketmine/entity/AttributeMap.php @@ -38,6 +38,9 @@ class AttributeMap implements \ArrayAccess{ return $this->attributes[$id] ?? null; } + /** + * @return Attribute[] + */ public function getAll(): array{ return $this->attributes; } diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index 732dd23f8..5d8db656c 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -99,6 +99,15 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ $this->skinId = $skinId; } + public function jump(){ + parent::jump(); + if($this->isSprinting()){ + $this->exhaust(0.8, PlayerExhaustEvent::CAUSE_SPRINT_JUMPING); + }else{ + $this->exhaust(0.2, PlayerExhaustEvent::CAUSE_JUMPING); + } + } + public function getFood() : float{ return $this->attributeMap->getAttribute(Attribute::HUNGER)->getValue(); } @@ -355,31 +364,35 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ if($this->isAlive()){ $food = $this->getFood(); $health = $this->getHealth(); - if($food >= 18){ - $this->foodTickTimer++; - if($this->foodTickTimer >= 80 and $health < $this->getMaxHealth()){ - $this->heal(1, new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION)); - $this->exhaust(3.0, PlayerExhaustEvent::CAUSE_HEALTH_REGEN); - $this->foodTickTimer = 0; + $difficulty = $this->server->getDifficulty(); + $this->foodTickTimer++; + if($this->foodTickTimer >= 80){ + $this->foodTickTimer = 0; + } + + if($difficulty === 0 and $this->foodTickTimer % 10 === 0){ //Peaceful + if($food < 20){ + $this->addFood(1.0); } - }elseif($food === 0){ - $this->foodTickTimer++; - if($this->foodTickTimer >= 80){ - $diff = $this->server->getDifficulty(); - $can = false; - if($diff === 1){ - $can = $health > 10; - }elseif($diff === 2){ - $can = $health > 1; - }elseif($diff === 3){ - $can = true; + if($this->foodTickTimer % 20 === 0 and $health < $this->getMaxHealth()){ + $this->heal(1, new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION)); + } + } + + if($this->foodTickTimer === 0){ + if($food >= 18){ + if($health < $this->getMaxHealth()){ + $this->heal(1, new EntityRegainHealthEvent($this, 1, EntityRegainHealthEvent::CAUSE_SATURATION)); + $this->exhaust(3.0, PlayerExhaustEvent::CAUSE_HEALTH_REGEN); } - if($can){ + }elseif($food <= 0){ + if(($difficulty === 1 and $health > 10) or ($difficulty === 2 and $health > 1) or $difficulty === 3){ $this->attack(1, new EntityDamageEvent($this, EntityDamageEvent::CAUSE_STARVATION, 1)); } } } + if($food <= 6){ if($this->isSprinting()){ $this->setSprinting(false); diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index 7a0a93e91..985b4fe3a 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -43,6 +43,8 @@ abstract class Living extends Entity implements Damageable{ protected $invisible = false; + protected $jumpVelocity = 0.42; + protected function initEntity(){ parent::initEntity(); @@ -115,6 +117,23 @@ abstract class Living extends Entity implements Damageable{ $this->attackTime = 0; } + /** + * Returns the initial upwards velocity of a jumping entity in blocks/tick, including additional velocity due to effects. + * @return float + */ + public function getJumpVelocity() : float{ + return $this->jumpVelocity + ($this->hasEffect(Effect::JUMP) ? (($this->getEffect(Effect::JUMP)->getAmplifier() + 1) / 10) : 0); + } + + /** + * Called when the entity jumps from the ground. This method adds upwards velocity to the entity. + */ + public function jump(){ + if($this->onGround){ + $this->motionY = $this->getJumpVelocity(); //Y motion should already be 0 if we're jumping from the ground. + } + } + public function attack($damage, EntityDamageEvent $source){ if($this->attackTime > 0 or $this->noDamageTicks > 0){ $lastCause = $this->getLastDamageCause(); @@ -183,6 +202,10 @@ abstract class Living extends Entity implements Damageable{ return; } parent::kill(); + $this->callDeathEvent(); + } + + protected function callDeathEvent(){ $this->server->getPluginManager()->callEvent($ev = new EntityDeathEvent($this, $this->getDrops())); foreach($ev->getDrops() as $item){ $this->getLevel()->dropItem($this, $item); diff --git a/src/pocketmine/event/player/PlayerExhaustEvent.php b/src/pocketmine/event/player/PlayerExhaustEvent.php index 623b5fdf4..747988fb5 100644 --- a/src/pocketmine/event/player/PlayerExhaustEvent.php +++ b/src/pocketmine/event/player/PlayerExhaustEvent.php @@ -34,19 +34,21 @@ class PlayerExhaustEvent extends PlayerEvent implements Cancellable{ const CAUSE_HEALTH_REGEN = 4; const CAUSE_POTION = 5; const CAUSE_WALKING = 6; - const CAUSE_SNEAKING = 7; + const CAUSE_SPRINTING = 7; const CAUSE_SWIMMING = 8; - const CAUSE_JUMPING = 10; + const CAUSE_JUMPING = 9; + const CAUSE_SPRINT_JUMPING = 10; const CAUSE_CUSTOM = 11; - const CAUSE_FLAG_SPRINT = 0x10000; - /** @var float */ private $amount; + /** @var int */ + private $cause; public function __construct(Human $human, float $amount, int $cause){ $this->player = $human; $this->amount = $amount; + $this->cause = $cause; } /** @@ -63,4 +65,12 @@ class PlayerExhaustEvent extends PlayerEvent implements Cancellable{ public function setAmount(float $amount){ $this->amount = $amount; } + + /** + * Returns an int cause of the exhaustion - one of the constants at the top of this class. + * @return int + */ + public function getCause() : int{ + return $this->cause; + } } From 559504225a46f5b9555dbcb02c12987605929a74 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 24 Apr 2017 09:50:55 +0100 Subject: [PATCH 94/96] Throw an exception before calling base entity constructor if skin is not set or invalid, close #835 (#855) --- src/pocketmine/entity/Human.php | 17 +++++++++++++++-- src/pocketmine/level/format/Chunk.php | 13 ++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index 5d8db656c..3ff95d79c 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -27,6 +27,7 @@ use pocketmine\event\player\PlayerExhaustEvent; use pocketmine\inventory\InventoryHolder; use pocketmine\inventory\PlayerInventory; use pocketmine\item\Item as ItemItem; +use pocketmine\level\Level; use pocketmine\nbt\NBT; use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\CompoundTag; @@ -61,13 +62,21 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ public $eyeHeight = 1.62; protected $skinId; - protected $skin; + protected $skin = null; protected $foodTickTimer = 0; protected $totalXp = 0; protected $xpSeed; + public function __construct(Level $level, CompoundTag $nbt){ + if($this->skin === null and (!isset($nbt->Skin) or !isset($nbt->Skin->Data) or !Player::isValidSkin($nbt->Skin->Data->getValue()))){ + throw new \InvalidStateException((new \ReflectionClass($this))->getShortName() . " must have a valid skin set"); + } + + parent::__construct($level, $nbt); + } + public function getSkinData(){ return $this->skin; } @@ -95,6 +104,10 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ * @param string $skinId */ public function setSkin($str, $skinId){ + if(!Player::isValidSkin($str)){ + throw new \InvalidStateException("Specified skin is not valid, must be 8KiB or 16KiB"); + } + $this->skin = $str; $this->skinId = $skinId; } @@ -483,7 +496,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ if($player !== $this and !isset($this->hasSpawned[$player->getLoaderId()])){ $this->hasSpawned[$player->getLoaderId()] = $player; - if(strlen($this->skin) < 64 * 32 * 4){ + if(!Player::isValidSkin($this->skin)){ throw new \InvalidStateException((new \ReflectionClass($this))->getShortName() . " must have a valid skin set"); } diff --git a/src/pocketmine/level/format/Chunk.php b/src/pocketmine/level/format/Chunk.php index 00db9a89c..636ad41a2 100644 --- a/src/pocketmine/level/format/Chunk.php +++ b/src/pocketmine/level/format/Chunk.php @@ -697,9 +697,16 @@ class Chunk{ continue; //Fixes entities allocated in wrong chunks. } - if(($entity = Entity::createEntity($nbt["id"], $level, $nbt)) instanceof Entity){ - $entity->spawnToAll(); - }else{ + try{ + $entity = Entity::createEntity($nbt["id"], $level, $nbt); + if($entity instanceof Entity){ + $entity->spawnToAll(); + }else{ + $changed = true; + continue; + } + }catch(\Throwable $t){ + $level->getServer()->getLogger()->logException($t); $changed = true; continue; } From 0e7f364a41954c7517a704a837b7eb3893516889 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 24 Apr 2017 11:55:33 +0100 Subject: [PATCH 95/96] Fixed chunk object memory leak when chunks are changed, close #419 If a player quit the server in the 1-second between a chunk changing and a fresh chunk-order requesting a resend of that chunk, the player wouldn't know they were using that chunk and did not unregister themselves, causing the subject chunks to always remain loaded. --- src/pocketmine/Player.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 781b82eeb..b5e461731 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -4088,7 +4088,9 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } public function onChunkChanged(Chunk $chunk){ - unset($this->usedChunks[Level::chunkHash($chunk->getX(), $chunk->getZ())]); + if(isset($this->usedChunks[$hash = Level::chunkHash($chunk->getX(), $chunk->getZ())])){ + $this->usedChunks[$hash] = false; + } } public function onChunkLoaded(Chunk $chunk){ From d682fdfdf0b4fff5a79018a8f63f496be37c4ed8 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 24 Apr 2017 13:31:05 +0100 Subject: [PATCH 96/96] Food and exhaustion should not apply in creative, close #860 --- src/pocketmine/Player.php | 14 ++++++++++++++ src/pocketmine/entity/Human.php | 10 +++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index b5e461731..27f71bef3 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1706,6 +1706,20 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade return true; } + public function doFoodTick(int $tickDiff = 1){ + if($this->isSurvival()){ + parent::doFoodTick($tickDiff); + } + } + + public function exhaust(float $amount, int $cause = PlayerExhaustEvent::CAUSE_CUSTOM) : float{ + if($this->isSurvival()){ + return parent::exhaust($amount, $cause); + } + + return 0.0; + } + public function checkNetwork(){ if(!$this->isOnline()){ return; diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index 3ff95d79c..9797ead87 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -374,12 +374,18 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ public function entityBaseTick($tickDiff = 1){ $hasUpdate = parent::entityBaseTick($tickDiff); + $this->doFoodTick($tickDiff); + + return $hasUpdate; + } + + public function doFoodTick(int $tickDiff = 1){ if($this->isAlive()){ $food = $this->getFood(); $health = $this->getHealth(); $difficulty = $this->server->getDifficulty(); - $this->foodTickTimer++; + $this->foodTickTimer += $tickDiff; if($this->foodTickTimer >= 80){ $this->foodTickTimer = 0; } @@ -412,8 +418,6 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ } } } - - return $hasUpdate; } public function getName(){