Skip to main content

Overview

The Player class represents a connected client in Sakuya AC. It holds information about the client including their username, aircraft, IP address, and connection state.

Constructor

Player(server_messages, client_messages, streamWriterObject)
Creates a new Player instance.
server_messages
object
required
Message queue for server-bound messages
client_messages
object
required
Message queue for client-bound messages
streamWriterObject
StreamWriter
required
asyncio StreamWriter object for sending data to the client

Properties

username
str
The player’s username. Initially empty until login.
alias
str
The player’s display alias/nickname. Initially empty until login.
aircraft
Aircraft
The Aircraft instance representing the player’s current aircraft.
version
int
The client version number. Initially 0 until login.
ip
str
The player’s IP address. Initially empty until set.
streamWriterObject
StreamWriter
The asyncio StreamWriter object for network communication.
is_a_bot
bool
default:"True"
Flag indicating if the connection is a bot. Set to False after successful LOGIN packet.
iff
int
default:"1"
Identification Friend or Foe value (team identifier).
connection_closed
bool
default:"False"
Flag indicating if the connection has been closed.

Methods

set_aircraft

set_aircraft(aircraft: Aircraft) -> None
Sets the player’s aircraft.
aircraft
Aircraft
required
The Aircraft instance to assign to this player
Example:
from lib.Aircraft import Aircraft

aircraft = Aircraft()
aircraft.name = "F-15C"
player.set_aircraft(aircraft)

login

login(packet: FSNETCMD_LOGON) -> None
Processes a login packet and updates player information.
packet
FSNETCMD_LOGON
required
The login packet containing username, alias, and version information
Updates:
  • Sets username from packet
  • Sets alias from packet
  • Sets version from packet
Example:
logon_packet = FSNETCMD_LOGON()
logon_packet.username = "pilot123"
logon_packet.alias = "TopGun"
logon_packet.version = 20190117

player.login(logon_packet)
print(player.username)  # "pilot123"
print(player.alias)     # "TopGun"

set_ip

set_ip(ip: str) -> None
Sets the player’s IP address.
ip
str
required
The IP address string to assign to this player
Example:
player.set_ip("192.168.1.100")
print(player.ip)  # "192.168.1.100"

check_add_object

check_add_object(packet: FSNETCMD_ADDOBJECT) -> bool
Checks if an ADDOBJECT packet belongs to this player and updates aircraft information if it matches.
packet
FSNETCMD_ADDOBJECT
required
The add object packet containing aircraft spawn information
return
bool
True if the packet pilot matches this player’s alias and aircraft was updated, False otherwise
Behavior:
  • Compares packet.pilot with player’s alias
  • If matched, creates new Aircraft instance and sets:
    • Aircraft name from packet.identifier
    • Aircraft ID from packet.object_id
    • Aircraft position from packet.pos
    • IFF configuration from packet.iff
Example:
add_object_packet = FSNETCMD_ADDOBJECT()
add_object_packet.pilot = "TopGun"
add_object_packet.identifier = "F-15C"
add_object_packet.object_id = 12345
add_object_packet.pos = [100.0, 200.0, 5000.0]
add_object_packet.iff = 1

if player.check_add_object(add_object_packet):
    print(f"Aircraft spawned: {player.aircraft.name}")
    print(f"Position: {player.aircraft.position}")
else:
    print("Packet doesn't belong to this player")

String Representation

The Player class implements __str__() for easy debugging:
print(player)
# Output: "Player pilot123 flying F-15C at [100.0, 200.0, 5000.0]"

Usage Example

import asyncio
from lib.Player import Player
from lib.Aircraft import Aircraft
from lib.PacketManager.packets import FSNETCMD_LOGON, FSNETCMD_ADDOBJECT

# Create player instance
reader, writer = await asyncio.open_connection('127.0.0.1', 7915)
player = Player(server_messages, client_messages, writer)

# Set IP address
player.set_ip(writer.get_extra_info('peername')[0])

# Process login
logon = FSNETCMD_LOGON()
logon.username = "ace_pilot"
logon.alias = "Maverick"
logon.version = 20190117
player.login(logon)

# Check if player is still a bot
if not player.is_a_bot:
    print(f"{player.username} successfully logged in")

# Handle aircraft spawn
add_obj = FSNETCMD_ADDOBJECT()
add_obj.pilot = "Maverick"
add_obj.identifier = "F-14A"
add_obj.object_id = 1001
add_obj.pos = [0, 0, 1000]
add_obj.iff = 1

if player.check_add_object(add_obj):
    print(f"Player aircraft: {player.aircraft.name}")
    print(f"Aircraft ID: {player.aircraft.id}")

Build docs developers (and LLMs) love