Wire character creation and housing into server login flow

This commit is contained in:
Jared Miller 2026-02-14 16:50:29 -05:00
parent 32c570b777
commit acfff671fe
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C
2 changed files with 28 additions and 3 deletions

View file

@ -42,7 +42,6 @@ from mudlib.creation import character_creation
from mudlib.dialogue import load_all_dialogues from mudlib.dialogue import load_all_dialogues
from mudlib.effects import clear_expired from mudlib.effects import clear_expired
from mudlib.gametime import get_game_hour, init_game_time from mudlib.gametime import get_game_hour, init_game_time
from mudlib.housing import init_housing, load_home_zone
from mudlib.gmcp import ( from mudlib.gmcp import (
send_char_status, send_char_status,
send_char_vitals, send_char_vitals,
@ -50,6 +49,7 @@ from mudlib.gmcp import (
send_msdp_vitals, send_msdp_vitals,
send_room_info, send_room_info,
) )
from mudlib.housing import init_housing, load_home_zone
from mudlib.if_session import broadcast_to_spectators from mudlib.if_session import broadcast_to_spectators
from mudlib.mob_ai import process_mob_movement, process_mobs from mudlib.mob_ai import process_mob_movement, process_mobs
from mudlib.mobs import load_mob_templates, mob_templates, 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 # Load player data from database or use defaults for new player
player_data: PlayerData | None = login_result["player_data"] 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: if player_data is None:
# New player - find a passable starting position # New player - find a passable starting position
center_x = _overworld.width // 2 center_x = _overworld.width // 2
@ -352,6 +361,11 @@ async def shell(
player_data["x"] = start_x player_data["x"] = start_x
player_data["y"] = start_y 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 # Create player instance
player = Player( player = Player(
name=player_name, name=player_name,
@ -366,6 +380,10 @@ async def shell(
reader=_reader, 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 # Load aliases from database
player.aliases = load_aliases(player_name) player.aliases = load_aliases(player_name)
@ -557,6 +575,11 @@ async def run_server() -> None:
register_zone(zone_name, zone) register_zone(zone_name, zone)
log.info("loaded %d zones from %s", len(loaded_zones), zones_dir) 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 # Load content-defined commands from TOML files
content_dir = pathlib.Path(__file__).resolve().parents[2] / "content" / "commands" content_dir = pathlib.Path(__file__).resolve().parents[2] / "content" / "commands"
if content_dir.exists(): if content_dir.exists():

View file

@ -70,12 +70,13 @@ async def test_shell_greets_and_accepts_commands(temp_db):
readline = "mudlib.server.readline2" readline = "mudlib.server.readline2"
with patch(readline, new_callable=AsyncMock) as mock_readline: 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 = [ mock_readline.side_effect = [
"TestPlayer", "TestPlayer",
"y", "y",
"password", "password",
"password", "password",
"A test character",
"look", "look",
"quit", "quit",
] ]
@ -125,12 +126,13 @@ async def test_shell_handles_quit(temp_db):
readline = "mudlib.server.readline2" readline = "mudlib.server.readline2"
with patch(readline, new_callable=AsyncMock) as mock_readline: 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 = [ mock_readline.side_effect = [
"TestPlayer", "TestPlayer",
"y", "y",
"password", "password",
"password", "password",
"A test character",
"quit", "quit",
] ]
await server.shell(reader, writer) await server.shell(reader, writer)