Skip to content

Commit

Permalink
Update front.py
Browse files Browse the repository at this point in the history
  • Loading branch information
BattlefieldDuck committed Dec 3, 2023
1 parent f6bbc5a commit 2935719
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions discordgsm/protocols/front.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
from dataclasses import dataclass
import json
import time
Expand Down Expand Up @@ -31,10 +32,34 @@ class FrontServer:


class Front(Protocol):
pre_query_required = True
pre_query_required = False
name = 'front'
master_servers = None

async def query(self):
host, port = str(self.kv['host']), int(str(self.kv['port']))
start = time.time()
source = opengsq.Source(host, port, self.timeout)
info, rules = await asyncio.gather(source.get_info(), source.get_rules())
ping = int((time.time() - start) * 1000)

result: GamedigResult = {
'name': rules.get('ServerName_s'),
'map': info['Map'],
'password': info['Visibility'] != 0,
'numplayers': info['Players'],
'numbots': info['Bots'],
'maxplayers': info['MaxPlayers'],
'players': None,
'bots': None,
'connect': f'{host}:{info["GamePort"]}',
'ping': ping,
'raw': info
}

return result

# Requires AccessKeyId
async def pre_query(self):
url = 'https://privatelist.playthefront.com/private_list'

Expand All @@ -60,7 +85,7 @@ async def pre_query(self):

return Front.master_servers

async def query(self):
async def _query(self):
if Front.master_servers is None:
await self.pre_query()
assert Front.master_servers is not None, "Front.master_servers is still None after pre_query"
Expand Down Expand Up @@ -97,8 +122,6 @@ async def query(self):


if __name__ == '__main__':
import asyncio

async def main():
front = Front({'host': '', 'port': 27015})
print(await front.query())
Expand Down

0 comments on commit 2935719

Please sign in to comment.