Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sampquery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .client import SAMPQuery_Client

__name__ = "sampquery"
__version__ = "0.0.1"
__version__ = "0.0.8"
__author__ = "larayavrs"
__email__ = "larayavrs@gmail.com"

Expand Down
48 changes: 47 additions & 1 deletion sampquery/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,50 @@ async def rcon(self, command: str) -> str:
except TimeoutError as e:
raise TimeoutError(
"Failed to retrieve RCON response due to a timeout. The server may be unresponsive."
) from e
) from e

async def ping_history(self, samples: int = 5, interval: float = 1.0) -> list[float]:
"""
Perform multiple ping measurements to the server and return a list with the results.

:param samples: Number of measurements to perform.
:param interval: Interval in seconds between each measurement.
:return: List of ping times (in seconds).
"""
results = []
for _ in range(samples):
ping = await self.__ping()
results.append(ping)
if _ < samples - 1:
await trio.sleep(interval)
return results

async def server_version(self) -> str:
"""
Retrieve the server version.

:return str: The server version.
"""
info = await self.info()
return getattr(
info, "version", "Unknown"
)

async def players_with_score(self, min_score: int = 0) -> list:
"""
Returns a list of players whose score is greater than or equal to min_score.

:param min_score: Minimum required score.
:return: List of players that meet the criteria.
"""
players = await self.detailed_players()
return [p for p in players if getattr(p, "score", 0) >= min_score]

async def free_slots(self) -> int:
"""
Returns the number of free slots on the server.

:return: Number of free slots.
"""
info = await self.info()
return getattr(info, "max_players", 0) - getattr(info, "players", 0)