session_client module
Session Client
Client-side multiplayer session manager.
Connects to a SessionHost, performs the
HELLO/WELCOME handshake, then listens for state updates, entity claims,
and chat messages. Players send actions through this client.
- class network.session_client.SessionClient(player_name, transport: TransportClient)
Bases:
objectManages a multiplayer session from the player (client) side.
Accepts a
TransportClient(real WebSocket orInMemoryClientfor testing).- Parameters:
player_name (str) – Display name for this player.
transport (TransportClient) – The transport client used to connect.
- async claim_entity(entity_id)
Send a CLAIM_ENTITY request to the host.
- Parameters:
entity_id (str) – Name/ID of the entity to claim.
- async connect()
Connect to the server and perform the HELLO/WELCOME handshake.
After a successful handshake,
session_id,player_id, andavailable_entitiesare populated.- Raises:
ConnectionError – If the server rejects the connection (version mismatch or protocol error).
- async disconnect()
Send a DISCONNECT message and close the connection.
- async listen()
Receive and dispatch messages in a loop.
Call after
connect(). Updatesworld_stateandturn_statefrom FULL_STATE and STATE_DELTA messages, and fires registered callbacks viaon()for every message type, includingTURN_CHANGEbroadcasts.
- on(msg_type, handler)
Register a callback for a specific message type.
- Parameters:
msg_type (MessageType) – The message type to listen for.
handler (callable) – Callable receiving a
Message.
- async request_action(action_type, params)
Send an ACTION_REQUEST to the host.
- Parameters:
action_type (str) – Type of action (e.g.
"move").params (dict) – Action-specific parameters.
- async send_chat(message)
Send a CHAT message to the session.
- Parameters:
message (str) – Chat text to send.