Skip to content

Commit

Permalink
Resolve the issue the Front server cannot query
Browse files Browse the repository at this point in the history
  • Loading branch information
BattlefieldDuck committed Feb 6, 2024
1 parent ff3f764 commit 7642fe0
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions discordgsm/protocols/front.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ class FrontServer:


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

async def query(self):
# old method
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)
Expand All @@ -59,7 +60,8 @@ async def query(self):

return result

# Requires AccessKeyId
# Before Requires AccessKeyId
# 2/7/2024: No need AccessKeyId now
async def pre_query(self):
url = "https://privatelist.playthefront.com/private_list"

Expand Down Expand Up @@ -88,21 +90,16 @@ 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"

host, port = str(self.kv["host"]), int(str(self.kv["port"]))
start = time.time()
source = opengsq.Source(host, port, self.timeout)
info = await source.get_info()
ping = int((time.time() - start) * 1000)

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

if host_address not in Front.master_servers:
raise Exception("Server not found")
Expand All @@ -112,14 +109,14 @@ async def _query(self):
result: GamedigResult = {
"name": server.server_name,
"map": server.info.get("game_map"),
"password": info["Visibility"] != 0,
"password": server.info.get("HasPWD"),
"numplayers": server.online,
"numbots": 0,
"maxplayers": server.info.get("maxplayer"),
"players": None,
"bots": None,
"connect": host_address,
"ping": ping,
"ping": 0,
"raw": server.__dict__,
}

Expand Down

0 comments on commit 7642fe0

Please sign in to comment.