PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
ResourcePackDataInfoPacket.php
1<?php
2
3/*
4 * This file is part of BedrockProtocol.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
6 *
7 * BedrockProtocol is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13declare(strict_types=1);
14
15namespace pocketmine\network\mcpe\protocol;
16
17use pmmp\encoding\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\LE;
23
25 public const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_DATA_INFO_PACKET;
26
27 public string $packId;
28 public int $maxChunkSize;
29 public int $chunkCount;
30 public int $compressedPackSize;
31 public string $sha256;
32 public bool $isPremium = false;
33 public int $packType = ResourcePackType::RESOURCES; //TODO: check the values for this
34
38 public static function create(
39 string $packId,
40 int $maxChunkSize,
41 int $chunkCount,
42 int $compressedPackSize,
43 string $sha256,
44 bool $isPremium,
45 int $packType,
46 ) : self{
47 $result = new self;
48 $result->packId = $packId;
49 $result->maxChunkSize = $maxChunkSize;
50 $result->chunkCount = $chunkCount;
51 $result->compressedPackSize = $compressedPackSize;
52 $result->sha256 = $sha256;
53 $result->isPremium = $isPremium;
54 $result->packType = $packType;
55 return $result;
56 }
57
58 protected function decodePayload(ByteBufferReader $in) : void{
59 $this->packId = CommonTypes::getString($in);
60 $this->maxChunkSize = LE::readUnsignedInt($in);
61 $this->chunkCount = LE::readUnsignedInt($in);
62 $this->compressedPackSize = LE::readUnsignedLong($in);
63 $this->sha256 = CommonTypes::getString($in);
64 $this->isPremium = CommonTypes::getBool($in);
65 $this->packType = Byte::readUnsigned($in);
66 }
67
68 protected function encodePayload(ByteBufferWriter $out) : void{
69 CommonTypes::putString($out, $this->packId);
70 LE::writeUnsignedInt($out, $this->maxChunkSize);
71 LE::writeUnsignedInt($out, $this->chunkCount);
72 LE::writeUnsignedLong($out, $this->compressedPackSize);
73 CommonTypes::putString($out, $this->sha256);
74 CommonTypes::putBool($out, $this->isPremium);
75 Byte::writeUnsigned($out, $this->packType);
76 }
77
78 public function handle(PacketHandlerInterface $handler) : bool{
79 return $handler->handleResourcePackDataInfo($this);
80 }
81}
static create(string $packId, int $maxChunkSize, int $chunkCount, int $compressedPackSize, string $sha256, bool $isPremium, int $packType,)