Remove resource pack packets dependency on ResourcePack, now supports decoding

This commit is contained in:
Dylan K. Taylor 2019-08-08 19:36:54 +01:00
parent a52e4f0392
commit d87b6f9ff7
5 changed files with 197 additions and 65 deletions

View File

@ -30,8 +30,11 @@ 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\types\ResourcePackInfoEntry;
use pocketmine\network\mcpe\protocol\types\ResourcePackStackEntry;
use pocketmine\resourcepacks\ResourcePack;
use pocketmine\resourcepacks\ResourcePackManager;
use function array_map;
use function ceil;
use function count;
use function implode;
@ -60,7 +63,11 @@ class ResourcePacksPacketHandler extends PacketHandler{
}
public function setUp() : void{
$this->session->sendDataPacket(ResourcePacksInfoPacket::create($this->resourcePackManager->getResourceStack(), [], $this->resourcePackManager->resourcePacksRequired(), false));
$resourcePackEntries = array_map(static function(ResourcePack $pack){
//TODO: more stuff
return new ResourcePackInfoEntry($pack->getPackId(), $pack->getPackVersion(), $pack->getPackSize(), "", "", "", false);
}, $this->resourcePackManager->getResourceStack());
$this->session->sendDataPacket(ResourcePacksInfoPacket::create($resourcePackEntries, [], $this->resourcePackManager->resourcePacksRequired(), false));
$this->session->getLogger()->debug("Waiting for client to accept resource packs");
}
@ -102,7 +109,10 @@ class ResourcePacksPacketHandler extends PacketHandler{
break;
case ResourcePackClientResponsePacket::STATUS_HAVE_ALL_PACKS:
$this->session->sendDataPacket(ResourcePackStackPacket::create($this->resourcePackManager->getResourceStack(), [], $this->resourcePackManager->resourcePacksRequired(), false));
$stack = array_map(static function(ResourcePack $pack){
return new ResourcePackStackEntry($pack->getPackId(), $pack->getPackVersion(), ""); //TODO: subpacks
}, $this->resourcePackManager->getResourceStack());
$this->session->sendDataPacket(ResourcePackStackPacket::create($stack, [], $this->resourcePackManager->resourcePacksRequired(), false));
$this->session->getLogger()->debug("Applying resource pack stack");
break;
case ResourcePackClientResponsePacket::STATUS_COMPLETED:

View File

@ -28,7 +28,7 @@ namespace pocketmine\network\mcpe\protocol;
use pocketmine\network\mcpe\handler\PacketHandler;
use pocketmine\resourcepacks\ResourcePack;
use pocketmine\network\mcpe\protocol\types\ResourcePackStackEntry;
use function count;
class ResourcePackStackPacket extends DataPacket implements ClientboundPacket{
@ -37,19 +37,19 @@ class ResourcePackStackPacket extends DataPacket implements ClientboundPacket{
/** @var bool */
public $mustAccept = false;
/** @var ResourcePack[] */
/** @var ResourcePackStackEntry[] */
public $behaviorPackStack = [];
/** @var ResourcePack[] */
/** @var ResourcePackStackEntry[] */
public $resourcePackStack = [];
/** @var bool */
public $isExperimental = false;
/**
* @param ResourcePack[] $resourcePacks
* @param ResourcePack[] $behaviorPacks
* @param bool $mustAccept
* @param bool $isExperimental
* @param ResourcePackStackEntry[] $resourcePacks
* @param ResourcePackStackEntry[] $behaviorPacks
* @param bool $mustAccept
* @param bool $isExperimental
*
* @return ResourcePackStackPacket
*/
@ -66,16 +66,12 @@ class ResourcePackStackPacket extends DataPacket implements ClientboundPacket{
$this->mustAccept = $this->getBool();
$behaviorPackCount = $this->getUnsignedVarInt();
while($behaviorPackCount-- > 0){
$this->getString();
$this->getString();
$this->getString();
$this->behaviorPackStack[] = ResourcePackStackEntry::read($this);
}
$resourcePackCount = $this->getUnsignedVarInt();
while($resourcePackCount-- > 0){
$this->getString();
$this->getString();
$this->getString();
$this->resourcePackStack[] = ResourcePackStackEntry::read($this);
}
$this->isExperimental = $this->getBool();
@ -86,16 +82,12 @@ class ResourcePackStackPacket extends DataPacket implements ClientboundPacket{
$this->putUnsignedVarInt(count($this->behaviorPackStack));
foreach($this->behaviorPackStack as $entry){
$this->putString($entry->getPackId());
$this->putString($entry->getPackVersion());
$this->putString(""); //TODO: subpack name
$entry->write($this);
}
$this->putUnsignedVarInt(count($this->resourcePackStack));
foreach($this->resourcePackStack as $entry){
$this->putString($entry->getPackId());
$this->putString($entry->getPackVersion());
$this->putString(""); //TODO: subpack name
$entry->write($this);
}
$this->putBool($this->isExperimental);

View File

@ -27,7 +27,7 @@ namespace pocketmine\network\mcpe\protocol;
use pocketmine\network\mcpe\handler\PacketHandler;
use pocketmine\resourcepacks\ResourcePack;
use pocketmine\network\mcpe\protocol\types\ResourcePackInfoEntry;
use function count;
class ResourcePacksInfoPacket extends DataPacket implements ClientboundPacket{
@ -37,16 +37,16 @@ class ResourcePacksInfoPacket extends DataPacket implements ClientboundPacket{
public $mustAccept = false; //if true, forces client to use selected resource packs
/** @var bool */
public $hasScripts = false; //if true, causes disconnect for any platform that doesn't support scripts yet
/** @var ResourcePack[] */
/** @var ResourcePackInfoEntry[] */
public $behaviorPackEntries = [];
/** @var ResourcePack[] */
/** @var ResourcePackInfoEntry[] */
public $resourcePackEntries = [];
/**
* @param ResourcePack[] $resourcePacks
* @param ResourcePack[] $behaviorPacks
* @param bool $mustAccept
* @param bool $hasScripts
* @param ResourcePackInfoEntry[] $resourcePacks
* @param ResourcePackInfoEntry[] $behaviorPacks
* @param bool $mustAccept
* @param bool $hasScripts
*
* @return ResourcePacksInfoPacket
*/
@ -64,24 +64,12 @@ class ResourcePacksInfoPacket extends DataPacket implements ClientboundPacket{
$this->hasScripts = $this->getBool();
$behaviorPackCount = $this->getLShort();
while($behaviorPackCount-- > 0){
$this->getString();
$this->getString();
$this->getLLong();
$this->getString();
$this->getString();
$this->getString();
$this->getBool();
$this->behaviorPackEntries[] = ResourcePackInfoEntry::read($this);
}
$resourcePackCount = $this->getLShort();
while($resourcePackCount-- > 0){
$this->getString();
$this->getString();
$this->getLLong();
$this->getString();
$this->getString();
$this->getString();
$this->getBool();
$this->resourcePackEntries[] = ResourcePackInfoEntry::read($this);
}
}
@ -90,23 +78,11 @@ class ResourcePacksInfoPacket extends DataPacket implements ClientboundPacket{
$this->putBool($this->hasScripts);
$this->putLShort(count($this->behaviorPackEntries));
foreach($this->behaviorPackEntries as $entry){
$this->putString($entry->getPackId());
$this->putString($entry->getPackVersion());
$this->putLLong($entry->getPackSize());
$this->putString(""); //TODO: encryption key
$this->putString(""); //TODO: subpack name
$this->putString(""); //TODO: content identity
$this->putBool(false); //TODO: has scripts (?)
$entry->write($this);
}
$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: encryption key
$this->putString(""); //TODO: subpack name
$this->putString(""); //TODO: content identity
$this->putBool(false); //TODO: seems useless for resource packs
$entry->write($this);
}
}

View File

@ -0,0 +1,125 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol\types;
use pocketmine\network\mcpe\serializer\NetworkBinaryStream;
class ResourcePackInfoEntry{
/** @var string */
private $packId;
/** @var string */
private $version;
/** @var int */
private $sizeBytes;
/** @var string */
private $encryptionKey;
/** @var string */
private $subPackName;
/** @var string */
private $contentId;
/** @var bool */
private $hasScripts;
public function __construct(string $packId, string $version, int $sizeBytes, string $encryptionKey = "", string $subPackName = "", string $contentId = "", bool $hasScripts = false){
$this->packId = $packId;
$this->version = $version;
$this->sizeBytes = $sizeBytes;
$this->encryptionKey = $encryptionKey;
$this->subPackName = $subPackName;
$this->contentId = $contentId;
$this->hasScripts = $hasScripts;
}
/**
* @return string
*/
public function getPackId() : string{
return $this->packId;
}
/**
* @return string
*/
public function getVersion() : string{
return $this->version;
}
/**
* @return int
*/
public function getSizeBytes() : int{
return $this->sizeBytes;
}
/**
* @return string
*/
public function getEncryptionKey() : string{
return $this->encryptionKey;
}
/**
* @return string
*/
public function getSubPackName() : string{
return $this->subPackName;
}
/**
* @return string
*/
public function getContentId() : string{
return $this->contentId;
}
/**
* @return bool
*/
public function hasScripts() : bool{
return $this->hasScripts;
}
public function write(NetworkBinaryStream $out) : void{
$out->putString($this->packId);
$out->putString($this->version);
$out->putLLong($this->sizeBytes);
$out->putString($this->encryptionKey ?? "");
$out->putString($this->subPackName ?? "");
$out->putString($this->contentId ?? "");
$out->putBool($this->hasScripts);
}
public static function read(NetworkBinaryStream $in) : self{
return new self(
$uuid = $in->getString(),
$version = $in->getString(),
$sizeBytes = $in->getLLong(),
$encryptionKey = $in->getString(),
$subPackName = $in->getString(),
$contentId = $in->getString(),
$hasScripts = $in->getBool()
);
}
}

View File

@ -21,28 +21,57 @@
declare(strict_types=1);
namespace pocketmine\resourcepacks;
namespace pocketmine\network\mcpe\protocol\types;
class ResourcePackInfoEntry{
protected $packId; //UUID
protected $version;
protected $packSize;
use pocketmine\network\mcpe\serializer\NetworkBinaryStream;
public function __construct(string $packId, string $version, int $packSize = 0){
class ResourcePackStackEntry{
/** @var string */
private $packId;
/** @var string */
private $version;
/** @var string */
private $subPackName;
public function __construct(string $packId, string $version, string $subPackName){
$this->packId = $packId;
$this->version = $version;
$this->packSize = $packSize;
$this->subPackName = $subPackName;
}
/**
* @return string
*/
public function getPackId() : string{
return $this->packId;
}
/**
* @return string
*/
public function getVersion() : string{
return $this->version;
}
public function getPackSize() : int{
return $this->packSize;
/**
* @return string
*/
public function getSubPackName() : string{
return $this->subPackName;
}
public function write(NetworkBinaryStream $out) : void{
$out->putString($this->packId);
$out->putString($this->version);
$out->putString($this->subPackName);
}
public static function read(NetworkBinaryStream $in) : self{
return new self(
$packId = $in->getString(),
$version = $in->getString(),
$subPackName = $in->getString()
);
}
}