Poodletooth-iLand/toontown/distributed/ToontownInternalRepository.py

79 lines
3 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
from direct.distributed.AstronInternalRepository import AstronInternalRepository
from otp.distributed.OtpDoGlobals import *
2015-07-12 11:48:58 -05:00
from toontown.distributed.ToontownNetMessengerAI import ToontownNetMessengerAI
2015-07-13 12:04:39 -05:00
from direct.distributed.PyDatagram import PyDatagram
import traceback
import sys
2015-03-03 16:10:12 -06:00
class ToontownInternalRepository(AstronInternalRepository):
GameGlobalsId = OTP_DO_ID_TOONTOWN
dbId = 4003
def __init__(self, baseChannel, serverId=None, dcFileNames=None,
dcSuffix='AI', connectMethod=None, threadedNet=None):
AstronInternalRepository.__init__(
self, baseChannel, serverId=serverId, dcFileNames=dcFileNames,
dcSuffix=dcSuffix, connectMethod=connectMethod, threadedNet=threadedNet)
2015-07-13 09:17:56 -05:00
2015-07-12 11:48:58 -05:00
def handleConnected(self):
self.__messenger = ToontownNetMessengerAI(self)
2015-07-18 11:57:36 -05:00
if config.GetBool('want-mongo', False):
import pymongo
self.dbConn = pymongo.MongoClient(config.GetString('mongodb-url', 'localhost'))
self.dbGlobalCursor = self.dbConn.toontownstride
self.dbCursor = self.dbGlobalCursor['air-%d' % self.ourChannel]
else:
self.dbConn = None
self.dbGlobalCursor = None
self.dbCursor = None
2015-07-13 09:17:56 -05:00
2015-07-12 11:48:58 -05:00
def sendNetEvent(self, message, sentArgs=[]):
self.__messenger.send(message, sentArgs)
def addExitEvent(self, message):
dg = self.__messenger.prepare(message)
self.addPostRemove(dg)
def handleDatagram(self, di):
msgType = self.getMsgType()
if msgType == self.__messenger.msgType:
self.__messenger.handle(msgType, di)
return
AstronInternalRepository.handleDatagram(self, di)
2015-03-03 16:10:12 -06:00
def getAvatarIdFromSender(self):
2015-07-13 12:04:39 -05:00
return int(self.getMsgSender() & 0xFFFFFFFF)
2015-03-03 16:10:12 -06:00
def getAccountIdFromSender(self):
2015-07-13 12:04:39 -05:00
return int((self.getMsgSender()>>32) & 0xFFFFFFFF)
2015-03-03 16:10:12 -06:00
def _isValidPlayerLocation(self, parentId, zoneId):
if zoneId < 1000 and zoneId != 1:
return False
return True
2015-07-13 12:04:39 -05:00
def readerPollOnce(self):
try:
return AstronInternalRepository.readerPollOnce(self)
except SystemExit, KeyboardInterrupt:
raise
except Exception as e:
if self.getAvatarIdFromSender() > 100000000:
dg = PyDatagram()
dg.addServerHeader(self.getMsgSender(), self.ourChannel, CLIENTAGENT_EJECT)
dg.addUint16(166)
dg.addString('You were disconnected to prevent a district reset.')
self.send(dg)
self.writeServerEvent('INTERNAL-EXCEPTION', self.getAvatarIdFromSender(), self.getAccountIdFromSender(), repr(e), traceback.format_exc())
self.notify.warning('INTERNAL-EXCEPTION: %s (%s)' % (repr(e), self.getAvatarIdFromSender()))
print traceback.format_exc()
sys.exc_clear()
return 1