Files
chat_grid/server/app/client.py

36 lines
1012 B
Python
Raw Permalink Normal View History

"""Client connection model used by the signaling server."""
2026-02-20 08:16:43 -05:00
from __future__ import annotations
from dataclasses import dataclass
from websockets.asyncio.server import ServerConnection
@dataclass
class ClientConnection:
"""Represents one connected websocket client and its world state."""
2026-02-20 08:16:43 -05:00
websocket: ServerConnection
id: str
authenticated: bool = False
user_id: str | None = None
username: str | None = None
role: str = "user"
permissions: set[str] | None = None
session_token: str | None = None
2026-02-20 08:16:43 -05:00
nickname: str = "user..."
saved_x: int | None = None
saved_y: int | None = None
2026-02-20 08:16:43 -05:00
x: int = 20
y: int = 20
last_position_update_ms: int = 0
movement_window_index: int = -1
movement_window_steps_used: int = 0
world_ready: bool = False
2026-02-20 08:16:43 -05:00
def summary(self) -> dict[str, str | int]:
"""Return a compact serializable snapshot for logs/diagnostics."""
2026-02-20 08:16:43 -05:00
return {"id": self.id, "nickname": self.nickname, "x": self.x, "y": self.y}