Skip to content

Commit 513d5bc

Browse files
Merge pull request #131 from swesner411/palworld
Palworld + opengsq Update
2 parents bc57b95 + 78102b5 commit 513d5bc

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

discordgsm/main.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,13 @@ def query_server_modal(game: GamedigGame, locale: Locale):
264264
modal.remove_item(query_param['port'])
265265
query_param['port']._value = '0'
266266
elif game['id'] == 'teamspeak3':
267-
query_extra['voice_port'] = TextInput(label='Voice Port', placeholder='Voice port', default=9987)
267+
query_extra['voice_port'] = TextInput(label='Voice Port', placeholder='Voice port', default='9987')
268268
modal.add_item(query_extra['voice_port'])
269+
elif game['id'] == 'palworld':
270+
query_extra['api_port'] = TextInput(label='REST API Port', default='8213')
271+
query_extra['admin_password'] = TextInput(label='Admin Password', placeholder='admin')
272+
modal.add_item(query_extra['api_port'])
273+
modal.add_item(query_extra['admin_password'])
269274
elif game['id'] == 'tmnf':
270275
query_extra['username'] = TextInput(label='Username', placeholder='Query Username', default="User")
271276
query_extra['password'] = TextInput(label='Password', placeholder='Query Password', default="User")
@@ -305,7 +310,6 @@ async def modal_on_submit(interaction: Interaction):
305310
return
306311
except database.ServerNotFoundError:
307312
pass
308-
309313
# Query the server
310314
try:
311315
result = await gamedig.run({**{'type': game_id}, **params})

discordgsm/protocols/palworld.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,44 @@
1-
import os
21
import time
32
from typing import TYPE_CHECKING
43

5-
import aiohttp
6-
from opengsq.protocol_socket import Socket
4+
import opengsq
75

86
from discordgsm.protocols.protocol import Protocol
97

108
if TYPE_CHECKING:
119
from discordgsm.gamedig import GamedigResult
1210

13-
1411
class Palworld(Protocol):
1512
name = "palworld"
1613

1714
async def query(self):
18-
host, port = str(self.kv["host"]), int(str(self.kv["port"]))
19-
ip = await Socket.gethostbyname(host)
20-
21-
base_url = os.getenv('OPENGSQ_MASTER_SERVER_URL', 'https://master-server.opengsq.com/').rstrip('/')
22-
url = f"{base_url}/palworld/search?host={ip}&port={port}"
15+
host, port, api_port, admin_password = (
16+
str(self.kv["host"]),
17+
int(str(self.kv["port"])),
18+
int(str(self.kv["api_port"])),
19+
str(self.kv["admin_password"]),
20+
)
21+
palworld = opengsq.Palworld(host, api_port, "admin", admin_password, self.timeout)
2322
start = time.time()
24-
25-
async with aiohttp.ClientSession() as session:
26-
async with session.get(url) as response:
27-
response.raise_for_status()
28-
data: dict = await response.json()
29-
ping = int((time.time() - start) * 1000)
30-
23+
data = await palworld.get_status()
24+
ping = int((time.time() - start) * 1000)
25+
if data.server_name:
26+
status = "online"
27+
else:
28+
status = "offline"
3129
result: GamedigResult = {
32-
"name": data.get("name", ""),
33-
"map": data.get("map_name", ""),
34-
"password": data.get("is_password", False),
35-
"numplayers": data.get("current_players", 0),
30+
"status": status,
31+
"name": data.server_name,
32+
"map": None,
33+
"password": False,
34+
"numplayers": data.num_players,
3635
"numbots": 0,
37-
"maxplayers": data.get("max_players", 0),
36+
"maxplayers": data.max_players,
3837
"players": None,
3938
"bots": None,
4039
"connect": f"{host}:{port}",
4140
"ping": ping,
42-
"raw": data,
41+
"raw": data.__dict__,
4342
}
4443

4544
return result

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ backports.zoneinfo==0.2.1;python_version<"3.9"
33
discord.py==2.3.2
44
flask[async]==3.0.3
55
gunicorn==22.0.0
6-
opengsq==3.1.0
6+
opengsq==3.2.0
77
psycopg2-binary==2.9.9
88
pymongo==4.7.3
99
python-dotenv==1.0.1

0 commit comments

Comments
 (0)