Skip to content

Commit

Permalink
Update protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
BattlefieldDuck committed Jan 28, 2024
1 parent 1aa7f15 commit a20d133
Show file tree
Hide file tree
Showing 27 changed files with 174 additions and 141 deletions.
11 changes: 5 additions & 6 deletions discordgsm/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,12 @@ def query_server_modal(game: GamedigGame, locale: Locale):
query_extra['_token'] = TextInput(label='REST user token')
modal.add_item(query_extra['_token'])
elif game['id'] == 'scpsl':
query_extra['_servername'] = TextInput(label='Server name')
query_extra['_token'] = TextInput(label='API Key')
query_extra['_accountid'] = TextInput(label='Account ID')
modal.add_item(query_extra['_token']).add_item(query_extra['_accountid']).add_item(query_extra['_servername'])
modal.remove_item(query_param['port']).remove_item(query_param['host'])
query_param['port']._value = '0'
query_extra['_api_key'] = TextInput(label='API Key')
query_extra['_account_id'] = TextInput(label='Account ID')
modal.add_item(query_extra['_api_key']).add_item(query_extra['_account_id'])
modal.remove_item(query_param['host']).remove_item(query_param['port'])
query_param['host']._value = 'api.scpslgame.com'
query_param['port']._value = '0'
elif game['id'] == 'gportal':
query_extra['serverId'] = TextInput(label='GPORTAL server id')
modal.add_item(query_extra['serverId'])
Expand Down
2 changes: 1 addition & 1 deletion discordgsm/protocols/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from .raknet import Raknet
from .samp import Samp
from .satisfactory import Satisfactory
from .scpsl import SCP_SL
from .scpsl import SCPSL
from .scum import Scum
from .source import Source
from .teamspeak3 import Teamspeak3
Expand Down
21 changes: 19 additions & 2 deletions discordgsm/protocols/asa.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,33 @@


class ASA(Protocol):
pre_query_required = True
name = 'asa'
__access_token = ''

__client_id = 'xyza7891muomRmynIIHaJB9COBKkwj6n'
__client_secret = 'PP5UGxysEieNfSrEicaD1N2Bb3TdXuD7xHYcsdUHZ7s'
__deployment_id = 'ad9a8feffb3b4b2ca315546f038c3ae2'
__grant_type = "client_credentials"
__external_auth_type = ""
__external_auth_token = ""

async def pre_query(self):
self.__access_token = await opengsq.EOS.get_access_token(
client_id=self.__client_id,
client_secret=self.__client_secret,
deployment_id=self.__deployment_id,
grant_type=self.__grant_type,
external_auth_type=self.__external_auth_type,
external_auth_token=self.__external_auth_token,
)

async def query(self):
if not self.__access_token:
await self.pre_query()

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)
eos = opengsq.EOS(host, port, self.__deployment_id, self.__access_token, self.timeout)
start = time.time()
info = await eos.get_info()
ping = int((time.time() - start) * 1000)
Expand Down
16 changes: 8 additions & 8 deletions discordgsm/protocols/ase.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ async def query(self):
ping = int((time.time() - start) * 1000)

result: GamedigResult = {
'name': status['hostname'],
'map': status['map'] if status['map'] != 'None' else '',
'password': int(status['password']) != 0,
'numplayers': int(status['numplayers']),
'name': status.hostname,
'map': status.map if status.map != 'None' else '',
'password': status.password,
'numplayers': status.num_players,
'numbots': 0,
'maxplayers': int(status['maxplayers']),
'players': [{'name': player['name'], 'raw': player} for player in status['players']],
'maxplayers': status.max_players,
'players': [{'name': player.name, 'raw': player.__dict__} for player in status.players],
'bots': None,
'connect': f"{host}:{status.get('gameport', port)}",
'connect': f"{host}:{status.game_port}",
'ping': ping,
'raw': status
'raw': status.__dict__
}

return result
14 changes: 7 additions & 7 deletions discordgsm/protocols/battlefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ async def query(self):
ping = int((time.time() - start) * 1000)

