login: clean up this mess a little bit

This commit is contained in:
John Cote 2019-11-28 01:00:02 -05:00
parent 9f56161955
commit 98b699d4b9

View file

@ -213,7 +213,7 @@ class GetAvatarsOperation:
def __handleAccountRetrieved(self, dclass, fields): def __handleAccountRetrieved(self, dclass, fields):
if dclass != self.loginManager.air.dclassesByName['AstronAccountUD']: if dclass != self.loginManager.air.dclassesByName['AstronAccountUD']:
# no uwu # TODO: Kill the connection
return return
self.account = fields self.account = fields
@ -231,7 +231,7 @@ class GetAvatarsOperation:
def response(dclass, fields, avId=avId): def response(dclass, fields, avId=avId):
if dclass != self.loginManager.air.dclassesByName['DistributedToonUD']: if dclass != self.loginManager.air.dclassesByName['DistributedToonUD']:
# mayonnaise # TODO: Kill the connection
return return
self.avatarFields[avId] = fields self.avatarFields[avId] = fields
@ -283,12 +283,12 @@ class CreateAvatarOperation:
def start(self, avDNA, avPosition): def start(self, avDNA, avPosition):
if avPosition >= 6: if avPosition >= 6:
# NO!!!!!!! # TODO: Kill the connection
return return
valid = ToonDNA().isValidNetString(avDNA) valid = ToonDNA().isValidNetString(avDNA)
if not valid: if not valid:
# time to eat paste # TODO: Kill the connection
return return
self.avPosition = avPosition self.avPosition = avPosition
@ -302,7 +302,7 @@ class CreateAvatarOperation:
def __handleAccountRetrieved(self, dclass, fields): def __handleAccountRetrieved(self, dclass, fields):
if dclass != self.loginManager.air.dclassesByName['AstronAccountUD']: if dclass != self.loginManager.air.dclassesByName['AstronAccountUD']:
# no uwu # TODO: Kill the connection
return return
self.account = fields self.account = fields
@ -310,7 +310,7 @@ class CreateAvatarOperation:
self.avList = self.avList[:6] self.avList = self.avList[:6]
self.avList += [0] * (6 - len(self.avList)) self.avList += [0] * (6 - len(self.avList))
if self.avList[self.avPosition]: if self.avList[self.avPosition]:
# my leg # TODO: Kill the connection
return return
self.__handleCreateAvatar() self.__handleCreateAvatar()
@ -333,7 +333,7 @@ class CreateAvatarOperation:
def __handleToonCreated(self, avId): def __handleToonCreated(self, avId):
if not avId: if not avId:
# WHAT! # TODO: Kill the connection
return return
self.avId = avId self.avId = avId
@ -349,10 +349,7 @@ class CreateAvatarOperation:
def __handleAvatarStored(self, fields): def __handleAvatarStored(self, fields):
if fields: if fields:
# What happen! # TODO: Kill the connection
# Someone set up us the bomb.
# We get signal.
# What!
return return
self.loginManager.sendUpdateToAccountId(self.sender, 'createAvatarResponse', [self.avId]) self.loginManager.sendUpdateToAccountId(self.sender, 'createAvatarResponse', [self.avId])
@ -379,7 +376,7 @@ class SetNamePatternOperation:
def __handleAccountRetrieved(self, dclass, fields): def __handleAccountRetrieved(self, dclass, fields):
if dclass != self.loginManager.air.dclassesByName['AstronAccountUD']: if dclass != self.loginManager.air.dclassesByName['AstronAccountUD']:
# no uwu # TODO: Kill the connection
return return
self.account = fields self.account = fields
@ -390,8 +387,7 @@ class SetNamePatternOperation:
def __handleRetrieveAvatar(self): def __handleRetrieveAvatar(self):
if self.avId and self.avId not in self.avList: if self.avId and self.avId not in self.avList:
# Main screen turn on. # TODO: Kill the connection
# It's you!
return return
self.loginManager.air.dbInterface.queryObject(self.loginManager.air.dbId, self.avId, self.loginManager.air.dbInterface.queryObject(self.loginManager.air.dbId, self.avId,
@ -399,13 +395,11 @@ class SetNamePatternOperation:
def __handleAvatarRetrieved(self, dclass, fields): def __handleAvatarRetrieved(self, dclass, fields):
if dclass != self.loginManager.air.dclassesByName['DistributedToonUD']: if dclass != self.loginManager.air.dclassesByName['DistributedToonUD']:
# How are you gentlemen? # TODO: Kill the connection
# All your base are belong to us
return return
if fields['WishNameState'][0] != 'OPEN': if fields['WishNameState'][0] != 'OPEN':
# You are on your way to destruction # TODO: Kill the connection
# What you say?
return return
self.__handleSetName() self.__handleSetName()
@ -461,7 +455,7 @@ class SetNameTypedOperation:
def __handleAccountRetrieved(self, dclass, fields): def __handleAccountRetrieved(self, dclass, fields):
if dclass != self.loginManager.air.dclassesByName['AstronAccountUD']: if dclass != self.loginManager.air.dclassesByName['AstronAccountUD']:
# no uwu # TODO: Kill the connection
return return
self.account = fields self.account = fields
@ -472,8 +466,7 @@ class SetNameTypedOperation:
def __handleRetrieveAvatar(self): def __handleRetrieveAvatar(self):
if self.avId and self.avId not in self.avList: if self.avId and self.avId not in self.avList:
# You have no chance to survive make your time # TODO: Kill the connection
# Hahaha
return return
self.loginManager.air.dbInterface.queryObject(self.loginManager.air.dbId, self.avId, self.loginManager.air.dbInterface.queryObject(self.loginManager.air.dbId, self.avId,
@ -481,13 +474,11 @@ class SetNameTypedOperation:
def __handleAvatarRetrieved(self, dclass, fields): def __handleAvatarRetrieved(self, dclass, fields):
if dclass != self.loginManager.air.dclassesByName['DistributedToonUD']: if dclass != self.loginManager.air.dclassesByName['DistributedToonUD']:
# How are you gentlemen? # TODO: Kill the connection
# All your base are belong to us
return return
if fields['WishNameState'][0] != 'OPEN': if fields['WishNameState'][0] != 'OPEN':
# You are on your way to destruction # TODO: Kill the connection
# What you say?
return return
self.__handleJudgeName() self.__handleJudgeName()
@ -522,7 +513,7 @@ class AcknowledgeNameOperation:
def __handleAccountRetrieved(self, dclass, fields): def __handleAccountRetrieved(self, dclass, fields):
if dclass != self.loginManager.air.dclassesByName['AstronAccountUD']: if dclass != self.loginManager.air.dclassesByName['AstronAccountUD']:
# no uwu # TODO: Kill the connection
return return
self.account = fields self.account = fields
@ -533,7 +524,7 @@ class AcknowledgeNameOperation:
def __handleGetTargetAvatar(self): def __handleGetTargetAvatar(self):
if self.avId not in self.avList: if self.avId not in self.avList:
# welp # TODO: Kill the connection
return return
self.loginManager.air.dbInterface.queryObject(self.loginManager.air.dbId, self.avId, self.loginManager.air.dbInterface.queryObject(self.loginManager.air.dbId, self.avId,
@ -588,7 +579,7 @@ class RemoveAvatarOperation:
def __handleAccountRetrieved(self, dclass, fields): def __handleAccountRetrieved(self, dclass, fields):
if dclass != self.loginManager.air.dclassesByName['AstronAccountUD']: if dclass != self.loginManager.air.dclassesByName['AstronAccountUD']:
# no uwu # TODO: Kill the connection
return return
self.account = fields self.account = fields
@ -599,7 +590,7 @@ class RemoveAvatarOperation:
def __handleRemoveAvatar(self): def __handleRemoveAvatar(self):
if self.avId not in self.avList: if self.avId not in self.avList:
# avatar doesn't exist. # TODO: Kill the connection
return return
index = self.avList.index(self.avId) index = self.avList.index(self.avId)
@ -623,7 +614,7 @@ class RemoveAvatarOperation:
def __handleAvatarRemoved(self, fields): def __handleAvatarRemoved(self, fields):
if fields: if fields:
# failed to remove the avatar. # TODO: Kill the connection
return return
self.__handleQueryAvatars() self.__handleQueryAvatars()
@ -637,7 +628,7 @@ class RemoveAvatarOperation:
def response(dclass, fields, avId=avId): def response(dclass, fields, avId=avId):
if dclass != self.loginManager.air.dclassesByName['DistributedToonUD']: if dclass != self.loginManager.air.dclassesByName['DistributedToonUD']:
# mayonnaise # TODO: Kill the connection
return return
self.avatarFields[avId] = fields self.avatarFields[avId] = fields
@ -696,7 +687,7 @@ class LoadAvatarOperation:
def __handleAccountRetrieved(self, dclass, fields): def __handleAccountRetrieved(self, dclass, fields):
if dclass != self.loginManager.air.dclassesByName['AstronAccountUD']: if dclass != self.loginManager.air.dclassesByName['AstronAccountUD']:
# no uwu # TODO: Kill the connection
return return
self.account = fields self.account = fields
@ -769,106 +760,75 @@ class AstronLoginManagerUD(DistributedObjectGlobalUD):
# TODO: In the future, add more database interfaces & make this configurable. # TODO: In the future, add more database interfaces & make this configurable.
self.accountDb = DeveloperAccountDB(self) self.accountDb = DeveloperAccountDB(self)
def requestLogin(self, playToken): def runLoginOperation(self, playToken):
# Get the connection ID: # Runs a login operation on the sender. First, get the sender:
sender = self.air.getMsgSender() sender = self.air.getMsgSender()
if sender in self.sender2loginOperation.keys(): # Is the sender already logged in?
# BAD!!!! if sender >> 32:
# TODO kill connection
return return
# Is the sender already logging in?
if sender in self.sender2loginOperation.keys():
# TODO kill connection
return
# Run the login operation:
newLoginOperation = LoginOperation(self, sender) newLoginOperation = LoginOperation(self, sender)
self.sender2loginOperation[sender] = newLoginOperation self.sender2loginOperation[sender] = newLoginOperation
newLoginOperation.start(playToken) newLoginOperation.start(playToken)
# TODO: CLEAN UP ALL THIS CODE!!!!!!!! def runGameOperation(self, operationType, *args):
# Runs a game operation on the sender. First, get the sender:
sender = self.air.getAccountIdFromSender()
if not sender:
# Sender doesn't exist; not logged in.
# TODO KILL CONNECTION
return
if sender in self.account2operation:
# Sender is already currently running a game operation.
# TODO KILL CONNECTION
return
# Run the game operation:
newOperation = operationType(self, sender)
self.account2operation[sender] = newOperation
newOperation.start(*args)
def requestLogin(self, playToken):
# Someone wants to log in to the game; run a LoginOperation:
self.runLoginOperation(playToken)
def requestAvatarList(self): def requestAvatarList(self):
sender = self.air.getAccountIdFromSender() # Someone wants their avatar list; run a GetAvatarsOperation:
if not sender: self.runGameOperation(GetAvatarsOperation)
# TODO KILL CONNECTION
return
if sender in self.account2operation:
# BAD!!!!
return
newOperation = GetAvatarsOperation(self, sender)
self.account2operation[sender] = newOperation
newOperation.start()
def createAvatar(self, avDNA, avPosition): def createAvatar(self, avDNA, avPosition):
sender = self.air.getAccountIdFromSender() # Someone wants to create a new avatar; run a CreateAvatarOperation:
if not sender: self.runGameOperation(CreateAvatarOperation, avDNA, avPosition)
# TODO KILL CONNECTION
return
if sender in self.account2operation:
# BAD!!!!
return
newOperation = CreateAvatarOperation(self, sender)
self.account2operation[sender] = newOperation
newOperation.start(avDNA, avPosition)
def setNamePattern(self, avId, p1, f1, p2, f2, p3, f3, p4, f4): def setNamePattern(self, avId, p1, f1, p2, f2, p3, f3, p4, f4):
sender = self.air.getAccountIdFromSender() # Someone wants to use a pattern name; run a SetNamePatternOperation:
if not sender: self.runGameOperation(SetNamePatternOperation, avId, [(p1, f1), (p2, f2),
# TODO KILL CONNECTION
return
if sender in self.account2operation:
# BAD!!!!
return
newOperation = SetNamePatternOperation(self, sender)
self.account2operation[sender] = newOperation
newOperation.start(avId, [(p1, f1), (p2, f2),
(p3, f3), (p4, f4)]) (p3, f3), (p4, f4)])
def setNameTyped(self, avId, name): def setNameTyped(self, avId, name):
sender = self.air.getAccountIdFromSender() # Someone has typed a name; run a SetNameTypedOperation:
if not sender: self.runGameOperation(SetNameTypedOperation, avId, name)
# TODO KILL CONNECTION
return
if sender in self.account2operation:
# BAD!!!!
return
newOperation = SetNameTypedOperation(self, sender)
self.account2operation[sender] = newOperation
newOperation.start(avId, name)
def acknowledgeAvatarName(self, avId): def acknowledgeAvatarName(self, avId):
sender = self.air.getAccountIdFromSender() # Someone has acknowledged their name; run an AcknowledgeNameOperation:
if not sender: self.runGameOperation(AcknowledgeNameOperation, avId)
# TODO KILL CONNECTION
return
if sender in self.account2operation:
# BAD!!!!
return
newOperation = AcknowledgeNameOperation(self, sender)
self.account2operation[sender] = newOperation
newOperation.start(avId)
def requestRemoveAvatar(self, avId): def requestRemoveAvatar(self, avId):
sender = self.air.getAccountIdFromSender() # Someone is requesting to have an avatar removed; run a RemoveAvatarOperation:
if not sender: self.runGameOperation(RemoveAvatarOperation, avId)
# TODO KILL CONNECTION
return
if sender in self.account2operation:
# BAD!!!!
return
newOperation = RemoveAvatarOperation(self, sender)
self.account2operation[sender] = newOperation
newOperation.start(avId)
def requestPlayAvatar(self, avId): def requestPlayAvatar(self, avId):
# Someone is requesting to play on an avatar.
# First, let's get the sender's avId & accId:
currentAvId = self.air.getAvatarIdFromSender() currentAvId = self.air.getAvatarIdFromSender()
accId = self.air.getAccountIdFromSender() accId = self.air.getAccountIdFromSender()
if currentAvId and avId: if currentAvId and avId:
@ -878,20 +838,10 @@ class AstronLoginManagerUD(DistributedObjectGlobalUD):
# I don't think we need to do anything extra here # I don't think we need to do anything extra here
return return
sender = self.air.getAccountIdFromSender()
if not sender:
# TODO KILL CONNECTION
return
if sender in self.account2operation:
# BAD!!!!
return
if avId: if avId:
newOperation = LoadAvatarOperation(self, sender) # If the avId is not a NoneType, that means the client wants
self.account2operation[sender] = newOperation # to load an avatar; run a LoadAvatarOperation.
newOperation.start(avId) self.runGameOperation(LoadAvatarOperation, avId)
else: else:
newOperation = UnloadAvatarOperation(self, sender) # Otherwise, the client wants to unload the avatar; run an UnloadAvatarOperation.
self.account2operation[sender] = newOperation self.runGameOperation(UnloadAvatarOperation, currentAvId)
newOperation.start(currentAvId)