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)