PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
ResourcePackClientResponsePacket.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;
22use function count;
23
25 public const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_CLIENT_RESPONSE_PACKET;
26
27 public const STATUS_REFUSED = 1;
28 public const STATUS_SEND_PACKS = 2;
29 public const STATUS_HAVE_ALL_PACKS = 3;
30 public const STATUS_COMPLETED = 4;
31
32 public int $status;
34 public array $packIds = [];
35
40 public static function create(int $status, array $packIds) : self{
41 $result = new self;
42 $result->status = $status;
43 $result->packIds = $packIds;
44 return $result;
45 }
46
47 protected function decodePayload(ByteBufferReader $in) : void{
48 $this->status = Byte::readUnsigned($in);
49 $entryCount = LE::readUnsignedShort($in);
50 $this->packIds = [];
51 while($entryCount-- > 0){
52 $this->packIds[] = CommonTypes::getString($in);
53 }
54 }
55
56 protected function encodePayload(ByteBufferWriter $out) : void{
57 Byte::writeUnsigned($out, $this->status);
58 LE::writeUnsignedShort($out, count($this->packIds));
59 foreach($this->packIds as $id){
60 CommonTypes::putString($out, $id);
61 }
62 }
63
64 public function handle(PacketHandlerInterface $handler) : bool{
65 return $handler->handleResourcePackClientResponse($this);
66 }
67}