From acfff671fee05d468b6a2c7cac5de812f1a3dae0 Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Sat, 14 Feb 2026 16:50:29 -0500 Subject: [PATCH] Wire character creation and housing into server login flow --- src/mudlib/server.py | 25 ++++++++++++++++++++++++- tests/test_server.py | 6 ++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/mudlib/server.py b/src/mudlib/server.py index 35d72fb..1d6c99d 100644 --- a/src/mudlib/server.py +++ b/src/mudlib/server.py @@ -42,7 +42,6 @@ from mudlib.creation import character_creation from mudlib.dialogue import load_all_dialogues from mudlib.effects import clear_expired from mudlib.gametime import get_game_hour, init_game_time -from mudlib.housing import init_housing, load_home_zone from mudlib.gmcp import ( send_char_status, send_char_vitals, @@ -50,6 +49,7 @@ from mudlib.gmcp import ( send_msdp_vitals, send_room_info, ) +from mudlib.housing import init_housing, load_home_zone from mudlib.if_session import broadcast_to_spectators from mudlib.mob_ai import process_mob_movement, process_mobs from mudlib.mobs import load_mob_templates, mob_templates, mobs @@ -314,6 +314,15 @@ async def shell( # Load player data from database or use defaults for new player player_data: PlayerData | None = login_result["player_data"] + + # Run character creation for new accounts + is_new_account = login_result.get("is_new", False) + if is_new_account: + creation_data = await character_creation(player_name, read_input, write_output) + if creation_data.get("description"): + save_player_description(player_name, creation_data["description"]) + if player_data is not None: + player_data["description"] = creation_data["description"] if player_data is None: # New player - find a passable starting position center_x = _overworld.width // 2 @@ -352,6 +361,11 @@ async def shell( player_data["x"] = start_x player_data["y"] = start_y + # Load player's home zone if they have one + home_zone_name = player_data.get("home_zone") + if home_zone_name and home_zone_name.startswith("home:"): + load_home_zone(player_name) + # Create player instance player = Player( name=player_name, @@ -366,6 +380,10 @@ async def shell( reader=_reader, ) + # Set description and home zone + player.description = player_data.get("description", "") + player.home_zone = player_data.get("home_zone") + # Load aliases from database player.aliases = load_aliases(player_name) @@ -557,6 +575,11 @@ async def run_server() -> None: register_zone(zone_name, zone) log.info("loaded %d zones from %s", len(loaded_zones), zones_dir) + # Initialize player housing + player_zones_dir = data_dir / "player_zones" + init_housing(player_zones_dir) + log.info("player housing initialized at %s", player_zones_dir) + # Load content-defined commands from TOML files content_dir = pathlib.Path(__file__).resolve().parents[2] / "content" / "commands" if content_dir.exists(): diff --git a/tests/test_server.py b/tests/test_server.py index 08a071b..08c0dcc 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -70,12 +70,13 @@ async def test_shell_greets_and_accepts_commands(temp_db): readline = "mudlib.server.readline2" with patch(readline, new_callable=AsyncMock) as mock_readline: - # Simulate: name, create account (y), password, confirm password, look, quit + # Simulate: name, create (y), pass, confirm pass, description, look, quit mock_readline.side_effect = [ "TestPlayer", "y", "password", "password", + "A test character", "look", "quit", ] @@ -125,12 +126,13 @@ async def test_shell_handles_quit(temp_db): readline = "mudlib.server.readline2" with patch(readline, new_callable=AsyncMock) as mock_readline: - # Simulate: name, create account (y), password, confirm password, quit + # Simulate: name, create (y), pass, confirm pass, description, quit mock_readline.side_effect = [ "TestPlayer", "y", "password", "password", + "A test character", "quit", ] await server.shell(reader, writer)