mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 20:21:32 -06:00
WebHost: allow APPlayerContainers from "custom" worlds to be displayed in rooms (#4981)
Gives WebHost the ability to verify that a patch file is an APPlayerContainer (defined by #4331 as a APContainer containing the "player" field), and allowed it to display any patch file that it can verify is an APPlayerContainer.
This commit is contained in:
@@ -6,6 +6,7 @@ import zipfile
|
||||
from enum import IntEnum
|
||||
import os
|
||||
import threading
|
||||
from io import BytesIO
|
||||
|
||||
from typing import ClassVar, Dict, List, Literal, Tuple, Any, Optional, Union, BinaryIO, overload, Sequence
|
||||
|
||||
@@ -70,6 +71,18 @@ class AutoPatchExtensionRegister(abc.ABCMeta):
|
||||
container_version: int = 6
|
||||
|
||||
|
||||
def is_ap_player_container(game: str, data: bytes, player: int):
|
||||
if not zipfile.is_zipfile(BytesIO(data)):
|
||||
return False
|
||||
with zipfile.ZipFile(BytesIO(data), mode='r') as zf:
|
||||
if "archipelago.json" in zf.namelist():
|
||||
manifest = json.loads(zf.read("archipelago.json"))
|
||||
if "game" in manifest and "player" in manifest:
|
||||
if game == manifest["game"] and player == manifest["player"]:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class InvalidDataError(Exception):
|
||||
"""
|
||||
Since games can override `read_contents` in APContainer,
|
||||
|
||||
Reference in New Issue
Block a user