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:
Silvris
2025-05-22 02:47:48 -05:00
committed by GitHub
parent 7079c17a0f
commit e3219ba452
4 changed files with 16 additions and 19 deletions

View File

@@ -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,