result: GamedigResult = {
'name': info['hostname'],
'map': info['map'],
'password': info['password'],
'numplayers': info['numplayers'],
'name': info.hostname,
'map': info.map,
'password': info.password,
'numplayers': info.num_players,
'numbots': 0,
'maxplayers': info['maxplayers'],
'maxplayers': info.max_players,
'players': [{'name': player['name'], 'raw': player} for player in players],
'bots': None,
'connect': info['ip_port'],
'connect': info.ip_port,
'ping': ping,
'raw': info
'raw': info.__dict__
}

return result
4 changes: 2 additions & 2 deletions discordgsm/protocols/beammp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import TYPE_CHECKING

import aiohttp
from opengsq.socket_async import SocketAsync
from opengsq.protocol_socket import Socket

from discordgsm.protocols.protocol import Protocol

Expand Down Expand Up @@ -38,7 +38,7 @@ async def query(self):
await self.pre_query()

host, port = str(self.kv['host']), int(str(self.kv['port']))
ip = await SocketAsync.gethostbyname(host)
ip = await Socket.gethostbyname(host)
key = f'{ip}:{port}'

if key not in BeamMP.master_servers:
Expand Down
4 changes: 2 additions & 2 deletions discordgsm/protocols/factorio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import TYPE_CHECKING

import aiohttp
from opengsq.socket_async import SocketAsync
from opengsq.protocol_socket import Socket

from discordgsm.environment import env
from discordgsm.protocols.protocol import Protocol
Expand Down Expand Up @@ -40,7 +40,7 @@ async def query(self):
await self.pre_query()

host, port = str(self.kv['host']), int(str(self.kv['port']))
ip = await SocketAsync.gethostbyname(host)
ip = await Socket.gethostbyname(host)
host_address = f'{ip}:{port}'

if host_address not in Factorio.master_servers:
Expand Down
4 changes: 2 additions & 2 deletions discordgsm/protocols/front.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import aiohttp
import opengsq
from opengsq.socket_async import SocketAsync
from opengsq.protocol_socket import Socket

if __name__ == '__main__':
from protocol import Protocol
Expand Down Expand Up @@ -96,7 +96,7 @@ async def _query(self):
info = await source.get_info()
ping = int((time.time() - start) * 1000)

ip = await SocketAsync.gethostbyname(host)
ip = await Socket.gethostbyname(host)
host_address = f'{ip}:{info["GamePort"]}'

if host_address not in Front.master_servers:
Expand Down
4 changes: 2 additions & 2 deletions discordgsm/protocols/gamespy1.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ async def query(self):
start = time.time()
status = await gamespy1.get_status()
ping = int((time.time() - start) * 1000)
info = dict(status['info'])
players = status['players']
info = status.info
players = status.players
password = str(info.get('password', '0')).lower()

# Fix bf1942 0 numplayers still contains player on player list issue
Expand Down
4 changes: 2 additions & 2 deletions discordgsm/protocols/gamespy2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ async def query(self):
start = time.time()
status = await gamespy2.get_status()
ping = int((time.time() - start) * 1000)
info = dict(status['info'])
players = status['players']
info = status.info
players = status.players
password = str(info.get('password', '0')).lower()

