Files
Commonwealth-Online-Server/server/transport_policy.py
T

29 lines
933 B
Python

from __future__ import annotations
from enum import Enum
class Delivery(str, Enum):
UNRELIABLE_SEQUENCED = "unreliable_sequenced"
RELIABLE_ORDERED = "reliable_ordered"
_SNAPSHOT_PACKET_TYPES = frozenset({"transform", "npcState"})
def delivery_for_packet_type(packet_type: str) -> Delivery:
"""Return the transport contract for one validated protocol packet type.
Unknown packet types intentionally default to reliable/ordered. Protocol
validation still decides whether an unknown packet is accepted; this
function only prevents a future transport adapter from accidentally
downgrading control traffic to an unreliable channel.
"""
if packet_type in _SNAPSHOT_PACKET_TYPES:
return Delivery.UNRELIABLE_SEQUENCED
return Delivery.RELIABLE_ORDERED
def is_snapshot_packet(packet_type: str) -> bool:
return delivery_for_packet_type(packet_type) is Delivery.UNRELIABLE_SEQUENCED