diff --git a/etc/otp.dc b/etc/otp.dc index 6f32aa4..535fc9c 100755 --- a/etc/otp.dc +++ b/etc/otp.dc @@ -536,4 +536,6 @@ dclass AstronLoginManager : DistributedObject { avatarListResponse(PotentialAvatar[]); createAvatar(blob, uint8) clsend; createAvatarResponse(uint32); + setNamePattern(uint32, int16, uint8, int16, uint8, int16, uint8, int16, uint8) clsend; + namePatternAnswer(uint32, uint8); }; diff --git a/otp/login/AstronLoginManager.py b/otp/login/AstronLoginManager.py index c8aa2f4..139e130 100644 --- a/otp/login/AstronLoginManager.py +++ b/otp/login/AstronLoginManager.py @@ -13,6 +13,7 @@ class AstronLoginManager(DistributedObjectGlobal): def __init__(self, cr): DistributedObjectGlobal.__init__(self, cr) self.doneEvent = None + self._callback = None def handleRequestLogin(self, doneEvent): self.doneEvent = doneEvent @@ -127,3 +128,10 @@ class AstronLoginManager(DistributedObjectGlobal): def createAvatarResponse(self, avId): messenger.send('nameShopCreateAvatarDone', [avId]) + + def sendSetNamePattern(self, avId, p1, f1, p2, f2, p3, f3, p4, f4, callback): + self._callback = callback + self.sendUpdate('setNamePattern', [avId, p1, f1, p2, f2, p3, f3, p4, f4]) + + def namePatternAnswer(self, avId, status): + self._callback(avId, status) diff --git a/otp/login/AstronLoginManagerUD.py b/otp/login/AstronLoginManagerUD.py index 2f99a1c..98f0e59 100644 --- a/otp/login/AstronLoginManagerUD.py +++ b/otp/login/AstronLoginManagerUD.py @@ -10,6 +10,7 @@ from direct.distributed.DistributedObjectGlobalUD import DistributedObjectGlobal from direct.distributed.PyDatagram import * from toontown.toon.ToonDNA import ToonDNA from toontown.toonbase import TTLocalizer +from toontown.makeatoon.NameGenerator import NameGenerator class AccountDB: """ @@ -345,11 +346,87 @@ class CreateAvatarOperation: del self.loginManager.account2operation[self.sender] +class SetNamePatternOperation: + notify = DirectNotifyGlobal.directNotify.newCategory('SetNamePatternOperation') + + def __init__(self, loginManager, sender): + self.loginManager = loginManager + self.sender = sender + self.avId = None + self.pattern = None + + def start(self, avId, pattern): + self.avId = avId + self.pattern = pattern + self.__handleRetrieveAccount() + + def __handleRetrieveAccount(self): + self.loginManager.air.dbInterface.queryObject(self.loginManager.air.dbId, self.sender, self.__handleAccountRetrieved) + + def __handleAccountRetrieved(self, dclass, fields): + if dclass != self.loginManager.air.dclassesByName['AstronAccountUD']: + # no uwu + return + + self.account = fields + self.avList = self.account['ACCOUNT_AV_SET'] + self.avList = self.avList[:6] + self.avList += [0] * (6 - len(self.avList)) + self.__handleRetrieveAvatar() + + def __handleRetrieveAvatar(self): + if self.avId and self.avId not in self.avList: + # Main screen turn on. + # It's you! + return + + self.loginManager.air.dbInterface.queryObject(self.loginManager.air.dbId, self.avId, self.__handleAvatarRetrieved) + + def __handleAvatarRetrieved(self, dclass, fields): + if dclass != self.loginManager.air.dclassesByName['DistributedToonUD']: + # How are you gentlemen? + # All your base are belong to us + return + + if fields['WishNameState'][0] != 'OPEN': + # You are on your way to destruction + # What you say? + return + + self.__handleSetName() + + def __handleSetName(self): + parts = [] + for p, f in self.pattern: + part = self.loginManager.nameGenerator.nameDictionary.get(p, ('', ''))[1] + if f: + part = part[:1].upper() + part[1:] + else: + part = part.lower() + + parts.append(part) + + parts[2] += parts.pop(3) + while '' in parts: + parts.remove('') + + name = ' '.join(parts) + + self.loginManager.air.dbInterface.updateObject(self.loginManager.air.dbId, self.avId, self.loginManager.air.dclassesByName['DistributedToonUD'], + {'WishNameState': ('LOCKED',), + 'WishName': ('',), + 'setName': (name,)}) + + self.loginManager.sendUpdateToAccountId(self.sender, 'namePatternAnswer', [self.avId, 1]) + del self.loginManager.account2operation[self.sender] + + class AstronLoginManagerUD(DistributedObjectGlobalUD): notify = DirectNotifyGlobal.directNotify.newCategory('AstronLoginManagerUD') def __init__(self, air): DistributedObjectGlobalUD.__init__(self, air) + self.nameGenerator = None self.accountDb = None self.sender2loginOperation = {} self.account2operation = {} @@ -357,6 +434,9 @@ class AstronLoginManagerUD(DistributedObjectGlobalUD): def announceGenerate(self): DistributedObjectGlobalUD.announceGenerate(self) + # This is for processing name patterns. + self.nameGenerator = NameGenerator() + # Instantiate the account database backend. # TODO: In the future, add more database interfaces & make this configurable. self.accountDb = DeveloperAccountDB(self) @@ -402,3 +482,18 @@ class AstronLoginManagerUD(DistributedObjectGlobalUD): newOperation = CreateAvatarOperation(self, sender) self.account2operation[sender] = newOperation newOperation.start(avDNA, avPosition) + + def setNamePattern(self, avId, p1, f1, p2, f2, p3, f3, p4, f4): + sender = self.air.getAccountIdFromSender() + if not sender: + # 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)]) diff --git a/toontown/makeatoon/NameShop.py b/toontown/makeatoon/NameShop.py index 1496825..4c52350 100644 --- a/toontown/makeatoon/NameShop.py +++ b/toontown/makeatoon/NameShop.py @@ -866,41 +866,70 @@ class NameShop(StateData.StateData): def checkNamePattern(self): self.notify.debug('checkNamePattern') - datagram = PyDatagram() - datagram.addUint16(CLIENT_SET_NAME_PATTERN) - datagram.addUint32(self.avId) - datagram.addInt16(self.nameIndices[0]) - datagram.addInt16(self.nameFlags[0]) - datagram.addInt16(self.nameIndices[1]) - datagram.addInt16(self.nameFlags[1]) - datagram.addInt16(self.nameIndices[2]) - datagram.addInt16(self.nameFlags[2]) - datagram.addInt16(self.nameIndices[3]) - datagram.addInt16(self.nameFlags[3]) - messenger.send('nameShopPost', [datagram]) + if base.cr.astronSupport: + base.cr.astronLoginManager.sendSetNamePattern(self.avId, + self.nameIndices[0], self.nameFlags[0], + self.nameIndices[1], self.nameFlags[1], + self.nameIndices[2], self.nameFlags[2], + self.nameIndices[3], self.nameFlags[3], + self.handleSetNamePatternAnswerMsg) + else: + datagram = PyDatagram() + datagram.addUint16(CLIENT_SET_NAME_PATTERN) + datagram.addUint32(self.avId) + datagram.addInt16(self.nameIndices[0]) + datagram.addInt16(self.nameFlags[0]) + datagram.addInt16(self.nameIndices[1]) + datagram.addInt16(self.nameFlags[1]) + datagram.addInt16(self.nameIndices[2]) + datagram.addInt16(self.nameFlags[2]) + datagram.addInt16(self.nameIndices[3]) + datagram.addInt16(self.nameFlags[3]) + messenger.send('nameShopPost', [datagram]) self.waitForServer() - def handleSetNamePatternAnswerMsg(self, di): - self.notify.debug('handleSetNamePatternAnswerMsg') - self.cleanupWaitForServer() - newavId = di.getUint32() - if newavId != self.avId: - self.notify.debug("doid's don't match up!") - self.rejectName(TTLocalizer.NameError) - returnCode = di.getUint8() - if returnCode == 0: - style = self.toon.getStyle() - avDNA = style.makeNetString() - self.notify.debug('pattern name accepted') - newPotAv = PotentialAvatar.PotentialAvatar(newavId, self.names, avDNA, self.index, 0) - self.avList.append(newPotAv) - self.doneStatus = 'done' - self.storeSkipTutorialRequest() - messenger.send(self.doneEvent) - else: - self.notify.debug('name pattern rejected') - self.rejectName(TTLocalizer.NameError) - return None + if not config.GetBool('astron-support', True): + def handleSetNamePatternAnswerMsg(self, di): + self.notify.debug('handleSetNamePatternAnswerMsg') + self.cleanupWaitForServer() + newavId = di.getUint32() + if newavId != self.avId: + self.notify.debug("doid's don't match up!") + self.rejectName(TTLocalizer.NameError) + returnCode = di.getUint8() + if returnCode == 0: + style = self.toon.getStyle() + avDNA = style.makeNetString() + self.notify.debug('pattern name accepted') + newPotAv = PotentialAvatar.PotentialAvatar(newavId, self.names, avDNA, self.index, 0) + self.avList.append(newPotAv) + self.doneStatus = 'done' + self.storeSkipTutorialRequest() + messenger.send(self.doneEvent) + else: + self.notify.debug('name pattern rejected') + self.rejectName(TTLocalizer.NameError) + return None + else: + def handleSetNamePatternAnswerMsg(self, newavId, returnCode): + self.notify.debug('handleSetNamePatternAnswerMsg') + self.cleanupWaitForServer() + if newavId != self.avId: + self.notify.debug("doid's don't match up!") + self.rejectName(TTLocalizer.NameError) + if returnCode == 1: + style = self.toon.getStyle() + avDNA = style.makeNetString() + self.notify.debug('pattern name accepted') + newPotAv = PotentialAvatar.PotentialAvatar(newavId, self.names, avDNA, self.index, 0) + self.avList.append(newPotAv) + self.doneStatus = 'done' + self.storeSkipTutorialRequest() + messenger.send(self.doneEvent) + else: + self.notify.debug('name pattern rejected') + self.rejectName(TTLocalizer.NameError) + return None def _submitTypeANameAsPickAName(self): pnp = TTPickANamePattern(self.nameEntry.get(), self.toon.style.gender)