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) self.wantMongo = config.GetBool('want-mongo', False) def handleConnected(self): self.__messenger = ToontownNetMessengerAI(self) if self.wantMongo: import pymongo mongourl = config.GetString('mongodb-url', 'mongodb://localhost') replicaset = config.GetString('mongodb-replicaset', '') db = (urlparse.urlparse(mongourl).path or '/Astron_Dev')[1:] if replicaset: self.dbConn = pymongo.MongoClient(mongourl, replicaset=replicaset) else: self.dbConn = pymongo.MongoClient(mongourl) self.database = self.dbConn[db] self.dbGlobalCursor = self.database.toontownstride else: self.dbConn = None self.database = None self.dbGlobalCursor = None 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) def getAvatarIdFromSender(self): return int(self.getMsgSender() & 0xFFFFFFFF) def getAccountIdFromSender(self): return int((self.getMsgSender()>>32) & 0xFFFFFFFF) def _isValidPlayerLocation(self, parentId, zoneId): if zoneId < 1000 and zoneId != 1: return False return True 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()
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) self.netMessenger.register(0, 'shardStatus') self.netMessenger.register(1, 'queryShardStatus') self.netMessenger.register(2, 'startInvasion') self.netMessenger.register(3, 'stopInvasion') self.__messenger = ToontownNetMessengerAI(self) def getAvatarIdFromSender(self): return self.getMsgSender() & 0xFFFFFFFF def getAccountIdFromSender(self): return (self.getMsgSender() >> 32) & 0xFFFFFFFF def _isValidPlayerLocation(self, parentId, zoneId): return False if zoneId < 1000 and zoneId != 1 else True def sendNetEvent(self, message, sentArgs=[], channels=None): self.__messenger.send(message, sentArgs, channels) def handleDatagram(self, di): msgType = self.getMsgType() if msgType == self.__messenger.msgType: self.__messenger.handle(msgType, di) return if msgType == CLIENTAGENT_GET_NETWORK_ADDRESS_RESP: context = di.getUint32() remoteIp = di.getString() port = di.getUint16() localIp = di.getString() localPort = di.getUint16() if self.csm: self.csm.completeLogin(context, remoteIp) return AstronInternalRepository.handleDatagram(self, di) def readerPollOnce(self): try: return AstronInternalRepository.readerPollOnce(self) except (SystemExit, KeyboardInterrupt): raise except Exception as e: if self.getAvatarIdFromSender( ) > 100000000: # If an avatar is sending, boot them dg = PyDatagram() dg.addServerHeader(self.getMsgSender(), self.ourChannel, CLIENTAGENT_EJECT) dg.addUint16(420) dg.addString( 'You were disconnected to prevent a district reset.') self.send(dg) self.writeServerEvent('EXCEPTION-POTENTIAL-CRASH', self.getAvatarIdFromSender(), self.getAccountIdFromSender(), repr(e), traceback.format_exc()) self.notify.warning('EXCEPTION-POTENTIAL-CRASH: %s (%s)' % (repr(e), self.getAvatarIdFromSender())) print traceback.format_exc() return 1
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) self.netMessenger.register(0, 'shardStatus') self.netMessenger.register(1, 'queryShardStatus') self.netMessenger.register(2, 'startInvasion') self.netMessenger.register(3, 'stopInvasion') self.__messenger = ToontownNetMessengerAI(self) def getAvatarIdFromSender(self): return self.getMsgSender() & 0xFFFFFFFF def getAccountIdFromSender(self): return (self.getMsgSender() >> 32) & 0xFFFFFFFF def _isValidPlayerLocation(self, parentId, zoneId): return False if zoneId < 1000 and zoneId != 1 else True def sendNetEvent(self, message, sentArgs=[], channels=None): self.__messenger.send(message, sentArgs, channels) def handleDatagram(self, di): msgType = self.getMsgType() if msgType == self.__messenger.msgType: self.__messenger.handle(msgType, di) return if msgType == CLIENTAGENT_GET_NETWORK_ADDRESS_RESP: context = di.getUint32() remoteIp = di.getString() port = di.getUint16() localIp = di.getString() localPort = di.getUint16() if self.csm: self.csm.completeLogin(context, remoteIp) return AstronInternalRepository.handleDatagram(self, di) def readerPollOnce(self): try: return AstronInternalRepository.readerPollOnce(self) except (SystemExit, KeyboardInterrupt): raise except Exception as e: if self.getAvatarIdFromSender( ) > 100000000: # If an avatar is sending, boot them dg = PyDatagram() dg.addServerHeader(self.getMsgSender(), self.ourChannel, CLIENTAGENT_EJECT) dg.addUint16(420) dg.addString( 'You were disconnected to prevent a district reset.') self.send(dg) self.writeServerEvent('EXCEPTION-POTENTIAL-CRASH', self.getAvatarIdFromSender(), self.getAccountIdFromSender(), repr(e), traceback.format_exc()) self.notify.warning('EXCEPTION-POTENTIAL-CRASH: %s (%s)' % (repr(e), self.getAvatarIdFromSender())) print traceback.format_exc() sys.exc_clear() import os if os.getenv('DISTRICT_NAME', 'Test Canvas') == "Test Canvas": return 1 from raven import Client from os.path import expanduser errorReporter = Client( 'https://*****:*****@sentry.io/189240' ) errorReporter.tags_context({ 'district_name': os.getenv('DISTRICT_NAME', 'UNDEFINED'), 'AVID_SENDER': self.getAvatarIdFromSender(), 'ACID_SENDER': self.getAccountIdFromSender(), 'homedir': expanduser('~'), 'CRITICAL': 'False' }) errorReporter.captureException() return 1
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) self.wantMongo = config.GetBool('want-mongo', False) def handleConnected(self): self.__messenger = ToontownNetMessengerAI(self) if self.wantMongo: import pymongo mongourl = config.GetString('mongodb-url', 'mongodb://localhost') replicaset = config.GetString('mongodb-replicaset', '') db = (urlparse.urlparse(mongourl).path or '/Astron_Dev')[1:] if replicaset: self.dbConn = pymongo.MongoClient(mongourl, replicaset=replicaset) else: self.dbConn = pymongo.MongoClient(mongourl) self.database = self.dbConn[db] self.dbGlobalCursor = self.database.toontownstride else: self.dbConn = None self.database = None self.dbGlobalCursor = None 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) def getAvatarIdFromSender(self): return int(self.getMsgSender() & 0xFFFFFFFF) def getAccountIdFromSender(self): return int((self.getMsgSender() >> 32) & 0xFFFFFFFF) def _isValidPlayerLocation(self, parentId, zoneId): if zoneId < 1000 and zoneId != 1: return False return True 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()