Skip to main content

Overview

Flight packets handle real-time aircraft state synchronization between clients and servers. These packets are sent frequently (multiple times per second) to keep all clients synchronized.

FSNETCMD_AIRPLANESTATE

Packet ID: 11 | Direction: Bidirectional (Server ↔ Client) The most important packet in YSFlight, sent to synchronize aircraft position, attitude, control surfaces, and weapons status.

Location

lib/PacketManager/packets/FSNETCMD_AIRPLANESTATE.py

Packet Versions

This packet has multiple versions with different structures:
  • Version 0: vh, vp, vr are 16-bit shorts
  • Version 1+: vh, vp, vr are 32-bit integers appended at end
  • Version 2+: Includes thrust vector, reverser, and bomb bay
  • Version 3+: idOnServer is 32-bit int
  • Version 4: Short version with thrust vector and bomb bay
  • Version 5: Short version without thrust vector or bomb bay (most common)

Fields

remote_time
float
Timestamp from the sending client’s simulation
player_id
int
Unique identifier for the aircraft in the simulation
packet_version
int
Version number determining packet structure (typically 4 or 5)
position
list[float, float, float]
Aircraft position in meters [x, y, z]
atti
list[float, float, float]
Aircraft attitude in radians [heading, pitch, bank]
velocity
list[float, float, float]
Aircraft velocity vector [vx, vy, vz]
atti_velocity
list[float, float, float]
Angular velocity [vh, vp, vr]
fuel
int
Current fuel amount
payload
int
Current payload weight
flight_state
int
Current flight state (flying, on ground, crashed, etc.)
vgw
float
Variable geometry wing position (0.0-1.0)
spoiler
float
Spoiler deployment (0.0-1.0)
landing_gear
float
Landing gear position (0.0-1.0)
flap
float
Flap position (0.0-1.0)
brake
float
Brake application (0.0-1.0)
flags
dict
Aircraft state flags:
  • ab (bool): Afterburner on/off
  • firing (bool): Currently firing guns
  • smoke (int): Smoke type (0 = off, 255 = default color)
  • nav_lights (bool): Navigation lights on/off
  • beacon (bool): Beacon light on/off
  • strobe (bool): Strobe lights on/off
  • landing_lights (bool): Landing lights on/off
gun_ammo
int
Remaining gun ammunition
rocket_ammo
int
Remaining rockets
aam
int
Remaining air-to-air missiles
agm
int
Remaining air-to-ground missiles
bomb
int
Remaining bombs
life
int
Aircraft health/damage state (0-255)
g_value
float
Current G-force experienced by aircraft
throttle
float
Throttle position (0.0-1.0)
elev
float
Elevator position (-1.0 to 1.0)
ail
float
Aileron position (-1.0 to 1.0)
rud
float
Rudder position (-1.0 to 1.0)
trim
float
Trim position (-1.0 to 1.0)

Methods

decode
method
Decodes the binary packet data into object fieldsExample:
packet = FSNETCMD_AIRPLANESTATE(data, should_decode=True)
print(f"Position: {packet.position}")
print(f"Fuel: {packet.fuel}")
print(f"Afterburner: {packet.flags['ab']}")
smoke
method
Returns a modified packet with smoke enabledReturns: bytes - Full packet with size headerExample:
# Enable smoke on aircraft
smoke_packet = FSNETCMD_AIRPLANESTATE(data).smoke()
writer.write(smoke_packet)
stop_firing
method
Returns a modified packet with firing flag disabledReturns: bytes - Full packet with size headerExample:
# Prevent aircraft from firing
modified = FSNETCMD_AIRPLANESTATE(data).stop_firing()
writer.write(modified)
get_life
static method
Quickly extract life value from packet without full decodeParameters:
  • buffer (bytes): Raw packet data
Returns: int - Aircraft life/health valueExample:
life = FSNETCMD_AIRPLANESTATE.get_life(packet_data)
if life < 50:
    print("Aircraft is heavily damaged")
encode
static method
Creates a new AIRPLANESTATE packetParameters: All fields listed above, plus:
  • with_size (bool): Include size header for network transmission
