session_host module

Session Host

Server-side multiplayer session manager.

Handles the full lifecycle of a hosted session: accepting connections, performing the HELLO/WELCOME handshake, managing entity claims, relaying chat, and dispatching gameplay actions. The Gamemaster is the authoritative source of truth for all game state.

class network.session_host.ConnectedPlayer(player_id, player_name, conn)

Bases: object

Tracks a connected player’s state.

Parameters:
  • player_id (str) – Unique identifier assigned on connection.

  • player_name (str) – Display name from the HELLO message.

  • conn (TransportConnection) – The player’s transport connection.

class network.session_host.SessionHost(gamemaster, transport: TransportServer)

Bases: object

Manages a multiplayer session from the DM (host) side.

Accepts a TransportServer (real WebSocket or InMemoryServer for testing). All game logic is delegated to the Gamemaster which remains the source of truth.

Parameters:
  • gamemaster – The authoritative game state holder.

  • transport (TransportServer) – The transport server to accept connections on.

async broadcast(msg, exclude=None)

Send a message to all connected players.

Parameters:
  • msg (Message) – The message to broadcast.

  • exclude (str or None) – Player ID to skip (e.g. the sender).

async start()

Start the session and begin accepting connections.

async stop()

Stop the session and disconnect all players.