From 83722598633bc231688520a0f8ac6e8ae42c39cc Mon Sep 17 00:00:00 2001 From: Battlefield Duck Date: Thu, 16 Nov 2023 08:52:37 +0800 Subject: [PATCH] Support Ark: Survival Ascended Co-Authored-By: Kozejin <2613841+dkoz@users.noreply.github.com> --- discordgsm/games.csv | 1 + discordgsm/protocols/__init__.py | 1 + discordgsm/protocols/asa.py | 45 ++++++++++++++++++++++++++++++++ requirements.txt | 2 +- 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 discordgsm/protocols/asa.py diff --git a/discordgsm/games.csv b/discordgsm/games.csv index 41330eb..8c2ac79 100644 --- a/discordgsm/games.csv +++ b/discordgsm/games.csv @@ -18,6 +18,7 @@ arma3,ARMA 3 (2013),source,port=2302;port_query_offset=1 armacwa,ARMA: Cold War Assault (2011),gamespy1,port=2302;port_query_offset=1 armar,ARMA: Resistance (2011),gamespy1,port=2302;port_query_offset=1 armareforger,Arma Reforger (2022),source,port=2001;port_query=17777 +asa,Ark: Survival Ascended (2023),asa,port=7777 assettocorsa,Assetto Corsa (2014),assettocorsa,port=9610 atlas,Atlas (2018),source,port=5761;port_query_offset=51800 avp2,Aliens versus Predator 2 (2001),gamespy1,port=27888 diff --git a/discordgsm/protocols/__init__.py b/discordgsm/protocols/__init__.py index 2eed280..21108d2 100644 --- a/discordgsm/protocols/__init__.py +++ b/discordgsm/protocols/__init__.py @@ -1,4 +1,5 @@ # flake8: noqa +from .asa import ASA from .ase import ASE from .assettocorsa import AssettoCorsa from .battlefield import Battlefield diff --git a/discordgsm/protocols/asa.py b/discordgsm/protocols/asa.py new file mode 100644 index 0000000..43efb7a --- /dev/null +++ b/discordgsm/protocols/asa.py @@ -0,0 +1,45 @@ +import time +from typing import TYPE_CHECKING + +import opengsq + +from discordgsm.protocols.protocol import Protocol + +if TYPE_CHECKING: + from discordgsm.gamedig import GamedigResult + + +class ASA(Protocol): + name = 'asa' + + __client_id = 'xyza7891muomRmynIIHaJB9COBKkwj6n' + __client_secret = 'PP5UGxysEieNfSrEicaD1N2Bb3TdXuD7xHYcsdUHZ7s' + __deployment_id = 'ad9a8feffb3b4b2ca315546f038c3ae2' + + async def query(self): + host, port = str(self.kv['host']), int(str(self.kv['port'])) + eos = opengsq.EOS(host, port, self.timeout, self.__client_id, + self.__client_secret, self.__deployment_id) + start = time.time() + info = await eos.get_info() + ping = int((time.time() - start) * 1000) + + # Credits: @dkoz https://github.com/DiscordGSM/GameServerMonitor/pull/54/files + attributes = dict(info.get('attributes', {})) + settings = dict(info.get('settings', {})) + + result: GamedigResult = { + 'name': attributes.get('CUSTOMSERVERNAME_s', 'Unknown Server'), + 'map': attributes.get('MAPNAME_s', 'Unknown Map'), + 'password': attributes.get('SERVERPASSWORD_b', False), + 'numplayers': info.get('totalPlayers', 0), + 'numbots': 0, + 'maxplayers': settings.get('maxPublicPlayers', 0), + 'players': None, + 'bots': None, + 'connect': attributes.get('ADDRESS_s', '') + ':' + str(port), + 'ping': ping, + 'raw': info + } + + return result diff --git a/requirements.txt b/requirements.txt index 33c1f4f..1f94e04 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ backports.zoneinfo==0.2.1;python_version<"3.9" discord.py==2.3.2 flask[async]==3.0.0 gunicorn==21.2.0 -opengsq==2.1.2 +opengsq==2.2.2 psycopg2-binary==2.9.9 pymongo==4.5.0 python-dotenv==1.0.0