From 9c25ec3afd6a723ddc0c075e3ec8de5668e6ec2b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 1 Apr 2017 19:20:30 +0100 Subject: [PATCH] Some protocol changes for 1.1.0.0 --- src/pocketmine/Player.php | 6 +-- src/pocketmine/entity/Entity.php | 38 ++++++++++--------- .../inventory/ContainerInventory.php | 1 - src/pocketmine/inventory/PlayerInventory.php | 3 ++ .../mcpe/protocol/AdventureSettingsPacket.php | 17 ++------- .../network/mcpe/protocol/AnimatePacket.php | 1 + .../mcpe/protocol/CommandStepPacket.php | 20 +++++----- .../mcpe/protocol/ContainerOpenPacket.php | 2 - .../protocol/ContainerSetContentPacket.php | 8 +++- .../mcpe/protocol/DisconnectPacket.php | 4 +- .../mcpe/protocol/EntityFallPacket.php | 4 ++ .../mcpe/protocol/InventoryActionPacket.php | 8 +++- .../mcpe/protocol/PlayStatusPacket.php | 3 +- 13 files changed, 61 insertions(+), 54 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 742126a27..3d1cbb3b2 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -3249,8 +3249,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } $this->craftingType = 0; $commandText = $packet->command; - if($packet->args !== null){ - foreach($packet->args as $arg){ //command ordering will be an issue + if($packet->inputJson !== null){ + foreach($packet->inputJson as $arg){ //command ordering will be an issue $commandText .= " " . $arg; } } @@ -3340,7 +3340,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() . ": " . bin2hex($packet->buffer)); } $timings->stopTiming(); diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index fa8aea85b..da4f5626b 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -125,34 +125,36 @@ abstract class Entity extends Location implements Metadatable{ const DATA_FLAG_SPRINTING = 3; const DATA_FLAG_ACTION = 4; const DATA_FLAG_INVISIBLE = 5; - const DATA_FLAG_TEMPTED = 6; //??? + const DATA_FLAG_TEMPTED = 6; const DATA_FLAG_INLOVE = 7; const DATA_FLAG_SADDLED = 8; const DATA_FLAG_POWERED = 9; - const DATA_FLAG_IGNITED = 10; //for creepers? + const DATA_FLAG_IGNITED = 10; const DATA_FLAG_BABY = 11; - const DATA_FLAG_CONVERTING = 12; //??? + const DATA_FLAG_CONVERTING = 12; const DATA_FLAG_CRITICAL = 13; const DATA_FLAG_CAN_SHOW_NAMETAG = 14; const DATA_FLAG_ALWAYS_SHOW_NAMETAG = 15; const DATA_FLAG_IMMOBILE = 16, DATA_FLAG_NO_AI = 16; const DATA_FLAG_SILENT = 17; const DATA_FLAG_WALLCLIMBING = 18; - const DATA_FLAG_RESTING = 19; //for bats? - const DATA_FLAG_SITTING = 20; - const DATA_FLAG_ANGRY = 21; - const DATA_FLAG_INTERESTED = 22; //for mobs following players with food? - const DATA_FLAG_CHARGED = 23; - const DATA_FLAG_TAMED = 24; - const DATA_FLAG_LEASHED = 25; - const DATA_FLAG_SHEARED = 26; //for sheep - const DATA_FLAG_GLIDING = 27, DATA_FLAG_FALL_FLYING = 27; - const DATA_FLAG_ELDER = 28; //elder guardian - const DATA_FLAG_MOVING = 29; - const DATA_FLAG_BREATHING = 30; //hides bubbles if true - const DATA_FLAG_CHESTED = 31; //for mules? - const DATA_FLAG_STACKABLE = 32; - const DATA_FLAG_IDLING = 36; + + const DATA_FLAG_RESTING = 22; + const DATA_FLAG_SITTING = 23; + const DATA_FLAG_ANGRY = 24; + const DATA_FLAG_INTERESTED = 25; + const DATA_FLAG_CHARGED = 26; + const DATA_FLAG_TAMED = 27; + const DATA_FLAG_LEASHED = 28; + const DATA_FLAG_SHEARED = 29; + const DATA_FLAG_GLIDING = 30; + const DATA_FLAG_ELDER = 31; + const DATA_FLAG_MOVING = 32; + const DATA_FLAG_BREATHING = 33; + const DATA_FLAG_CHESTED = 34; + const DATA_FLAG_STACKABLE = 35; + + const DATA_FLAG_IDLING = 39; public static $entityCount = 1; /** @var Entity[] */ diff --git a/src/pocketmine/inventory/ContainerInventory.php b/src/pocketmine/inventory/ContainerInventory.php index e17c96964..5b1bc652a 100644 --- a/src/pocketmine/inventory/ContainerInventory.php +++ b/src/pocketmine/inventory/ContainerInventory.php @@ -32,7 +32,6 @@ abstract class ContainerInventory extends BaseInventory{ $pk = new ContainerOpenPacket(); $pk->windowid = $who->getWindowId($this); $pk->type = $this->getType()->getNetworkType(); - $pk->slots = $this->getSize(); $holder = $this->getHolder(); if($holder instanceof Vector3){ $pk->x = $holder->getX(); diff --git a/src/pocketmine/inventory/PlayerInventory.php b/src/pocketmine/inventory/PlayerInventory.php index ebc3f5862..7db7759b3 100644 --- a/src/pocketmine/inventory/PlayerInventory.php +++ b/src/pocketmine/inventory/PlayerInventory.php @@ -401,6 +401,7 @@ class PlayerInventory extends BaseInventory{ $pk2 = new ContainerSetContentPacket(); $pk2->windowid = ContainerSetContentPacket::SPECIAL_ARMOR; $pk2->slots = $armor; + $pk2->targetEid = $player->getId(); $player->dataPacket($pk2); }else{ $player->dataPacket($pk); @@ -490,6 +491,7 @@ class PlayerInventory extends BaseInventory{ continue; } $pk->windowid = $id; + $pk->targetEid = $player->getId(); //TODO: check if this is correct $player->dataPacket(clone $pk); } } @@ -502,6 +504,7 @@ class PlayerInventory extends BaseInventory{ $pk->slots[$i] = clone $item; } } + $pk->targetEid = $this->getHolder()->getId(); $this->getHolder()->dataPacket($pk); } diff --git a/src/pocketmine/network/mcpe/protocol/AdventureSettingsPacket.php b/src/pocketmine/network/mcpe/protocol/AdventureSettingsPacket.php index 8cc7989ac..fa5372638 100644 --- a/src/pocketmine/network/mcpe/protocol/AdventureSettingsPacket.php +++ b/src/pocketmine/network/mcpe/protocol/AdventureSettingsPacket.php @@ -45,20 +45,7 @@ class AdventureSettingsPacket extends DataPacket{ public $noClip = false; public $worldBuilder = false; public $isFlying = false; - - /* - bit mask | flag name - 0x00000001 world_immutable - 0x00000002 no_pvp - 0x00000004 no_pvm - 0x00000008 no_mvp - 0x00000010 ? - 0x00000020 auto_jump - 0x00000040 allow_fly - 0x00000080 noclip - 0x00000100 world_builder (seems to allow building even if the world_immutable flag is set (???)) - 0x00000200 is_flying - */ + public $muted = false; public $flags = 0; public $userPermission; @@ -77,6 +64,7 @@ class AdventureSettingsPacket extends DataPacket{ $this->noClip = (bool) ($this->flags & (1 << 7)); $this->worldBuilder = (bool) ($this->flags & (1 << 8)); $this->isFlying = (bool) ($this->flags & (1 << 9)); + $this->muted = (bool) ($this->flags & (1 << 10)); } public function encode(){ @@ -92,6 +80,7 @@ class AdventureSettingsPacket extends DataPacket{ $this->flags |= ((int) $this->noClip) << 7; $this->flags |= ((int) $this->worldBuilder) << 8; $this->flags |= ((int) $this->isFlying) << 9; + $this->flags |= ((int) $this->muted) << 10; $this->putUnsignedVarInt($this->flags); $this->putUnsignedVarInt($this->userPermission); diff --git a/src/pocketmine/network/mcpe/protocol/AnimatePacket.php b/src/pocketmine/network/mcpe/protocol/AnimatePacket.php index fba81c904..0a6e01954 100644 --- a/src/pocketmine/network/mcpe/protocol/AnimatePacket.php +++ b/src/pocketmine/network/mcpe/protocol/AnimatePacket.php @@ -35,6 +35,7 @@ class AnimatePacket extends DataPacket{ public function decode(){ $this->action = $this->getVarInt(); $this->eid = $this->getEntityRuntimeId(); + //TODO: check extra float which appears when 0x80 bitflag is set } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/CommandStepPacket.php b/src/pocketmine/network/mcpe/protocol/CommandStepPacket.php index 26ccf3233..f9dcc3df2 100644 --- a/src/pocketmine/network/mcpe/protocol/CommandStepPacket.php +++ b/src/pocketmine/network/mcpe/protocol/CommandStepPacket.php @@ -31,21 +31,21 @@ class CommandStepPacket extends DataPacket{ public $command; public $overload; public $uvarint1; - public $uvarint2; - public $bool; - public $uvarint64; - public $args; - public $string4; + public $currentStep; + public $done; + public $clientId; + public $inputJson; + public $outputJson; public function decode(){ $this->command = $this->getString(); $this->overload = $this->getString(); $this->uvarint1 = $this->getUnsignedVarInt(); - $this->uvarint2 = $this->getUnsignedVarInt(); - $this->bool = (bool) $this->getByte(); - $this->uvarint64 = $this->getUnsignedVarLong(); - $this->args = json_decode($this->getString()); - $this->string4 = $this->getString(); + $this->currentStep = $this->getUnsignedVarInt(); + $this->done = (bool) $this->getByte(); + $this->clientId = $this->getUnsignedVarLong(); + $this->inputJson = json_decode($this->getString()); + $this->outputJson = $this->getString(); $this->get(true); //TODO: read command origin data } diff --git a/src/pocketmine/network/mcpe/protocol/ContainerOpenPacket.php b/src/pocketmine/network/mcpe/protocol/ContainerOpenPacket.php index 698c9d058..af221ec79 100644 --- a/src/pocketmine/network/mcpe/protocol/ContainerOpenPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ContainerOpenPacket.php @@ -31,7 +31,6 @@ class ContainerOpenPacket extends DataPacket{ public $windowid; public $type; - public $slots; public $x; public $y; public $z; @@ -45,7 +44,6 @@ class ContainerOpenPacket extends DataPacket{ $this->reset(); $this->putByte($this->windowid); $this->putByte($this->type); - $this->putVarInt($this->slots); $this->putBlockPosition($this->x, $this->y, $this->z); $this->putEntityUniqueId($this->entityId); } diff --git a/src/pocketmine/network/mcpe/protocol/ContainerSetContentPacket.php b/src/pocketmine/network/mcpe/protocol/ContainerSetContentPacket.php index ade1394d4..f8c7e0ef4 100644 --- a/src/pocketmine/network/mcpe/protocol/ContainerSetContentPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ContainerSetContentPacket.php @@ -33,8 +33,10 @@ class ContainerSetContentPacket extends DataPacket{ const SPECIAL_ARMOR = 0x78; const SPECIAL_CREATIVE = 0x79; const SPECIAL_HOTBAR = 0x7a; + const SPECIAL_FIXED_INVENTORY = 0x7b; public $windowid; + public $targetEid; public $slots = []; public $hotbar = []; @@ -45,7 +47,8 @@ class ContainerSetContentPacket extends DataPacket{ } public function decode(){ - $this->windowid = $this->getByte(); + $this->windowid = $this->getUnsignedVarInt(); + $this->targetEid = $this->getEntityUniqueId(); $count = $this->getUnsignedVarInt(); for($s = 0; $s < $count and !$this->feof(); ++$s){ $this->slots[$s] = $this->getSlot(); @@ -60,7 +63,8 @@ class ContainerSetContentPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putByte($this->windowid); + $this->putUnsignedVarInt($this->windowid); + $this->putEntityUniqueId($this->targetEid); $this->putUnsignedVarInt(count($this->slots)); foreach($this->slots as $slot){ $this->putSlot($slot); diff --git a/src/pocketmine/network/mcpe/protocol/DisconnectPacket.php b/src/pocketmine/network/mcpe/protocol/DisconnectPacket.php index 627e76015..12aa936cb 100644 --- a/src/pocketmine/network/mcpe/protocol/DisconnectPacket.php +++ b/src/pocketmine/network/mcpe/protocol/DisconnectPacket.php @@ -44,7 +44,9 @@ class DisconnectPacket extends DataPacket{ public function encode(){ $this->reset(); $this->putBool($this->hideDisconnectionScreen); - $this->putString($this->message); + if(!$this->hideDisconnectionScreen){ + $this->putString($this->message); + } } public function handle(NetworkSession $session) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/EntityFallPacket.php b/src/pocketmine/network/mcpe/protocol/EntityFallPacket.php index cd166f93f..e97259945 100644 --- a/src/pocketmine/network/mcpe/protocol/EntityFallPacket.php +++ b/src/pocketmine/network/mcpe/protocol/EntityFallPacket.php @@ -29,10 +29,14 @@ use pocketmine\network\mcpe\NetworkSession; class EntityFallPacket extends DataPacket{ const NETWORK_ID = ProtocolInfo::ENTITY_FALL_PACKET; + public $eid; public $fallDistance; + public $bool1; public function decode(){ + $this->eid = $this->getEntityRuntimeId(); $this->fallDistance = $this->getLFloat(); + $this->bool1 = $this->getBool(); } public function encode(){ diff --git a/src/pocketmine/network/mcpe/protocol/InventoryActionPacket.php b/src/pocketmine/network/mcpe/protocol/InventoryActionPacket.php index ac13818f7..46fb5802f 100644 --- a/src/pocketmine/network/mcpe/protocol/InventoryActionPacket.php +++ b/src/pocketmine/network/mcpe/protocol/InventoryActionPacket.php @@ -28,16 +28,20 @@ use pocketmine\network\mcpe\NetworkSession; class InventoryActionPacket extends DataPacket{ const NETWORK_ID = ProtocolInfo::INVENTORY_ACTION_PACKET; - public $unknown; + public $uvarint0; public $item; + public $varint1; + public $varint2; public function decode(){ } public function encode(){ - $this->putUnsignedVarInt($this->unknown); + $this->putUnsignedVarInt($this->uvarint0); $this->putSlot($this->item); + $this->putVarInt($this->varint1); + $this->putVarInt($this->varint2); } public function handle(NetworkSession $session) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/PlayStatusPacket.php b/src/pocketmine/network/mcpe/protocol/PlayStatusPacket.php index 621f6c05c..cc22b2ee2 100644 --- a/src/pocketmine/network/mcpe/protocol/PlayStatusPacket.php +++ b/src/pocketmine/network/mcpe/protocol/PlayStatusPacket.php @@ -34,7 +34,8 @@ class PlayStatusPacket extends DataPacket{ const LOGIN_FAILED_SERVER = 2; const PLAYER_SPAWN = 3; const LOGIN_FAILED_INVALID_TENANT = 4; - const LOGIN_FAILED_EDITION_MISMATCH = 5; + const LOGIN_FAILED_VANILLA_EDU = 5; + const LOGIN_FAILED_EDU_VANILLA = 6; public $status;