Returns: bytes - Encoded packetExample:
packet = FSNETCMD_AIRPLANESTATE.encode(
    remote_time=10.5,
    player_id=1,
    packet_version=5,
    position=[0.0, 100.0, 0.0],
    atti=[0.0, 0.0, 0.0],
    velocity=[100.0, 0.0, 0.0],
    atti_velocity=[0.0, 0.0, 0.0],
    smoke_oil=0,
    fuel=5000,
    payload=1000,
    flight_state=1,
    vgw=0.0,
    spoiler=0.0,
    landing_gear=1.0,
    flap=0.3,
    brake=0.0,
    flags={"ab": False, "firing": False, "smoke": 0},
    gun_ammo=500,
    rocket_ammo=10,
    aam=4,
    agm=2,
    bomb=4,
    life=255,
    g_value=1.0,
    throttle=0.8,
    elev=0.0,
    ail=0.0,
    rud=0.0,
    trim=0.0,
    thrust_vector={"vector": 0.0, "reverser": 0.0},
    bomb_bay_info=0.0,
    with_size=True
)

Usage Examples

Monitoring Aircraft State

from lib.PacketManager.packets import FSNETCMD_AIRPLANESTATE

def on_airplane_state(data, player):
    decode = FSNETCMD_AIRPLANESTATE(data)
    
    # Store in aircraft object
    player.aircraft.add_state(decode)
    
    # Check for critical conditions
    if decode.g_value > 12.0:
        print(f"{player.username} is exceeding G-limits!")
    
    if decode.fuel < 500:
        print(f"{player.username} is low on fuel")
    
    if decode.life < 100:
        print(f"{player.username} is heavily damaged")

Modifying Aircraft State

# From smoke_on_damage plugin
def on_damage(player, damage):
    if damage > 50:
        # Enable smoke on damaged aircraft
        smoke_packet = FSNETCMD_AIRPLANESTATE(data).smoke()
        player.message_to_client.append(smoke_packet)

Tracking Positions

# From radar plugin
flying_players = {}

def track_aircraft(data, player):
    state = FSNETCMD_AIRPLANESTATE(data)
    flying_players[player.aircraft.id] = {
        'position': state.position,
        'velocity': state.velocity,
        'heading': state.atti[0]
    }

FSNETCMD_UNJOIN

Packet ID: 12 | Direction: Client → Server Sent when a client leaves the server voluntarily.

Location

lib/PacketManager/packets/FSNETCMD_UNJOIN.py

Fields

object_id
int
ID of the aircraft leaving the server
explosion
bool
Whether to show explosion effect (unused in YSFlight)

Methods

encode
static method
Creates an UNJOIN packetExample:
packet = FSNETCMD_UNJOIN.encode(
    object_id=player.aircraft.id,
    explosion=False,
    with_size=True
)

FSNETCMD_REMOVEAIRPLANE

Packet ID: 13 | Direction: Bidirectional (Server ↔ Client) Sent by the server to notify clients that an aircraft has been removed from the simulation.

Location

lib/PacketManager/packets/FSNETCMD_REMOVEAIRPLANE.py

Fields

Identical to UNJOIN - this class extends FSNETCMD_UNJOIN.
object_id
int
ID of the aircraft being removed
explosion
bool
Whether to show explosion effect

Methods

encode
static method
Creates a REMOVEAIRPLANE packetExample:
packet = FSNETCMD_REMOVEAIRPLANE.encode(
    object_id=aircraft_id,
    explosion=True,  # Show explosion when removing
    with_size=True
)

Notes

The difference between UNJOIN and REMOVEAIRPLANE is semantic:
  • UNJOIN: Client-initiated disconnect
  • REMOVEAIRPLANE: Server-initiated removal (kicked, crashed, etc.)
Both use the same packet structure internally.

Performance Considerations

  • AIRPLANESTATE packets are sent very frequently (10-30 times per second)
  • Minimize processing time for these packets to avoid lag
  • Use should_decode=False if you only need to forward the packet
  • Cache commonly accessed values rather than decoding repeatedly

Build docs developers (and LLMs) love