TimeManager cleanup and add death on game exit in cog battle

This commit is contained in:
DenialMC 2015-04-25 14:18:50 +03:00
parent 1ba18164bb
commit 587e734ba2
5 changed files with 16 additions and 58 deletions

View file

@ -1,20 +1,13 @@
import base64
from direct.directnotify import DirectNotifyGlobal from direct.directnotify import DirectNotifyGlobal
from direct.distributed import DistributedObject from direct.distributed import DistributedObject
from direct.distributed.ClockDelta import * from direct.distributed.ClockDelta import *
from direct.showbase import GarbageReport
from direct.showbase import PythonUtil from direct.showbase import PythonUtil
from direct.showbase.DirectObject import * from direct.showbase.DirectObject import *
from direct.task import Task from direct.task import Task
import os
from pandac.PandaModules import * from pandac.PandaModules import *
import re
import sys
import time
from otp.otpbase import OTPGlobals from otp.otpbase import OTPGlobals
from toontown.chat.ChatGlobals import * from toontown.chat.ChatGlobals import *
import time
class TimeManager(DistributedObject.DistributedObject): class TimeManager(DistributedObject.DistributedObject):
notify = DirectNotifyGlobal.directNotify.newCategory('TimeManager') notify = DirectNotifyGlobal.directNotify.newCategory('TimeManager')
@ -26,10 +19,6 @@ class TimeManager(DistributedObject.DistributedObject):
self.minWait = base.config.GetFloat('time-manager-min-wait', 10) self.minWait = base.config.GetFloat('time-manager-min-wait', 10)
self.maxUncertainty = base.config.GetFloat('time-manager-max-uncertainty', 1) self.maxUncertainty = base.config.GetFloat('time-manager-max-uncertainty', 1)
self.maxAttempts = base.config.GetInt('time-manager-max-attempts', 5) self.maxAttempts = base.config.GetInt('time-manager-max-attempts', 5)
self.extraSkew = base.config.GetInt('time-manager-extra-skew', 0)
if self.extraSkew != 0:
self.notify.info('Simulating clock skew of %0.3f s' % self.extraSkew)
self.talkResult = 0
self.thisContext = -1 self.thisContext = -1
self.nextContext = 0 self.nextContext = 0
self.attemptCount = 0 self.attemptCount = 0
@ -42,10 +31,10 @@ class TimeManager(DistributedObject.DistributedObject):
self.cr.timeManager.delete() self.cr.timeManager.delete()
self.cr.timeManager = self self.cr.timeManager = self
DistributedObject.DistributedObject.generate(self) DistributedObject.DistributedObject.generate(self)
self.accept(OTPGlobals.SynchronizeHotkey, self.handleHotkey)
self.accept('clock_error', self.handleClockError) self.accept('clock_error', self.handleClockError)
if self.updateFreq > 0: if self.updateFreq > 0:
self.startTask() self.startTask()
self.setDisconnectReason(OTPGlobals.DisconnectNone)
return return
def announceGenerate(self): def announceGenerate(self):
@ -56,7 +45,6 @@ class TimeManager(DistributedObject.DistributedObject):
return self._gotFirstTimeSync return self._gotFirstTimeSync
def disable(self): def disable(self):
self.ignore(OTPGlobals.SynchronizeHotkey)
self.ignore('clock_error') self.ignore('clock_error')
self.stopTask() self.stopTask()
if self.cr.timeManager == self: if self.cr.timeManager == self:
@ -66,7 +54,6 @@ class TimeManager(DistributedObject.DistributedObject):
return return
def delete(self): def delete(self):
self.ignore(OTPGlobals.SynchronizeHotkey)
self.ignore('clock_error') self.ignore('clock_error')
self.stopTask() self.stopTask()
if self.cr.timeManager == self: if self.cr.timeManager == self:
@ -86,13 +73,6 @@ class TimeManager(DistributedObject.DistributedObject):
taskMgr.doMethodLater(self.updateFreq, self.doUpdate, 'timeMgrTask') taskMgr.doMethodLater(self.updateFreq, self.doUpdate, 'timeMgrTask')
return Task.done return Task.done
def handleHotkey(self):
self.lastAttempt = -self.minWait * 2
if self.synchronize('user hotkey'):
self.talkResult = 1
else:
base.localAvatar.setChatAbsolute('Too soon.', CFSpeech | CFTimeout)
def handleClockError(self): def handleClockError(self):
self.synchronize('clock error') self.synchronize('clock error')
@ -101,7 +81,6 @@ class TimeManager(DistributedObject.DistributedObject):
if now - self.lastAttempt < self.minWait: if now - self.lastAttempt < self.minWait:
self.notify.debug('Not resyncing (too soon): %s' % description) self.notify.debug('Not resyncing (too soon): %s' % description)
return 0 return 0
self.talkResult = 0
self.thisContext = self.nextContext self.thisContext = self.nextContext
self.attemptCount = 0 self.attemptCount = 0
self.nextContext = self.nextContext + 1 & 255 self.nextContext = self.nextContext + 1 & 255
@ -121,8 +100,8 @@ class TimeManager(DistributedObject.DistributedObject):
self.attemptCount += 1 self.attemptCount += 1
self.notify.info('Clock sync roundtrip took %0.3f ms' % (elapsed * 1000.0)) 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)) self.notify.info('AI time delta is %s from server delta' % PythonUtil.formatElapsedSeconds(aiTimeSkew))
average = (self.start + end) / 2.0 - self.extraSkew average = (self.start + end) / 2.0
uncertainty = (end - self.start) / 2.0 + abs(self.extraSkew) uncertainty = (end - self.start) / 2.0
globalClockDelta.resynchronize(average, timestamp, uncertainty) globalClockDelta.resynchronize(average, timestamp, uncertainty)
self.notify.info('Local clock uncertainty +/- %.3f s' % globalClockDelta.getUncertainty()) self.notify.info('Local clock uncertainty +/- %.3f s' % globalClockDelta.getUncertainty())
if globalClockDelta.getUncertainty() > self.maxUncertainty: if globalClockDelta.getUncertainty() > self.maxUncertainty:
@ -132,8 +111,6 @@ class TimeManager(DistributedObject.DistributedObject):
self.sendUpdate('requestServerTime', [self.thisContext]) self.sendUpdate('requestServerTime', [self.thisContext])
return return
self.notify.info('Giving up on uncertainty requirement.') 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 self._gotFirstTimeSync = True
messenger.send('gotTimeSync') messenger.send('gotTimeSync')
@ -142,7 +119,6 @@ class TimeManager(DistributedObject.DistributedObject):
toontownTimeManager.updateLoginTimes(timeOfDay, int(time.time()), globalClock.getRealTime()) toontownTimeManager.updateLoginTimes(timeOfDay, int(time.time()), globalClock.getRealTime())
def setDisconnectReason(self, disconnectCode): def setDisconnectReason(self, disconnectCode):
self.notify.info('Client disconnect reason %s.' % disconnectCode)
self.sendUpdate('setDisconnectReason', [disconnectCode]) self.sendUpdate('setDisconnectReason', [disconnectCode])
def setExceptionInfo(self): def setExceptionInfo(self):

