From 6436cb9f0f0be6477be1b1ca4b6b082ac43eb326 Mon Sep 17 00:00:00 2001 From: DenialMC Date: Sat, 4 Apr 2015 13:29:27 +0300 Subject: [PATCH] Code Redemption cleanup --- astron/dclass/united.dc | 18 +----- deployment/deploy.py | 2 - otp/distributed/DCClassImports.py | 4 +- .../coderedemption/TTCodeRedemptionMgr.py | 20 ++----- .../coderedemption/TTCodeRedemptionMgrAI.py | 18 +++--- .../NonRepeatableRandomSourceAI.py | 49 ----------------- .../NonRepeatableRandomSourceUD.py | 55 ------------------- toontown/shtiker/OptionsPage.py | 10 ++-- 8 files changed, 22 insertions(+), 154 deletions(-) delete mode 100644 toontown/distributed/NonRepeatableRandomSourceAI.py delete mode 100644 toontown/distributed/NonRepeatableRandomSourceUD.py diff --git a/astron/dclass/united.dc b/astron/dclass/united.dc index 655b2477..d3a2b0e2 100644 --- a/astron/dclass/united.dc +++ b/astron/dclass/united.dc @@ -711,8 +711,6 @@ from toontown.uberdog.DistributedMailManager/AI/UD import DistributedMailManager from toontown.uberdog.DistributedPartyManager/AI/UD import DistributedPartyManager/AI/UD from toontown.rpc.AwardManager/UD import AwardManager/UD from toontown.coderedemption.TTCodeRedemptionMgr/AI import TTCodeRedemptionMgr/AI -from toontown.distributed.NonRepeatableRandomSourceAI import NonRepeatableRandomSourceAI -from toontown.distributed.NonRepeatableRandomSourceUD import NonRepeatableRandomSourceUD from toontown.ai.DistributedPhaseEventMgr/AI import DistributedPhaseEventMgr/AI from toontown.ai.DistributedHydrantZeroMgr/AI import DistributedHydrantZeroMgr/AI from toontown.ai.DistributedMailboxZeroMgr/AI import DistributedMailboxZeroMgr/AI @@ -3615,19 +3613,9 @@ dclass AwardManager : DistributedObjectGlobal { giveAwardToToon(uint32, DoId, string, DoId, uint32, uint32); }; -dclass NonRepeatableRandomSourceClient { - getRandomSamplesReply(uint32, uint32 []) airecv; -}; - -dclass TTCodeRedemptionMgr : DistributedObject, NonRepeatableRandomSourceClient { - redeemCode(uint32, char [0-256]) airecv clsend; - redeemCodeResult(uint32, uint32, uint32); -}; - -dclass NonRepeatableRandomSource : DistributedObject, NonRepeatableRandomSourceClient { - getRandomSamples(DoId, string, uint32, uint32); - randomSample(DoId, uint32); - randomSampleAck() airecv; +dclass TTCodeRedemptionMgr : DistributedObject { + redeemCode(char [0-256]) airecv clsend; + redeemCodeResult(uint32); }; struct Friend diff --git a/deployment/deploy.py b/deployment/deploy.py index fa981bc8..e99cea4a 100644 --- a/deployment/deploy.py +++ b/deployment/deploy.py @@ -206,8 +206,6 @@ cmd = (pythonPath + ' ../tools/prepare_client.py' + ' --build-mfs' + ' --resources-dir src/resources' + ' --config-dir ' + configDir + - ' --include NonRepeatableRandomSourceUD.py' + - ' --include NonRepeatableRandomSourceAI.py' + ' --exclude ServiceStart.py') for vfsMount in vfsMounts: cmd += ' --vfs ' + vfsMount diff --git a/otp/distributed/DCClassImports.py b/otp/distributed/DCClassImports.py index 08fd1b8b..3ca46ec2 100644 --- a/otp/distributed/DCClassImports.py +++ b/otp/distributed/DCClassImports.py @@ -2,7 +2,7 @@ from pandac.PandaModules import * -hashVal = 4270694562L +hashVal = 2680034445L from toontown.coghq import DistributedCashbotBossSafe, DistributedCashbotBossCrane, DistributedBattleFactory, DistributedCashbotBossTreasure, DistributedCogHQDoor, DistributedSellbotHQDoor, DistributedFactoryElevatorExt, DistributedMintElevatorExt, DistributedLawOfficeElevatorExt, DistributedLawOfficeElevatorInt, LobbyManager, DistributedMegaCorp, DistributedFactory, DistributedLawOffice, DistributedLawOfficeFloor, DistributedLift, DistributedDoorEntity, DistributedSwitch, DistributedButton, DistributedTrigger, DistributedCrushableEntity, DistributedCrusherEntity, DistributedStomper, DistributedStomperPair, DistributedLaserField, DistributedGolfGreenGame, DistributedSecurityCamera, DistributedMover, DistributedElevatorMarker, DistributedBarrelBase, DistributedGagBarrel, DistributedBeanBarrel, DistributedHealBarrel, DistributedGrid, ActiveCell, DirectionalCell, CrusherCell, DistributedCrate, DistributedSinkingPlatform, BattleBlocker, DistributedMint, DistributedMintRoom, DistributedMintBattle, DistributedStage, DistributedStageRoom, DistributedStageBattle, DistributedLawbotBossGavel, DistributedLawbotCannon, DistributedLawbotChair, DistributedCogKart, DistributedCountryClub, DistributedCountryClubRoom, DistributedMoleField, DistributedCountryClubBattle, DistributedMaze, DistributedFoodBelt, DistributedBanquetTable, DistributedGolfSpot @@ -30,7 +30,6 @@ from toontown.safezone import DistributedTrolley, DistributedPartyGate, Distribu from toontown.fishing import DistributedFishingPond, DistributedFishingTarget, DistributedPondBingoManager from toontown.minigame import DistributedMinigame, DistributedMinigameTemplate, DistributedRaceGame, DistributedCannonGame, DistributedPhotoGame, DistributedPatternGame, DistributedRingGame, DistributedTagGame, DistributedMazeGame, DistributedTugOfWarGame, DistributedCatchGame, DistributedDivingGame, DistributedTargetGame, DistributedTravelGame, DistributedPairingGame, DistributedVineGame, DistributedIceGame, DistributedCogThiefGame, DistributedTwoDGame from toontown.racing import DistributedVehicle, DistributedStartingBlock, DistributedRace, DistributedKartPad, DistributedRacePad, DistributedViewPad, DistributedStartingBlock, DistributedLeaderBoard, DistributedGag, DistributedProjectile -from toontown.distributed.NonRepeatableRandomSourceUD import NonRepeatableRandomSourceUD from toontown.catalog import CatalogManager, AccountDate from toontown.ai.DistributedHydrantZeroMgr import DistributedHydrantZeroMgr from toontown.rpc.AwardManager import AwardManager @@ -44,7 +43,6 @@ from toontown.toon import DistributedToon, DistributedNPCToonBase, DistributedNP from toontown.tutorial import DistributedBattleTutorial, TutorialManager from toontown.pets import DistributedPetProxy from toontown.coderedemption.TTCodeRedemptionMgr import TTCodeRedemptionMgr -from toontown.distributed.NonRepeatableRandomSourceAI import NonRepeatableRandomSourceAI from toontown.ai.DistributedMailboxZeroMgr import DistributedMailboxZeroMgr from toontown.uberdog.DistributedDeliveryManager import DistributedDeliveryManager from direct.distributed import DistributedObject, DistributedNode, DistributedSmoothNode, DistributedCartesianGrid, DistributedCamera, DistributedObjectGlobal diff --git a/toontown/coderedemption/TTCodeRedemptionMgr.py b/toontown/coderedemption/TTCodeRedemptionMgr.py index 7ba47e94..9ab3d5a6 100644 --- a/toontown/coderedemption/TTCodeRedemptionMgr.py +++ b/toontown/coderedemption/TTCodeRedemptionMgr.py @@ -11,25 +11,15 @@ class TTCodeRedemptionMgr(DistributedObject): def announceGenerate(self): DistributedObject.announceGenerate(self) base.cr.codeRedemptionMgr = self - self._contextGen = SerialMaskedGen(4294967295L) - self._context2callback = {} def delete(self): if hasattr(base.cr, 'codeRedemptionMgr'): - if base.cr.codeRedemptionMgr is self: - del base.cr.codeRedemptionMgr - self._context2callback = None - self._contextGen = None + del base.cr.codeRedemptionMgr DistributedObject.delete(self) - return def redeemCode(self, code, callback): - context = self._contextGen.next() - self._context2callback[context] = callback - self.notify.debug('redeemCode(%s, %s)' % (context, code)) - self.sendUpdate('redeemCode', [context, code]) + self.callback = callback + self.sendUpdate('redeemCode', [code]) - def redeemCodeResult(self, context, result, awardMgrResult): - self.notify.debug('redeemCodeResult(%s, %s, %s)' % (context, result, awardMgrResult)) - callback = self._context2callback.pop(context) - callback(result, awardMgrResult) + def redeemCodeResult(self, result): + self.callback(result) \ No newline at end of file diff --git a/toontown/coderedemption/TTCodeRedemptionMgrAI.py b/toontown/coderedemption/TTCodeRedemptionMgrAI.py index 76c3fd04..eb6d312f 100644 --- a/toontown/coderedemption/TTCodeRedemptionMgrAI.py +++ b/toontown/coderedemption/TTCodeRedemptionMgrAI.py @@ -82,8 +82,8 @@ class TTCodeRedemptionMgrAI(DistributedObjectAI): count += 1 return count - - def redeemCode(self, context, code): + + def redeemCode(self, code): avId = self.air.getAvatarIdFromSender() av = self.air.doId2do.get(avId) @@ -92,26 +92,26 @@ class TTCodeRedemptionMgrAI(DistributedObjectAI): if code in self.codes: if av.isCodeRedeemed(code): - self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [context, 3, 2]) + self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [4]) return codeInfo = self.codes[code] date = datetime.now() if ('month' in codeInfo and date.month is not codeInfo['month']) or ('day' in codeInfo and date.day is not codeInfo['day']) or ('expirationDate' in codeInfo and codeInfo['expirationDate'] - date < timedelta(hours = 1)): - self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [context, 2, 0]) + self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [2]) return av.redeemCode(code) - self.requestCodeRedeem(context, avId, av, codeInfo['items']) + self.requestCodeRedeem(avId, av, codeInfo['items']) else: - self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [context, 1, 0]) + self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [1]) - def requestCodeRedeem(self, context, avId, av, items): + def requestCodeRedeem(self, avId, av, items): count = self.getMailboxCount(items) if len(av.onOrder) + count > 5 or len(av.mailboxContents) + len(av.onOrder) + count >= ToontownGlobals.MaxMailboxContents: - self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [context, 3, 1]) + self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [3]) return for item in items: @@ -122,4 +122,4 @@ class TTCodeRedemptionMgrAI(DistributedObjectAI): av.onOrder.append(item) av.b_setDeliverySchedule(av.onOrder) - self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [context, 0, 0]) + self.sendUpdateToAvatarId(avId, 'redeemCodeResult', [0]) diff --git a/toontown/distributed/NonRepeatableRandomSourceAI.py b/toontown/distributed/NonRepeatableRandomSourceAI.py deleted file mode 100644 index a3de26bf..00000000 --- a/toontown/distributed/NonRepeatableRandomSourceAI.py +++ /dev/null @@ -1,49 +0,0 @@ -from direct.directnotify.DirectNotifyGlobal import directNotify -from direct.distributed.DistributedObjectAI import DistributedObjectAI -from direct.task import Task -from otp.distributed import OtpDoGlobals -import random - -class NonRepeatableRandomSourceAI(DistributedObjectAI): - notify = directNotify.newCategory('NonRepeatableRandomSourceAI') - - def __init__(self, air): - DistributedObjectAI.__init__(self, air) - - def announceGenerate(self): - DistributedObjectAI.announceGenerate(self) - self._contextGen = SerialMaskedGen((1L << 32) - 1) - self._requests = {} - self._sampleTask = self.doMethodLater(3 * 60, self._sampleRandomTask, self.uniqueName('sampleRandom')) - self._sampleRandom() - - def delete(self): - self.removeTask(self._sampleTask) - self._sampleTask = None - DistributedObjectAI.delete(self) - return - - def _sampleRandomTask(self, task = None): - self._sampleRandom() - return Task.again - - def _sampleRandom(self): - self.air.sendUpdateToDoId('NonRepeatableRandomSource', 'randomSample', OtpDoGlobals.OTP_DO_ID_TOONTOWN_NON_REPEATABLE_RANDOM_SOURCE, [self.doId, int(random.randrange(1L << 32))]) - - def randomSampleAck(self): - self._sampleRandom() - - def getRandomSamples(self, callback, num = None): - if num is None: - num = 1 - context = self._contextGen.next() - self._requests[context] = (callback,) - self.air.sendUpdateToDoId('NonRepeatableRandomSource', 'getRandomSamples', OtpDoGlobals.OTP_DO_ID_TOONTOWN_NON_REPEATABLE_RANDOM_SOURCE, [self.doId, - 'NonRepeatableRandomSource', - context, - num]) - return - - def getRandomSamplesReply(self, context, samples): - callback, = self._requests.pop(context) - callback(samples) diff --git a/toontown/distributed/NonRepeatableRandomSourceUD.py b/toontown/distributed/NonRepeatableRandomSourceUD.py deleted file mode 100644 index 1dc148d2..00000000 --- a/toontown/distributed/NonRepeatableRandomSourceUD.py +++ /dev/null @@ -1,55 +0,0 @@ -from direct.distributed.DistributedObjectGlobalUD import DistributedObjectGlobalUD -from direct.directnotify.DirectNotifyGlobal import directNotify -import random - -class NonRepeatableRandomSourceUD(DistributedObjectGlobalUD): - notify = directNotify.newCategory('NonRepeatableRandomSourceUD') - RandomNumberCacheSize = 2000000 - - class Request(ScratchPad): - - def __init__(self, replyTo, replyToClass, context, num): - ScratchPad.__init__(self, replyTo=replyTo, replyToClass=replyToClass, context=context, num=num, randoms=[]) - - def __init__(self, air): - DistributedObjectGlobalUD.__init__(self, air) - - def announceGenerate(self): - DistributedObjectGlobalUD.announceGenerate(self) - self._randoms = [] - self._requests = [] - self._fakeIt = 0 - if __dev__: - NonRepeatableRandomSourceUD.RandomNumberCacheSize = config.GetInt('random-source-cache-size', 5000) - self._fakeIt = config.GetBool('fake-non-repeatable-random-source', self._fakeIt) - - def randomSample(self, nrrsDoId, random): - self._randoms = [random] + self._randoms - if len(self._randoms) > self.RandomNumberCacheSize: - self._randoms.pop() - self._processRequests() - self.air.sendUpdateToDoId('NonRepeatableRandomSource', 'randomSampleAck', nrrsDoId, []) - - def getRandomSamples(self, replyTo, replyToClass, context, num): - self._requests.append(self.Request(replyTo, replyToClass, context, num)) - self._processRequests() - - def _processRequests(self): - while len(self._requests): - request = self._requests[0] - if not self._fakeIt and len(request.randoms) < request.num: - if len(self._randoms) == 0: - break - needed = request.num - len(request.randoms) - if needed > 0: - numRandoms = min(needed, len(self._randoms)) - if self._fakeIt: - for i in xrange(numRandoms): - request.randoms.append(random.random() * 4294967295L) - - else: - request.randoms += self._randoms[:numRandoms] - self._randoms = self._randoms[numRandoms:] - if request.num == len(request.randoms): - self._requests.pop(0) - self.air.dispatchUpdateToDoId(request.replyToClass, 'getRandomSamplesReply', request.replyTo, [request.context, request.randoms]) diff --git a/toontown/shtiker/OptionsPage.py b/toontown/shtiker/OptionsPage.py index 7c8211fb..e7b01e6d 100644 --- a/toontown/shtiker/OptionsPage.py +++ b/toontown/shtiker/OptionsPage.py @@ -665,9 +665,8 @@ class CodesTabPage(DirectFrame): self.__disableCodeEntry() return - def __getCodeResult(self, result, awardMgrResult): + def __getCodeResult(self, result): self.notify.debug('result = %s' % result) - self.notify.debug('awardMgrResult = %s' % awardMgrResult) self.__enableCodeEntry() if result == 0: self.resultPanel['image'] = self.resultPanelSuccessGui @@ -680,10 +679,9 @@ class CodesTabPage(DirectFrame): self.resultPanel['text'] = TTLocalizer.CdrResultExpiredCode elif result == 3: self.resultPanel['image'] = self.resultPanelErrorGui - if awardMgrResult == 1: - self.resultPanel['text'] = TTLocalizer.CdrResultMailboxFull - elif awardMgrResult == 2: - self.resultPanel['text'] = TTLocalizer.CdrResultAlreadyRedeemed + elif result == 4: + self.resultPanel['image'] = self.resultPanelErrorGui + self.resultPanel['text'] = TTLocalizer.CdrResultAlreadyRedeemed if result == 0: self.successSfx.play() else: