From b51ec9e606b308c1075ffe3cc3f9e43660d10691 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 1 Nov 2017 20:12:13 +0000 Subject: [PATCH] rough work for CommandOutputPacket, no idea if it works --- .../mcpe/protocol/CommandOutputPacket.php | 61 ++++++++++++++++++- .../protocol/types/CommandOutputMessage.php | 34 +++++++++++ 2 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 src/pocketmine/network/mcpe/protocol/types/CommandOutputMessage.php diff --git a/src/pocketmine/network/mcpe/protocol/CommandOutputPacket.php b/src/pocketmine/network/mcpe/protocol/CommandOutputPacket.php index 0cc331c10..857e298a8 100644 --- a/src/pocketmine/network/mcpe/protocol/CommandOutputPacket.php +++ b/src/pocketmine/network/mcpe/protocol/CommandOutputPacket.php @@ -26,16 +26,73 @@ namespace pocketmine\network\mcpe\protocol; #include use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\protocol\types\CommandOriginData; +use pocketmine\network\mcpe\protocol\types\CommandOutputMessage; class CommandOutputPacket extends DataPacket{ const NETWORK_ID = ProtocolInfo::COMMAND_OUTPUT_PACKET; + /** @var CommandOriginData */ + public $originData; + /** @var int */ + public $outputType; + /** @var int */ + public $successCount; + /** @var CommandOutputMessage[] */ + public $messages = []; + /** @var string */ + public $unknownString; + protected function decodePayload(){ - //TODO + $this->originData = $this->getCommandOriginData(); + $this->outputType = $this->getByte(); + $this->successCount = $this->getUnsignedVarInt(); + + for($i = 0, $size = $this->getUnsignedVarInt(); $i < $size; ++$i){ + $this->messages[] = $this->getCommandMessage(); + } + + if($this->outputType === 4){ + $this->unknownString = $this->getString(); + } + } + + protected function getCommandMessage() : CommandOutputMessage{ + $message = new CommandOutputMessage(); + + $message->isInternal = $this->getBool(); + $message->messageId = $this->getString(); + + for($i = 0, $size = $this->getUnsignedVarInt(); $i < $size; ++$i){ + $message->parameters[] = $this->getString(); + } + + return $message; } protected function encodePayload(){ - //TODO + $this->putCommandOriginData($this->originData); + $this->putByte($this->outputType); + $this->putUnsignedVarInt($this->successCount); + + $this->putUnsignedVarInt(count($this->messages)); + foreach($this->messages as $message){ + $this->putCommandMessage($message); + } + + if($this->outputType === 4){ + $this->putString($this->unknownString); + } + } + + protected function putCommandMessage(CommandOutputMessage $message){ + $this->putBool($message->isInternal); + $this->putString($message->messageId); + + $this->putUnsignedVarInt(count($message->parameters)); + foreach($message->parameters as $parameter){ + $this->putString($parameter); + } } public function handle(NetworkSession $session) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/types/CommandOutputMessage.php b/src/pocketmine/network/mcpe/protocol/types/CommandOutputMessage.php new file mode 100644 index 000000000..90ccc681e --- /dev/null +++ b/src/pocketmine/network/mcpe/protocol/types/CommandOutputMessage.php @@ -0,0 +1,34 @@ +