diff --git a/otp/login/AstronLoginManager.py b/otp/login/AstronLoginManager.py index c4bde0f..a715e56 100644 --- a/otp/login/AstronLoginManager.py +++ b/otp/login/AstronLoginManager.py @@ -1,12 +1,6 @@ -import json -import time -from datetime import datetime - from direct.directnotify import DirectNotifyGlobal from direct.distributed.DistributedObjectGlobal import DistributedObjectGlobal -from otp.uberdog.AccountDetailRecord import AccountDetailRecord - class AstronLoginManager(DistributedObjectGlobal): notify = DirectNotifyGlobal.directNotify.newCategory('AstronLoginManager') @@ -15,7 +9,6 @@ class AstronLoginManager(DistributedObjectGlobal): DistributedObjectGlobal.__init__(self, cr) self.doneEvent = None self._callback = None - self.userName = '' def handleRequestLogin(self, doneEvent): self.doneEvent = doneEvent @@ -26,106 +19,7 @@ class AstronLoginManager(DistributedObjectGlobal): self.sendUpdate('requestLogin', [playToken]) def loginResponse(self, responseBlob): - self.notify.debug("loginResponse") - responseData = json.loads(responseBlob) - now = time.time() - returnCode = responseData.get('returnCode') - respString = responseData.get('respString') - errorString = self.getExtendedErrorMsg(respString) - accountNumber = responseData.get('accountNumber') - self.cr.DISLIdFromLogin = accountNumber - accountDetailRecord = AccountDetailRecord() - self.cr.accountDetailRecord = accountDetailRecord - createFriendsWithChat = responseData.get('createFriendsWithChat') - canChat = createFriendsWithChat == "YES" or createFriendsWithChat == "CODE" - self.cr.secretChatAllowed = canChat - if base.logPrivateInfo: - self.notify.info("CREATE_FRIENDS_WITH_CHAT from game server login: %s %s" % (createFriendsWithChat, canChat)) - chatCodeCreationRule = responseData.get('chatCodeCreationRule') - self.cr.chatChatCodeCreationRule = chatCodeCreationRule - if base.logPrivateInfo: - self.notify.info("Chat code creation rule = %s" % chatCodeCreationRule) - self.cr.secretChatNeedsParentPassword = chatCodeCreationRule == "PARENT" - serverTime = responseData.get('serverTime') - self.cr.serverTimeUponLogin = serverTime - self.cr.clientTimeUponLogin = now - self.cr.globalClockRealTimeUponLogin = globalClock.getRealTime() - if hasattr(self.cr, "toontownTimeManager"): - self.cr.toontownTimeManager.updateLoginTimes(serverTime, now, self.cr.globalClockRealTimeUponLogin) - serverDelta = serverTime - now - self.cr.setServerDelta(serverDelta) - self.notify.setServerDelta(serverDelta, 28800) - access = responseData.get('access') - isPaid = access == "FULL" - self.cr.parentPasswordSet = isPaid - self.cr.setIsPaid(isPaid) - if isPaid: - launcher.setPaidUserLoggedIn() - if base.logPrivateInfo: - self.notify.info("Paid from game server login: %s" % isPaid) - WhiteListResponse = responseData.get('WhiteListResponse') - if WhiteListResponse == "YES": - self.cr.whiteListChatEnabled = 1 - else: - self.cr.whiteListChatEnabled = 0 - lastLoggedInStr = responseData.get('lastLoggedInStr') - self.cr.lastLoggedIn = datetime.now() - if hasattr(self.cr, "toontownTimeManager"): - self.cr.lastLoggedIn = self.cr.toontownTimeManager.convertStrToToontownTime(lastLoggedInStr) - accountDaysFromServer = responseData.get('accountDays') - if accountDaysFromServer is not None: - self.cr.accountDays = self.parseAccountDays(accountDaysFromServer) - else: - self.cr.accountDays = 100000 - toonAccountType = responseData.get('toonAccountType') - if toonAccountType == "WITH_PARENT_ACCOUNT": - self.cr.withParentAccount = True - elif toonAccountType == "NO_PARENT_ACCOUNT": - self.cr.withParentAccount = False - else: - self.notify.error("unknown toon account type %s" % toonAccountType) - if base.logPrivateInfo: - self.notify.info("toonAccountType=%s" % toonAccountType) - self.userName = responseData.get('userName') - self.cr.userName = self.userName - self.notify.info("Login response return code %s" % returnCode) - if returnCode == 0: - self.__handleLoginSuccess() - elif returnCode == -13: - self.notify.info("Period Time Expired") - self.cr.loginScreen.request("showLoginFailDialog", [OTPLocalizer.LoginScreenPeriodTimeExpired]) - else: - self.notify.info("Login failed: %s" % errorString) - messenger.send(self.doneEvent, [{'mode': 'reject'}]) - - def __handleLoginSuccess(self): - self.cr.logAccountInfo() - launcher.setGoUserName(self.userName) - launcher.setLastLogin(self.userName) - launcher.setUserLoggedIn() - if self.cr.loginScreen.loginInterface.freeTimeExpires == -1: - launcher.setPaidUserLoggedIn() - if self.cr.loginScreen.loginInterface.needToSetParentPassword(): - messenger.send(self.doneEvent, [{'mode': 'getChatPassword'}]) - else: - messenger.send(self.doneEvent, [{'mode': 'success'}]) - - def getExtendedErrorMsg(self, errorString): - prefix = 'Bad DC Version Compare' - if len(errorString) < len(prefix): - return errorString - if errorString[:len(prefix)] == prefix: - return '%s%s' % (errorString, ', address=%s' % base.cr.getServerAddress()) - return errorString - - def parseAccountDays(self, accountDays): - result = 100000 - if accountDays >= 0: - result = accountDays - else: - self.notify.warning('account days is negative %s' % accountDays) - self.notify.debug('result=%s' % result) - return result + self.cr.loginScreen.handleLoginToontownResponse(responseBlob) def sendRequestAvatarList(self): self.sendUpdate('requestAvatarList') diff --git a/otp/login/AstronLoginScreen.py b/otp/login/AstronLoginScreen.py index 0eaa95a..95c420a 100644 --- a/otp/login/AstronLoginScreen.py +++ b/otp/login/AstronLoginScreen.py @@ -1,7 +1,13 @@ +import json +import time +from datetime import datetime + from direct.directnotify import DirectNotifyGlobal from direct.distributed.MsgTypes import * from otp.login.LoginScreen import LoginScreen +from otp.otpbase import OTPLocalizer +from otp.uberdog.AccountDetailRecord import AccountDetailRecord class AstronLoginScreen(LoginScreen): @@ -11,6 +17,81 @@ class AstronLoginScreen(LoginScreen): if msgType == CLIENT_HELLO_RESP: # Now we can start the heartbeat: self.cr.startHeartbeat() + + # Send the login request: self.cr.astronLoginManager.handleRequestLogin(self.doneEvent) else: self.cr.handleMessageType(msgType, di) + + def handleLoginToontownResponse(self, responseBlob): + self.notify.debug("handleLoginToontownResponse") + responseData = json.loads(responseBlob) + now = time.time() + returnCode = responseData.get('returnCode') + respString = responseData.get('respString') + errorString = self.getExtendedErrorMsg(respString) + self.accountNumber = responseData.get('accountNumber') + self.cr.DISLIdFromLogin = self.accountNumber + accountDetailRecord = AccountDetailRecord() + self.cr.accountDetailRecord = accountDetailRecord + createFriendsWithChat = responseData.get('createFriendsWithChat') + canChat = createFriendsWithChat == "YES" or createFriendsWithChat == "CODE" + self.cr.secretChatAllowed = canChat + if base.logPrivateInfo: + self.notify.info("CREATE_FRIENDS_WITH_CHAT from game server login: %s %s" % (createFriendsWithChat, canChat)) + self.chatCodeCreationRule = responseData.get('chatCodeCreationRule') + self.cr.chatChatCodeCreationRule = self.chatCodeCreationRule + if base.logPrivateInfo: + self.notify.info("Chat code creation rule = %s" % self.chatCodeCreationRule) + self.cr.secretChatNeedsParentPassword = self.chatCodeCreationRule == "PARENT" + serverTime = responseData.get('serverTime') + self.cr.serverTimeUponLogin = serverTime + self.cr.clientTimeUponLogin = now + self.cr.globalClockRealTimeUponLogin = globalClock.getRealTime() + if hasattr(self.cr, "toontownTimeManager"): + self.cr.toontownTimeManager.updateLoginTimes(serverTime, now, self.cr.globalClockRealTimeUponLogin) + serverDelta = serverTime - now + self.cr.setServerDelta(serverDelta) + self.notify.setServerDelta(serverDelta, 28800) + access = responseData.get('access') + self.isPaid = access == "FULL" + self.cr.parentPasswordSet = self.isPaid + self.cr.setIsPaid(self.isPaid) + if self.isPaid: + launcher.setPaidUserLoggedIn() + if base.logPrivateInfo: + self.notify.info("Paid from game server login: %s" % self.isPaid) + WhiteListResponse = responseData.get('WhiteListResponse') + if WhiteListResponse == "YES": + self.cr.whiteListChatEnabled = 1 + else: + self.cr.whiteListChatEnabled = 0 + self.lastLoggedInStr = responseData.get('lastLoggedInStr') + self.cr.lastLoggedIn = datetime.now() + if hasattr(self.cr, "toontownTimeManager"): + self.cr.lastLoggedIn = self.cr.toontownTimeManager.convertStrToToontownTime(self.lastLoggedInStr) + accountDaysFromServer = responseData.get('accountDays') + if accountDaysFromServer is not None: + self.cr.accountDays = self.parseAccountDays(accountDaysFromServer) + else: + self.cr.accountDays = 100000 + self.toonAccountType = responseData.get('toonAccountType') + if self.toonAccountType == "WITH_PARENT_ACCOUNT": + self.cr.withParentAccount = True + elif self.toonAccountType == "NO_PARENT_ACCOUNT": + self.cr.withParentAccount = False + else: + self.notify.error("unknown toon account type %s" % self.toonAccountType) + if base.logPrivateInfo: + self.notify.info("toonAccountType=%s" % self.toonAccountType) + self.userName = responseData.get('userName') + self.cr.userName = self.userName + self.notify.info("Login response return code %s" % returnCode) + if returnCode == 0: + self._LoginScreen__handleLoginSuccess() + elif returnCode == -13: + self.notify.info("Period Time Expired") + self.fsm.request("showLoginFailDialog", [OTPLocalizer.LoginScreenPeriodTimeExpired]) + else: + self.notify.info("Login failed: %s" % errorString) + messenger.send(self.doneEvent, [{'mode': 'reject'}])