Skip to content

Commit a27e813

Browse files
committed
fix(cm): Fetches CM server list from WebAPI
ValvePython#474 (comment)
1 parent 371b9c9 commit a27e813

File tree

1 file changed

+14
-36
lines changed

1 file changed

+14
-36
lines changed

steam/core/cm.py

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def connect(self, retry=0, delay=0):
136136
return False
137137

138138
if isinstance(self.connection, WebsocketConnection):
139-
self.cm_servers.bootstrap_from_webapi_websocket()
139+
self.cm_servers.bootstrap_from_webapi(cmtype='websockets')
140140
elif isinstance(self.connection, TCPConnection):
141141
if not self.cm_servers.bootstrap_from_webapi():
142142
self.cm_servers.bootstrap_from_dns()
@@ -484,26 +484,33 @@ def bootstrap_from_dns(self):
484484
self._LOG.error("DNS boostrap: cm0.steampowered.com resolved no A records")
485485
return False
486486

487-
def bootstrap_from_webapi(self, cell_id=0):
487+
def bootstrap_from_webapi(self, cell_id=0, cmtype='netfilter'):
488488
"""
489489
Fetches CM server list from WebAPI and replaces the current one
490490
491491
:param cellid: cell id (0 = global)
492492
:type cellid: :class:`int`
493+
:param cmtype: CM type filter
494+
:type cellid: :class:`str`
493495
:return: booststrap success
494496
:rtype: :class:`bool`
495497
"""
496-
self._LOG.debug("Attempting bootstrap via WebAPI")
498+
self._LOG.debug("Attempting bootstrap via WebAPI for %s" % cmtype)
497499

498500
from steam import webapi
499501
try:
500-
resp = webapi.get('ISteamDirectory', 'GetCMList', 1, params={'cellid': cell_id,
501-
'http_timeout': 3})
502+
resp = webapi.get('ISteamDirectory', 'GetCMListForConnect', 1,
503+
params={
504+
'cellid': cell_id,
505+
'cmtype': cmtype,
506+
'http_timeout': 3
507+
}
508+
)
502509
except Exception as exp:
503510
self._LOG.error("WebAPI boostrap failed: %s" % str(exp))
504511
return False
505512

506-
result = EResult(resp['response']['result'])
513+
result = EResult(resp['response']['success'])
507514

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

515-
def str_to_tuple(serveraddr):
516-
ip, port = serveraddr.split(':')
517-
return str(ip), int(port)
518-
519-
self.clear()
520-
self.cell_id = cell_id
521-
self.merge_list(map(str_to_tuple, serverlist))
522-
523-
return True
524-
525-
def bootstrap_from_webapi_websocket(self):
526-
"""
527-
Fetches CM server list from WebAPI and replaces the current one
528-
529-
:return: booststrap success
530-
:rtype: :class:`bool`
531-
"""
532-
self._LOG.debug("Attempting bootstrap via WebAPI for websocket")
533-
534-
from steam import webapi
535-
try:
536-
resp = webapi.get('ISteamDirectory', 'GetCMListForConnect', 1, params={'cmtype': 'websockets',
537-
'http_timeout': 3})
538-
except Exception as exp:
539-
self._LOG.error("WebAPI boostrap failed: %s" % str(exp))
540-
return False
541-
542-
serverlist = resp['response']['serverlist']
543-
self._LOG.debug("Received %d servers from WebAPI" % len(serverlist))
544-
545522
def str_to_tuple(serverinfo):
546523
ip, port = serverinfo['endpoint'].split(':')
547524
return str(ip), int(port)
548525

549526
self.clear()
527+
self.cell_id = cell_id
550528
self.merge_list(map(str_to_tuple, serverlist))
551529

552530
return True

0 commit comments

Comments
 (0)