Skip to content

Commit

Permalink
Resolve some Palworld servers cannot be queried issue
Browse files Browse the repository at this point in the history
  • Loading branch information
BattlefieldDuck committed Feb 8, 2024
1 parent 195f96f commit 3a7967e
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions discordgsm/protocols/palworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from typing import TYPE_CHECKING

import opengsq
from opengsq.protocol_socket import Socket
from opengsq.exceptions.server_not_found_exception import ServerNotFoundException

from discordgsm.protocols.protocol import Protocol

Expand Down Expand Up @@ -46,10 +48,43 @@ async def query(self):
host, port, self._deployment_id, Palworld._access_token, self.timeout
)
start = time.time()
info = await eos.get_info()

try:
# Filter the servers by ADDRESS_s and (ADDRESSBOUND_s or GAMESERVER_PORT_l)
# Most of the Palworld servers work
info = await eos.get_info()
except ServerNotFoundException:
# Get IP Address
address = await Socket.gethostbyname(host)

# Filter the servers by GAMESERVER_ADDRESS_s and GAMESERVER_PORT_l
matchmaking = await eos.get_matchmaking(
self._deployment_id,
self._access_token,
{
"criteria": [
{
"key": "attributes.GAMESERVER_ADDRESS_s",
"op": "EQUAL",
"value": address,
},
{
"key": "attributes.GAMESERVER_PORT_l",
"op": "EQUAL",
"value": port,
},
]
},
)

if matchmaking.count <= 0:
raise ServerNotFoundException()

info = matchmaking.sessions[0]
attributes = dict(info.get("attributes", {}))

ping = int((time.time() - start) * 1000)

attributes = dict(info.get("attributes", {}))
settings = dict(info.get("settings", {}))

result: GamedigResult = {
Expand All @@ -61,7 +96,7 @@ async def query(self):
"maxplayers": settings.get("maxPublicPlayers", 0),
"players": None,
"bots": None,
"connect": attributes.get("ADDRESS_s", "") + ":" + str(port),
"connect": f"{host}:{port}",
"ping": ping,
"raw": info,
}
Expand Down

0 comments on commit 3a7967e

Please sign in to comment.