moved location code

This commit is contained in:
Dave Schuyler 2005-05-26 21:22:55 +00:00
parent 417e68593b
commit 77831d02f1
1 changed files with 0 additions and 82 deletions

View File

@ -168,88 +168,6 @@ class ClientRepository(ConnectionRepository):
"""
return time.time() + self.serverDelta
if wantOtpServer:
def handleObjectLocation(self, di):
# CLIENT_OBJECT_LOCATION
doId = di.getUint32()
parentId = di.getUint32()
zoneId = di.getUint32()
obj = self.doId2do.get(doId)
if obj is not None:
self.notify.info("handleObjectLocation: doId: %s parentId: %s zoneId: %s" %
(doId, parentId, zoneId))
# Let the object finish the job
obj.setLocation(parentId, zoneId)
else:
ClientRepository.notify.warning(
"handleObjectLocation: Asked to update non-existent obj: %s" % (doId))
def storeObjectLocation(self, objId, parentId, zoneId):
# Do not store null values
if ((parentId is None) or (zoneId is None)):
return
# TODO: check current location
obj = self.doId2do.get(objId)
oldParentId, oldZoneId = obj.getLocation()
# Case 1: Same parent, new zone
if (oldParentId == parentId):
parentZoneDict = self.__doHierarchy.get(parentId)
# Remove this objId from the old zone list
oldObjList = parentZoneDict.get(oldZoneId)
oldObjList.remove(objId)
# Add it to the new zone list
objList = parentZoneDict.get(zoneId)
if objList is None:
# No existing objList for this zone, let's make a new one
parentZoneDict[zoneId] = [objId]
return
else:
# Just add this objId to the existing list
assert(objId not in objList)
objList.append(objId)
return
# Case 2: New parent, valid old parent
# First delete the old location
if ((oldParentId is not None) and (oldZoneId is not None)):
self.deleteObjectLocation(objId, oldParentId, oldZoneId)
# Do not return because we still need to add to the new location
# Case 2: continued, already deleted from old location
# Case 3: New parent - no old parent
parentZoneDict = self.__doHierarchy.get(parentId)
if parentZoneDict is None:
# This parent is not here, just fill the whole entry in
self.__doHierarchy[parentId] = {zoneId : [objId]}
else:
objList = parentZoneDict.get(zoneId)
if objList is None:
# This parent has no objects in this zone before
# create a new entry for this zone and list this objId
parentZoneDict[zoneId] = [objId]
else:
# Just add this objId to the existing list
objList.append(objId)
def deleteObjectLocation(self, objId, parentId, zoneId):
# Do not worry about null values
if ((parentId is None) or (zoneId is None)):
return
parentZoneDict = self.__doHierarchy.get(parentId)
assert(parentZoneDict is not None, "deleteObjectLocation: parentId: %s not found" % (parentId))
objList = parentZoneDict.get(zoneId)
assert(objList is not None, "deleteObjectLocation: zoneId: %s not found" % (zoneId))
assert(objId in objList, "deleteObjectLocation: objId: %s not found" % (objId))
if len(objList) == 1:
# If this is the last obj in this zone, delete the entire entry
del parentZoneDict[zoneId]
else:
# Just remove the object
objList.remove(objId)
def handleGenerateWithRequired(self, di):
if wantOtpServer:
parentId = di.getUint32()