From e78d345fab6b1ee04e8f1ec6531fc61f54fb00a9 Mon Sep 17 00:00:00 2001 From: John Cote Date: Mon, 28 Jun 2021 14:29:12 -0400 Subject: [PATCH] login: Handle closing the connection in game operations --- otp/login/AstronLoginManagerUD.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/otp/login/AstronLoginManagerUD.py b/otp/login/AstronLoginManagerUD.py index d617481..e48dbc9 100644 --- a/otp/login/AstronLoginManagerUD.py +++ b/otp/login/AstronLoginManagerUD.py @@ -103,11 +103,24 @@ class GameOperation: self.callback = callback def _handleDone(self): + # Deletes the sender from either sender2loginOperation or account2operation + # depending on the type of operation we are running. if self.__class__.__name__ == 'LoginOperation': del self.loginManager.sender2loginOperation[self.sender] else: del self.loginManager.account2operation[self.sender] + def _handleCloseConnection(self, reason=''): + # Closes either the sender connection or the sender account + # depending on the type of operation we are running, and then + # finishes off this operation. + if self.__class__.__name__ == 'LoginOperation': + self.loginManager.closeConnection(self.sender, reason=reason) + else: + self.loginManager.closeConnection(self.sender, reason=reason, isAccount=True) + + self._handleDone() + class LoginOperation(GameOperation): @@ -123,17 +136,25 @@ class LoginOperation(GameOperation): self.loginManager.accountDb.lookup(playToken, self.__handleLookup) def __handleLookup(self, result): + # This is a callback function that will be called by the lookup function + # of the AstronLoginManager's account DB interface. It processes the + # lookup function's result & determines which operation should run next. if not result.get('success'): - # TODO: Kill the connection + # The play token was rejected! + self.loginManager.air.writeServerEvent('play-token-rejected', self.sender, self.playToken) + self._handleCloseConnection(result.get('reason', 'The accounts database rejected your play token.')) return + # Grab the databaseId, accessLevel, and the accountId from the result. self.databaseId = result.get('databaseId', 0) self.accessLevel = result.get('accessLevel', 0) accountId = result.get('accountId', 0) if accountId: + # There is an account ID, so let's retrieve the associated account. self.accountId = accountId self.__handleRetrieveAccount() else: + # There is no account ID, so let's create a new account. self.__handleCreateAccount() def __handleRetrieveAccount(self):