39 lines
1.3 KiB
Python
39 lines
1.3 KiB
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
|
|
|
|
|
|
def requires_application_sequence(packet_type: str) -> bool:
|
|
"""Return whether the protocol must reject stale copies after reordering.
|
|
|
|
GameNetworkingSockets can deliver unreliable messages without retransmit,
|
|
but the application still owns latest-wins snapshot semantics. Sequence
|
|
numbers are therefore required for every unreliable snapshot family.
|
|
"""
|
|
return is_snapshot_packet(packet_type)
|