diff --git a/server/transport_policy.py b/server/transport_policy.py new file mode 100644 index 0000000..d50c5fb --- /dev/null +++ b/server/transport_policy.py @@ -0,0 +1,28 @@ +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