summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSkipper <[email protected]>2025-02-10 21:18:05 +0000
committerSkipper <[email protected]>2025-02-10 21:18:05 +0000
commit67ccf67b206873f8a8d099af5def66d7f3ff22d2 (patch)
treed2875bb6b155e28e8b6ac147877d1565a29a4673
parent3d29b59dae6b93c28c321c2df3cbc49d20d5661c (diff)
Added afterburner toggle on damage
-rw-r--r--lib/Aircraft.py10
-rw-r--r--lib/PacketManager/packets/FSNETCMD_AIRCMD.py27
-rw-r--r--proxy.py16
3 files changed, 37 insertions, 16 deletions
diff --git a/lib/Aircraft.py b/lib/Aircraft.py
index 215a1cb..2672621 100644
--- a/lib/Aircraft.py
+++ b/lib/Aircraft.py
@@ -69,6 +69,7 @@ class Aircraft:
def add_state(self, packet:FSNETCMD_AIRPLANESTATE):
"""Adds the state of the aircraft"""
+
if packet.player_id != self.id:
return None
self.prev_life = self.life
@@ -79,9 +80,16 @@ class Aircraft:
return packet
def check_command(self,command:FSNETCMD_AIRCMD):
- """Checks the command"""
+ """Checks the command, and adds it to the aircraft"""
if command.aircraft_id != self.id:
return
if command.command:
self.initial_config[command.command[0]] = command.command[1]
debug(f"Command: {command.command}")
+
+ def set_afterburner(self, enabled:bool):
+ """If the afterburner is avaialble on the aircraft, will send a command
+ to toggle it."""
+ if self.get_initial_config_value("AFTBURNR") == "TRUE":
+ return FSNETCMD_AIRCMD.set_afterburner(self.id,enabled, True)
+ return None
diff --git a/lib/PacketManager/packets/FSNETCMD_AIRCMD.py b/lib/PacketManager/packets/FSNETCMD_AIRCMD.py
index 094da7d..50a9228 100644
--- a/lib/PacketManager/packets/FSNETCMD_AIRCMD.py
+++ b/lib/PacketManager/packets/FSNETCMD_AIRCMD.py
@@ -42,7 +42,7 @@ class FSNETCMD_AIRCMD: #30
return buffer
@staticmethod
- def setPayload(aircraft_id:int, payload:int, units:str='kg', with_size:bool=False):
+ def set_payload(aircraft_id:int, payload:int, units:str='kg', with_size:bool=False):
"""
This will set the payload of the aircraft, useful if you want to
load or unload passengers/cargo - for YSRP I use this to load and unload
@@ -52,5 +52,28 @@ class FSNETCMD_AIRCMD: #30
message = f"INITLOAD {payload} {units}"
return FSNETCMD_AIRCMD.encode(aircraft_id, message, with_size)
+ @staticmethod
+ def set_command(aircraft_id:int, command:str, value:int, with_size:bool=False):
+ """
+ This will set the command of the aircraft, useful if you want to
+ set the engine power, fuel, etc.
+ """
+ if command in AIRCMD_KEYWORDS:
+ command = AIRCMD_KEYWORDS.index(command)
+
+ message = f"*{command} {value}"
+ return FSNETCMD_AIRCMD.encode(aircraft_id, message, with_size)
+
+ @staticmethod
+ def set_afterburner(aircarft_id:int, enabled:int, with_size:bool=False):
+ """
+ This will set the afterburner of the aircraft, useful if you want to
+ enable or disable the afterburner.
+ """
+
+ command = "AFTBURNR"
+ value = str(enabled).upper()
+ return FSNETCMD_AIRCMD.set_command(aircarft_id, command, value, with_size)
+
def __str__(self):
- return "Aircraft ID : {self.aircraft_id}; Message : {self.message}; Command : {self.command}"
+ return f"Aircraft ID : {self.aircraft_id}; Message : {self.message}; Command : {self.command}"
diff --git a/proxy.py b/proxy.py
index b1160df..552c34f 100644
--- a/proxy.py
+++ b/proxy.py
@@ -86,13 +86,6 @@ async def handle_client(client_reader, client_writer):
packet = player.aircraft.add_state(FSNETCMD_AIRPLANESTATE(packet))
- """
- Just for fun!
- if packet.flags['firing']:
- bomb_drop = FSNETCMD_MISSILELAUNCH.drop_bombs(player.aircraft)
- message_to_server.append(bomb_drop)
- message_to_client.append(bomb_drop)
- """
if player.aircraft.last_packet.g_value > G_LIM:
debug("G Value exceeded : ", player.aircraft.last_packet.g_value)
# We make a packet which damages the aircraft using the same pilot ID, using a gun
@@ -107,8 +100,7 @@ async def handle_client(client_reader, client_writer):
elif prev_life > player.aircraft.life:
cheatingMsg = YSchat.message(f"{HEALTH_HACK_MESSAGE} by {player.username}")
- writer.write(cheatingMsg)
- await writer.drain()
+ message_to_client.append(cheatingMsg)
elif player.aircraft.life < SMOKE_LIFE and SMOKE_PLANE:
@@ -117,15 +109,13 @@ async def handle_client(client_reader, client_writer):
debug(f"Sending warning to {player.username}")
message_to_client.append(warningMsg)
player.aircraft.damage_engine_warn_sent = True
+ message_to_client.append(FSNETCMD_AIRCMD.set_afterburner(player.aircraft.id, False, True))
player.aircraft.life = prev_life
elif packet_type == "FSNETCMD_UNJOIN":
player.aircraft.reset()
- elif packet_type == "FSNETCMD_AIRCMD":
- h = FSNETCMD_AIRCMD(packet)
- print(h.decode)
# elif packet_type == "FSNETCMD_GETDAMAGE":
# h = FSNETCMD_GETDAMAGE(packet, True)
@@ -219,7 +209,6 @@ async def handle_client(client_reader, client_writer):
# # We drop the packets from YSFlight and use it for ourselves
# debug("Packet verification unimplemented!")
# continue
-
except Exception as e:
warning(f"Error parsing flight data: {e}", exc_info=True)
@@ -236,6 +225,7 @@ async def handle_client(client_reader, client_writer):
elif packet_type == "FSNETCMD_AIRCMD":
#Check the configs against the current aircraft
+ #These come server to client, not the other way around.
command = FSNETCMD_AIRCMD(packet)
player.aircraft.check_command(command)