2015-03-03 16:10:12 -06:00
|
|
|
from direct.directnotify import DirectNotifyGlobal
|
|
|
|
from direct.distributed.DistributedObjectAI import DistributedObjectAI
|
|
|
|
from direct.distributed.ClockDelta import globalClockDelta
|
2015-04-25 07:18:30 -05:00
|
|
|
from otp.otpbase import OTPGlobals
|
2015-03-03 16:10:12 -06:00
|
|
|
import time
|
|
|
|
|
|
|
|
class TimeManagerAI(DistributedObjectAI):
|
|
|
|
notify = DirectNotifyGlobal.directNotify.newCategory("TimeManagerAI")
|
|
|
|
|
2015-04-25 06:18:50 -05:00
|
|
|
def __init__(self, air):
|
|
|
|
DistributedObjectAI.__init__(self, air)
|
|
|
|
self.avId2DcReason = {}
|
2015-07-05 18:59:25 -05:00
|
|
|
|
2015-03-03 16:10:12 -06:00
|
|
|
def requestServerTime(self, context):
|
2015-04-25 06:18:50 -05:00
|
|
|
self.sendUpdateToAvatarId(self.air.getAvatarIdFromSender(), 'serverTime', [context, globalClockDelta.getRealNetworkTime(bits=32), int(time.time())])
|
2015-03-03 16:10:12 -06:00
|
|
|
|
|
|
|
def setDisconnectReason(self, reason):
|
2015-04-25 07:18:30 -05:00
|
|
|
avId = self.air.getAvatarIdFromSender()
|
2015-07-05 18:59:25 -05:00
|
|
|
|
2015-04-25 07:18:30 -05:00
|
|
|
if reason == OTPGlobals.DisconnectNone and avId in self.avId2DcReason:
|
|
|
|
del self.avId2DcReason[avId]
|
|
|
|
else:
|
|
|
|
self.avId2DcReason[avId] = reason
|
2015-03-03 16:10:12 -06:00
|
|
|
|
|
|
|
def setExceptionInfo(self, exception):
|
|
|
|
avId = self.air.getAvatarIdFromSender()
|
2015-04-25 06:18:50 -05:00
|
|
|
self.air.writeServerEvent('client-exception', avId, exception)
|
2015-07-05 18:59:25 -05:00
|
|
|
|
2015-04-25 06:18:50 -05:00
|
|
|
def getDisconnectReason(self, avId):
|
2015-07-05 18:59:25 -05:00
|
|
|
return self.avId2DcReason.get(avId, 0)
|