diff --git a/server/client_session.py b/server/client_session.py index cd142c0..d5c11b6 100644 --- a/server/client_session.py +++ b/server/client_session.py @@ -17,7 +17,10 @@ class ClientSession: packets_received: int = 0 packets_sent: int = 0 packets_broadcast: int = 0 + gameplay_active: bool = False + protocol_version: int = 0 _lock: Any = field(repr=False, compare=False, default_factory=threading.RLock) + _send_lock: Any = field(repr=False, compare=False, default_factory=threading.Lock) @property def label(self) -> str: @@ -39,6 +42,18 @@ class ClientSession: if broadcast: self.packets_broadcast += 1 + def mark_gameplay_active(self, protocol_version: int) -> bool: + with self._lock: + if self.gameplay_active: + return False + self.gameplay_active = True + self.protocol_version = int(protocol_version) + return True + + def send_bytes(self, payload: bytes) -> None: + with self._send_lock: + self.connection.sendall(payload) + def to_snapshot(self) -> dict[str, Any]: with self._lock: return { @@ -51,4 +66,6 @@ class ClientSession: "packetsReceived": self.packets_received, "packetsSent": self.packets_sent, "packetsBroadcast": self.packets_broadcast, + "gameplayActive": self.gameplay_active, + "protocolVersion": self.protocol_version, }