View file

@ -6,16 +6,19 @@ import time
class TimeManagerAI(DistributedObjectAI): class TimeManagerAI(DistributedObjectAI):
notify = DirectNotifyGlobal.directNotify.newCategory("TimeManagerAI") notify = DirectNotifyGlobal.directNotify.newCategory("TimeManagerAI")
def __init__(self, air):
DistributedObjectAI.__init__(self, air)
self.avId2DcReason = {}
def requestServerTime(self, context): def requestServerTime(self, context):
self.sendUpdateToAvatarId(self.air.getAvatarIdFromSender(), self.sendUpdateToAvatarId(self.air.getAvatarIdFromSender(), 'serverTime', [context, globalClockDelta.getRealNetworkTime(bits=32), int(time.time())])
'serverTime', [context,
globalClockDelta.getRealNetworkTime(bits=32),
int(time.time())])
def setDisconnectReason(self, reason): def setDisconnectReason(self, reason):
avId = self.air.getAvatarIdFromSender() self.avId2DcReason[self.air.getAvatarIdFromSender()] = reason
self.air.writeServerEvent('disconnect-reason', avId, reason)
def setExceptionInfo(self, exception): def setExceptionInfo(self, exception):
avId = self.air.getAvatarIdFromSender() avId = self.air.getAvatarIdFromSender()
self.air.writeServerEvent('client-exception', avId, exception) self.air.writeServerEvent('client-exception', avId, exception)
def getDisconnectReason(self, avId):
return self.avId2DcReason.get(avId, 0)

View file

