diff --git a/server/client_session.py b/server/client_session.py index 399abec..f1e0e7b 100644 --- a/server/client_session.py +++ b/server/client_session.py @@ -5,10 +5,13 @@ import threading from dataclasses import dataclass, field from typing import Any +from packet_codec import EncodedPacket +from tcp_transport import send_message + @dataclass class ClientSession: - connection: socket.socket + connection: Any address: tuple[str, int] player_id: int connected_at: float @@ -61,6 +64,20 @@ class ClientSession: with self._send_lock: self.connection.sendall(payload) + def send_packet(self, encoded: EncodedPacket) -> None: + """Send one already-serialized protocol message through the active transport. + + TCP compatibility adds its newline delimiter here. Message-oriented + transports can expose ``send_encoded`` and receive the raw JSON payload + plus its delivery policy without TCP framing leaking into the protocol. + """ + with self._send_lock: + send_encoded = getattr(self.connection, "send_encoded", None) + if callable(send_encoded): + send_encoded(encoded) + return + send_message(self.connection, encoded.payload) + def to_snapshot(self) -> dict[str, Any]: with self._lock: return {