Skip to content

Commit

Permalink
Merge pull request #127 from Hornochs/main
Browse files Browse the repository at this point in the history
Adding Support for Nadeo Games (like Trackmania Nations Forever)
  • Loading branch information
BattlefieldDuck authored Feb 3, 2025
2 parents bddae68 + 7fde13d commit bc57b95
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
1 change: 1 addition & 0 deletions discordgsm/games.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion discordgsm/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -266,6 +266,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

Expand Down
1 change: 1 addition & 0 deletions discordgsm/protocols/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 51 additions & 0 deletions discordgsm/protocols/nadeo.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit bc57b95

Please sign in to comment.