result: GamedigResult = {
Expand Down
4 changes: 2 additions & 2 deletions discordgsm/protocols/hexen2.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ async def query(self):
start = time.time()
status = await quake1.get_status()
ping = int((time.time() - start) * 1000)
info = dict(status['info'])
info = status.info
players = []
bots = []

for player in status['players']:
for player in status.players:
(bots if player['ping'] == 0 else players).append({'name': player['name'], 'raw': player})

result: GamedigResult = {
Expand Down
4 changes: 2 additions & 2 deletions discordgsm/protocols/nwn1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import TYPE_CHECKING

import aiohttp
from opengsq.socket_async import SocketAsync
from opengsq.protocol_socket import Socket

from discordgsm.protocols.protocol import Protocol

Expand Down Expand Up @@ -53,7 +53,7 @@ async def query(self):
await self.pre_query()

host, port = str(self.kv['host']), int(str(self.kv['port']))
ip = await SocketAsync.gethostbyname(host)
ip = await Socket.gethostbyname(host)
key = f'{ip}:{port}'

if key not in NWN1.master_servers:
Expand Down
4 changes: 2 additions & 2 deletions discordgsm/protocols/nwn2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import TYPE_CHECKING

import aiohttp
from opengsq.socket_async import SocketAsync
from opengsq.protocol_socket import Socket

from discordgsm.protocols.protocol import Protocol

Expand Down Expand Up @@ -53,7 +53,7 @@ async def query(self):
await self.pre_query()

host, port = str(self.kv['host']), int(str(self.kv['port']))
ip = await SocketAsync.gethostbyname(host)
ip = await Socket.gethostbyname(host)
key = f'{ip}:{port}'

if key not in NWN2.master_servers:
Expand Down
6 changes: 3 additions & 3 deletions discordgsm/protocols/quake1.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ async def query(self):
start = time.time()
status = await quake1.get_status()
ping = int((time.time() - start) * 1000)
info = dict(status['info'])
info = status.info
players = []
bots = []

for player in status['players']:
(bots if player['ping'] == 0 else players).append({'name': player['name'], 'raw': player})
for player in status.players:
(bots if player.ping == 0 else players).append({'name': player.name, 'raw': player.__dict__})

result: GamedigResult = {
'name': info.get('hostname', info.get('sv_hostname', '')),
Expand Down
6 changes: 3 additions & 3 deletions discordgsm/protocols/quake2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ async def query(self):
start = time.time()
status = await quake2.get_status()
ping = int((time.time() - start) * 1000)
info = dict(status['info'])
info = status.info
players = []
bots = []

for player in status['players']:
(bots if player['ping'] == 0 else players).append({'name': player['name'], 'raw': player})
for player in status.players:
(bots if player.ping == 0 else players).append({'name': player.name, 'raw': player.__dict__})

result: GamedigResult = {
'name': info.get('hostname', info.get('sv_hostname', '')),
Expand Down
6 changes: 3 additions & 3 deletions discordgsm/protocols/quake3.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ async def query(self):
start = time.time()
status = await quake3.get_status(strip_color=True)
ping = int((time.time() - start) * 1000)
info = dict(status['info'])
info = status.info
players = []
bots = []

for player in status['players']:
(bots if player['ping'] == 0 else players).append({'name': player['name'], 'raw': player})
for player in status.players:
(bots if player.ping == 0 else players).append({'name': player.name, 'raw': player.__dict__})

result: GamedigResult = {
'name': info.get('hostname', info.get('sv_hostname', '')),
Expand Down
12 changes: 6 additions & 6 deletions discordgsm/protocols/raknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ class Raknet(Protocol):

async def query(self):
host, port = str(self.kv['host']), int(str(self.kv['port']))
raknet = opengsq.Raknet(host, port, self.timeout)
raknet = opengsq.RakNet(host, port, self.timeout)
start = time.time()
status = await raknet.get_status()
ping = int((time.time() - start) * 1000)

result: GamedigResult = {
'name': status.get('motd_line_1', ''),
'map': status.get('motd_line_2', ''),
'name': status.motd_line1,
'map': status.motd_line2,
'password': False,
'numplayers': int(status.get('num_players', '')),
'numplayers': status.num_players,
'numbots': 0,
'maxplayers': int(status.get('max_players', '')),
'maxplayers': status.max_players,
'players': None,
'bots': None,
'connect': f"{host}:{status.get('port_ipv4', port)}",
'connect': f"{host}:{status.port_ipv4}",
'ping': ping,
'raw': status
}
Expand Down
10 changes: 5 additions & 5 deletions discordgsm/protocols/samp.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ async def get_players():
ping = int((time.time() - start) * 1000)

result: GamedigResult = {
'name': status['servername'],
'name': status.server_name,
'map': rules.get('mapname', ''),
'password': status['password'] == 1,
'password': status.password,
'numplayers': len(players),
'numbots': 0,
'maxplayers': status['maxplayers'],
'players': [{'name': player['name'], 'raw': player} for player in players],
'maxplayers': status.max_players,
'players': [{'name': player.name, 'raw': player.__dict__} for player in players],
'bots': None,
'connect': f'{host}:{port}',
'ping': ping,
'raw': {
'info': status,
'info': status.__dict__,
'rules': rules
}
}
Expand Down
2 changes: 1 addition & 1 deletion discordgsm/protocols/satisfactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def query(self):
'bots': None,
'connect': f'{host}:{port}',
'ping': ping,
'raw': status
'raw': status.__dict__
}

return result
Loading

0 comments on commit a20d133

Please sign in to comment.