From 057a746687d2c4771583296a1f8c731470effc34 Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Mon, 9 Feb 2026 16:25:39 -0500 Subject: [PATCH] Wire up spectator broadcasting in server and play command - server.py: broadcast IF output to spectators after each input (skip :: escape commands) - server.py: broadcast leave message when player exits IF mode - play.py: broadcast game intro text when player starts a game Spectators at the same x,y coordinates now see formatted output with [PlayerName's terminal] header and game text. --- src/mudlib/commands/play.py | 5 ++++- src/mudlib/server.py | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/mudlib/commands/play.py b/src/mudlib/commands/play.py index b502644..8fc19cb 100644 --- a/src/mudlib/commands/play.py +++ b/src/mudlib/commands/play.py @@ -3,7 +3,7 @@ import pathlib from mudlib.commands import CommandDefinition, register -from mudlib.if_session import IFSession +from mudlib.if_session import IFSession, broadcast_to_spectators from mudlib.player import Player # Story files directory @@ -79,6 +79,9 @@ async def cmd_play(player: Player, args: str) -> None: await player.send("(type ::help for escape commands)\r\n") if intro: await player.send(intro + "\r\n") + # Broadcast intro to spectators + spectator_msg = f"[{player.name}'s terminal]\r\n{intro}\r\n" + await broadcast_to_spectators(player, spectator_msg) register( diff --git a/src/mudlib/server.py b/src/mudlib/server.py index 8cde532..27f6d6b 100644 --- a/src/mudlib/server.py +++ b/src/mudlib/server.py @@ -27,6 +27,7 @@ from mudlib.combat.commands import register_combat_commands from mudlib.combat.engine import process_combat from mudlib.content import load_commands from mudlib.effects import clear_expired +from mudlib.if_session import broadcast_to_spectators from mudlib.mob_ai import process_mobs from mudlib.mobs import load_mob_templates, mob_templates from mudlib.player import Player, players @@ -340,11 +341,22 @@ async def shell( response = await player.if_session.handle_input(command) if response.output: await player.send(response.output) + # Broadcast to spectators unless it's an escape command + if not command.startswith("::"): + spectator_msg = ( + f"[{player.name}'s terminal]\r\n" + f"> {command}\r\n" + f"{response.output}" + ) + await broadcast_to_spectators(player, spectator_msg) if response.done: await player.if_session.stop() player.if_session = None player.mode_stack.pop() await player.send("you leave the terminal.\r\n") + # Notify spectators + leave_msg = f"{player.name} steps away from the terminal.\r\n" + await broadcast_to_spectators(player, leave_msg) else: # Dispatch normal command await mudlib.commands.dispatch(player, command)