From a08d7bb1b2e6c79629becab1f1fd565dafbf3b33 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Fri, 18 Jun 2021 22:15:54 +0200 Subject: [PATCH] Settings: add requires --- FactorioClient.py | 2 +- LttPClient.py | 2 +- Main.py | 4 ++-- MultiServer.py | 10 +++++----- Mystery.py | 18 +++++++++++++++++- Utils.py | 4 ++-- playerSettings.yaml | 2 ++ setup.py | 4 ++-- 8 files changed, 32 insertions(+), 14 deletions(-) diff --git a/FactorioClient.py b/FactorioClient.py index 8567f299..0e9017fd 100644 --- a/FactorioClient.py +++ b/FactorioClient.py @@ -76,7 +76,7 @@ class FactorioContext(CommonContext): await super(FactorioContext, self).server_auth(password_requested) await self.send_msgs([{"cmd": 'Connect', - 'password': self.password, 'name': self.auth, 'version': Utils._version_tuple, + 'password': self.password, 'name': self.auth, 'version': Utils.version_tuple, 'tags': ['AP'], 'uuid': Utils.get_unique_identifier(), 'game': "Factorio" }]) diff --git a/LttPClient.py b/LttPClient.py index 828fe17e..4c0f1f65 100644 --- a/LttPClient.py +++ b/LttPClient.py @@ -97,7 +97,7 @@ class Context(CommonContext): self.auth = self.rom auth = base64.b64encode(self.rom).decode() await self.send_msgs([{"cmd": 'Connect', - 'password': self.password, 'name': auth, 'version': Utils._version_tuple, + 'password': self.password, 'name': auth, 'version': Utils.version_tuple, 'tags': get_tags(self), 'uuid': Utils.get_unique_identifier(), 'game': "A Link to the Past" }]) diff --git a/Main.py b/Main.py index c35f5b9d..2ef8ccc4 100644 --- a/Main.py +++ b/Main.py @@ -20,7 +20,7 @@ from worlds.alttp.Dungeons import create_dungeons, fill_dungeons, fill_dungeons_ from Fill import distribute_items_restrictive, flood_items, balance_multiworld_progression, distribute_planned from worlds.alttp.Shops import create_shops, ShopSlotFill, SHOP_ID_START, total_shop_slots, FillDisabledShopSlots from worlds.alttp.ItemPool import generate_itempool, difficulties, fill_prizes -from Utils import output_path, parse_player_names, get_options, __version__, _version_tuple +from Utils import output_path, parse_player_names, get_options, __version__, version_tuple from worlds.hk import gen_hollow from worlds.hk import create_regions as hk_create_regions from worlds.minecraft import gen_minecraft, fill_minecraft_slot_data, generate_mc_data @@ -557,7 +557,7 @@ def main(args, seed=None): "er_hint_data": er_hint_data, "precollected_items": precollected_items, "precollected_hints": precollected_hints, - "version": tuple(_version_tuple), + "version": tuple(version_tuple), "tags": ["AP"], "minimum_versions": minimum_versions, "seed_name": world.seed_name diff --git a/MultiServer.py b/MultiServer.py index 592dc13b..feba63bf 100644 --- a/MultiServer.py +++ b/MultiServer.py @@ -30,7 +30,7 @@ from worlds import network_data_package, lookup_any_item_id_to_name, lookup_any_ lookup_any_location_id_to_name, lookup_any_location_name_to_id import Utils from Utils import get_item_name_from_id, get_location_name_from_id, \ - _version_tuple, restricted_loads, Version + version_tuple, restricted_loads, Version from NetUtils import Node, Endpoint, ClientStatus, NetworkItem, decode, NetworkPlayer colorama.init() @@ -136,9 +136,9 @@ class Context(Node): def _load(self, decoded_obj: dict, use_embedded_server_options: bool): mdata_ver = decoded_obj["minimum_versions"]["server"] - if mdata_ver > Utils._version_tuple: + if mdata_ver > Utils.version_tuple: raise RuntimeError(f"Supplied Multidata (.archipelago) requires a server of at least version {mdata_ver}," - f"however this server is of version {Utils._version_tuple}") + f"however this server is of version {Utils.version_tuple}") clients_ver = decoded_obj["minimum_versions"].get("clients", {}) self.minimum_client_versions = {} for player, version in clients_ver.items(): @@ -379,7 +379,7 @@ async def on_client_connected(ctx: Context, client: Client): # tags are for additional features in the communication. # Name them by feature or fork, as you feel is appropriate. 'tags': ctx.tags, - 'version': Utils._version_tuple, + 'version': Utils.version_tuple, 'forfeit_mode': ctx.forfeit_mode, 'remaining_mode': ctx.remaining_mode, 'hint_cost': ctx.hint_cost, @@ -1011,7 +1011,7 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict): errors.add('IncompatibleVersion') # only exact version match allowed - if ctx.compatibility == 0 and args['version'] != _version_tuple: + if ctx.compatibility == 0 and args['version'] != version_tuple: errors.add('IncompatibleVersion') if errors: logging.info(f"A client connection was refused due to: {errors}") diff --git a/Mystery.py b/Mystery.py index 074b3e87..4f56ee14 100644 --- a/Mystery.py +++ b/Mystery.py @@ -13,7 +13,7 @@ from worlds.generic import PlandoItem, PlandoConnection ModuleUpdate.update() -from Utils import parse_yaml +from Utils import parse_yaml, version_tuple, __version__, tuplize_version from worlds.alttp.EntranceRandomizer import parse_arguments from Main import main as ERmain from Main import get_seed, seeddigits @@ -453,6 +453,22 @@ def get_plando_bosses(boss_shuffle: str, plando_options: typing.Set[str]) -> str def roll_settings(weights: dict, plando_options: typing.Set[str] = frozenset(("bosses",))): + requirements = weights.get("requires", {}) + if requirements: + version = requirements.get("version", __version__) + if tuplize_version(version) > version_tuple: + raise Exception(f"Settings reports required version of generator is at least {version}, " + f"however generator is of version {__version__}") + required_plando_options = requirements.get("plando", "") + required_plando_options = set(option.strip() for option in required_plando_options.split(",")) + required_plando_options -= plando_options + if required_plando_options: + if len(required_plando_options) == 1: + raise Exception(f"Settings reports required plando module {', '.join(required_plando_options)}, " + f"which is not enabled.") + else: + raise Exception(f"Settings reports required plando modules {', '.join(required_plando_options)}, " + f"which are not enabled.") if "pre_rolled" in weights: pre_rolled = weights["pre_rolled"] diff --git a/Utils.py b/Utils.py index 1e1e3341..f82c9622 100644 --- a/Utils.py +++ b/Utils.py @@ -12,8 +12,8 @@ class Version(typing.NamedTuple): minor: int build: int -__version__ = "0.1.2" -_version_tuple = tuplize_version(__version__) +__version__ = "0.1.3" +version_tuple = tuplize_version(__version__) import builtins import os diff --git a/playerSettings.yaml b/playerSettings.yaml index b6f6f6c3..769f3208 100644 --- a/playerSettings.yaml +++ b/playerSettings.yaml @@ -27,6 +27,8 @@ game: A Link to the Past: 1 Factorio: 1 Minecraft: 1 +requires: + version: 0.1.3 # Version of Archipelago required for this yaml to work as expected. # Shared Options supported by all games: accessibility: items: 0 # Guarantees you will be able to acquire all items, but you may not be able to access all locations diff --git a/setup.py b/setup.py index 8bc3f45d..34bba7f4 100644 --- a/setup.py +++ b/setup.py @@ -48,10 +48,10 @@ def manifest_creation(folder): path = os.path.join(dirpath, filename) hashes[os.path.relpath(path, start=folder)] = pool.submit(_threaded_hash, path) import json - from Utils import _version_tuple + from Utils import version_tuple manifest = {"buildtime": buildtime.isoformat(sep=" ", timespec="seconds"), "hashes": {path: hash.result() for path, hash in hashes.items()}, - "version": _version_tuple} + "version": version_tuple} json.dump(manifest, open(manifestpath, "wt"), indent=4) print("Created Manifest")