From 44fa2a7bd3e5bff100acbcf3bc1cc2738fed7d8c Mon Sep 17 00:00:00 2001 From: Hornochs Date: Thu, 23 Jan 2025 14:52:49 +0100 Subject: [PATCH 1/4] Adding new Nadeo Protocol and Trackmania Nations Forever Game --- discordgsm/games.csv | 1 + discordgsm/protocols/__init__.py | 1 + discordgsm/protocols/nadeo.py | 55 ++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 discordgsm/protocols/nadeo.py diff --git a/discordgsm/games.csv b/discordgsm/games.csv index 31132a1..0110282 100644 --- a/discordgsm/games.csv +++ b/discordgsm/games.csv @@ -282,6 +282,7 @@ thps3,Tony Hawk's Pro Skater 3,gamespy1,port_query=6500 thps4,Tony Hawk's Pro Skater 4,gamespy1,port_query=6500 thu2,Tony Hawk's Underground 2,gamespy1,port_query=5153 towerunite,Tower Unite,source,port=27015 +tmnf,Trackmania Nations Forever,nadeo,port=5000 tremulous,Tremulous,quake3,port_query=30720 tribesvengeance,Tribes: Vengeance,gamespy2,port=7777;port_query_offset=1 tron20,Tron 2.0,gamespy2,port_query=27888 diff --git a/discordgsm/protocols/__init__.py b/discordgsm/protocols/__init__.py index 634da72..33a72cd 100644 --- a/discordgsm/protocols/__init__.py +++ b/discordgsm/protocols/__init__.py @@ -16,6 +16,7 @@ from .gportal import GPortal from .hexen2 import Hexen2 from .minecraft import Minecraft +from .nadeo import Nadeo from .nwn1 import NWN1 from .nwn2 import NWN2 from .palworld import Palworld diff --git a/discordgsm/protocols/nadeo.py b/discordgsm/protocols/nadeo.py new file mode 100644 index 0000000..d2f4357 --- /dev/null +++ b/discordgsm/protocols/nadeo.py @@ -0,0 +1,55 @@ +import time +from typing import TYPE_CHECKING + +import opengsq + +from discordgsm.protocols.protocol import Protocol + +if TYPE_CHECKING: + from discordgsm.gamedig import GamedigResult + + +class Nadeo(Protocol): + name = "nadeo" + + async def query(self): + host, port = str(self.kv["host"]), int(str(self.kv["port"])) + username = str(self.kv.get("username", "")) + password = str(self.kv.get("password", "")) + + nadeo = opengsq.Nadeo(host, port, self.timeout) + start = time.time() + + async with nadeo: + if username and password: + await nadeo.authenticate(username, password) + + status = await nadeo.get_status() + ping = int((time.time() - start) * 1000) + + players = [] + for player in status.players: + players.append({ + "name": player.get("Name", player.get("Login", "")), + "raw": player + }) + + result: GamedigResult = { + "name": status.server.get("Name", ""), + "map": status.map.get("Name", ""), + "password": bool(status.server.get("Password", False)), + "numplayers": len(status.players), + "numbots": 0, + "maxplayers": int(status.server.get("CurrentMaxPlayers", 0)), + "players": players, + "bots": None, + "connect": f"{host}:{port}", + "ping": ping, + "raw": { + "version": status.version, + "server": status.server, + "map": status.map + } + } + + return result \ No newline at end of file From 9fb08e2f5a1bc3cdc04f16def1f1ecfff9953b3c Mon Sep 17 00:00:00 2001 From: Hornochs Date: Thu, 23 Jan 2025 15:03:00 +0100 Subject: [PATCH 2/4] Adding new Element to ask necessary Username / Passwort for querying TMNF Server --- discordgsm/main.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/discordgsm/main.py b/discordgsm/main.py index fa3f6c2..2bda4f3 100644 --- a/discordgsm/main.py +++ b/discordgsm/main.py @@ -263,6 +263,11 @@ def query_server_modal(game: GamedigGame, locale: Locale): elif game['id'] == 'teamspeak3': query_extra['voice_port'] = TextInput(label='Voice Port', placeholder='Voice port', default=9987) modal.add_item(query_extra['voice_port']) + elif game['id'] == 'tmnf': + query_extra['username'] = TextInput(label='Username', placeholder='Query Username', default="User") + query_extra['password'] = TextInput(label='Password', placeholder='Query Password', default="User", style=TextStyle.short) + modal.add_item(query_extra['username']) + modal.add_item(query_extra['password']) return modal, query_param, query_extra From 41cb7cbd4444015f473a1b85d654701044613566 Mon Sep 17 00:00:00 2001 From: Hornochs Date: Thu, 23 Jan 2025 15:25:29 +0100 Subject: [PATCH 3/4] Fixing main.py for wrong style --- discordgsm/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discordgsm/main.py b/discordgsm/main.py index 2bda4f3..4a443a6 100644 --- a/discordgsm/main.py +++ b/discordgsm/main.py @@ -215,7 +215,7 @@ async def send_alert(server: Server, alert: Alert): content = None if not content else content username = 'Game Server Monitor Alert' avatar_url = 'https://avatars.githubusercontent.com/u/61296017' - + async with aiohttp.ClientSession() as session: webhook = Webhook.from_url(webhook_url, session=session) await webhook.send(content, username=username, avatar_url=avatar_url, embed=alert_embed(server, alert)) @@ -265,7 +265,7 @@ def query_server_modal(game: GamedigGame, locale: Locale): modal.add_item(query_extra['voice_port']) elif game['id'] == 'tmnf': query_extra['username'] = TextInput(label='Username', placeholder='Query Username', default="User") - query_extra['password'] = TextInput(label='Password', placeholder='Query Password', default="User", style=TextStyle.short) + query_extra['password'] = TextInput(label='Password', placeholder='Query Password', default="User") modal.add_item(query_extra['username']) modal.add_item(query_extra['password']) From 7fde13d21817bd4c671dbadcbfb70c5f8c08e629 Mon Sep 17 00:00:00 2001 From: Hornochs Date: Thu, 23 Jan 2025 16:07:24 +0100 Subject: [PATCH 4/4] updating nadeo Protocol --- discordgsm/protocols/nadeo.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/discordgsm/protocols/nadeo.py b/discordgsm/protocols/nadeo.py index d2f4357..f00225f 100644 --- a/discordgsm/protocols/nadeo.py +++ b/discordgsm/protocols/nadeo.py @@ -35,21 +35,17 @@ async def query(self): }) result: GamedigResult = { - "name": status.server.get("Name", ""), - "map": status.map.get("Name", ""), - "password": bool(status.server.get("Password", False)), + "name": status.server_options.name, + "map": status.map_info.name, + "password": status.server_options.password, "numplayers": len(status.players), "numbots": 0, - "maxplayers": int(status.server.get("CurrentMaxPlayers", 0)), + "maxplayers": status.server_options.max_players, "players": players, - "bots": None, + "bots": [], "connect": f"{host}:{port}", "ping": ping, - "raw": { - "version": status.version, - "server": status.server, - "map": status.map - } + "raw": status.server_options.__dict__ } return result \ No newline at end of file