From 6ba9b959c9c2b2a57c07e94a70ecaad75cc14ce4 Mon Sep 17 00:00:00 2001 From: John Cote Date: Wed, 11 Sep 2024 20:14:59 -0400 Subject: [PATCH] general: More fixes --- toontown/ai/WelcomeValleyManagerAI.py | 2 +- toontown/hood/QuietZoneState.py | 8 +- toontown/uberdog/DistributedCpuInfoMgrAI.py | 93 ++++++++++++++++++++- toontown/uberdog/DistributedCpuInfoMgrUD.py | 4 +- 4 files changed, 99 insertions(+), 8 deletions(-) diff --git a/toontown/ai/WelcomeValleyManagerAI.py b/toontown/ai/WelcomeValleyManagerAI.py index a213c0e..aafd872 100644 --- a/toontown/ai/WelcomeValleyManagerAI.py +++ b/toontown/ai/WelcomeValleyManagerAI.py @@ -432,7 +432,7 @@ class WelcomeValleyManagerAI(DistributedObjectAI.DistributedObjectAI): assert((hoodId % 2000) == 0) del self.welcomeValleys[hoodId] - self.welcomeValleyAllocator.free(hoodId / 2000) + self.welcomeValleyAllocator.free(hoodId // 2000) self.air.shutdownHood(hood[0]) self.air.shutdownHood(hood[1]) diff --git a/toontown/hood/QuietZoneState.py b/toontown/hood/QuietZoneState.py index df65ddf..93e2078 100644 --- a/toontown/hood/QuietZoneState.py +++ b/toontown/hood/QuietZoneState.py @@ -139,7 +139,9 @@ class QuietZoneState(StateData.StateData): return def handleWaitForQuietZoneResponse(self, msgType, di): - self.notify.debug('handleWaitForQuietZoneResponse(' + 'msgType=' + str(msgType) + ', di=' + str(di) + ')') + self.notify.debug('handleWaitForQuietZoneResponse(' + 'msgType=' + str(msgType) + ')') + if self.notify.getDebug(): + di.getDatagram().dumpHex(Notify.out()) if msgType == CLIENT_CREATE_OBJECT_REQUIRED: base.cr.handleQuietZoneGenerateWithRequired(di) elif msgType == CLIENT_CREATE_OBJECT_REQUIRED_OTHER: @@ -152,7 +154,9 @@ class QuietZoneState(StateData.StateData): base.cr.handlePlayGame(msgType, di) def handleWaitForZoneRedirect(self, msgType, di): - self.notify.debug('handleWaitForZoneRedirect(' + 'msgType=' + str(msgType) + ', di=' + str(di) + ')') + self.notify.debug('handleWaitForZoneRedirect(' + 'msgType=' + str(msgType) + ')') + if self.notify.getDebug(): + di.getDatagram().dumpHex(Notify.out()) if msgType == CLIENT_CREATE_OBJECT_REQUIRED: base.cr.handleQuietZoneGenerateWithRequired(di) elif msgType == CLIENT_CREATE_OBJECT_REQUIRED_OTHER: diff --git a/toontown/uberdog/DistributedCpuInfoMgrAI.py b/toontown/uberdog/DistributedCpuInfoMgrAI.py index b508d3b..8cdb3ee 100644 --- a/toontown/uberdog/DistributedCpuInfoMgrAI.py +++ b/toontown/uberdog/DistributedCpuInfoMgrAI.py @@ -1,5 +1,92 @@ -from direct.directnotify import DirectNotifyGlobal +import socket +import datetime +import os +from direct.distributed.DistributedObjectGlobal import DistributedObjectGlobal from direct.distributed.DistributedObjectAI import DistributedObjectAI +from otp.distributed import OtpDoGlobals +from toontown.toonbase import ToontownGlobals +from toontown.uberdog import InGameNewsResponses -class DistributedCpuInfoMgrAI(DistributedObjectAI): - notify = DirectNotifyGlobal.directNotify.newCategory('DistributedCpuInfoMgrAI') +ParentClass = DistributedObjectAI +#ParentClass = DistributedObjectGlobal +class DistributedCpuInfoMgrAI(ParentClass ): + """ + Uberdog object that keeps track of the last time in game news has been updated + """ + notify = directNotify.newCategory('DistributedInGameNewsMgrAI') + + + def __init__(self, cr): + """Construct ourselves, set up web dispatcher.""" + assert self.notify.debugCall() + ParentClass.__init__(self, cr) + self.latestIssueStr = "" + self.avId2Fingerprint = {} + self.accept("avatarEntered", self.handleAvatarEntered) + + def generate(self): + """We have zone info but not required fields, register for the special.""" + # IN_GAME_NEWS_MGR_UD_TO_ALL_AI will arrive on this channel + self.air.registerForChannel(OtpDoGlobals.OTP_DO_ID_TOONTOWN_CPU_INFO_MANAGER) + ParentClass.generate(self) + + def announceGenerate(self): + # tell uberdog we are starting up, so we can get info on the currently running public parties + # do whatever other sanity checks is necessary here + DistributedObjectAI.announceGenerate(self) + #self.air.sendUpdateToDoId("DistributedInGameNewsMgr", + # 'inGameNewsMgrAIStartingUp', + # OtpDoGlobals.OTP_DO_ID_TOONTOWN_CPU_INFO_MANAGER, + # [self.doId, self.air.districtId] + #) + def setLatestIssueStr(self, issueStr): + """We normally get this once, we could get this when a new issue is released while logged in.""" + # we receive this as a utc str + assert self.notify.debugStateCall(self) + self.latestIssueStr = issueStr + pass + + def b_setLatestIssueStr(self, latestIssue): + self.setLatestIssueStr(latestIssue) + self.d_setLatestIssueStr(latestIssue) + + def d_setLatestIssueStr(self, latestIssue): + self.sendUpdate("setLatestIssueStr",[self.getLatestIssueStr()]) + + + def getLatestIssueStr(self): + """We normally get this once, we could get this when a new issue is released while logged in.""" + assert self.notify.debugStateCall(self) + return self.latestIssueStr + pass + + + def newIssueUDtoAI(self, issueStr): + """Well the UD is telling us we have a new issue, spread it to the clients.""" + self.b_setLatestIssueStr(issueStr) + + def sendCpuInfoToUd(self, info, fingerprint): + """Prepare to send the info to the UD, we don't have the DISLid yet.""" + requesterId = self.air.getAvatarIdFromSender() + self.avId2Fingerprint[requesterId] = (info,fingerprint) + + def handleAvatarEntered(self, avatar): + """Send the cpu info to the UD once we get the avatar and the DISL id.""" + if avatar.doId in self.avId2Fingerprint: + info, fingerprint = self.avId2Fingerprint.get(avatar.doId) + dislId = 0 + if avatar: + try: + dislId = avatar.DISLid + except: + pass + if dislId: + self.air.sendUpdateToDoId("DistributedCpuInfoMgr", + 'setCpuInfoToUd', + OtpDoGlobals.OTP_DO_ID_TOONTOWN_CPU_INFO_MANAGER, + [avatar.doId, dislId, info[:255],fingerprint[:255]] + ) + else: + self.notify.warning("avId=%s has dislId=%s" % (avatar.doId, dislId)) + del self.avId2Fingerprint[avatar.doId] + diff --git a/toontown/uberdog/DistributedCpuInfoMgrUD.py b/toontown/uberdog/DistributedCpuInfoMgrUD.py index bc1eabb..d53529e 100644 --- a/toontown/uberdog/DistributedCpuInfoMgrUD.py +++ b/toontown/uberdog/DistributedCpuInfoMgrUD.py @@ -1,5 +1,5 @@ from direct.directnotify import DirectNotifyGlobal -from direct.distributed.DistributedObjectUD import DistributedObjectUD +from direct.distributed.DistributedObjectGlobalUD import DistributedObjectGlobalUD -class DistributedCpuInfoMgrUD(DistributedObjectUD): +class DistributedCpuInfoMgrUD(DistributedObjectGlobalUD): notify = DirectNotifyGlobal.directNotify.newCategory('DistributedCpuInfoMgrUD')