Beispiel #1
0
 def serverTime(self, context, timestamp, timeOfDay):
     end = globalClock.getRealTime()
     aiTimeSkew = timeOfDay - self.cr.getServerTimeOfDay()
     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))
     average = (self.start + end) / 2.0 - self.extraSkew
     uncertainty = (end - self.start) / 2.0 + abs(self.extraSkew)
     globalClockDelta.resynchronize(average, timestamp, uncertainty)
     self.notify.info('Local clock uncertainty +/- %.3f s' % globalClockDelta.getUncertainty())
     if globalClockDelta.getUncertainty() > self.maxUncertainty:
         if self.attemptCount < self.maxAttempts:
             self.notify.info('Uncertainty is too high, trying again.')
             self.start = globalClock.getRealTime()
             self.sendUpdate('requestServerTime', [self.thisContext])
             return
         self.notify.info('Giving up on uncertainty requirement.')
     if self.talkResult:
         base.localAvatar.setChatAbsolute('latency %0.0f ms, sync \xc2\xb1%0.0f ms' % (elapsed * 1000.0, globalClockDelta.getUncertainty() * 1000.0), CFSpeech | CFTimeout)
     self._gotFirstTimeSync = True
     messenger.send('gotTimeSync')
Beispiel #2
0
    def serverTime(self, context, timestamp, timeOfDay):
        end = globalClock.getRealTime()
        aiTimeSkew = timeOfDay - self.cr.getServerTimeOfDay()
        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))
        average = (self.start + end) / 2.0
        uncertainty = (end - self.start) / 2.0
        globalClockDelta.resynchronize(average, timestamp, uncertainty)
        self.notify.info('Local clock uncertainty +/- %.3f s' % globalClockDelta.getUncertainty())
        if globalClockDelta.getUncertainty() > self.maxUncertainty:
            if self.attemptCount < self.maxAttempts:
                self.notify.info('Uncertainty is too high, trying again.')
                self.start = globalClock.getRealTime()
                self.sendUpdate('requestServerTime', [self.thisContext])
                return
            self.notify.info('Giving up on uncertainty requirement.')
        self._gotFirstTimeSync = True
        messenger.send('gotTimeSync')

        toontownTimeManager = getattr(base.cr, 'toontownTimeManager', None)
        if toontownTimeManager:
            toontownTimeManager.updateLoginTimes(timeOfDay, int(time.time()), globalClock.getRealTime())
Beispiel #3
0
 def serverTime(self, context, timestamp, timeOfDay):
     end = globalClock.getRealTime()
     aiTimeSkew = timeOfDay - self.cr.getServerTimeOfDay()
     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))
     average = (self.start + end) / 2.0 - self.extraSkew
     uncertainty = (end - self.start) / 2.0 + abs(self.extraSkew)
     globalClockDelta.resynchronize(average, timestamp, uncertainty)
     self.notify.info('Local clock uncertainty +/- %.3f s' % globalClockDelta.getUncertainty())
     if globalClockDelta.getUncertainty() > self.maxUncertainty:
         if self.attemptCount < self.maxAttempts:
             self.notify.info('Uncertainty is too high, trying again.')
             self.start = globalClock.getRealTime()
             self.sendUpdate('requestServerTime', [
                 self.thisContext])
             return None
         
         self.notify.info('Giving up on uncertainty requirement.')
     
     if self.talkResult:
         base.localAvatar.setChatAbsolute('latency %0.0f ms, sync \xc2\xb1%0.0f ms' % (elapsed * 1000.0, globalClockDelta.getUncertainty() * 1000.0), CFSpeech | CFTimeout)
     
     self._gotFirstTimeSync = True
     messenger.send('gotTimeSync')
 def setServerDelta(self, delta, timezone):
     delta = int(round(delta))
     Notifier.serverDelta = delta + time.timezone - timezone
     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))
