ToonTownRewritten/toontown/uberdog/ToontownUberRepository.py
2014-08-14 23:59:07 +01:00

47 lines
2.2 KiB
Python

import toontown.minigame.MinigameCreatorAI
from toontown.distributed.ToontownInternalRepository import ToontownInternalRepository
from direct.distributed.PyDatagram import *
from otp.rpc.RPCServer import RPCServer
from otp.distributed.DistributedDirectoryAI import DistributedDirectoryAI
from otp.distributed.OtpDoGlobals import *
from ToontownRPCHandler import *
class ToontownUberRepository(ToontownInternalRepository):
def __init__(self, baseChannel, serverId):
ToontownInternalRepository.__init__(self, baseChannel, serverId, dcSuffix='UD')
self.wantUD = config.GetBool('want-ud', True)
def handleConnected(self):
ToontownInternalRepository.handleConnected(self)
if config.GetBool('want-ClientServicesManagerUD', self.wantUD):
# Only generate the root object once, with the CSMUD.
rootObj = DistributedDirectoryAI(self)
rootObj.generateWithRequiredAndId(self.getGameDoId(), 0, 0)
self.createGlobals()
if config.GetBool('want-rpc-server', False):
self.rpcserver = RPCServer(ToontownRPCHandler(self))
def createGlobals(self):
"""
Create "global" objects.
"""
self.csm = self.generateGlobalIfWanted(OTP_DO_ID_CLIENT_SERVICES_MANAGER, 'ClientServicesManager')
self.chatAgent = self.generateGlobalIfWanted(OTP_DO_ID_CHAT_MANAGER, 'ChatAgent')
self.friendsManager = self.generateGlobalIfWanted(OTP_DO_ID_TTR_FRIENDS_MANAGER, 'TTRFriendsManager')
if config.GetBool('want-parties', True):
# want-parties overrides config for want-GlobalPartyManagerUD
self.globalPartyMgr = self.generateGlobalIfWanted(OTP_DO_ID_GLOBAL_PARTY_MANAGER, 'GlobalPartyManager')
else:
self.globalPartyMgr = None
def generateGlobalIfWanted(self, doId, name):
"""
We only create the "global" objects if we explicitly want them, or if
the config file doesn't define it, we resort to the value of self.wantUD.
If we don't want the object, we return None.
"""
if config.GetBool('want-%sUD' % name, self.wantUD):
return self.generateGlobalObject(doId, name)
else:
return None