From 9c3d12dc55bc2ad4a84e8bbbfcecd8fd6cd82c86 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Sun, 9 May 2021 17:26:53 +0200 Subject: [PATCH] Factorio: Embed slot name into mod --- CommonClient.py | 1 - FactorioClient.py | 18 +++++++++++------- data/factorio/mod_template/control.lua | 4 +++- worlds/factorio/Mod.py | 3 ++- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CommonClient.py b/CommonClient.py index d5a39d72..019828f3 100644 --- a/CommonClient.py +++ b/CommonClient.py @@ -184,7 +184,6 @@ class CommonContext(): async def disconnect(self): if self.server and not self.server.socket.closed: await self.server.socket.close() - self.ui_node.send_connection_status(self) if self.server_task is not None: await self.server_task diff --git a/FactorioClient.py b/FactorioClient.py index d0bc84a0..abbaed4a 100644 --- a/FactorioClient.py +++ b/FactorioClient.py @@ -37,6 +37,7 @@ if not os.path.exists(executable): threadpool = ThreadPoolExecutor(10) + class FactorioCommandProcessor(ClientCommandProcessor): @mark_raw def _cmd_factorio(self, text: str) -> bool: @@ -48,9 +49,10 @@ class FactorioCommandProcessor(ClientCommandProcessor): return True return False - def _cmd_connect(self, address: str = "", name="") -> bool: + def _cmd_connect(self, address: str = "") -> bool: """Connect to a MultiWorld Server""" - self.ctx.auth = name + if not self.ctx.auth: + self.output("Cannot connect to a server with unknown own identity, bridge to Factorio first.") return super(FactorioCommandProcessor, self)._cmd_connect(address) @@ -66,9 +68,6 @@ class FactorioContext(CommonContext): async def server_auth(self, password_requested): if password_requested and not self.password: await super(FactorioContext, self).server_auth(password_requested) - if self.auth is None: - logging.info('Enter the name of your slot to join this game:') - self.auth = await self.console_input() await self.send_msgs([{"cmd": 'Connect', 'password': self.password, 'name': self.auth, 'version': Utils._version_tuple, @@ -85,7 +84,7 @@ class FactorioContext(CommonContext): def on_print_json(self, args: dict): if not self.found_items and args.get("type", None) == "ItemSend" and args["receiving"] == args["sending"]: pass # don't want info on other player's local pickups. - copy_data = copy.deepcopy(args["data"]) # jsontotextparser is destructive currently + copy_data = copy.deepcopy(args["data"]) # jsontotextparser is destructive currently logger.info(self.jsontotextparser(args["data"])) if self.rcon_client: cleaned_text = self.raw_json_text_parser(copy_data).replace('"', '') @@ -105,6 +104,7 @@ async def game_watcher(ctx: FactorioContext, bridge_file: str): research_data = data["research_done"] research_data = {int(tech_name.split("-")[1]) for tech_name in research_data} victory = data["victory"] + ctx.auth = data["slot_name"] if not ctx.finished_game and victory: await ctx.send_msgs([{"cmd": "StatusUpdate", "status": ClientStatus.CLIENT_GOAL}]) @@ -119,13 +119,17 @@ async def game_watcher(ctx: FactorioContext, bridge_file: str): else: bridge_counter += 1 if bridge_counter >= 60: - bridge_logger.info("Did not find Factorio Bridge file, waiting for mod to run, which requires the server to run, which requires a player to be connected.") + bridge_logger.info( + "Did not find Factorio Bridge file, " + "waiting for mod to run, which requires the server to run, " + "which requires a player to be connected.") bridge_counter = 0 await asyncio.sleep(1) except Exception as e: logging.exception(e) logging.error("Aborted Factorio Server Bridge") + def stream_factorio_output(pipe, queue): def queuer(): while 1: diff --git a/data/factorio/mod_template/control.lua b/data/factorio/mod_template/control.lua index d5432284..9fdeaf49 100644 --- a/data/factorio/mod_template/control.lua +++ b/data/factorio/mod_template/control.lua @@ -2,6 +2,7 @@ require "lib" require "util" FREE_SAMPLES = {{ free_samples }} +SLOT_NAME = "{{ slot_name }}" --SUPPRESS_INVENTORY_EVENTS = false -- Initialize force data, either from it being created or already being part of the game when the mod was added. @@ -183,7 +184,8 @@ function dumpInfo(force) local research_done = {} local data_collection = { ["research_done"] = research_done, - ["victory"] = chain_lookup(global, "forcedata", force.name, "victory") + ["victory"] = chain_lookup(global, "forcedata", force.name, "victory"), + ["slot_name"] = SLOT_NAME } for tech_name, tech in pairs(force.technologies) do diff --git a/worlds/factorio/Mod.py b/worlds/factorio/Mod.py index 251404de..af34705d 100644 --- a/worlds/factorio/Mod.py +++ b/worlds/factorio/Mod.py @@ -70,7 +70,8 @@ def generate_mod(world: MultiWorld, player: int, seedname: str): "mod_name": mod_name, "allowed_science_packs": world.max_science_pack[player].get_allowed_packs(), "tech_cost_scale": tech_cost, "custom_data": world.custom_data[player], "tech_tree_layout_prerequisites": world.tech_tree_layout_prerequisites[player], - "rocket_recipe" : rocket_recipes[world.max_science_pack[player].value]} + "rocket_recipe" : rocket_recipes[world.max_science_pack[player].value], + "slot_name": world.player_names[player][0]} for factorio_option in Options.factorio_options: template_data[factorio_option] = getattr(world, factorio_option)[player].value control_code = control_template.render(**template_data)