Beispiel #5
0
    def serverTime(self, context, timestamp, timeOfDay):
        """serverTime(self, int8 context, int32 timestamp, uint32 timeOfDay)

        This message is sent from the AI to the client in response to
        a previous requestServerTime.  It contains the time of day as
        observed by the AI.

        The client should use this, in conjunction with the time
        measurement taken before calling requestServerTime (above), to
        determine the clock delta between the AI and the client
        machines.
        """
        end = globalClock.getRealTime()

        # Compare the AI's current time with that previously reported
        # by the server at login (and adjusted since then by the local
        # clock).  It shouldn't be very different.
        aiTimeSkew = timeOfDay - self.cr.getServerTimeOfDay()

        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)))

        average = (self.start + end) / 2.0 - self.extraSkew
        uncertainty = (end - self.start) / 2.0 + abs(self.extraSkew)

        globalClockDelta.resynchronize(average, timestamp, uncertainty)

        self.notify.info("Local clock uncertainty +/- %.3f s" %
                         (globalClockDelta.getUncertainty()))

        if globalClockDelta.getUncertainty() > self.maxUncertainty:
            if self.attemptCount < self.maxAttempts:
                self.notify.info("Uncertainty is too high, trying again.")
                self.start = globalClock.getRealTime()
                self.sendUpdate("requestServerTime", [self.thisContext])
                return
            self.notify.info("Giving up on uncertainty requirement.")

        if self.talkResult:
            # This should change to be more generic
            # maybe self.cr.localAv
            base.localAvatar.setChatAbsolute(
                "latency %0.0f ms, sync ±%0.0f ms" %
                (elapsed * 1000.0, globalClockDelta.getUncertainty() * 1000.0),
                CFSpeech | CFTimeout)

        self._gotFirstTimeSync = True
        messenger.send("gotTimeSync")
Beispiel #6
0
    def __checkMailbox(self,
                       onOrder,
                       mailboxContents,
                       liveDatabase,
                       awardMailboxContents,
                       numMailItems=0,
                       numPartyInvites=0):
        # We have gotten the above data for the owner of this house.
        # Check whether we should raise the flag because he has
        # something in his mailbox.

        assert (self.notify.debug(
            "__checkMailbox(%s, %s, %s): %s" %
            (onOrder, mailboxContents, liveDatabase, self.doId)))

        # Is the mailbox full?
        if mailboxContents or (numMailItems > 0) or (
                numPartyInvites > 0) or awardMailboxContents:
            self.notify.debug("mailbox is full; raising flag: %s" %
                              (self.doId))
            self.mailbox.b_setFullIndicator(1)

        elif onOrder:
            # Maybe we have something coming soon.
            nextTime = onOrder.getNextDeliveryDate()
            if nextTime != None:
                duration = nextTime * 60 - time.time()
                if (duration > 0):
                    if not liveDatabase:
                        # If the toon is expecting a delivery later,
                        # set a timer to raise the flag at that
                        # time--but don't bother if the toon was found
                        # in the live database (because in that case,
                        # the DistributedToonAI will raise the flag).
                        self.notify.debug(
                            "expecting delivery in %s, will raise flag later: %s"
                            % (PythonUtil.formatElapsedSeconds(duration),
                               self.doId))
                        self.mailbox.raiseFlagLater(duration)
                else:
                    self.notify.debug(
                        "delivery has been completed, raising flag: %s" %
                        (self.doId))
                    self.mailbox.b_setFullIndicator(1)

        # Now tell the client that the house is ready.
        self.d_setHouseReady()
Beispiel #7
0
    def setServerDelta(self, delta, timezone):
        """
        Call this method on any Notify object to globally change the
        timestamp printed for each line of all Notify objects.

        This synchronizes the timestamp with the server's known time
        of day, and also switches into the server's timezone.
        """
        delta = int(round(delta))
        Notifier.serverDelta = delta + time.timezone - timezone

        from pandac 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))
Beispiel #8
0
    def setServerDelta(self, delta, timezone):
        """
        Call this method on any Notify object to globally change the
        timestamp printed for each line of all Notify objects.

        This synchronizes the timestamp with the server's known time
        of day, and also switches into the server's timezone.
        """
        delta = int(round(delta))
        Notifier.serverDelta = delta + time.timezone - timezone

        # The following call is necessary to make the output from C++
        # notify messages show the same timestamp as those generated
        # from Python-level notify messages.
        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))
Beispiel #9
0
    def setServerDelta(self, delta, timezone):
        """
        Call this method on any Notify object to globally change the
        timestamp printed for each line of all Notify objects.

        This synchronizes the timestamp with the server's known time
        of day, and also switches into the server's timezone.
        """
        delta = int(round(delta))
        Notifier.serverDelta = delta + time.timezone - timezone

        # The following call is necessary to make the output from C++
        # notify messages show the same timestamp as those generated
        # from Python-level notify messages.
        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))
Beispiel #10
0
 def setServerDelta(self, delta, timezone):
     delta = int(round(delta))
     Notifier.serverDelta = delta + time.timezone - timezone
     from pandac.PandaModules import 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))
Beispiel #11
0
    def setServerDelta(self, delta, timezone):
        """
        Call this method on any Notify object to globally change the
        timestamp printed for each line of all Notify objects.

        This synchronizes the timestamp with the server's known time
        of day, and also switches into the server's timezone.
        """
        delta = int(round(delta))
        Notifier.serverDelta = delta + time.timezone - timezone

        from pandac 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))