@ -16,10 +16,6 @@ DefaultCameraFar = 800.0
DefaultCameraNear = 1.0 DefaultCameraNear = 1.0
AICollisionPriority = 10 AICollisionPriority = 10
AICollMovePriority = 8 AICollMovePriority = 8
# As of right now, 200 friends is pretty insane, especially with the current CONSTANT db querying.
# But since we told people that we are allowing "unlimited" friends, we instead can give them a
# high amount.
MaxFriends = 200 MaxFriends = 200
MaxBackCatalog = 48 MaxBackCatalog = 48
FriendChat = 1 FriendChat = 1
@ -67,18 +63,12 @@ CEName2Id = {
} }
BigToonScale = 1.5 BigToonScale = 1.5
SmallToonScale = 0.5 SmallToonScale = 0.5
DisconnectUnknown = 0 DisconnectNone = 0
DisconnectBookExit = 1 DisconnectBookExit = 1
DisconnectCloseWindow = 2 DisconnectCloseWindow = 2
DisconnectPythonError = 3 DisconnectPythonError = 3
DisconnectSwitchShards = 4 DisconnectSwitchShards = 4
DisconnectGraphicsError = 5 DisconnectGraphicsError = 5
DisconnectReasons = {DisconnectUnknown: 'unknown',
DisconnectBookExit: 'book exit',
DisconnectCloseWindow: 'closed window',
DisconnectPythonError: 'python error',
DisconnectSwitchShards: 'switch shards',
DisconnectGraphicsError: 'graphics error'}
DatabaseDialogTimeout = 20.0 DatabaseDialogTimeout = 20.0
DatabaseGiveupTimeout = 45.0 DatabaseGiveupTimeout = 45.0
WalkCutOff = 0.5 WalkCutOff = 0.5
@ -201,7 +191,6 @@ FriendsListHotkey = 'f7'
StickerBookHotkey = 'f8' StickerBookHotkey = 'f8'
OptionsPageHotkey = 'escape' OptionsPageHotkey = 'escape'
ScreenshotHotkey = 'f9' ScreenshotHotkey = 'f9'
SynchronizeHotkey = 'shift-f6'
QuestsHotkeyOn = 'end' QuestsHotkeyOn = 'end'
QuestsHotkeyOff = 'end-up' QuestsHotkeyOff = 'end-up'
InventoryHotkeyOn = 'home' InventoryHotkeyOn = 'home'

View file

@ -1,8 +1,6 @@
from pandac.PandaModules import * from pandac.PandaModules import *
from direct.distributed import DistributedObject from direct.distributed import DistributedObject
from direct.directnotify import DirectNotifyGlobal from direct.directnotify import DirectNotifyGlobal
from toontown.toonbase import ToontownGlobals
from direct.showbase import PythonUtil
class WelcomeValleyManager(DistributedObject.DistributedObject): class WelcomeValleyManager(DistributedObject.DistributedObject):
notify = DirectNotifyGlobal.directNotify.newCategory('WelcomeValleyManager') notify = DirectNotifyGlobal.directNotify.newCategory('WelcomeValleyManager')
@ -19,13 +17,11 @@ class WelcomeValleyManager(DistributedObject.DistributedObject):
return return
def disable(self): def disable(self):
self.ignore(ToontownGlobals.SynchronizeHotkey)
base.cr.welcomeValleyManager = None base.cr.welcomeValleyManager = None
DistributedObject.DistributedObject.disable(self) DistributedObject.DistributedObject.disable(self)
return return
def delete(self): def delete(self):
self.ignore(ToontownGlobals.SynchronizeHotkey)
base.cr.welcomeValleyManager = None base.cr.welcomeValleyManager = None
DistributedObject.DistributedObject.delete(self) DistributedObject.DistributedObject.delete(self)
return return

View file

@ -620,13 +620,7 @@ class DistributedBattleBaseAI(DistributedObjectAI.DistributedObjectAI, BattleBas
self.notify.debug('requestAdjust() - in state: %s' % cstate) self.notify.debug('requestAdjust() - in state: %s' % cstate)
def __handleUnexpectedExit(self, avId): def __handleUnexpectedExit(self, avId):
#TODO: fixme userAborted = self.air.timeManager.getDisconnectReason(avId) == ToontownGlobals.DisconnectCloseWindow
#disconnectCode = self.air.getAvatarDisconnectReason(avId)
disconnectCode = "placeHolder dc code, need self.air.getAvatarDisconnectReason(avId)"
self.notify.warning('toon: %d exited unexpectedly, reason %s' % (avId, disconnectCode))
#userAborted = disconnectCode == ToontownGlobals.DisconnectCloseWindow
#TODO: fixme
userAborted = False
self.__handleSuddenExit(avId, userAborted) self.__handleSuddenExit(avId, userAborted)
def __handleSuddenExit(self, avId, userAborted): def __handleSuddenExit(self, avId, userAborted):