Overview
Sakuya AC uses a packet-based communication system to handle all network traffic between YSFlight clients and servers. The PacketManager class provides the core functionality for identifying and routing packets.PacketManager
The PacketManager class is responsible for parsing incoming network data and identifying packet types.Location
lib/PacketManager/PacketManager.py
Methods
Returns the message type of a packet by reading its header.Parameters:
data(bytes): Raw packet data (minimum 4 bytes)
str | None: Packet type name from MESSAGE_TYPES, or None if data is too short
Packet Structure
All YSFlight packets follow a common structure:- Size Header (4 bytes): Packet length excluding the size header itself
- Packet Type (4 bytes): Integer ID identifying the packet type
- Payload: Packet-specific data
Message Types
All packet types are defined inlib/PacketManager/packets/constants.py as the MESSAGE_TYPES list:
- Connection Packets (0-3): NULL, LOGON, LOGOFF, ERROR
- Flight Packets (11-13): AIRPLANESTATE, UNJOIN, REMOVEAIRPLANE
- Join Packets (8-10): JOINREQUEST, JOINAPPROVAL, REJECTJOINREQ
- Command Packets (30-36): AIRCMD, TEXTMESSAGE, WEAPONCONFIG
- Combat Packets (18-22): LOCKON, MISSILELAUNCH, GETDAMAGE
- Environment Packets (33, 48-50): ENVIRONMENT, FOGCOLOR, SKYCOLOR
Packet Decoding Pattern
All packet classes follow a consistent pattern:Usage in Proxy
In proxy.py, packets are intercepted and processed:Packet Modification
Packets can be modified before forwarding:Creating New Packets
You can create packets to send to clients or servers:Best Practices
- Always use
with_size=Truewhen sending packets over the network - Check packet length before decoding to avoid errors
- Use
should_decode=Falseif you only need to forward the packet - Handle packet versions for AIRPLANESTATE (versions 0-5 have different structures)
- Validate packet data before processing to prevent crashes
Related Pages
- Flight Packets - AIRPLANESTATE, UNJOIN, REMOVEAIRPLANE
- Connection Packets - LOGON, LOGOFF, JOINREQUEST, JOINAPPROVAL
- Command Packets - AIRCMD, TEXTMESSAGE, WEAPONCONFIG