From 4c59fc24b86fda2e317f4fce77eea7a11ff87e30 Mon Sep 17 00:00:00 2001 From: Ritabrata Das Date: Mon, 3 Mar 2025 14:41:24 +0530 Subject: Fix crash on ground plugin, add additional logging, fix readback packet --- lib/PacketManager/packets/FSNETCMD_READBACK.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/PacketManager') diff --git a/lib/PacketManager/packets/FSNETCMD_READBACK.py b/lib/PacketManager/packets/FSNETCMD_READBACK.py index 0fd4ead..b86199f 100644 --- a/lib/PacketManager/packets/FSNETCMD_READBACK.py +++ b/lib/PacketManager/packets/FSNETCMD_READBACK.py @@ -6,7 +6,7 @@ class FSNETCMD_READBACK: #6 * Client sends FSNETREADBACK_ADDAIRPLAN or FSNETREADBACK_ADDGROUND to acknowledge FSNETCMD_ADDOBJECT - * Client sends FSNETREADBACK_REMOVEAIRPLANE or FSNETREADBACK_REMOVEGROUND + * Client sends FSNETREADBACK_REMOVEAIRPLANE or FSNETREADBACK_REMOVEGROUND to acknowledge FSNETCMD_REMOVEAIRPLANE or FSNETCMD_REMOVEGROUND * Client sends FSNETREADBACK_ENVIRONMENT to acknowledge FSNETCMD_ENVIRONMENT * Client sends FSNETREADBACK_JOINREQUEST to acknowledge FSNETCMD_JOINREQUEST @@ -14,7 +14,7 @@ class FSNETCMD_READBACK: #6 * Client sends FSNETREADBACK_USEMISSILE to acknowledge FSNETCMD_USEMISSILE * Client sends FSNETREADBACK_USEUNGUIDEDWEAPON to acknowledge FSNETCMD_USEUNGUIDEDWEAPON * Client sends FSNETREADBACK_CTRLSHOWUSERNAME to acknowledge FSNETCMD_CTRLSHOWUSERNAME - + * Server sends FSNETREADBACK_JOINREQUEST to acknowledge FSNETCMD_JOINREQUEST - Will punt the user if the server receives this from them * There are probably more, but I've not gone into much detail here yet. @@ -33,7 +33,7 @@ class FSNETCMD_READBACK: #6 @staticmethod def encode(read_back_type, read_back_param, with_size:bool=False): - buffer = pack("IhhI", 6, read_back_type, 0, read_back_param) + buffer = pack("IhhI", 6, 0, read_back_type, read_back_param) if with_size: return pack("I",len(buffer))+buffer - return buffer \ No newline at end of file + return buffer -- cgit v1.2.3 From 42d2d3acfc44455b70bb46c7bcd9cb1487a79ca4 Mon Sep 17 00:00:00 2001 From: Ritabrata Das Date: Sun, 9 Mar 2025 12:01:43 +0530 Subject: Add support for longer than 16 char username and fix bugs --- lib/PacketManager/packets/FSNETCMD_LOGON.py | 2 +- lib/Player.py | 3 ++- plugins/crash_on_ground.py | 2 -- plugins/radar.py | 2 +- proxy.py | 23 +++++++++++++++++------ 5 files changed, 21 insertions(+), 11 deletions(-) (limited to 'lib/PacketManager') diff --git a/lib/PacketManager/packets/FSNETCMD_LOGON.py b/lib/PacketManager/packets/FSNETCMD_LOGON.py index 9848590..620b2cd 100644 --- a/lib/PacketManager/packets/FSNETCMD_LOGON.py +++ b/lib/PacketManager/packets/FSNETCMD_LOGON.py @@ -55,4 +55,4 @@ class FSNETCMD_LOGON: #1 @staticmethod def alter_version(buffer:bytes, new_version:int): - return buffer[:20]+pack("I",new_version)+buffer[24:] \ No newline at end of file + return buffer[:20]+pack("I",new_version)+buffer[24:] diff --git a/lib/Player.py b/lib/Player.py index cfd50a8..f8da70e 100644 --- a/lib/Player.py +++ b/lib/Player.py @@ -27,7 +27,8 @@ class Player: self.ip = ip def check_add_object(self, packet:FSNETCMD_ADDOBJECT): - if packet.pilot == self.username: + # we check the full name here + if packet.pilot == self.alias: self.aircraft = Aircraft() self.aircraft.name = packet.identifier self.aircraft.id = packet.object_id diff --git a/plugins/crash_on_ground.py b/plugins/crash_on_ground.py index 4cc334b..15b1fbf 100644 --- a/plugins/crash_on_ground.py +++ b/plugins/crash_on_ground.py @@ -10,8 +10,6 @@ class Plugin: def register(self, plugin_manager): self.plugin_manager = plugin_manager - #self.plugin_manager.register_hook('on_unjoin', self.on_death) - #self.plugin_manager.register_hook('on_add_object_server', self.on_join) self.plugin_manager.register_hook('on_remove_airplane_server', self.on_death) def on_death(self, data, player, message_to_client, message_to_server): diff --git a/plugins/radar.py b/plugins/radar.py index e09447d..ac47b5b 100644 --- a/plugins/radar.py +++ b/plugins/radar.py @@ -60,7 +60,7 @@ class Plugin: try: # This is a really arbitary position thats hard to reach, better would # be to randomise it for every time the server starts. - position_data = struct.pack("3f", 10e7, 10e7, 10e7) + position_data = struct.pack("3f", 10e8, 200, 10e8) if decode.packet_version == 4 or 5: updated_data = data[:14] + position_data + data[26:] else: diff --git a/proxy.py b/proxy.py index ad81590..f68e6d7 100644 --- a/proxy.py +++ b/proxy.py @@ -131,11 +131,17 @@ async def handle_client(client_reader, client_writer): try: if packet_type == "FSNETCMD_LOGON": - # keep_message = plugin_manager.triggar_hook('on_login', packet, player, message_to_client, message_to_server) - # if not keep_message: - # data = None - player.login(FSNETCMD_LOGON(packet)) + decode = FSNETCMD_LOGON(packet) + for p in CONNECTED_PLAYERS: + if p.username == decode.username: + client_writer.write(YSchat.message(f"Same username {decode.username} is aldready connected to server! Kicked {ipAddr}")) + data = None + info(f"Same username {decode.username} is aldready connected to server! Kicked {ipAddr}") + await close_connection(client_writer, server_writer) + + player.login(decode) info(f"Player {player.username} connected from {player.ip}") + if player.version != YSF_VERSION and VIA_VERSION: info(f"ViaVersion enabled : Porting {player.username} from {player.version} to {YSF_VERSION}") message_to_client.append(YSchat.message(f"Porting you to YSFlight {YSF_VERSION}, This is currently Experimental")) @@ -152,7 +158,9 @@ async def handle_client(client_reader, client_writer): elif packet_type == "FSNETCMD_AIRPLANESTATE": decode = FSNETCMD_AIRPLANESTATE(packet) - player.aircraft.add_state(decode) #TODO: Do we want to convert all this to plugins? Probably not, but there is duplicated functionality + player.aircraft.add_state(decode) + + #TODO: Do we want to convert all this to plugins? Probably not, but there is duplicated functionality # keep_message = plugin_manager.triggar_hook('on_flight_data', packet, player, message_to_client, message_to_server) # if not keep_message: # data = None @@ -186,6 +194,7 @@ async def handle_client(client_reader, client_writer): data = None command = msg.message.split(" ")[0][1:] asyncio.create_task(triggerCommand.triggerCommand(command, msg.message, player, message_to_client, message_to_server, plugin_manager)) + info(f"Command {command} triggered by {player.username}") else: if DISCORD_ENABLED: # Make it non blocking! @@ -267,8 +276,10 @@ async def handle_client(client_reader, client_writer): """ if not player.connection_closed: player.connection_closed = True + CONNECTED_PLAYERS.remove(player) if not player.is_a_bot: - message_to_server.append(YSchat.message(f"{player.username} has left the server!")) + for player in CONNECTED_PLAYERS: + player.streamWriterObject.write(YSchat.message(f"{player.username} has left the server!")) if DISCORD_ENABLED: await discord_send_message(CHANNEL_ID, f"{player.username} has left the server!") await close_connection(client_writer, server_writer) -- cgit v1.2.3