From 30c7e24aa8de762a1b8c21476e9e8436db1b9826 Mon Sep 17 00:00:00 2001 From: Ritabrata Das Date: Sun, 23 Feb 2025 19:04:58 +0530 Subject: Work on discord chat sync, and fix smoke --- lib/PacketManager/packets/FSNETCMD_AIRPLANESTATE.py | 4 ++-- proxy.py | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/PacketManager/packets/FSNETCMD_AIRPLANESTATE.py b/lib/PacketManager/packets/FSNETCMD_AIRPLANESTATE.py index 8c5aec7..9ebfc00 100644 --- a/lib/PacketManager/packets/FSNETCMD_AIRPLANESTATE.py +++ b/lib/PacketManager/packets/FSNETCMD_AIRPLANESTATE.py @@ -198,7 +198,7 @@ class FSNETCMD_AIRPLANESTATE: #11 packet = self.buffer[:56] + pack('h',flag) + self.buffer[58:] return pack('I',len(packet)) + packet else: - flag = unpack('h',self.buffer[74:75])[0] + flag = unpack('h',self.buffer[74:76])[0] flag &= ~((255<<8)|2) flag |= (255<<8) | 2 @@ -213,7 +213,7 @@ class FSNETCMD_AIRPLANESTATE: #11 packet = self.buffer[:56] + pack('h',flag) + self.buffer[58:] return pack('I',len(packet)) + packet else: - flag = unpack('h',self.buffer[74:75])[0] + flag = unpack('h',self.buffer[74:76])[0] flag &= ~(8) packet = self.buffer[:74] + pack('h',flag) + self.buffer[76:] return pack('I',len(packet)) + packet diff --git a/proxy.py b/proxy.py index 9cb6a5e..d043b32 100644 --- a/proxy.py +++ b/proxy.py @@ -132,6 +132,8 @@ async def handle_client(client_reader, client_writer): elif packet_type == "FSNETCMD_JOINREQUEST": player.iff = FSNETCMD_JOINREQUEST(packet).iff + 1 + if DISCORD_ENABLED: + asyncio.create_task(discord_send_message(CHANNEL_ID, f"{player.username} has taken off! 🛫")) elif packet_type == "FSNETCMD_AIRPLANESTATE": player.aircraft.add_state(FSNETCMD_AIRPLANESTATE(packet)) #TODO: Do we want to convert all this to plugins? Probably not, but there is duplicated functionality @@ -147,6 +149,8 @@ async def handle_client(client_reader, client_writer): player.aircraft.just_repaired = False elif packet_type == "FSNETCMD_UNJOIN": + if DISCORD_ENABLED: + asyncio.create_task(discord_send_message(CHANNEL_ID, f"{player.username} has left the airplane! 🛬")) player.aircraft.reset() elif packet_type == "FSNETCMD_WEAPONCONFIG": @@ -248,12 +252,16 @@ async def start_proxy(): info(f"Proxy server listening on port {PROXY_PORT}") if DISCORD_ENABLED: await asyncio.create_task(monitor_channel(CHANNEL_ID, CONNECTED_PLAYERS)) + # await asyncio.create_task(set_bot_status_online()) async with server: await server.serve_forever() if __name__ == "__main__": try: + if DISCORD_ENABLED: + asyncio.run(discord_send_message(CHANNEL_ID, "✅ Server has started.")) asyncio.run(start_proxy()) except KeyboardInterrupt: + asyncio.run(discord_send_message(CHANNEL_ID, "❌ Server has stopped.")) info("Goodbye!") -- cgit v1.2.3