From c2ce74b25dd1038629857da50d168c4ffa8ddc7b Mon Sep 17 00:00:00 2001 From: Rossen Georgiev Date: Sun, 11 Dec 2016 00:53:32 +0000 Subject: [PATCH] Add Account builtin New methods * register steam account * validate email * change password * change email --- docs/api/steam.client.builtins.rst | 8 ++ steam/client/builtins/__init__.py | 3 +- steam/client/builtins/account.py | 130 +++++++++++++++++++++++++++++ steam/core/msg/__init__.py | 2 + steam/core/msg/structs.py | 76 +++++++++++++++++ 5 files changed, 218 insertions(+), 1 deletion(-) create mode 100644 steam/client/builtins/account.py diff --git a/docs/api/steam.client.builtins.rst b/docs/api/steam.client.builtins.rst index 7f52493..f7d7d61 100644 --- a/docs/api/steam.client.builtins.rst +++ b/docs/api/steam.client.builtins.rst @@ -11,6 +11,14 @@ Apps :undoc-members: :show-inheritance: +Account +------- + +.. automodule:: steam.client.builtins.account + :members: + :undoc-members: + :show-inheritance: + User ---- diff --git a/steam/client/builtins/__init__.py b/steam/client/builtins/__init__.py index c9f3d55..2e0f2f5 100644 --- a/steam/client/builtins/__init__.py +++ b/steam/client/builtins/__init__.py @@ -1,6 +1,7 @@ """ 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.web import Web 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.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. The features are separated into submodules. diff --git a/steam/client/builtins/account.py b/steam/client/builtins/account.py new file mode 100644 index 0000000..d526a5d --- /dev/null +++ b/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) diff --git a/steam/core/msg/__init__.py b/steam/core/msg/__init__.py index 4c249d0..ddf6b56 100644 --- a/steam/core/msg/__init__.py +++ b/steam/core/msg/__init__.py @@ -21,6 +21,8 @@ cmsg_lookup_predefined = { EMsg.ClientGetNumberOfCurrentPlayersDPResponse: steammessages_clientserver_2_pb2.CMsgDPGetNumberOfCurrentPlayersResponse, EMsg.ClientCreateAccountProto: steammessages_clientserver_2_pb2.CMsgClientCreateAccount, 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): diff --git a/steam/core/msg/structs.py b/steam/core/msg/structs.py index 7f4e31b..bbe3855 100644 --- a/steam/core/msg/structs.py +++ b/steam/core/msg/structs.py @@ -351,3 +351,79 @@ class ClientChatEnter(StructMessage): "numMembers: %r" % self.numMembers, "chatRoomName: %s" % repr(self.chatRoomName), ] + map(lambda x: "memberList: %s" % x, self.memberList)) + +################################################################################################## + +class _ResultStruct(StructMessage): + eresult = EResult.Invalid + + def serialize(self): + return struct.pack("