From 67f6b458d7292c44a2a3870523d28868fbbb056c Mon Sep 17 00:00:00 2001 From: Aaron Wagener Date: Tue, 1 Oct 2024 14:08:13 -0500 Subject: [PATCH 01/11] Core: add race mode to multidata and datastore (#4017) * add race mode to multidata and datastore * have commonclient check race mode on connect and add it to the tooltip ui --- CommonClient.py | 2 ++ Main.py | 1 + MultiServer.py | 2 ++ kvui.py | 2 ++ 4 files changed, 7 insertions(+) diff --git a/CommonClient.py b/CommonClient.py index 1aedd518b4f8..8325227d5e5c 100644 --- a/CommonClient.py +++ b/CommonClient.py @@ -325,6 +325,7 @@ def __init__(self, server_address: typing.Optional[str] = None, password: typing "collect": "disabled", "remaining": "disabled", } + self.race_mode: int = 0 # own state self.finished_game = False @@ -454,6 +455,7 @@ async def send_connect(self, **kwargs: typing.Any) -> None: if kwargs: payload.update(kwargs) await self.send_msgs([payload]) + await self.send_msgs([{"cmd": "Get", "keys": ["race_mode"]}]) async def console_input(self) -> str: if self.ui: diff --git a/Main.py b/Main.py index 5a0f5c98bcc4..4008ca5e9017 100644 --- a/Main.py +++ b/Main.py @@ -338,6 +338,7 @@ def precollect_hint(location): "seed_name": multiworld.seed_name, "spheres": spheres, "datapackage": data_package, + "race_mode": int(multiworld.is_race), } AutoWorld.call_all(multiworld, "modify_multidata", multidata) diff --git a/MultiServer.py b/MultiServer.py index e0b137fd68ce..91f4eec61574 100644 --- a/MultiServer.py +++ b/MultiServer.py @@ -427,6 +427,8 @@ def _load(self, decoded_obj: dict, game_data_packages: typing.Dict[str, typing.A use_embedded_server_options: bool): self.read_data = {} + # there might be a better place to put this. + self.stored_data["race_mode"] = decoded_obj.get("race_mode", 0) mdata_ver = decoded_obj["minimum_versions"]["server"] if mdata_ver > version_tuple: raise RuntimeError(f"Supplied Multidata (.archipelago) requires a server of at least version {mdata_ver}," diff --git a/kvui.py b/kvui.py index 536dce12208e..d58af3ed0e78 100644 --- a/kvui.py +++ b/kvui.py @@ -243,6 +243,8 @@ def get_text(self): f"\nYou currently have {ctx.hint_points} points." elif ctx.hint_cost == 0: text += "\n!hint is free to use." + if ctx.stored_data and "race_mode" in ctx.stored_data: + text += "\nRace mode is enabled." if ctx.stored_data["race_mode"] else "\nRace mode is disabled." else: text += f"\nYou are not authenticated yet." From dc1da4e88b4268ba12f6fd8b4a1ce362b4e9eebf Mon Sep 17 00:00:00 2001 From: Bryce Wilson Date: Tue, 1 Oct 2024 12:08:43 -0700 Subject: [PATCH 02/11] Pokemon Emerald: Another wonder trade fix (#4014) * Pokemon Emerald: Another guarded write on wonder trades * Pokemon Emerald: Reorder sending wonder trade and erasing data In case the guarded write fails --- worlds/pokemon_emerald/client.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/worlds/pokemon_emerald/client.py b/worlds/pokemon_emerald/client.py index c91b7d3e26b0..4405b34074e0 100644 --- a/worlds/pokemon_emerald/client.py +++ b/worlds/pokemon_emerald/client.py @@ -545,11 +545,12 @@ async def handle_wonder_trade(self, ctx: "BizHawkClientContext", guards: Dict[st if trade_is_sent == 0 and wonder_trade_pokemon_data[19] == 2: # Game has wonder trade data to send. Send it to data storage, remove it from the game's memory, # and mark that the game is waiting on receiving a trade - Utils.async_start(self.wonder_trade_send(ctx, pokemon_data_to_json(wonder_trade_pokemon_data))) - await bizhawk.write(ctx.bizhawk_ctx, [ + success = await bizhawk.guarded_write(ctx.bizhawk_ctx, [ (sb1_address + 0x377C, bytes(0x50), "System Bus"), (sb1_address + 0x37CC, [1], "System Bus"), - ]) + ], [guards["SAVE BLOCK 1"]]) + if success: + Utils.async_start(self.wonder_trade_send(ctx, pokemon_data_to_json(wonder_trade_pokemon_data))) elif trade_is_sent != 0 and wonder_trade_pokemon_data[19] != 2: # Game is waiting on receiving a trade. if self.queued_received_trade is not None: From 23469fa5c3113f83d21d608c25535aa1da95370b Mon Sep 17 00:00:00 2001 From: Alex Nordstrom Date: Tue, 1 Oct 2024 15:09:23 -0400 Subject: [PATCH 03/11] LADX: ghost fills ammo to initial max (#4005) * ghost fills ammo to max * Revert "ghost fills ammo to max" This reverts commit 68804fef1403197f2192e4c7d02f8793ac1c7ca0. * fill to first max --- worlds/ladx/LADXR/patches/owl.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/worlds/ladx/LADXR/patches/owl.py b/worlds/ladx/LADXR/patches/owl.py index 47e575191a31..20b8221604c6 100644 --- a/worlds/ladx/LADXR/patches/owl.py +++ b/worlds/ladx/LADXR/patches/owl.py @@ -81,23 +81,23 @@ def removeOwlEvents(rom): ; Give powder ld a, [$DB4C] - cp $10 + cp $20 jr nc, doNotGivePowder - ld a, $10 + ld a, $20 ld [$DB4C], a doNotGivePowder: ld a, [$DB4D] - cp $10 + cp $30 jr nc, doNotGiveBombs - ld a, $10 + ld a, $30 ld [$DB4D], a doNotGiveBombs: ld a, [$DB45] - cp $10 + cp $30 jr nc, doNotGiveArrows - ld a, $10 + ld a, $30 ld [$DB45], a doNotGiveArrows: From 5a853dfccdfe138e00dff7dc55890980e71b7e05 Mon Sep 17 00:00:00 2001 From: Mysteryem Date: Tue, 1 Oct 2024 20:30:45 +0100 Subject: [PATCH 04/11] Tests: Fix indentation in TestTwoPlayerMulti (#4010) The "filling multiworld" subtest was at the wrong indentation, so was only running for the last world_type. "games" has additionally been added to the subtest to help better identify failures. Now that the subtest is actually being run for each world type, this adds about 20 seconds to the duration of the test on my machine. --- test/multiworld/test_multiworlds.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/multiworld/test_multiworlds.py b/test/multiworld/test_multiworlds.py index 8415ac4c8429..3c1d0e4544eb 100644 --- a/test/multiworld/test_multiworlds.py +++ b/test/multiworld/test_multiworlds.py @@ -71,7 +71,7 @@ def test_two_player_single_game_fills(self) -> None: for world in self.multiworld.worlds.values(): world.options.accessibility.value = Accessibility.option_full self.assertSteps(gen_steps) - with self.subTest("filling multiworld", seed=self.multiworld.seed): - distribute_items_restrictive(self.multiworld) - call_all(self.multiworld, "post_fill") - self.assertTrue(self.fulfills_accessibility(), "Collected all locations, but can't beat the game") + with self.subTest("filling multiworld", games=world_type.game, seed=self.multiworld.seed): + distribute_items_restrictive(self.multiworld) + call_all(self.multiworld, "post_fill") + self.assertTrue(self.fulfills_accessibility(), "Collected all locations, but can't beat the game") From f06f95d03dd88f4a8aa35a88d2b75eedc7526a24 Mon Sep 17 00:00:00 2001 From: Aaron Wagener Date: Tue, 1 Oct 2024 16:55:34 -0500 Subject: [PATCH 05/11] Core: move race_mode to read_data instead of stored_data (#4020) * move race_mode to read_data * add race_mode to docs --- CommonClient.py | 3 +-- MultiServer.py | 2 +- docs/network protocol.md | 1 + kvui.py | 5 +++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CommonClient.py b/CommonClient.py index 8325227d5e5c..296c10ed4b4e 100644 --- a/CommonClient.py +++ b/CommonClient.py @@ -325,7 +325,6 @@ def __init__(self, server_address: typing.Optional[str] = None, password: typing "collect": "disabled", "remaining": "disabled", } - self.race_mode: int = 0 # own state self.finished_game = False @@ -455,7 +454,7 @@ async def send_connect(self, **kwargs: typing.Any) -> None: if kwargs: payload.update(kwargs) await self.send_msgs([payload]) - await self.send_msgs([{"cmd": "Get", "keys": ["race_mode"]}]) + await self.send_msgs([{"cmd": "Get", "keys": ["_read_race_mode"]}]) async def console_input(self) -> str: if self.ui: diff --git a/MultiServer.py b/MultiServer.py index 91f4eec61574..c3e377e9a29d 100644 --- a/MultiServer.py +++ b/MultiServer.py @@ -428,7 +428,7 @@ def _load(self, decoded_obj: dict, game_data_packages: typing.Dict[str, typing.A self.read_data = {} # there might be a better place to put this. - self.stored_data["race_mode"] = decoded_obj.get("race_mode", 0) + self.read_data["race_mode"] = lambda: decoded_obj.get("race_mode", 0) mdata_ver = decoded_obj["minimum_versions"]["server"] if mdata_ver > version_tuple: raise RuntimeError(f"Supplied Multidata (.archipelago) requires a server of at least version {mdata_ver}," diff --git a/docs/network protocol.md b/docs/network protocol.md index f8080fecc879..1c4579c4066f 100644 --- a/docs/network protocol.md +++ b/docs/network protocol.md @@ -395,6 +395,7 @@ Some special keys exist with specific return data, all of them have the prefix ` | item_name_groups_{game_name} | dict\[str, list\[str\]\] | item_name_groups belonging to the requested game. | | location_name_groups_{game_name} | dict\[str, list\[str\]\] | location_name_groups belonging to the requested game. | | client_status_{team}_{slot} | [ClientStatus](#ClientStatus) | The current game status of the requested player. | +| race_mode | int | 0 if race mode is disabled, and 1 if it's enabled. | ### Set Used to write data to the server's data storage, that data can then be shared across worlds or just saved for later. Values for keys in the data storage can be retrieved with a [Get](#Get) package, or monitored with a [SetNotify](#SetNotify) package. diff --git a/kvui.py b/kvui.py index d58af3ed0e78..74d8ad06734a 100644 --- a/kvui.py +++ b/kvui.py @@ -243,8 +243,9 @@ def get_text(self): f"\nYou currently have {ctx.hint_points} points." elif ctx.hint_cost == 0: text += "\n!hint is free to use." - if ctx.stored_data and "race_mode" in ctx.stored_data: - text += "\nRace mode is enabled." if ctx.stored_data["race_mode"] else "\nRace mode is disabled." + if ctx.stored_data and "_read_race_mode" in ctx.stored_data: + text += "\nRace mode is enabled." \ + if ctx.stored_data["_read_race_mode"] else "\nRace mode is disabled." else: text += f"\nYou are not authenticated yet." From 0ec9039ca6955129ba0fd15b0ba5a48cc71108da Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Wed, 2 Oct 2024 00:02:17 +0200 Subject: [PATCH 06/11] The Witness: Small code refactor (cast_not_none) (#3798) * cast not none * ruff * Missed a spot --- worlds/witness/__init__.py | 6 +++--- worlds/witness/data/utils.py | 7 ++++++- worlds/witness/player_items.py | 8 ++++---- worlds/witness/test/__init__.py | 5 +++-- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/worlds/witness/__init__.py b/worlds/witness/__init__.py index b4b38c883e7d..c9848f2ffe47 100644 --- a/worlds/witness/__init__.py +++ b/worlds/witness/__init__.py @@ -14,7 +14,7 @@ from .data import static_locations as static_witness_locations from .data import static_logic as static_witness_logic from .data.item_definition_classes import DoorItemDefinition, ItemData -from .data.utils import get_audio_logs +from .data.utils import cast_not_none, get_audio_logs from .hints import CompactHintData, create_all_hints, make_compact_hint_data, make_laser_hints from .locations import WitnessPlayerLocations from .options import TheWitnessOptions, witness_option_groups @@ -55,7 +55,7 @@ class WitnessWorld(World): item_name_to_id = { # ITEM_DATA doesn't have any event items in it - name: cast(int, data.ap_code) for name, data in static_witness_items.ITEM_DATA.items() + name: cast_not_none(data.ap_code) for name, data in static_witness_items.ITEM_DATA.items() } location_name_to_id = static_witness_locations.ALL_LOCATIONS_TO_ID item_name_groups = static_witness_items.ITEM_GROUPS @@ -336,7 +336,7 @@ def fill_slot_data(self) -> Dict[str, Any]: for item_name, hint in laser_hints.items(): item_def = cast(DoorItemDefinition, static_witness_logic.ALL_ITEMS[item_name]) self.laser_ids_to_hints[int(item_def.panel_id_hexes[0], 16)] = make_compact_hint_data(hint, self.player) - already_hinted_locations.add(cast(Location, hint.location)) + already_hinted_locations.add(cast_not_none(hint.location)) # Audio Log Hints diff --git a/worlds/witness/data/utils.py b/worlds/witness/data/utils.py index 84eca5afc43f..737daff70fae 100644 --- a/worlds/witness/data/utils.py +++ b/worlds/witness/data/utils.py @@ -1,7 +1,7 @@ from math import floor from pkgutil import get_data from random import Random -from typing import Any, Collection, Dict, FrozenSet, Iterable, List, Set, Tuple, TypeVar +from typing import Any, Collection, Dict, FrozenSet, Iterable, List, Optional, Set, Tuple, TypeVar T = TypeVar("T") @@ -13,6 +13,11 @@ WitnessRule = FrozenSet[FrozenSet[str]] +def cast_not_none(value: Optional[T]) -> T: + assert value is not None + return value + + def weighted_sample(world_random: Random, population: List[T], weights: List[float], k: int) -> List[T]: positions = range(len(population)) indices: List[int] = [] diff --git a/worlds/witness/player_items.py b/worlds/witness/player_items.py index 72dfc2b7ee54..4c98cb78495e 100644 --- a/worlds/witness/player_items.py +++ b/worlds/witness/player_items.py @@ -15,7 +15,7 @@ ProgressiveItemDefinition, WeightedItemDefinition, ) -from .data.utils import build_weighted_int_list +from .data.utils import build_weighted_int_list, cast_not_none from .locations import WitnessPlayerLocations from .player_logic import WitnessPlayerLogic @@ -200,7 +200,7 @@ def get_symbol_ids_not_in_pool(self) -> List[int]: """ return [ # data.ap_code is guaranteed for a symbol definition - cast(int, data.ap_code) for name, data in static_witness_items.ITEM_DATA.items() + cast_not_none(data.ap_code) for name, data in static_witness_items.ITEM_DATA.items() if name not in self.item_data.keys() and data.definition.category is ItemCategory.SYMBOL ] @@ -211,8 +211,8 @@ def get_progressive_item_ids_in_pool(self) -> Dict[int, List[int]]: if isinstance(item.definition, ProgressiveItemDefinition): # Note: we need to reference the static table here rather than the player-specific one because the child # items were removed from the pool when we pruned out all progression items not in the options. - output[cast(int, item.ap_code)] = [cast(int, static_witness_items.ITEM_DATA[child_item].ap_code) - for child_item in item.definition.child_item_names] + output[cast_not_none(item.ap_code)] = [cast_not_none(static_witness_items.ITEM_DATA[child_item].ap_code) + for child_item in item.definition.child_item_names] return output diff --git a/worlds/witness/test/__init__.py b/worlds/witness/test/__init__.py index 4453609ddcdb..c3b427851af0 100644 --- a/worlds/witness/test/__init__.py +++ b/worlds/witness/test/__init__.py @@ -1,4 +1,4 @@ -from typing import Any, ClassVar, Dict, Iterable, List, Mapping, Union, cast +from typing import Any, ClassVar, Dict, Iterable, List, Mapping, Union from BaseClasses import CollectionState, Entrance, Item, Location, Region @@ -7,6 +7,7 @@ from test.multiworld.test_multiworlds import MultiworldTestBase from .. import WitnessWorld +from ..data.utils import cast_not_none class WitnessTestBase(WorldTestBase): @@ -32,7 +33,7 @@ def assert_dependency_on_event_item(self, spot: Union[Location, Region, Entrance event_items = [item for item in self.multiworld.get_items() if item.name == item_name] self.assertTrue(event_items, f"Event item {item_name} does not exist.") - event_locations = [cast(Location, event_item.location) for event_item in event_items] + event_locations = [cast_not_none(event_item.location) for event_item in event_items] # Checking for an access dependency on an event item requires a bit of extra work, # as state.remove forces a sweep, which will pick up the event item again right after we tried to remove it. From 05a67386c61c4be699b8a54067b84a72ea004126 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Wed, 2 Oct 2024 03:09:43 +0200 Subject: [PATCH 07/11] Core: use shlex splitting instead of whitespace splitting for client and server commands (#4011) --- MultiServer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MultiServer.py b/MultiServer.py index c3e377e9a29d..0fe950b5e4f3 100644 --- a/MultiServer.py +++ b/MultiServer.py @@ -15,6 +15,7 @@ import operator import pickle import random +import shlex import threading import time import typing @@ -1152,7 +1153,7 @@ def __call__(self, raw: str) -> typing.Optional[bool]: if not raw: return try: - command = raw.split() + command = shlex.split(raw, comments=False) basecommand = command[0] if basecommand[0] == self.marker: method = self.commands.get(basecommand[1:].lower(), None) From 216e0603e1bcc4fea9985338212b333e38f1d468 Mon Sep 17 00:00:00 2001 From: Silvris <58583688+Silvris@users.noreply.github.com> Date: Fri, 4 Oct 2024 14:27:23 -0500 Subject: [PATCH 08/11] KDL3: Fix webhost not giving a patch #4023 --- worlds/kdl3/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worlds/kdl3/__init__.py b/worlds/kdl3/__init__.py index f01c82dd16a3..1b5acbe97a3c 100644 --- a/worlds/kdl3/__init__.py +++ b/worlds/kdl3/__init__.py @@ -325,7 +325,7 @@ def generate_basic(self) -> None: def generate_output(self, output_directory: str) -> None: try: - patch = KDL3ProcedurePatch() + patch = KDL3ProcedurePatch(player=self.player, player_name=self.player_name) patch_rom(self, patch) self.rom_name = patch.name From e5a0ef799f513d3d6231140e5a4ba561b0bfdcd8 Mon Sep 17 00:00:00 2001 From: Bryce Wilson Date: Fri, 4 Oct 2024 12:28:43 -0700 Subject: [PATCH 09/11] Pokemon Emerald: Update changelog (#4003) --- worlds/pokemon_emerald/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/worlds/pokemon_emerald/CHANGELOG.md b/worlds/pokemon_emerald/CHANGELOG.md index 6a1844e79fde..2d7db0dad4d5 100644 --- a/worlds/pokemon_emerald/CHANGELOG.md +++ b/worlds/pokemon_emerald/CHANGELOG.md @@ -8,6 +8,9 @@ ### Fixes +- Fixed a rare issue where receiving a wonder trade could partially corrupt the save data, preventing the player from +receiving new items. +- Fixed the client spamming the "goal complete" status update to the server instead of sending it once. - Fixed a logic issue where the "Mauville City - Coin Case from Lady in House" location only required a Harbor Mail if the player randomized NPC gifts. - The Dig tutor has its compatibility percentage raised to 50% if the player's TM/tutor compatibility is set lower. From 97f2c25924b0b75f9dcb74e9dc28e5546a22b3e9 Mon Sep 17 00:00:00 2001 From: palex00 <32203971+palex00@users.noreply.github.com> Date: Sat, 5 Oct 2024 02:13:04 +0200 Subject: [PATCH 10/11] [KH2] Adds more options to slot data #4031 --- worlds/kh2/__init__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/worlds/kh2/__init__.py b/worlds/kh2/__init__.py index faf0bed88567..2809460aed6a 100644 --- a/worlds/kh2/__init__.py +++ b/worlds/kh2/__init__.py @@ -101,7 +101,18 @@ def fill_slot_data(self) -> dict: if ability in self.goofy_ability_dict and self.goofy_ability_dict[ability] >= 1: self.goofy_ability_dict[ability] -= 1 - slot_data = self.options.as_dict("Goal", "FinalXemnas", "LuckyEmblemsRequired", "BountyRequired") + slot_data = self.options.as_dict( + "Goal", + "FinalXemnas", + "LuckyEmblemsRequired", + "BountyRequired", + "FightLogic", + "FinalFormLogic", + "AutoFormLogic", + "LevelDepth", + "DonaldGoofyStatsanity", + "CorSkipToggle" + ) slot_data.update({ "hitlist": [], # remove this after next update "PoptrackerVersionCheck": 4.3, From 6287bc27a68ace32679fe8a41a580df7180cd9d8 Mon Sep 17 00:00:00 2001 From: black-sliver <59490463+black-sliver@users.noreply.github.com> Date: Sat, 5 Oct 2024 18:14:22 +0200 Subject: [PATCH 11/11] WebHost: Fix too-many-players error not showing (#4033) * WebHost: fix 'too many players' error not showing * WebHost, Tests: add basic tests for generate endpoint * WebHost: hopefully make CodeQL happy with MAX_ROLL redirect --- WebHostLib/generate.py | 1 + test/webhost/test_generate.py | 73 +++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 test/webhost/test_generate.py diff --git a/WebHostLib/generate.py b/WebHostLib/generate.py index dbe7dd958910..b19f3d483515 100644 --- a/WebHostLib/generate.py +++ b/WebHostLib/generate.py @@ -81,6 +81,7 @@ def start_generation(options: Dict[str, Union[dict, str]], meta: Dict[str, Any]) elif len(gen_options) > app.config["MAX_ROLL"]: flash(f"Sorry, generating of multiworlds is limited to {app.config['MAX_ROLL']} players. " f"If you have a larger group, please generate it yourself and upload it.") + return redirect(url_for(request.endpoint, **(request.view_args or {}))) elif len(gen_options) >= app.config["JOB_THRESHOLD"]: gen = Generation( options=pickle.dumps({name: vars(options) for name, options in gen_options.items()}), diff --git a/test/webhost/test_generate.py b/test/webhost/test_generate.py new file mode 100644 index 000000000000..5440f6e02bec --- /dev/null +++ b/test/webhost/test_generate.py @@ -0,0 +1,73 @@ +import zipfile +from io import BytesIO + +from flask import url_for + +from . import TestBase + + +class TestGenerate(TestBase): + def test_valid_yaml(self) -> None: + """ + Verify that posting a valid yaml will start generating a game. + """ + with self.app.app_context(), self.app.test_request_context(): + yaml_data = """ + name: Player1 + game: Archipelago + Archipelago: {} + """ + response = self.client.post(url_for("generate"), + data={"file": (BytesIO(yaml_data.encode("utf-8")), "test.yaml")}, + follow_redirects=True) + self.assertEqual(response.status_code, 200) + self.assertTrue("/seed/" in response.request.path or + "/wait/" in response.request.path, + f"Response did not properly redirect ({response.request.path})") + + def test_empty_zip(self) -> None: + """ + Verify that posting an empty zip will give an error. + """ + with self.app.app_context(), self.app.test_request_context(): + zip_data = BytesIO() + zipfile.ZipFile(zip_data, "w").close() + zip_data.seek(0) + self.assertGreater(len(zip_data.read()), 0) + zip_data.seek(0) + response = self.client.post(url_for("generate"), + data={"file": (zip_data, "test.zip")}, + follow_redirects=True) + self.assertIn("user-message", response.text, + "Request did not call flash()") + self.assertIn("not find any valid files", response.text, + "Response shows unexpected error") + self.assertIn("generate-game-form", response.text, + "Response did not get user back to the form") + + def test_too_many_players(self) -> None: + """ + Verify that posting too many players will give an error. + """ + max_roll = self.app.config["MAX_ROLL"] + # validate that max roll has a sensible value, otherwise we probably changed how it works + self.assertIsInstance(max_roll, int) + self.assertGreater(max_roll, 1) + self.assertLess(max_roll, 100) + # create a yaml with max_roll+1 players and watch it fail + with self.app.app_context(), self.app.test_request_context(): + yaml_data = "---\n".join([ + f"name: Player{n}\n" + "game: Archipelago\n" + "Archipelago: {}\n" + for n in range(1, max_roll + 2) + ]) + response = self.client.post(url_for("generate"), + data={"file": (BytesIO(yaml_data.encode("utf-8")), "test.yaml")}, + follow_redirects=True) + self.assertIn("user-message", response.text, + "Request did not call flash()") + self.assertIn("limited to", response.text, + "Response shows unexpected error") + self.assertIn("generate-game-form", response.text, + "Response did not get user back to the form")