Skip to content

Commit

Permalink
fix(cm): Fetches CM server list from WebAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
detiam committed Oct 14, 2024
1 parent 371b9c9 commit a27e813
Showing 1 changed file with 14 additions and 36 deletions.
50 changes: 14 additions & 36 deletions steam/core/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def connect(self, retry=0, delay=0):
return False

if isinstance(self.connection, WebsocketConnection):
self.cm_servers.bootstrap_from_webapi_websocket()
self.cm_servers.bootstrap_from_webapi(cmtype='websockets')
elif isinstance(self.connection, TCPConnection):
if not self.cm_servers.bootstrap_from_webapi():
self.cm_servers.bootstrap_from_dns()
Expand Down Expand Up @@ -484,26 +484,33 @@ def bootstrap_from_dns(self):
self._LOG.error("DNS boostrap: cm0.steampowered.com resolved no A records")
return False

def bootstrap_from_webapi(self, cell_id=0):
def bootstrap_from_webapi(self, cell_id=0, cmtype='netfilter'):
"""
Fetches CM server list from WebAPI and replaces the current one
:param cellid: cell id (0 = global)
:type cellid: :class:`int`
:param cmtype: CM type filter
:type cellid: :class:`str`
:return: booststrap success
:rtype: :class:`bool`
"""
self._LOG.debug("Attempting bootstrap via WebAPI")
self._LOG.debug("Attempting bootstrap via WebAPI for %s" % cmtype)

from steam import webapi
try:
resp = webapi.get('ISteamDirectory', 'GetCMList', 1, params={'cellid': cell_id,
'http_timeout': 3})
resp = webapi.get('ISteamDirectory', 'GetCMListForConnect', 1,
params={
'cellid': cell_id,
'cmtype': cmtype,
'http_timeout': 3
}
)
except Exception as exp:
self._LOG.error("WebAPI boostrap failed: %s" % str(exp))
return False

result = EResult(resp['response']['result'])
result = EResult(resp['response']['success'])

if result != EResult.OK:
self._LOG.error("GetCMList failed with %s" % repr(result))
Expand All @@ -512,41 +519,12 @@ def bootstrap_from_webapi(self, cell_id=0):
serverlist = resp['response']['serverlist']
self._LOG.debug("Received %d servers from WebAPI" % len(serverlist))

def str_to_tuple(serveraddr):
ip, port = serveraddr.split(':')
return str(ip), int(port)

self.clear()
self.cell_id = cell_id
self.merge_list(map(str_to_tuple, serverlist))

return True

def bootstrap_from_webapi_websocket(self):
"""
Fetches CM server list from WebAPI and replaces the current one
:return: booststrap success
:rtype: :class:`bool`
"""
self._LOG.debug("Attempting bootstrap via WebAPI for websocket")

from steam import webapi
try:
resp = webapi.get('ISteamDirectory', 'GetCMListForConnect', 1, params={'cmtype': 'websockets',
'http_timeout': 3})
except Exception as exp:
self._LOG.error("WebAPI boostrap failed: %s" % str(exp))
return False

serverlist = resp['response']['serverlist']
self._LOG.debug("Received %d servers from WebAPI" % len(serverlist))

def str_to_tuple(serverinfo):
ip, port = serverinfo['endpoint'].split(':')
return str(ip), int(port)

self.clear()
self.cell_id = cell_id
self.merge_list(map(str_to_tuple, serverlist))

return True
Expand Down

0 comments on commit a27e813

Please sign in to comment.