Skip to content
This repository was archived by the owner on Jun 20, 2024. It is now read-only.

Commit 75a4939

Browse files
AzaleeXVirvoltaSenseiTarzan
authored
Merge next-dev branch -> stable branch (#22)
* add symply.yml config * set to Symply name * add support native waterdogpe in symply and fix system symply.yml * fix php-cs-fixer and add new rule * oups no commit rules for php-cs-fixer * fix rules and add support multi rules * fix rules for pmmp * fix finder for exclude file * fix cs * add system url resources pack in symply (#20) Co-authored-by: AzaleeX <azaleemcpe@gmail.com> --------- Signed-off-by: AzaleeX <azaleemcpe@gmail.com> Co-authored-by: Vuillamier Lilian <33796736+Virvolta@users.noreply.github.com> Co-authored-by: Sensei Tarzan <gabrielcaptari0@gmail.com>
1 parent 30904e8 commit 75a4939

File tree

10 files changed

+497
-23
lines changed

10 files changed

+497
-23
lines changed

composer.lock

Lines changed: 163 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/resource_packs.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,12 @@ resource_stack:
99
#Example
1010
# - natural.zip
1111
# - vanilla.zip
12+
# - path: file.zip
13+
# encryptionKey: "your encrypt Key" <- is optionnal option
14+
# - path: 'https://exemple.com/natural.zip'
15+
# name: "name in manifest.json"
16+
# uuid: "uuid in manifest.json"
17+
# version: "version in manifest.json"
18+
# encryptionKey: "your encrypt Key" <- is optionnal option
1219
#If you want to force clients to use vanilla resources, you must place a vanilla resource pack in your resources folder and add it to the stack here.
1320
#To specify a resource encryption key, put the key in the <resource>.key file alongside the resource pack. Example: vanilla.zip.key

src/network/mcpe/handler/ResourcePacksPacketHandler.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use pocketmine\network\mcpe\protocol\types\resourcepacks\ResourcePackType;
3939
use pocketmine\resourcepacks\ResourcePack;
4040
use pocketmine\resourcepacks\ResourcePackManager;
41+
use symply\resourcepacks\URLResourcePack;
4142
use function array_map;
4243
use function ceil;
4344
use function count;
@@ -67,20 +68,19 @@ public function __construct(
6768
public function setUp() : void{
6869
$resourcePackEntries = array_map(function(ResourcePack $pack) : ResourcePackInfoEntry{
6970
//TODO: more stuff
70-
$encryptionKey = $this->resourcePackManager->getPackEncryptionKey($pack->getPackId());
7171

7272
return new ResourcePackInfoEntry(
7373
$pack->getPackId(),
7474
$pack->getPackVersion(),
7575
$pack->getPackSize(),
76-
$encryptionKey ?? "",
76+
$pack->getEncryptionKey(),
7777
"",
78-
$pack->getPackId(),
78+
$pack->getContentId(),
7979
false
8080
);
8181
}, $this->resourcePackManager->getResourceStack());
8282
//TODO: support forcing server packs
83-
$this->session->sendDataPacket(ResourcePacksInfoPacket::create($resourcePackEntries, [], $this->resourcePackManager->resourcePacksRequired(), false, false, []));
83+
$this->session->sendDataPacket(ResourcePacksInfoPacket::create($resourcePackEntries, [], $this->resourcePackManager->resourcePacksRequired(), false, false, $this->resourcePackManager->getPackUrl()));
8484
$this->session->getLogger()->debug("Waiting for client to accept resource packs");
8585
}
8686

@@ -109,6 +109,10 @@ public function handleResourcePackClientResponse(ResourcePackClientResponsePacke
109109
$this->disconnectWithError("Unknown pack $uuid requested, available packs: " . implode(", ", $this->resourcePackManager->getPackIdList()));
110110
return false;
111111
}
112+
if ($pack instanceof URLResourcePack){
113+
$this->disconnectWithError("Invalid URL for pack chunk in $uuid. Unable to use the getPackChunk method.");
114+
return false;
115+
}
112116

113117
$this->session->sendDataPacket(ResourcePackDataInfoPacket::create(
114118
$pack->getPackId(),
@@ -154,8 +158,11 @@ public function handleResourcePackChunkRequest(ResourcePackChunkRequestPacket $p
154158
$this->disconnectWithError("Invalid request for chunk $packet->chunkIndex of unknown pack $packet->packId, available packs: " . implode(", ", $this->resourcePackManager->getPackIdList()));
155159
return false;
156160
}
157-
158161
$packId = $pack->getPackId(); //use this because case may be different
162+
if ($pack instanceof URLResourcePack){
163+
$this->disconnectWithError("Invalid URL for pack chunk in $packId. Unable to use the getPackChunk method.");
164+
return false;
165+
}
159166

160167
if(isset($this->downloadedChunks[$packId][$packet->chunkIndex])){
161168
$this->disconnectWithError("Duplicate request for chunk $packet->chunkIndex of pack $packet->packId");

src/resourcepacks/ResourcePack.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,19 @@ public function getSha256() : string;
6464
* @throws \InvalidArgumentException if the chunk does not exist
6565
*/
6666
public function getPackChunk(int $start, int $length) : string;
67+
68+
/**
69+
* Returns the EncryptionKey of ResourcesPack
70+
*/
71+
public function getEncryptionKey() : string;
72+
73+
/**
74+
* Returns the ContentId of ResourcesPack
75+
*/
76+
public function getContentId() : string;
77+
78+
/**
79+
* can set the EncryptionKey without pass by new system symplu
80+
*/
81+
public function setEncryptionKey(string $key) : void;
6782
}

src/resourcepacks/ResourcePackManager.php

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
use pocketmine\utils\Config;
2727
use pocketmine\utils\Filesystem;
2828
use Symfony\Component\Filesystem\Path;
29+
use symply\resourcepacks\URLResourcePack;
30+
use symply\utils\Utils as UtilsSymply;
2931
use function array_keys;
3032
use function copy;
3133
use function count;
@@ -56,7 +58,7 @@ class ResourcePackManager{
5658
* @var string[]
5759
* @phpstan-var array<string, string>
5860
*/
59-
private array $encryptionKeys = [];
61+
private array $packUrl = [];
6062

6163
/**
6264
* @param string $path Path to resource-packs directory.
@@ -88,17 +90,23 @@ public function __construct(string $path, \Logger $logger){
8890
}
8991

9092
foreach($resourceStack as $pos => $pack){
91-
if(!is_string($pack) && !is_int($pack) && !is_float($pack)){
93+
if(!(is_string($pack) || is_array($pack)) && !is_int($pack) && !is_float($pack)){
9294
$logger->critical("Found invalid entry in resource pack list at offset $pos of type " . gettype($pack));
9395
continue;
9496
}
95-
$pack = (string) $pack;
9697
try{
97-
$newPack = $this->loadPackFromPath(Path::join($this->path, $pack));
98-
98+
if (is_string($pack)) {
99+
$newPack = $this->loadPackFromPath(Path::join($this->path, (string) $pack));
100+
}else {
101+
$newPack = $this->loadPackFromArray((array) $pack);
102+
}
99103
$this->resourcePacks[] = $newPack;
100104
$index = strtolower($newPack->getPackId());
101105
$this->uuidList[$index] = $newPack;
106+
if ($newPack instanceof URLResourcePack){
107+
$this->addPackUrl($newPack);
108+
return;
109+
}
102110

103111
$keyPath = Path::join($this->path, $pack . ".key");
104112
if(file_exists($keyPath)){
@@ -111,7 +119,7 @@ public function __construct(string $path, \Logger $logger){
111119
if(strlen($key) !== 32){
112120
throw new ResourcePackException("Invalid encryption key length, must be exactly 32 bytes");
113121
}
114-
$this->encryptionKeys[$index] = $key;
122+
$this->setPackEncryptionKey($index, $key);
115123
}
116124
}catch(ResourcePackException $e){
117125
$logger->critical("Could not load resource pack \"$pack\": " . $e->getMessage());
@@ -140,6 +148,21 @@ private function loadPackFromPath(string $packPath) : ResourcePack{
140148
throw new ResourcePackException("Format not recognized");
141149
}
142150

151+
private function loadPackFromArray(array $info) : ResourcePack{
152+
$packPath = $info['path'];
153+
if (UtilsSymply::isUrl($packPath)){
154+
return new URLResourcePack($info['name'], $info['uuid'], $info['version'], $packPath, UtilsSymply::getSizeOfResourcesPack($packPath), $info['encryptionKey'] ?? "");
155+
}
156+
$packPath = Path::join($this->path, $packPath);
157+
if(!file_exists($packPath)){
158+
throw new ResourcePackException("File or directory not found");
159+
}
160+
if(is_dir($packPath)){
161+
throw new ResourcePackException("Directory resource packs are unsupported");
162+
}
163+
return new ZippedResourcePack($packPath, $info['encryptionKey'] ?? "");
164+
}
165+
143166
/**
144167
* Returns the directory which resource packs are loaded from.
145168
*/
@@ -207,29 +230,34 @@ public function getPackIdList() : array{
207230
return array_keys($this->uuidList);
208231
}
209232

210-
/**
211-
* Returns the key with which the pack was encrypted, or null if the pack has no key.
212-
*/
213-
public function getPackEncryptionKey(string $id) : ?string{
214-
return $this->encryptionKeys[strtolower($id)] ?? null;
215-
}
216-
217233
/**
218234
* Sets the encryption key to use for decrypting the specified resource pack. The pack will **NOT** be decrypted by
219235
* PocketMine-MP; the key is simply passed to the client to allow it to decrypt the pack after downloading it.
220236
*/
221237
public function setPackEncryptionKey(string $id, ?string $key) : void{
222238
$id = strtolower($id);
239+
if (!isset($this->uuidList[$id])){
240+
throw new ResourcePackException("Resource pack with ID $id not found.");
241+
}
223242
if($key === null){
224-
//allow deprovisioning keys for resource packs that have been removed
225-
unset($this->encryptionKeys[$id]);
243+
$this->uuidList[$id]->setEncryptionKey("");
226244
}elseif(isset($this->uuidList[$id])){
227245
if(strlen($key) !== 32){
228246
throw new \InvalidArgumentException("Encryption key must be exactly 32 bytes long");
229247
}
230-
$this->encryptionKeys[$id] = $key;
248+
$this->uuidList[$id]->setEncryptionKey($key);
231249
}else{
232250
throw new \InvalidArgumentException("Unknown pack ID $id");
233251
}
234252
}
253+
254+
public function getPackUrl() : array
255+
{
256+
return $this->packUrl;
257+
}
258+
259+
public function addPackUrl(URLResourcePack $packUrl) : void
260+
{
261+
$this->packUrl[$packUrl->getRealName()] = $packUrl->getUrl();
262+
}
235263
}

0 commit comments

Comments
 (0)