DeaD_EyE

srcds query simple

Jul 1st, 2022 (edited)
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. """
  2. https://python-valve.readthedocs.io/en/latest/index.html
  3. """
  4. from unicodedata import normalize
  5. from valve.source.a2s import ServerQuerier
  6.  
  7.  
  8. def query(ip, port=None):
  9.     if ":" in ip and port is None:
  10.         ip, port = ip.split(":")
  11.         port = int(port)
  12.  
  13.     with ServerQuerier((ip, port)) as server:
  14.         info = server.info()
  15.         players = server.players()
  16.  
  17.     players = [
  18.         (normalize("NFKC", player["name"]), player["score"])
  19.         for player in sorted(players["players"], key=lambda i: i["score"], reverse=True)
  20.     ]
  21.  
  22.     print(info["server_name"])
  23.     print("Max players:", info["max_players"])
  24.     print("Current Players:", len(players))
  25.     print("="*30)
  26.  
  27.     for player, score in players:
  28.         print(player.ljust(25), str(score).rjust(4))
  29.  
  30.  
  31. query("5.9.8.124:10032")
Add Comment
Please, Sign In to add comment