2026-02-21 16:51:07 -05:00
|
|
|
"""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:
|
2026-02-21 16:51:07 -05:00
|
|
|
"""Represents one connected websocket client and its world state."""
|
|
|
|
|
|
2026-02-20 08:16:43 -05:00
|
|
|
websocket: ServerConnection
|
|
|
|
|
id: str
|
|
|
|
|
nickname: str = "user..."
|
|
|
|
|
x: int = 20
|
|
|
|
|
y: int = 20
|
2026-02-24 19:52:38 -05:00
|
|
|
last_position_update_ms: int = 0
|
2026-02-20 08:16:43 -05:00
|
|
|
|
|
|
|
|
def summary(self) -> dict[str, str | int]:
|
2026-02-21 16:51:07 -05:00
|
|
|
"""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}
|