Browse Source

SteamClient: login() now returns LogOn eresult

pull/55/head
Rossen Georgiev 9 years ago
parent
commit
610de3dd8a
  1. 28
      recipes/1.Login/persistent_login.py
  2. 18
      steam/client/__init__.py

28
recipes/1.Login/persistent_login.py

@ -9,11 +9,10 @@ LOG = logging.getLogger()
LOG.info("Persistent logon recipe")
LOG.info("-"*30)
logon_details = {
LOGON_DETAILS = {
"username": raw_input("Steam user: "),
"password": getpass("Password: "),
}
logged_on_once = False
client = SteamClient()
client.set_credential_location(".")
@ -26,10 +25,10 @@ def handle_error(result):
def send_login():
if client.relogin_available:
client.relogin()
else:
client.login(**logon_details)
logon_details.pop('auth_code', None)
logon_details.pop('two_factor_code', None)
@client.on("new_login_key")
def got_login_key():
LOG.info("got new login key")
@client.on("connected")
def handle_connected():
@ -43,9 +42,8 @@ def handle_reconnect(delay):
def handle_disconnect():
LOG.info("Disconnected.")
if logged_on_once:
LOG.info("Reconnecting...")
client.reconnect(maxdelay=30)
LOG.info("Reconnecting...")
client.reconnect(maxdelay=30)
@client.on("auth_code_required")
def auth_code_prompt(is_2fa, mismatch):
@ -54,18 +52,13 @@ def auth_code_prompt(is_2fa, mismatch):
if is_2fa:
code = raw_input("Enter 2FA Code: ")
logon_details['two_factor_code'] = code
client.login(two_factor_code=code, **LOGON_DETAILS)
else:
code = raw_input("Enter Email Code: ")
logon_details['auth_code'] = code
client.connect()
client.login(auth_code=code, **LOGON_DETAILS)
@client.on("logged_on")
def handle_after_logon():
global logged_on_once
logged_on_once = True
LOG.info("-"*30)
LOG.info("Logged on as: %s", client.user.name)
LOG.info("Community profile: %s", client.steam_id.community_url)
@ -76,10 +69,9 @@ def handle_after_logon():
try:
client.connect()
client.login(**LOGON_DETAILS)
client.run_forever()
except KeyboardInterrupt:
if client.connected:
logged_on_once = False
LOG.info("Logout")
client.logout()

18
steam/client/__init__.py

@ -428,8 +428,7 @@ class SteamClient(CMClient, BuiltinBase):
self.login(self.username, '', self.login_key)
def login(self, username, password='', login_key=None, auth_code=None, two_factor_code=None):
"""
Login as a specific user
"""Login as a specific user
:param username: username
:type username: :class:`str`
@ -441,6 +440,8 @@ class SteamClient(CMClient, BuiltinBase):
:type auth_code: :class:`str`
:param two_factor_code: 2FA authentication code
:type two_factor_code: :class:`str`
:return: logon result, see `CMsgClientLogonResponse.eresult <https://github.com/ValvePython/steam/blob/513c68ca081dc9409df932ad86c66100164380a6/protobufs/steammessages_clientserver.proto#L95-L118>`_
:rtype: :class:`.EResult`
.. note::
Failure to login will result in the server dropping the connection, ``error`` event is fired
@ -498,9 +499,14 @@ class SteamClient(CMClient, BuiltinBase):
self.send(message)
resp = self.wait_msg(EMsg.ClientLogOnResponse, timeout=30)
return EResult(resp.body.eresult) if resp else EResult.Fail
def anonymous_login(self):
"""
Login as anonymous user
"""Login as anonymous user
:return: logon result, see `CMsgClientLogonResponse.eresult <https://github.com/ValvePython/steam/blob/513c68ca081dc9409df932ad86c66100164380a6/protobufs/steammessages_clientserver.proto#L95-L118>`_
:rtype: :class:`.EResult`
"""
self._LOG.debug("Attempting Anonymous login")
@ -514,6 +520,9 @@ class SteamClient(CMClient, BuiltinBase):
message.body.protocol_version = 65579
self.send(message)
resp = self.wait_msg(EMsg.ClientLogOnResponse, timeout=30)
return EResult(resp.body.eresult) if resp else EResult.Fail
def logout(self):
"""
Logout from steam. Doesn't nothing if not logged on.
@ -525,6 +534,7 @@ class SteamClient(CMClient, BuiltinBase):
self.logged_on = False
self.send(MsgProto(EMsg.ClientLogOff))
self.wait_event('disconnected')
gevent.idle()
def run_forever(self):
"""

Loading…
Cancel
Save