Exemple #1
0
 def serverTime(self, context, timestamp, timeOfDay):
     end = globalClock.getRealTime()
     now = int(time.time())
     aiTimeDelta = timeOfDay - now
     aiTimeSkew = aiTimeDelta - self.cr.getServerDelta()
     if context != self.thisContext:
         self.notify.info('Ignoring TimeManager response for old context %d' % context)
         return None
     
     elapsed = end - self.start
     self.attemptCount += 1
     self.notify.info('Clock sync roundtrip took %0.3f ms' % elapsed * 1000.0)
     self.notify.info('AI time delta is %s from server delta' % PythonUtil.formatElapsedSeconds(aiTimeSkew))
     if elapsed > self.maxLatency:
         if self.attemptCount < self.maxAttempts:
             self.notify.info('Latency is too high, trying again.')
             self.start = globalClock.getRealTime()
             self.sendUpdate('requestServerTime', [
                 self.thisContext])
             return None
         
         self.notify.info('Giving up on latency requirement.')
     
     average = (self.start + end) / 2.0 - self.extraSkew
     change = globalClockDelta.resynchronize(average, timestamp)
     self.notify.info('Clock delta changed by %.3f s' % change)
     if self.talkResult:
         toonbase.localToon.setChatAbsolute('latency %0.0f ms, clock adjusted %.1f s' % (elapsed * 1000.0, change), CFSpeech | CFTimeout)
     
     self.gotSync = 1
     messenger.send('gotTimeSync')
 def serverTime(self, context, timestamp, timeOfDay):
     end = globalClock.getRealTime()
     now = int(time.time())
     aiTimeDelta = timeOfDay - now
     aiTimeSkew = aiTimeDelta - self.cr.getServerDelta()
     if context != self.thisContext:
         self.notify.info('Ignoring TimeManager response for old context %d' % context)
         return
     elapsed = end - self.start
     self.attemptCount += 1
     self.notify.info('Clock sync roundtrip took %0.3f ms' % (elapsed * 1000.0))
     self.notify.info('AI time delta is %s from server delta' % PythonUtil.formatElapsedSeconds(aiTimeSkew))
     if elapsed > self.maxLatency:
         if self.attemptCount < self.maxAttempts:
             self.notify.info('Latency is too high, trying again.')
             self.start = globalClock.getRealTime()
             self.sendUpdate('requestServerTime', [self.thisContext])
             return
         self.notify.info('Giving up on latency requirement.')
     average = (self.start + end) / 2.0 - self.extraSkew
     change = globalClockDelta.resynchronize(average, timestamp)
     self.notify.info('Clock delta changed by %.3f s' % change)
     if self.talkResult:
         toonbase.localToon.setChatAbsolute('latency %0.0f ms, clock adjusted %.1f s' % (elapsed * 1000.0, change), CFSpeech | CFTimeout)
     self.gotSync = 1
     messenger.send('gotTimeSync')
Exemple #3
0
 def setServerDelta(self, delta, timezone):
     delta = int(round(delta))
     Notifier.serverDelta = delta + time.timezone - timezone
     import NotifyCategory
     NotifyCategory.NotifyCategory.setServerDelta(self.serverDelta)
     self.info(
         'Notify clock adjusted by %s (and timezone adjusted by %s hours) to synchronize with server.'
         % (PythonUtil.formatElapsedSeconds(delta),
            (time.timezone - timezone) / 3600))
 def setCheesyEffect(self, effect, hoodId, expireTime):
     self.savedCheesyEffect = effect
     self.savedCheesyHoodId = hoodId
     self.savedCheesyExpireTime = expireTime
     if self == toonbase.localToon:
         self.notify.info('setCheesyEffect(%s, %s, %s)' % (effect, hoodId, expireTime))
         if effect != ToontownGlobals.CENormal:
             serverTime = time.time() + self.cr.getServerDelta()
             duration = expireTime * 60 - serverTime
             if duration < 0:
                 self.notify.info('effect should have expired %s ago.' % PythonUtil.formatElapsedSeconds(-duration))
             else:
                 self.notify.info('effect will expire in %s.' % PythonUtil.formatElapsedSeconds(duration))
         
     
     if self.activeState == DistributedObject.ESGenerated:
         self.reconsiderCheesyEffect(lerpTime = 0.5)
     else:
         self.reconsiderCheesyEffect()