I am currently working on a project. I want to make a bot feature, which would query the steam servers, to get which players are currently playing on that server. I know you can get it with GetPlayerSummaries(), however that returns only the player name score and time played on the server. As some, who already worked with steam API or server queries will know, that you can kinda hide from people in some games by using Steam Name 123.
Which is why I am looking if there is a possibility to get players playing on that server with their Steam ID's - that way I would love to whitelist who is enemy, friendly etc. Which would give me a possibility to do alert feature in *******. I managed to get the Servers Steam ID, but as from reading Web API documentation I only found the function to find IP by the Server ID. I am currently working with Python 3.5 and using other libraries such as python-valve.
Additional info:
I already tried one method, which should technically is a workaround. I call the players ID to get which server they are playing on, then I call to check if the server is the server which I am checking. I could leave it like that, but I think it is way too slow, especially, checking +50 players every minute or so.
#This gets the basic stats of the server
Code:
def getServerStats(server_address):
playerlist = []
tempstr = ""
with valve.source.a2s.ServerQuerier(server_address) as server:
info = server.info()
players = server.players()
print("{player_count}/{max_players}{server_name}".format(**info))
for player in sorted(players["players"], key=lambda p: p["score"], reverse=True):
if player["name"]:
name = "{name}".format(**player)
seconds = float("{duration}".format(**player))
seconds = round(seconds)
hours = round(int(seconds) / 3600)
minutes = (seconds / 60) - (hours*60)
playerlist.append(name + " - Online: " + "%dhours %dminutes" % (hours,minutes))
print(playerlist)
return playerlist[0::]
These are the options I can get from this call:
Header byte Always equal to 'I' (0x49)
Protocol byte Protocol version used by the server.
Name string Name of the server.
Map string Map the server has currently loaded.
Folder string Name of the folder containing the game files.
Game string Full name of the game.
ID short Steam Application ID of game.
Players byte Number of players on the server.
Max. Players byte Maximum number of players the server reports it can hold.
Bots byte Number of bots on the server.
Server type byte Indicates the type of server:
Environment byte Indicates the operating system of the server:
Visibility byte Indicates whether the server requires a password:
VAC byte Specifies whether the server uses VAC:
And additionally A2S Player:
For every player in "Players" there is this chunk in the response:
Data Type Comment
Index byte Index of player chunk starting from 0.
Name string Name of the player.
Score long Player's score (usually "frags" or "kills".)
Duration float Time (in seconds) player has been connected to the server.
The workaround code, which I talked above:
Code:
def onServer(steamID):
with urlopen(STEAM_GET_PLAYER_SUMMARIES_URL.format(api_key=STEAM_WEB_API_KEY, steamid=steamID)) as response:
profile_info = json.loads(response.read().decode('utf-8'))
print(profile_info)
playerSeenOn = profile_info['response']['players'][0]['gameserverip']
playerSeenOn_serverID = profile_info['response']['players'][0]['gameserversteamid']
print(playerSeenOn_serverID)
temp = playerSeenOn.split(":")
temp_port = temp[1]
server_ip = temp[0]
with urlopen(STEAM_GET_SERVER_PORT.format(ip=server_ip)) as response:
temp_server = json.loads(response.read().decode('utf-8'))
temp = temp_server['response']['servers']
for servers in temp:
if int(servers['gameport']) == int(temp_port):
tmp = str(servers['addr'])
server_port = tmp.split(":")
server_port = server_port[1]
server_adress = (server_ip, int(server_port))
if(getServerStats(server_adress)):
print("Player seen on the server!")
So I am expecting to make something like this(Bear in mind that this photo is not mine, but from this, I know that there is a possibility):