Sync from GitHub main #1
@@ -0,0 +1,34 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from client_session import ClientSession
|
||||||
|
from packet_codec import PacketCodecError, encode_packet
|
||||||
|
from server_core import MAX_PACKET_CHARS, FalloutTogetherServer
|
||||||
|
|
||||||
|
|
||||||
|
class TransportAwareFalloutTogetherServer(FalloutTogetherServer):
|
||||||
|
"""Authoritative server with serialization separated from transport framing.
|
||||||
|
|
||||||
|
All gameplay validation and relay behavior stays in ``FalloutTogetherServer``.
|
||||||
|
Only the final outbound serialization boundary is replaced: TCP sessions add
|
||||||
|
line framing in ``ClientSession.send_packet`` while message transports receive
|
||||||
|
the raw encoded packet and delivery policy.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def _send_packet(self, client: ClientSession, packet: dict[str, Any], *, broadcast: bool = False) -> None:
|
||||||
|
try:
|
||||||
|
encoded = encode_packet(packet)
|
||||||
|
except PacketCodecError as error:
|
||||||
|
raise ValueError(str(error)) from error
|
||||||
|
|
||||||
|
uses_message_transport = callable(getattr(client.connection, "send_encoded", None))
|
||||||
|
if not uses_message_transport and len(encoded.payload) + 1 > MAX_PACKET_CHARS:
|
||||||
|
raise ValueError("Outbound TCP packet exceeds maximum line size")
|
||||||
|
|
||||||
|
client.send_packet(encoded)
|
||||||
|
client.record_sent(broadcast=broadcast)
|
||||||
|
with self._lock:
|
||||||
|
self._stats["packetsSent"] += 1
|
||||||
|
if broadcast:
|
||||||
|
self._stats["packetsBroadcast"] += 1
|
||||||
Reference in New Issue
Block a user