diff --git a/opengsq/protocols/palworld.py b/opengsq/protocols/palworld.py index e1e4700..7cdbbee 100644 --- a/opengsq/protocols/palworld.py +++ b/opengsq/protocols/palworld.py @@ -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 @@ -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 @@ -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()) diff --git a/opengsq/responses/palworld/__init__.py b/opengsq/responses/palworld/__init__.py index 2f91dae..2d020e2 100644 --- a/opengsq/responses/palworld/__init__.py +++ b/opengsq/responses/palworld/__init__.py @@ -1 +1,2 @@ from .status import Status +from .player import Player diff --git a/opengsq/responses/palworld/player.py b/opengsq/responses/palworld/player.py new file mode 100644 index 0000000..ffa552b --- /dev/null +++ b/opengsq/responses/palworld/player.py @@ -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."""