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/main.py b/discordgsm/main.py index fa3f6c2..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)) @@ -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") + modal.add_item(query_extra['username']) + modal.add_item(query_extra['password']) return modal, query_param, query_extra 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..f00225f --- /dev/null +++ b/discordgsm/protocols/nadeo.py @@ -0,0 +1,51 @@ +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_options.name, + "map": status.map_info.name, + "password": status.server_options.password, + "numplayers": len(status.players), + "numbots": 0, + "maxplayers": status.server_options.max_players, + "players": players, + "bots": [], + "connect": f"{host}:{port}", + "ping": ping, + "raw": status.server_options.__dict__ + } + + return result \ No newline at end of file