Browse Source

Improved SteamClient

Added setting of cell_id and handling for server list
pull/180/head
philippj 7 years ago
parent
commit
bca39f9d16
  1. 13
      steam/client/__init__.py

13
steam/client/__init__.py

@ -51,6 +51,8 @@ class SteamClient(CMClient, BuiltinBase):
_cm_servers_timestamp = None # used to decide when to update CM list on disk _cm_servers_timestamp = None # used to decide when to update CM list on disk
_reconnect_backoff_c = 0 _reconnect_backoff_c = 0
current_jobid = 0 current_jobid = 0
cell_id = 0
servers = {}
credential_location = None #: location for sentry credential_location = None #: location for sentry
username = None #: username when logged on username = None #: username when logged on
login_key = None #: can be used for subsequent logins (no 2FA code will be required) login_key = None #: can be used for subsequent logins (no 2FA code will be required)
@ -65,6 +67,7 @@ class SteamClient(CMClient, BuiltinBase):
self.on(self.EVENT_RECONNECT, self._handle_disconnect) self.on(self.EVENT_RECONNECT, self._handle_disconnect)
self.on(EMsg.ClientNewLoginKey, self._handle_login_key) self.on(EMsg.ClientNewLoginKey, self._handle_login_key)
self.on(EMsg.ClientUpdateMachineAuth, self._handle_update_machine_auth) self.on(EMsg.ClientUpdateMachineAuth, self._handle_update_machine_auth)
self.on(EMsg.ClientServerList, self._handle_server_list)
#: indicates logged on status. Listen to ``logged_on`` when change to ``True`` #: indicates logged on status. Listen to ``logged_on`` when change to ``True``
self.logged_on = False self.logged_on = False
@ -115,6 +118,13 @@ class SteamClient(CMClient, BuiltinBase):
self.cm_servers.merge_list(data['servers']) self.cm_servers.merge_list(data['servers'])
self._cm_servers_timestamp = int(data['timestamp']) self._cm_servers_timestamp = int(data['timestamp'])
def _handle_server_list(self, msg):
for server in msg.body.servers:
if server.server_type not in self.servers:
self.servers[server.server_type] = []
self.servers[server.server_type].append((ip_from_int(server.server_ip), server.server_port))
def _handle_cm_list(self, msg): def _handle_cm_list(self, msg):
if self._cm_servers_timestamp is None: if self._cm_servers_timestamp is None:
self._cm_servers_timestamp = int(time()) self._cm_servers_timestamp = int(time())
@ -152,6 +162,8 @@ class SteamClient(CMClient, BuiltinBase):
def _handle_disconnect(self, *args): def _handle_disconnect(self, *args):
self.logged_on = False self.logged_on = False
self.current_jobid = 0 self.current_jobid = 0
self.cell_id = 0
self.servers = {}
def _handle_logon(self, msg): def _handle_logon(self, msg):
CMClient._handle_logon(self, msg) CMClient._handle_logon(self, msg)
@ -162,6 +174,7 @@ class SteamClient(CMClient, BuiltinBase):
self._reconnect_backoff_c = 0 self._reconnect_backoff_c = 0
self.logged_on = True self.logged_on = True
self.emit(self.EVENT_LOGGED_ON) self.emit(self.EVENT_LOGGED_ON)
self.cell_id = msg.body.cell_id
return return
# CM kills the connection on error anyway # CM kills the connection on error anyway

Loading…
Cancel
Save