Skip to content

Commit

Permalink
Merge pull request #33 from swesner411/palworld-players
Browse files Browse the repository at this point in the history
Palworld Players Support
  • Loading branch information
BattlefieldDuck authored Feb 14, 2025
2 parents 70dc359 + 7311d29 commit 5522524
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
16 changes: 15 additions & 1 deletion opengsq/protocols/palworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import time
import aiohttp

from opengsq.responses.palworld import Status
from opengsq.responses.palworld import Player, Status
from opengsq.protocol_base import ProtocolBase


Expand Down Expand Up @@ -62,6 +62,18 @@ async def get_status(self) -> Status:
max_players=server_max_players,
)

async def get_players(self) -> list[Player]:
players = []
player_data = await self.api_request(f"{self.api_url}/players")
for obj in player_data["players"]:
players.append(
Player(
name=obj["name"],
ping=obj["ping"],
level=obj["level"],
)
)
return players

if __name__ == "__main__":
import asyncio
Expand All @@ -76,5 +88,7 @@ async def main_async():
)
status = await palworld.get_status()
print(status)
players = await palworld.get_players()
print(players)

asyncio.run(main_async())
1 change: 1 addition & 0 deletions opengsq/responses/palworld/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .status import Status
from .player import Player
16 changes: 16 additions & 0 deletions opengsq/responses/palworld/player.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from dataclasses import dataclass

@dataclass
class Player:
"""
Represents a player in the game.
"""

name: str
"""The player's name."""

ping: int
"""The player's ping."""

level: int
"""The player's level."""

0 comments on commit 5522524

Please sign in to comment.