diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Aircraft.py | 3 | ||||
| -rw-r--r-- | lib/PacketManager/packets/FSNETCMD_LOGON.py | 2 | ||||
| -rw-r--r-- | lib/PacketManager/packets/FSNETCMD_READBACK.py | 8 | ||||
| -rw-r--r-- | lib/Player.py | 4 | ||||
| -rw-r--r-- | lib/discordSync.py | 2 | ||||
| -rw-r--r-- | lib/plugin_manager.py | 22 | ||||
| -rw-r--r-- | lib/triggerRespectiveHook.py | 4 |
7 files changed, 28 insertions, 17 deletions
diff --git a/lib/Aircraft.py b/lib/Aircraft.py index 5e6e24d..9f162ef 100644 --- a/lib/Aircraft.py +++ b/lib/Aircraft.py @@ -78,9 +78,8 @@ class Aircraft: return None if self.life == -1: self.life=packet.life - + self.prev_life = self.life - self.life = packet.life self.set_position(packet.position) self.set_attitude(packet.atti) 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/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 diff --git a/lib/Player.py b/lib/Player.py index 8e2250a..f8da70e 100644 --- a/lib/Player.py +++ b/lib/Player.py @@ -13,6 +13,7 @@ class Player: self.streamWriterObject = streamWriterObject self.is_a_bot = True # We check if they are still present after LOGIN packet, then they're not a bot self.iff = 1 + self.connection_closed = False def set_aircraft(self, aircraft:Aircraft): self.aircraft = aircraft @@ -26,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/lib/discordSync.py b/lib/discordSync.py index 0a8e8be..770543e 100644 --- a/lib/discordSync.py +++ b/lib/discordSync.py @@ -84,8 +84,6 @@ async def monitor_channel(channel_id, playerList:list): encoded_msg = txtMsgr.encode(f"[Discord] {message['author']['username']}: {message['content']}", True) for player in playerList: if player.streamWriterObject.is_closing(): - if not player.is_a_bot: - asyncio.create_task(discord_send_message(channel_id, f"{player.username} has left the server!")) playerList.remove(player) # Remove disconnected players continue player.streamWriterObject.write(encoded_msg) diff --git a/lib/plugin_manager.py b/lib/plugin_manager.py index 52fb1f7..b96045b 100644 --- a/lib/plugin_manager.py +++ b/lib/plugin_manager.py @@ -7,12 +7,13 @@ PLUGIN_DIR = os.path.join(os.path.dirname(__file__), '../plugins') sys.path.append(PLUGIN_DIR) class PluginManager: - def __init__(self): + def __init__(self, connected_players): self.plugins = {} self.hooks= {} - self.commands = {} + self.commands = {'help': None} self.help_message = "List of Available Commands:\n" self.load_plugins() + self.connected_players = connected_players def load_plugins(self): for plugin in os.listdir(PLUGIN_DIR): @@ -45,13 +46,24 @@ class PluginManager: self.hooks[hook_name] = [] self.hooks[hook_name].append(callback) - def register_command(self, command_name, callback): - """Registers the command with the plugin manager""" + def register_command(self, command_name, callback, help_text="No Description", alias:str=None): + """Registers the command with the plugin manager + Set help text to help users understand what your command does. + """ if command_name in self.commands: warning(f"Command {command_name} already registered, Ignoring this registration") else: self.commands[command_name] = callback - self.help_message = self.help_message + f"/{command_name}\n" + if alias == None: + self.help_message = self.help_message + f"/{command_name} : {help_text}\n" + if alias != None: + if alias in self.commands: + warning(f"Command {alias} already registered, Ignoring this registration") + else: + self.commands[alias] = callback + self.help_message = self.help_message + f"/{command_name} [{alias}] : {help_text}\n" + + def triggar_hook(self, hook_name, data, *args, **kwargs): """Triggars the callbacks for the hook. diff --git a/lib/triggerRespectiveHook.py b/lib/triggerRespectiveHook.py index 25801a0..f7dc443 100644 --- a/lib/triggerRespectiveHook.py +++ b/lib/triggerRespectiveHook.py @@ -59,7 +59,7 @@ def triggerRespectiveHook(packet_type, packet, player, message_to_client, messag keep_message = plugin_manager.triggar_hook('on_list', packet, player, message_to_client, message_to_server) else: keep_message = True - debug(f"Unknown packet type {packet_type}, C2S") + debug(f"Unimplemented packet type {packet_type}, C2S") return keep_message @@ -122,6 +122,6 @@ def triggerRespectiveHookServer(packet_type, packet, player, message_to_client, keep_message = plugin_manager.triggar_hook('on_list_server', packet, player, message_to_client, message_to_server) else: keep_message = True - debug(f"Unknown packet type {packet_type}, S2C") + debug(f"Unimplemented packet type {packet_type}, S2C") return keep_message |
