Browse Source

Add Account builtin

New methods

* register steam account
* validate email
* change password
* change email
pull/60/merge
Rossen Georgiev 8 years ago
parent
commit
c2ce74b25d
  1. 8
      docs/api/steam.client.builtins.rst
  2. 3
      steam/client/builtins/__init__.py
  3. 130
      steam/client/builtins/account.py
  4. 2
      steam/core/msg/__init__.py
  5. 76
      steam/core/msg/structs.py

8
docs/api/steam.client.builtins.rst

@ -11,6 +11,14 @@ Apps
:undoc-members: :undoc-members:
:show-inheritance: :show-inheritance:
Account
-------
.. automodule:: steam.client.builtins.account
:members:
:undoc-members:
:show-inheritance:
User User
---- ----

3
steam/client/builtins/__init__.py

@ -1,6 +1,7 @@
""" """
All high level features of :class:`steam.client.SteamClient` are implemented here in separate submodules. All high level features of :class:`steam.client.SteamClient` are implemented here in separate submodules.
""" """
from steam.client.builtins.account import Account
from steam.client.builtins.user import User from steam.client.builtins.user import User
from steam.client.builtins.web import Web from steam.client.builtins.web import Web
from steam.client.builtins.unified_messages import UnifiedMessages from steam.client.builtins.unified_messages import UnifiedMessages
@ -9,7 +10,7 @@ from steam.client.builtins.gameservers import GameServers
from steam.client.builtins.friends import Friends from steam.client.builtins.friends import Friends
from steam.client.builtins.apps import Apps from steam.client.builtins.apps import Apps
class BuiltinBase(User, Web, UnifiedMessages, Leaderboards, GameServers, Friends, Apps): class BuiltinBase(Account, User, Web, UnifiedMessages, Leaderboards, GameServers, Friends, Apps):
""" """
This object is used as base to implement all high level functionality. This object is used as base to implement all high level functionality.
The features are separated into submodules. The features are separated into submodules.

130
steam/client/builtins/account.py

@ -0,0 +1,130 @@
from steam.steamid import SteamID
from steam.enums import EResult
from steam.enums.emsg import EMsg
from steam.core.msg import Msg, MsgProto
class Account(object):
def __init__(self, *args, **kwargs):
super(Account, self).__init__(*args, **kwargs)
def create_account(self, account_name, password, email=''):
"""Create a new Steam account
:param account_name: desired account name
:type account_name: :class:`str`
:param password: desired password
:type password: :class:`str`
:param email: desired email
:type email: :class:`str`
:return: (EResult, SteamID)
:rtype: :class:`tuple`
"""
message = MsgProto(EMsg.ClientCreateAccountProto)
message.body.account_name = account_name
message.body.password = password
if email:
message.body.email = email
resp = self.send_job_and_wait(message, timeout=10)
if resp is None:
return EResult.Timeout, None
else:
return EResult(resp.eresult), SteamID(resp.steamid) if resp.steamid else None
def request_validation_mail(self):
"""Request validation email
:return: result
:rtype: :class:`.EResult`
"""
message = Msg(EMsg.ClientRequestValidationMail, extended=True)
resp = self.send_job_and_wait(message, timeout=10)
if resp is None:
return EResult.Timeout
else:
return EResult(resp.eresult)
def request_password_change_mail(self, password):
"""Request password change mail
:param password: current account password
:type password: :class:`str`
:return: result
:rtype: :class:`.EResult`
"""
message = Msg(EMsg.ClientRequestChangeMail, extended=True)
message.body.password = password
resp = self.send_job_and_wait(message, timeout=10)
if resp is None:
return EResult.Timeout
else:
return EResult(resp.eresult)
def change_password(self, password, new_password, email_code):
"""Change account's password
:param password: current account password
:type password: :class:`str`
:param new_password: new account password
:type new_password: :class:`str`
:param email_code: confirmation code from email
:type email_code: :class:`str`
:return: result
:rtype: :class:`.EResult`
.. note::
First request change mail via :meth:`request_password_change_mail()`
to get the email code
"""
message = Msg(EMsg.ClientPasswordChange3, extended=True)
message.body.password = password
message.body.new_password = new_password
message.body.code = email_code
resp = self.send_job_and_wait(message, timeout=10)
if resp is None:
return EResult.Timeout
else:
return EResult(resp.eresult)
def change_email(self, password, email, email_code=''):
"""Change account's email address
:param password: current account password
:type password: :class:`str`
:param new_email: new account email
:type new_email: :class:`str`
:param email_code: email code
:type email_code: :class:`str`
:return: result
:rtype: :class:`.EResult`
.. note::
To change email, first call without ``email_code``
and then with to finalize the change
"""
message = MsgProto(EMsg.ClientEmailChange4)
message.body.password = password
message.body.email = email
if code:
message.body.code = code
message.body.final = not not code
message.body.newmethod = True
message.body.client_supports_sms = True
resp = self.send_job_and_wait(message, timeout=10)
if resp is None:
return EResult.Timeout
else:
return EResult(resp.eresult)

