2019-11-27 19:14:30 -06:00
|
|
|
import time
|
|
|
|
|
2019-11-08 22:55:55 -06:00
|
|
|
from direct.directnotify import DirectNotifyGlobal
|
2019-11-22 21:11:12 -06:00
|
|
|
from direct.distributed.ClockDelta import globalClockDelta
|
2019-11-27 19:14:30 -06:00
|
|
|
from direct.distributed.DistributedObjectAI import DistributedObjectAI
|
|
|
|
|
|
|
|
from otp.otpbase import OTPGlobals
|
|
|
|
|
2019-11-08 22:55:55 -06:00
|
|
|
|
|
|
|
class TimeManagerAI(DistributedObjectAI):
|
|
|
|
notify = DirectNotifyGlobal.directNotify.newCategory('TimeManagerAI')
|
2019-11-22 21:11:12 -06:00
|
|
|
|
2019-11-27 19:14:30 -06:00
|
|
|
def __init__(self, air):
|
|
|
|
DistributedObjectAI.__init__(self, air)
|
|
|
|
self.avId2disconnectcode = {}
|
|
|
|
|
2019-11-22 21:11:12 -06:00
|
|
|
def requestServerTime(self, context):
|
|
|
|
avId = self.air.getAvatarIdFromSender()
|
|
|
|
if not avId:
|
|
|
|
return
|
|
|
|
|
2019-11-27 19:14:30 -06:00
|
|
|
self.sendUpdateToAvatarId(avId, 'serverTime',
|
|
|
|
[context, globalClockDelta.getRealNetworkTime(bits=32), int(time.time())])
|
|
|
|
|
|
|
|
def setDisconnectReason(self, disconnectCode):
|
|
|
|
avId = self.air.getAvatarIdFromSender()
|
|
|
|
if not avId:
|
|
|
|
return
|
2019-11-22 21:11:12 -06:00
|
|
|
|
2019-11-27 19:14:30 -06:00
|
|
|
self.avId2disconnectcode[avId] = disconnectCode
|
|
|
|
self.air.writeServerEvent('disconnect-reason', avId=avId,
|
|
|
|
reason=OTPGlobals.DisconnectReasons.get(disconnectCode, 'unknown'))
|