diff --git a/src/mudlib/commands/play.py b/src/mudlib/commands/play.py index df5cfbd..5fc2b03 100644 --- a/src/mudlib/commands/play.py +++ b/src/mudlib/commands/play.py @@ -39,9 +39,11 @@ async def cmd_play(player: Player, args: str) -> None: try: intro = await session.start() except FileNotFoundError: + await session.stop() await player.send("error: dfrotz not found. cannot play IF games.\r\n") return except OSError as e: + await session.stop() await player.send(f"error starting game: {e}\r\n") return diff --git a/src/mudlib/if_session.py b/src/mudlib/if_session.py index b9cb116..3cf26bc 100644 --- a/src/mudlib/if_session.py +++ b/src/mudlib/if_session.py @@ -42,10 +42,10 @@ class IFSession: async def handle_input(self, text: str) -> IFResponse: """Handle player input. Route to dfrotz or handle escape commands.""" # Check for escape commands (:: prefix) - if text == "::quit": + if text.lower() == "::quit": return IFResponse(output="", done=True) - if text == "::help": + if text.lower() == "::help": help_text = """escape commands: ::quit - exit the game ::help - show this help""" diff --git a/src/mudlib/server.py b/src/mudlib/server.py index ffa197d..8cde532 100644 --- a/src/mudlib/server.py +++ b/src/mudlib/server.py @@ -353,6 +353,9 @@ async def shell( if _writer.is_closing(): break finally: + # Clean up IF session if player was playing + if player.if_session: + await player.if_session.stop() # Save player state on disconnect (if not already saved by quit command) if player_name in players: save_player(player) diff --git a/tests/test_play_command.py b/tests/test_play_command.py index 7d122e2..13bcd02 100644 --- a/tests/test_play_command.py +++ b/tests/test_play_command.py @@ -95,6 +95,7 @@ async def test_play_handles_dfrotz_missing(player): # Mock IFSession to raise FileNotFoundError on start mock_session = Mock() mock_session.start = AsyncMock(side_effect=FileNotFoundError()) + mock_session.stop = AsyncMock() with patch("mudlib.commands.play.IFSession") as MockIFSession: MockIFSession.return_value = mock_session @@ -114,3 +115,6 @@ async def test_play_handles_dfrotz_missing(player): # Verify session was NOT attached assert player.if_session is None + + # Verify session.stop() was called + mock_session.stop.assert_called_once()