diff --git a/CommonClient.py b/CommonClient.py old mode 100644 new mode 100755 index 41cc08d1d0..7230fcb3eb --- a/CommonClient.py +++ b/CommonClient.py @@ -572,6 +572,10 @@ class CommonContext: return print_json_packet.get("type", "") == "ItemSend" \ and not self.slot_concerns_self(print_json_packet["receiving"]) \ and not self.slot_concerns_self(print_json_packet["item"].player) + + def is_connection_change(self, print_json_packet: dict) -> bool: + """Helper function for filtering out connection changes.""" + return print_json_packet.get("type", "") in ["Join","Part"] def on_print(self, args: dict): logger.info(args["text"]) diff --git a/worlds/factorio/Client.py b/worlds/factorio/Client.py old mode 100644 new mode 100755 index 51eb487f84..422f719b65 --- a/worlds/factorio/Client.py +++ b/worlds/factorio/Client.py @@ -56,6 +56,10 @@ class FactorioCommandProcessor(ClientCommandProcessor): """Toggle filtering of item sends that get displayed in-game to only those that involve you.""" self.ctx.toggle_filter_item_sends() + def _cmd_toggle_connection_change_filter(self): + """Toggle filtering of Connected/Disconnected players.""" + self.ctx.toggle_filter_connection_changes() + def _cmd_toggle_chat(self): """Toggle sending of chat messages from players on the Factorio server to Archipelago.""" self.ctx.toggle_bridge_chat_out() @@ -82,7 +86,7 @@ class FactorioContext(CommonContext): # updated by spinup server mod_version: Version = Version(0, 0, 0) - def __init__(self, server_address, password, filter_item_sends: bool, bridge_chat_out: bool, + def __init__(self, server_address, password, filter_connection_changes: bool, filter_item_sends: bool, bridge_chat_out: bool, rcon_port: int, rcon_password: str, server_settings_path: str | None, factorio_server_args: tuple[str, ...]): super(FactorioContext, self).__init__(server_address, password) @@ -94,6 +98,7 @@ class FactorioContext(CommonContext): self.factorio_json_text_parser = FactorioJSONtoTextParser(self) self.energy_link_increment = 0 self.last_deplete = 0 + self.filter_connection_changes: bool = filter_connection_changes self.filter_item_sends: bool = filter_item_sends self.multiplayer: bool = False # whether multiple different players have connected self.bridge_chat_out: bool = bridge_chat_out @@ -130,6 +135,7 @@ class FactorioContext(CommonContext): def on_print_json(self, args: dict): if self.rcon_client: if (not self.filter_item_sends or not self.is_uninteresting_item_send(args)) \ + and (not self.filter_connection_changes or not self.is_connection_change(args)) \ and not self.is_echoed_chat(args): text = self.factorio_json_text_parser(copy.deepcopy(args["data"])) if not text.startswith( @@ -222,6 +228,15 @@ class FactorioContext(CommonContext): logger.info(announcement) self.print_to_game(announcement) + def toggle_filter_connection_changes(self) -> None: + self.filter_connection_changes = not self.filter_connection_changes + if self.filter_connection_changes: + announcement = "Connection changes are now filtered." + else: + announcement = "Connection changes are no longer filtered." + logger.info(announcement) + self.print_to_game(announcement) + def toggle_bridge_chat_out(self) -> None: self.bridge_chat_out = not self.bridge_chat_out if self.bridge_chat_out: @@ -388,6 +403,9 @@ async def factorio_server_watcher(ctx: FactorioContext): elif re.match(r"^[0-9.]+ Script @[^ ]+\.lua:\d+: Player command toggle-ap-send-filter$", msg): factorio_server_logger.debug(msg) ctx.toggle_filter_item_sends() + elif re.match(r"^[0-9.]+ Script @[^ ]+\.lua:\d+: Player command toggle-ap-connection-change-filter$", msg): + factorio_server_logger.debug(msg) + ctx.toggle_filter_connection_changes() elif re.match(r"^[0-9.]+ Script @[^ ]+\.lua:\d+: Player command toggle-ap-chat$", msg): factorio_server_logger.debug(msg) ctx.toggle_bridge_chat_out() @@ -586,6 +604,7 @@ def launch(*new_args: str): raise FileNotFoundError(f"Could not find file {server_settings} for server_settings. Aborting.") initial_filter_item_sends = bool(settings.filter_item_sends) + initial_filter_connection_changes = bool(settings.filter_connection_changes) initial_bridge_chat_out = bool(settings.bridge_chat_out) if not os.path.exists(os.path.dirname(executable)): @@ -600,7 +619,7 @@ def launch(*new_args: str): asyncio.run(main(lambda: FactorioContext( args.connect, args.password, - initial_filter_item_sends, initial_bridge_chat_out, + initial_filter_connection_changes, initial_filter_item_sends, initial_bridge_chat_out, rcon_port, rcon_password, server_settings, rest ))) colorama.deinit() diff --git a/worlds/factorio/data/mod_template/control.lua b/worlds/factorio/data/mod_template/control.lua index cd0c00e987..3f754d925c 100644 --- a/worlds/factorio/data/mod_template/control.lua +++ b/worlds/factorio/data/mod_template/control.lua @@ -859,6 +859,10 @@ commands.add_command("toggle-ap-send-filter", "Toggle filtering of item sends th log("Player command toggle-ap-send-filter") -- notifies client end) +commands.add_command("toggle-ap-connection-change-filter", "Toggle filtering of players joining or parting", function(call) + log("Player command toggle-ap-connection-change-filter") -- notifies client +end) + commands.add_command("toggle-ap-chat", "Toggle sending of chat messages from players on the Factorio server to Archipelago.", function(call) log("Player command toggle-ap-chat") -- notifies client end) diff --git a/worlds/factorio/docs/setup_en.md b/worlds/factorio/docs/setup_en.md index 0219486b20..1cf5c09d6a 100644 --- a/worlds/factorio/docs/setup_en.md +++ b/worlds/factorio/docs/setup_en.md @@ -179,6 +179,18 @@ factorio_options: filter_item_sends: true ``` +### filter_connection_changes + +By default, all player joined and player stopped tracking notifications are displayed in-game. In larger async seeds this may become overly spammy. +To hide all connection changes, do one of the following: +- Type `/toggle-ap-connection-change-filter` in-game +- Type `/toggle_connection_change_filter` in the Achipelago Client +- In your `host.yaml` set +``` +factorio_options: + filter_connection_changes: true +``` + ### bridge_chat_out By default, in-game chat is bridged to Archipelago. If you prefer to be able to speak privately, you can disable this feature by doing one of the following: diff --git a/worlds/factorio/settings.py b/worlds/factorio/settings.py index a2296e7395..15d6f637aa 100644 --- a/worlds/factorio/settings.py +++ b/worlds/factorio/settings.py @@ -19,8 +19,12 @@ If this file does exist, then it will be used. class BridgeChatOut(settings.Bool): """Whether to send chat messages from players on the Factorio server to Archipelago.""" + + class FilterConnectionChanges(settings.Bool): + """Whether to filter connection changes displayed in-game.""" executable: Executable = Executable("factorio/bin/x64/factorio") server_settings: typing.Optional[ServerSettings] = None filter_item_sends: typing.Union[FilterItemSends, bool] = False + filter_connection_changes: typing.Union[FilterConnectionChanges, bool] = False bridge_chat_out: typing.Union[BridgeChatOut, bool] = True