From 44edf68ff774c256398decd422b08facc1c3e0ee Mon Sep 17 00:00:00 2001 From: John Date: Sun, 21 Jun 2015 12:27:40 +0300 Subject: [PATCH] DBObject holocaust --- otp/ai/AIMsgTypes.py | 70 ------ toontown/ai/DatabaseObject.py | 210 ------------------ toontown/ai/ToontownAIMsgTypes.py | 8 - toontown/battle/BattleCalculatorAI.py | 2 +- toontown/battle/DistributedBattleBaseAI.py | 22 +- .../building/DistributedPetshopInteriorAI.py | 4 +- toontown/toon/DistributedNPCTailorAI.py | 16 +- 7 files changed, 11 insertions(+), 321 deletions(-) delete mode 100755 otp/ai/AIMsgTypes.py delete mode 100755 toontown/ai/DatabaseObject.py delete mode 100755 toontown/ai/ToontownAIMsgTypes.py diff --git a/otp/ai/AIMsgTypes.py b/otp/ai/AIMsgTypes.py deleted file mode 100755 index 4b7d07e2..00000000 --- a/otp/ai/AIMsgTypes.py +++ /dev/null @@ -1,70 +0,0 @@ -from otp.distributed.OtpDoGlobals import * -from direct.showbase.PythonUtil import invertDictLossless -CHANNEL_CLIENT_BROADCAST = 4014 -BAD_CHANNEL_ID = 0 -CONTROL_MESSAGE = 4001 -CONTROL_SET_CHANNEL = 2001 -CONTROL_REMOVE_CHANNEL = 2002 -CONTROL_SET_CON_NAME = 2004 -CONTROL_SET_CON_URL = 2005 -CONTROL_ADD_RANGE = 2008 -CONTROL_REMOVE_RANGE = 2009 -CONTROL_ADD_POST_REMOVE = 2010 -CONTROL_CLEAR_POST_REMOVE = 2011 -AIMsgName2Id = {'STATESERVER_OBJECT_GENERATE_WITH_REQUIRED': 2001, - 'STATESERVER_OBJECT_GENERATE_WITH_REQUIRED_OTHER': 2003, - 'STATESERVER_OBJECT_UPDATE_FIELD': 2004, - 'STATESERVER_OBJECT_UPDATE_FIELD_MULTIPLE': 2005, - 'STATESERVER_OBJECT_DELETE_RAM': 2007, - 'STATESERVER_OBJECT_SET_ZONE': 2008, - 'STATESERVER_OBJECT_CHANGE_ZONE': 2009, - 'STATESERVER_OBJECT_NOTFOUND': 2015, - 'STATESERVER_QUERY_OBJECT_ALL': 2020, - 'STATESERVER_QUERY_ZONE_OBJECT_ALL': 2021, - 'STATESERVER_OBJECT_LOCATE': 2022, - 'STATESERVER_OBJECT_LOCATE_RESP': 2023, - 'STATESERVER_OBJECT_QUERY_FIELD': 2024, - 'STATESERVER_QUERY_OBJECT_ALL_RESP': 2030, - 'STATESERVER_SHARD_REST': 2061, - 'STATESERVER_ADD_AI_RECV': 2045, - 'STATESERVER_QUERY_ZONE_OBJECT_ALL_DONE': 2046, - 'STATESERVER_OBJECT_CREATE_WITH_REQUIRED_CONTEXT': 2050, - 'STATESERVER_OBJECT_CREATE_WITH_REQUIR_OTHER_CONTEXT': 2051, - 'STATESERVER_OBJECT_CREATE_WITH_REQUIRED_CONTEXT_RESP': 2052, - 'STATESERVER_OBJECT_CREATE_WITH_REQUIR_OTHER_CONTEXT_RESP': 2053, - 'STATESERVER_OBJECT_DELETE_DISK': 2060, - 'STATESERVER_OBJECT_QUERY_FIELD_RESP': 2062, - 'STATESERVER_OBJECT_ENTERZONE_WITH_REQUIRED_OTHER': 2066, - 'STATESERVER_OBJECT_ENTER_AI_RECV': 2067, - 'STATESERVER_OBJECT_LEAVING_AI_INTEREST': 2033, - 'STATESERVER_OBJECT_ENTER_OWNER_RECV': 2068, - 'STATESERVER_OBJECT_CHANGE_OWNER_RECV': 2069, - 'STATESERVER_OBJECT_SET_OWNER_RECV': 2070, - 'STATESERVER_OBJECT_QUERY_FIELDS': 2080, - 'STATESERVER_OBJECT_QUERY_FIELDS_RESP': 2081, - 'STATESERVER_OBJECT_QUERY_FIELDS_STRING': 2082, - 'STATESERVER_OBJECT_QUERY_MANAGING_AI': 2083, - 'STATESERVER_BOUNCE_MESSAGE': 2086, - 'STATESERVER_QUERY_OBJECT_CHILDREN_LOCAL': 2087, - 'STATESERVER_QUERY_OBJECT_CHILDREN_LOCAL_DONE': 2089, - 'STATESERVER_QUERY_OBJECT_CHILDREN_RESP': 2087, - 'ACCOUNT_AVATAR_USAGE': 3005, - 'ACCOUNT_ACCOUNT_USAGE': 3006, - 'CLIENT_AGENT_OPEN_CHANNEL': 3104, - 'CLIENT_AGENT_CLOSE_CHANNEL': 3105, - 'CLIENT_AGENT_SET_INTEREST': 3106, - 'CLIENT_AGENT_REMOVE_INTEREST': 3107, - 'CHANNEL_PUPPET_ACTION': 4004, - 'DBSERVER_MAKE_FRIENDS': 1017, - 'DBSERVER_MAKE_FRIENDS_RESP': 1031, - 'DBSERVER_CREATE_STORED_OBJECT': 1003, - 'DBSERVER_CREATE_STORED_OBJECT_RESP': 1004, - 'DBSERVER_DELETE_STORED_OBJECT': 1008, - 'DBSERVER_GET_STORED_VALUES': 1012, - 'DBSERVER_GET_STORED_VALUES_RESP': 1013, - 'DBSERVER_SET_STORED_VALUES': 1014, - 'SERVER_PING': 5002} -AIMsgId2Names = invertDictLossless(AIMsgName2Id) -globals().update(AIMsgName2Id) - -DBSERVER_ID = 4003 \ No newline at end of file diff --git a/toontown/ai/DatabaseObject.py b/toontown/ai/DatabaseObject.py deleted file mode 100755 index 9213e831..00000000 --- a/toontown/ai/DatabaseObject.py +++ /dev/null @@ -1,210 +0,0 @@ -from pandac.PandaModules import * -from ToontownAIMsgTypes import * -from direct.directnotify.DirectNotifyGlobal import * -from toontown.toon import DistributedToonAI -from direct.distributed.PyDatagram import PyDatagram -from direct.distributed.PyDatagramIterator import PyDatagramIterator -import types - -class DatabaseObject: - notify = directNotify.newCategory('DatabaseObject') - notify.setInfo(0) - - def __init__(self, air, doId = None, doneEvent = 'DatabaseObject'): - self.air = air - self.doId = doId - self.values = {} - self.gotDataHandler = None - self.doneEvent = doneEvent - return - - def readToon(self, fields = None): - toon = DistributedToonAI.DistributedToonAI(self.air) - self.readObject(toon, fields) - return toon - - if simbase.wantPets: - - def readPet(self): - from toontown.pets import DistributedPetAI - pet = DistributedPetAI.DistributedPetAI(self.air) - self.readObject(pet, None) - return pet - - def readPetProxy(self): - from toontown.pets import DistributedPetProxyAI - petProxy = DistributedPetProxyAI.DistributedPetProxyAI(self.air) - self.readObject(petProxy, None) - return petProxy - - def readObject(self, do, fields = None): - self.do = do - className = do.__class__.__name__ - self.dclass = self.air.dclassesByName[className] - self.gotDataHandler = self.fillin - if fields != None: - self.getFields(fields) - else: - self.getFields(self.getDatabaseFields(self.dclass)) - return - - def storeObject(self, do, fields = None): - self.do = do - className = do.__class__.__name__ - self.dclass = self.air.dclassesByName[className] - if fields != None: - self.reload(self.do, self.dclass, fields) - else: - dbFields = self.getDatabaseFields(self.dclass) - self.reload(self.do, self.dclass, dbFields) - values = self.values - if fields != None: - values = {} - for field in fields: - if field in self.values: - values[field] = self.values[field] - else: - self.notify.warning('Field %s not defined.' % field) - - self.setFields(values) - return - - def getFields(self, fields): - context = self.air.dbObjContext - self.air.dbObjContext += 1 - self.air.dbObjMap[context] = self - dg = PyDatagram() - dg.addServerHeader(DBSERVER_ID, self.air.ourChannel, DBSERVER_GET_STORED_VALUES) - dg.addUint32(context) - dg.addUint32(self.doId) - dg.addUint16(len(fields)) - for f in fields: - dg.addString(f) - - self.air.send(dg) - - def getFieldsResponse(self, di): - objId = di.getUint32() - if objId != self.doId: - self.notify.warning('Unexpected doId %d' % objId) - return - count = di.getUint16() - fields = [] - for i in xrange(count): - name = di.getString() - fields.append(name) - - retCode = di.getUint8() - if retCode != 0: - self.notify.warning('Failed to retrieve data for object %d' % self.doId) - else: - values = [] - for i in xrange(count): - value = di.getString() - values.append(value) - - for i in xrange(count): - found = di.getUint8() - if not found: - self.notify.info('field %s is not found' % fields[i]) - try: - del self.values[fields[i]] - except: - pass - - else: - self.values[fields[i]] = PyDatagram(values[i]) - - self.notify.info('got data for %d' % self.doId) - if self.gotDataHandler != None: - self.gotDataHandler(self.do, self.dclass) - self.gotDataHandler = None - if self.doneEvent != None: - messenger.send(self.doneEvent, [self, retCode]) - return - - def setFields(self, values): - dg = PyDatagram() - dg.addServerHeader(DBSERVER_ID, self.air.ourChannel, DBSERVER_SET_STORED_VALUES) - dg.addUint32(self.doId) - dg.addUint16(len(values)) - items = values.items() - for field, value in items: - dg.addString(field) - - for field, value in items: - dg.addString(value.getMessage()) - - self.air.send(dg) - - def getDatabaseFields(self, dclass): - fields = [] - for i in xrange(dclass.getNumInheritedFields()): - dcf = dclass.getInheritedField(i) - af = dcf.asAtomicField() - if af: - if af.isDb(): - fields.append(af.getName()) - - return fields - - def fillin(self, do, dclass): - do.doId = self.doId - for field, value in self.values.items(): - dclass.directUpdate(do, field, value) - - def reload(self, do, dclass, fields): - self.doId = do.doId - self.values = {} - for fieldName in fields: - field = dclass.getFieldByName(fieldName) - if field == None: - self.notify.warning('No definition for %s' % fieldName) - else: - dg = PyDatagram() - packOk = dclass.packRequiredField(dg, do, field) - self.values[fieldName] = dg - - return - - def createObject(self, objectType): - values = {} - for key, value in values.items(): - values[key] = PyDatagram(str(value)) - - context = self.air.dbObjContext - self.air.dbObjContext += 1 - self.air.dbObjMap[context] = self - self.createObjType = objectType - dg = PyDatagram() - dg.addServerHeader(DBSERVER_ID, self.air.ourChannel, DBSERVER_CREATE_STORED_OBJECT) - dg.addUint32(context) - dg.addString('') - dg.addUint16(objectType) - dg.addUint16(len(values)) - for field in values.keys(): - dg.addString(field) - - for value in values.values(): - dg.addString(value.getMessage()) - - self.air.send(dg) - - def handleCreateObjectResponse(self, di): - retCode = di.getUint8() - if retCode != 0: - self.notify.warning('Database object %s create failed' % self.createObjType) - else: - del self.createObjType - self.doId = di.getUint32() - if self.doneEvent != None: - messenger.send(self.doneEvent, [self, retCode]) - return - - def deleteObject(self): - self.notify.warning('deleting object %s' % self.doId) - dg = PyDatagram() - dg.addServerHeader(DBSERVER_ID, self.air.ourChannel, DBSERVER_DELETE_STORED_OBJECT) - dg.addUint32(self.doId) - dg.addUint32(3735928559L) - self.air.send(dg) diff --git a/toontown/ai/ToontownAIMsgTypes.py b/toontown/ai/ToontownAIMsgTypes.py deleted file mode 100755 index 2d194ea9..00000000 --- a/toontown/ai/ToontownAIMsgTypes.py +++ /dev/null @@ -1,8 +0,0 @@ -from otp.ai.AIMsgTypes import * -TTAIMsgName2Id = {'DBSERVER_GET_ESTATE': 1040, - 'DBSERVER_GET_ESTATE_RESP': 1041, - 'PARTY_MANAGER_UD_TO_ALL_AI': 1042} -TTAIMsgId2Names = invertDictLossless(TTAIMsgName2Id) -globals().update(TTAIMsgName2Id) - -DBSERVER_PET_OBJECT_TYPE = 5 diff --git a/toontown/battle/BattleCalculatorAI.py b/toontown/battle/BattleCalculatorAI.py index 18d328e4..46af95d9 100755 --- a/toontown/battle/BattleCalculatorAI.py +++ b/toontown/battle/BattleCalculatorAI.py @@ -6,7 +6,7 @@ from toontown.suit import DistributedSuitBaseAI import SuitBattleGlobals import BattleExperienceAI from toontown.toon import NPCToons -from toontown.pets import PetTricks, DistributedPetProxyAI +from toontown.pets import PetTricks from toontown.hood import ZoneUtil from direct.showbase.PythonUtil import lerp import sys diff --git a/toontown/battle/DistributedBattleBaseAI.py b/toontown/battle/DistributedBattleBaseAI.py index 6ff74cb0..73fd1c11 100755 --- a/toontown/battle/DistributedBattleBaseAI.py +++ b/toontown/battle/DistributedBattleBaseAI.py @@ -8,13 +8,11 @@ from pandac.PandaModules import * import BattleExperienceAI from direct.distributed import DistributedObjectAI from direct.fsm import ClassicFSM, State -from direct.fsm import State from direct.task import Task from direct.directnotify import DirectNotifyGlobal -from toontown.ai import DatabaseObject -from toontown.toon import DistributedToonAI from toontown.toon import InventoryBase from toontown.toonbase import ToontownGlobals +from toontown.pets import DistributedPetProxyAI import random from toontown.toon import NPCToons from otp.ai.MagicWordGlobal import * @@ -699,23 +697,13 @@ class DistributedBattleBaseAI(DistributedObjectAI.DistributedObjectAI, BattleBas toon.d_setInventory(toon.inventory.makeNetString()) self.air.cogPageManager.toonEncounteredCogs(toon, self.suitsEncountered, self.getTaskZoneId()) elif len(self.suits) > 0 and not self.streetBattle: - self.notify.info('toon %d aborted non-street battle; clearing inventory and hp.' % toonId) - toon = DistributedToonAI.DistributedToonAI(self.air) - toon.doId = toonId - empty = InventoryBase.InventoryBase(toon) - toon.b_setInventory(empty.makeNetString()) - toon.b_setHp(0) - db = DatabaseObject.DatabaseObject(self.air, toonId) - db.storeObject(toon, ['setInventory', 'setHp']) - self.notify.info('killing mem leak from temporary DistributedToonAI %d' % toonId) - toon.deleteDummy() - return + empty = InventoryBase.InventoryBase(None).makeNetString() + self.air.dbInterface.updateObject(self.air.dbId, toonId, self.air.dclassesByName['DistributedToonAI'], {'setHp': [0], 'setInventory': [empty]}) def getToon(self, toonId): if toonId in self.air.doId2do: return self.air.doId2do[toonId] - else: - self.notify.warning('getToon() - toon: %d not in repository!' % toonId) + self.notify.warning('getToon() - toon: %d not in repository!' % toonId) return None def toonRequestRun(self): @@ -1857,4 +1845,4 @@ def skipMovie(): return 'You are not currently in a battle!' battle = simbase.air.doId2do.get(battleId) battle._DistributedBattleBaseAI__movieDone() - return 'Battle movie skipped.' + return 'Battle movie skipped.' \ No newline at end of file diff --git a/toontown/building/DistributedPetshopInteriorAI.py b/toontown/building/DistributedPetshopInteriorAI.py index 7a7b9c00..bc0640d7 100755 --- a/toontown/building/DistributedPetshopInteriorAI.py +++ b/toontown/building/DistributedPetshopInteriorAI.py @@ -1,7 +1,7 @@ from direct.distributed import DistributedObjectAI - class DistributedPetshopInteriorAI(DistributedObjectAI.DistributedObjectAI): + def __init__(self, block, air, zoneId): DistributedObjectAI.DistributedObjectAI.__init__(self, air) self.block = block @@ -11,4 +11,4 @@ class DistributedPetshopInteriorAI(DistributedObjectAI.DistributedObjectAI): DistributedObjectAI.DistributedObjectAI.generate(self) def getZoneIdAndBlock(self): - return [self.zoneId, self.block] + return [self.zoneId, self.block] \ No newline at end of file diff --git a/toontown/toon/DistributedNPCTailorAI.py b/toontown/toon/DistributedNPCTailorAI.py index ca85a252..51d4b4d5 100755 --- a/toontown/toon/DistributedNPCTailorAI.py +++ b/toontown/toon/DistributedNPCTailorAI.py @@ -3,7 +3,6 @@ from pandac.PandaModules import * from DistributedNPCToonBaseAI import * import ToonDNA from direct.task.Task import Task -from toontown.ai import DatabaseObject from toontown.estate import ClosetGlobals #Going to code this later. For now lets just have it return false. @@ -26,8 +25,6 @@ class DistributedNPCTailorAI(DistributedNPCToonBaseAI): if self.freeClothes: self.useJellybeans = False - return - def getTailor(self): return 1 @@ -194,18 +191,11 @@ class DistributedNPCTailorAI(DistributedNPCToonBaseAI): def __handleUnexpectedExit(self, avId): self.notify.warning('avatar:' + str(avId) + ' has exited unexpectedly') if self.customerId == avId: - toon = self.air.doId2do.get(avId) - if toon == None: - toon = DistributedToonAI.DistributedToonAI(self.air) - toon.doId = avId - if self.customerDNA: - toon.b_setDNAString(self.customerDNA.makeNetString()) - db = DatabaseObject.DatabaseObject(self.air, avId) - db.storeObject(toon, ['setDNAString']) + dna = self.customerDNA.makeNetString() + self.air.dbInterface.updateObject(self.air.dbId, avId, self.air.dclassesByName['DistributedToonAI'], {'setDNAString': [dna]}) else: self.notify.warning('invalid customer avId: %s, customerId: %s ' % (avId, self.customerId)) if self.busy == avId: self.sendClearMovie(None) else: - self.notify.warning('not busy with avId: %s, busy: %s ' % (avId, self.busy)) - return + self.notify.warning('not busy with avId: %s, busy: %s ' % (avId, self.busy)) \ No newline at end of file