2
steam/core/msg/__init__.py

@ -21,6 +21,8 @@ cmsg_lookup_predefined = {
EMsg.ClientGetNumberOfCurrentPlayersDPResponse: steammessages_clientserver_2_pb2.CMsgDPGetNumberOfCurrentPlayersResponse, EMsg.ClientGetNumberOfCurrentPlayersDPResponse: steammessages_clientserver_2_pb2.CMsgDPGetNumberOfCurrentPlayersResponse,
EMsg.ClientCreateAccountProto: steammessages_clientserver_2_pb2.CMsgClientCreateAccount, EMsg.ClientCreateAccountProto: steammessages_clientserver_2_pb2.CMsgClientCreateAccount,
EMsg.ClientCreateAccountProtoResponse: steammessages_clientserver_2_pb2.CMsgClientCreateAccountResponse, EMsg.ClientCreateAccountProtoResponse: steammessages_clientserver_2_pb2.CMsgClientCreateAccountResponse,
EMsg.ClientEmailChange4: steammessages_clientserver_2_pb2.CMsgClientEmailChange,
EMsg.ClientEmailChangeResponse4: steammessages_clientserver_2_pb2.CMsgClientEmailChangeResponse,
} }
def get_cmsg(emsg): def get_cmsg(emsg):

76
steam/core/msg/structs.py

@ -351,3 +351,79 @@ class ClientChatEnter(StructMessage):
"numMembers: %r" % self.numMembers, "numMembers: %r" % self.numMembers,
"chatRoomName: %s" % repr(self.chatRoomName), "chatRoomName: %s" % repr(self.chatRoomName),
] + map(lambda x: "memberList: %s" % x, self.memberList)) ] + map(lambda x: "memberList: %s" % x, self.memberList))
##################################################################################################
class _ResultStruct(StructMessage):
eresult = EResult.Invalid
def serialize(self):
return struct.pack("<I", self.eresult)
def load(self, data):
eresult, = struct.unpack_from("<I", data)
self.eresult = EResult(eresult)
def __str__(self):
return "eresult: %s" % repr(self.eresult)
##################################################################################################
class ClientRequestValidationMail(StructMessage):
UNKNOWN1 = b'\x00'
def serialize(self):
return self.UNKNOWN1
def load(self, data):
self.UNKNOWN1 = data
def __str__(self):
return "UNKNOWN1: %s" % repr(self.UNKNOWN1)
class ClientRequestValidationMailResponse(_ResultStruct):
pass
##################################################################################################
class ClientRequestChangeMail(StructMessage):
password = ''
UNKNOWN1 = 0
def serialize(self):
return struct.pack("<81sI", self.password[:80].encode('ascii'), self.UNKNOWN1)
def __str__(self):
return '\n'.join(["password: %s" % repr(self.password),
"UNKNOWN1: %d" % self.UNKNOWN1,
])
class ClientRequestChangeMailResponse(_ResultStruct):
pass
##################################################################################################
class ClientPasswordChange3(StructMessage):
password = ''
new_password = ''
code = ''
def serialize(self):
return (b'\x00'
+ self.password.encode('ascii') + b'\x00'
+ self.new_password.encode('ascii') + b'\x00'
+ self.code.encode('ascii') + b'\x00'
)
def __str__(self):
return '\n'.join(["password: %s" % repr(self.password),
"new_password: %s" % repr(self.new_password),
"code: %s" % repr(self.code),
])
class ClientPasswordChangeResponse(_ResultStruct):
pass

Loading…
Cancel
Save