|
|
@ -49,9 +49,10 @@ class GameServers(object): |
|
|
|
|
|
|
|
class SteamGameServers(object): |
|
|
|
def __init__(self, steam): |
|
|
|
self.steam = steam |
|
|
|
self._s = steam |
|
|
|
self._um = steam.unified_messages |
|
|
|
|
|
|
|
def query(self, filter_text, max_servers=10, **kwargs): |
|
|
|
def query(self, filter_text, max_servers=10, timeout=30, **kw): |
|
|
|
r""" |
|
|
|
Query game servers |
|
|
|
|
|
|
@ -62,13 +63,15 @@ class SteamGameServers(object): |
|
|
|
as literal characters (e.g. ``query(r'\appid\730\white\1')``) |
|
|
|
|
|
|
|
:param filter_text: filter for servers |
|
|
|
:type filter_text: str |
|
|
|
:type filter_text: str |
|
|
|
:param max_servers: (optional) number of servers to return |
|
|
|
:type max_servers: int |
|
|
|
:type max_servers: int |
|
|
|
:param timeout: (optional) timeout for request in seconds |
|
|
|
:type timeout: int |
|
|
|
:param app_id: (optional) app id |
|
|
|
:type app_id: int |
|
|
|
:type app_id: int |
|
|
|
:param geo_location_ip: (optional) ip (e.g. '1.2.3.4') |
|
|
|
:type geo_location_ip: str |
|
|
|
:type geo_location_ip: str |
|
|
|
:returns: list of servers, see below. (``None`` is returned steam doesn't respond) |
|
|
|
:rtype: :class:`list`, :class:`None` |
|
|
|
|
|
|
@ -81,15 +84,19 @@ class SteamGameServers(object): |
|
|
|
... |
|
|
|
] |
|
|
|
""" |
|
|
|
if 'geo_location_ip' in kwargs: |
|
|
|
kwargs['geo_location_ip'] = ip_to_int(kwargs['geo_location_ip']) |
|
|
|
if 'geo_location_ip' in kw: |
|
|
|
kw['geo_location_ip'] = ip_to_int(kw['geo_location_ip']) |
|
|
|
|
|
|
|
kwargs['filter_text'] = filter_text |
|
|
|
kwargs['max_servers'] = max_servers |
|
|
|
kw['filter_text'] = filter_text |
|
|
|
kw['max_servers'] = max_servers |
|
|
|
|
|
|
|
resp = self.steam.send_job_and_wait(MsgProto(EMsg.ClientGMSServerQuery), kwargs, timeout=30) |
|
|
|
resp = self._s.send_job_and_wait(MsgProto(EMsg.ClientGMSServerQuery), |
|
|
|
kw, |
|
|
|
timeout=timeout, |
|
|
|
) |
|
|
|
|
|
|
|
if resp is None: return None |
|
|
|
if resp is None: |
|
|
|
return None |
|
|
|
|
|
|
|
resp = proto_to_dict(resp) |
|
|
|
|
|
|
@ -98,16 +105,19 @@ class SteamGameServers(object): |
|
|
|
|
|
|
|
return resp['servers'] |
|
|
|
|
|
|
|
def get_server_list(self, filter_text, max_servers=10): |
|
|
|
def get_server_list(self, filter_text, max_servers=10, timeout=20): |
|
|
|
""" |
|
|
|
Get list of servers. Works similiarly to :meth:`query`, but the response has more details. |
|
|
|
|
|
|
|
:param filter_text: filter for servers |
|
|
|
:type filter_text: str |
|
|
|
:type filter_text: str |
|
|
|
:param max_servers: (optional) number of servers to return |
|
|
|
:type max_servers: int |
|
|
|
:type max_servers: int |
|
|
|
:param timeout: (optional) timeout for request in seconds |
|
|
|
:type timeout: int |
|
|
|
:returns: list of servers, see below. (``None`` is returned steam doesn't respond) |
|
|
|
:rtype: :class:`list`, :class:`None` |
|
|
|
:raises: :class:`.UnifiedMessageError` |
|
|
|
|
|
|
|
|
|
|
|
Sample response: |
|
|
@ -133,11 +143,16 @@ class SteamGameServers(object): |
|
|
|
'version': '1.35.4.0'} |
|
|
|
] |
|
|
|
""" |
|
|
|
resp = self.steam.unified_messages.send_and_wait("GameServers.GetServerList#1", { |
|
|
|
"filter": filter_text, |
|
|
|
"limit": max_servers, |
|
|
|
}, timeout=20) |
|
|
|
|
|
|
|
resp, error = self._um.send_and_wait("GameServers.GetServerList#1", |
|
|
|
{ |
|
|
|
"filter": filter_text, |
|
|
|
"limit": max_servers, |
|
|
|
}, |
|
|
|
timeout=20, |
|
|
|
) |
|
|
|
|
|
|
|
if error: |
|
|
|
raise error |
|
|
|
if resp is None: |
|
|
|
return None |
|
|
|
|
|
|
@ -151,13 +166,16 @@ class SteamGameServers(object): |
|
|
|
|
|
|
|
return resp['servers'] |
|
|
|
|
|
|
|
def get_ips_from_steamid(self, server_steam_ids): |
|
|
|
def get_ips_from_steamids(self, server_steam_ids, timeout=30): |
|
|
|
"""Resolve IPs from SteamIDs |
|
|
|
|
|
|
|
:param server_steam_ids: a list of steamids |
|
|
|
:type server_steam_ids: list |
|
|
|
:type server_steam_ids: list |
|
|
|
:param timeout: (optional) timeout for request in seconds |
|
|
|
:type timeout: int |
|
|
|
:return: map of ips to steamids |
|
|
|
:rtype: dict |
|
|
|
:raises: :class:`.UnifiedMessageError` |
|
|
|
|
|
|
|
Sample response: |
|
|
|
|
|
|
@ -165,21 +183,27 @@ class SteamGameServers(object): |
|
|
|
|
|
|
|
{SteamID(id=123456, type='AnonGameServer', universe='Public', instance=1234): '1.2.3.4:27060'} |
|
|
|
""" |
|
|
|
resp = self.steam.unified_messages.send_and_wait("GameServers.GetServerIPsBySteamID#1", { |
|
|
|
"server_steamids": server_steam_ids, |
|
|
|
}, timeout=30) |
|
|
|
|
|
|
|
if resp is None: return None |
|
|
|
resp, error = self._um.send_and_wait("GameServers.GetServerIPsBySteamID#1", |
|
|
|
{"server_steamids": server_steam_ids}, |
|
|
|
timeout=timeout, |
|
|
|
) |
|
|
|
if error: |
|
|
|
raise error |
|
|
|
if resp is None: |
|
|
|
return None |
|
|
|
|
|
|
|
return {SteamID(server.steamid): server.addr for server in resp.servers} |
|
|
|
|
|
|
|
def get_steamids_from_ip(self, server_ips): |
|
|
|
def get_steamids_from_ips(self, server_ips, timeout=30): |
|
|
|
"""Resolve SteamIDs from IPs |
|
|
|
|
|
|
|
:param steam_ids: a list of ips (e.g. ``['1.2.3.4:27015',...]``) |
|
|
|
:type steam_ids: list |
|
|
|
:type steam_ids: list |
|
|
|
:param timeout: (optional) timeout for request in seconds |
|
|
|
:type timeout: int |
|
|
|
:return: map of steamids to ips |
|
|
|
:rtype: dict |
|
|
|
:raises: :class:`.UnifiedMessageError` |
|
|
|
|
|
|
|
Sample response: |
|
|
|
|
|
|
@ -187,10 +211,14 @@ class SteamGameServers(object): |
|
|
|
|
|
|
|
{'1.2.3.4:27060': SteamID(id=123456, type='AnonGameServer', universe='Public', instance=1234)} |
|
|
|
""" |
|
|
|
resp = self.steam.unified_messages.send_and_wait("GameServers.GetServerSteamIDsByIP#1", { |
|
|
|
"server_ips": server_ips, |
|
|
|
}, timeout=30) |
|
|
|
resp, error = self._um.send_and_wait("GameServers.GetServerSteamIDsByIP#1", |
|
|
|
{"server_ips": server_ips}, |
|
|
|
timeout=timeout, |
|
|
|
) |
|
|
|
|
|
|
|
if resp is None: return None |
|
|
|
if error: |
|
|
|
raise error |
|
|
|
if resp is None: |
|
|
|
return None |
|
|
|
|
|
|
|
return {server.addr: SteamID(server.steamid) for server in resp.servers} |
|
|
|