PocketMine-MP 5.18.1 git-9381fc4172e5dce4cada1cb356050c8a2ab57b94
ResourcePacksInfoPacket.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
20use function count;
21
23 public const NETWORK_ID = ProtocolInfo::RESOURCE_PACKS_INFO_PACKET;
24
26 public array $resourcePackEntries = [];
28 public array $behaviorPackEntries = [];
29 public bool $mustAccept = false; //if true, forces client to choose between accepting packs or being disconnected
30 public bool $hasAddons = false;
31 public bool $hasScripts = false; //if true, causes disconnect for any platform that doesn't support scripts yet
32 public bool $forceServerPacks = false;
37 public array $cdnUrls = [];
38
46 public static function create(
47 array $resourcePackEntries,
48 array $behaviorPackEntries,
49 bool $mustAccept,
50 bool $hasAddons,
51 bool $hasScripts,
52 bool $forceServerPacks,
53 array $cdnUrls,
54 ) : self{
55 $result = new self;
56 $result->resourcePackEntries = $resourcePackEntries;
57 $result->behaviorPackEntries = $behaviorPackEntries;
58 $result->mustAccept = $mustAccept;
59 $result->hasAddons = $hasAddons;
60 $result->hasScripts = $hasScripts;
61 $result->forceServerPacks = $forceServerPacks;
62 $result->cdnUrls = $cdnUrls;
63 return $result;
64 }
65
66 protected function decodePayload(PacketSerializer $in) : void{
67 $this->mustAccept = $in->getBool();
68 $this->hasAddons = $in->getBool();
69 $this->hasScripts = $in->getBool();
70 $this->forceServerPacks = $in->getBool();
71 $behaviorPackCount = $in->getLShort();
72 while($behaviorPackCount-- > 0){
73 $this->behaviorPackEntries[] = BehaviorPackInfoEntry::read($in);
74 }
75
76 $resourcePackCount = $in->getLShort();
77 while($resourcePackCount-- > 0){
78 $this->resourcePackEntries[] = ResourcePackInfoEntry::read($in);
79 }
80
81 $this->cdnUrls = [];
82 for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; $i++){
83 $packId = $in->getString();
84 $cdnUrl = $in->getString();
85 $this->cdnUrls[$packId] = $cdnUrl;
86 }
87 }
88
89 protected function encodePayload(PacketSerializer $out) : void{
90 $out->putBool($this->mustAccept);
91 $out->putBool($this->hasAddons);
92 $out->putBool($this->hasScripts);
93 $out->putBool($this->forceServerPacks);
94 $out->putLShort(count($this->behaviorPackEntries));
95 foreach($this->behaviorPackEntries as $entry){
96 $entry->write($out);
97 }
98 $out->putLShort(count($this->resourcePackEntries));
99 foreach($this->resourcePackEntries as $entry){
100 $entry->write($out);
101 }
102 $out->putUnsignedVarInt(count($this->cdnUrls));
103 foreach($this->cdnUrls as $packId => $cdnUrl){
104 $out->putString($packId);
105 $out->putString($cdnUrl);
106 }
107 }
108
109 public function handle(PacketHandlerInterface $handler) : bool{
110 return $handler->handleResourcePacksInfo($this);
111 }
112}
static create(array $resourcePackEntries, array $behaviorPackEntries, bool $mustAccept, bool $hasAddons, bool $hasScripts, bool $forceServerPacks, array $cdnUrls,)