Fixed encode/decode of ResourcePacksInfoPacket and ResourcePackClientResponsePacket

This commit is contained in:
Dylan K. Taylor 2017-02-24 13:28:11 +00:00
parent 1ee689e759
commit 0cd1e82c52
2 changed files with 30 additions and 7 deletions

View File

@ -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);
}
}
}

View File

@ -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());