DBObject holocaust

This commit is contained in:
John 2015-06-21 12:27:40 +03:00
parent 3c853dbc00
commit 44edf68ff7
7 changed files with 11 additions and 321 deletions

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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,22 +697,12 @@ 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)
return None

View file

@ -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

View file

@ -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