浏览代码

wantOtpServer

Dave Schuyler 21 年之前
父节点
当前提交
b07b7fb4eb
共有 1 个文件被更改,包括 63 次插入16 次删除
  1. 63 16
      direct/src/distributed/DistributedObjectAI.py

+ 63 - 16
direct/src/distributed/DistributedObjectAI.py

@@ -18,6 +18,8 @@ class DistributedObjectAI(DirectObject.DirectObject):
             self.DistributedObjectAI_initialized
             self.DistributedObjectAI_initialized
         except:
         except:
             self.DistributedObjectAI_initialized = 1
             self.DistributedObjectAI_initialized = 1
+
+            self.accountName=''
             # Record the repository
             # Record the repository
             self.air = air
             self.air = air
             # Record our distributed class
             # Record our distributed class
@@ -96,6 +98,8 @@ class DistributedObjectAI(DirectObject.DirectObject):
                 if self.air:
                 if self.air:
                     self.air.deallocateChannel(self.doId)
                     self.air.deallocateChannel(self.doId)
             self.air = None
             self.air = None
+            if hasattr(self, 'parentId'):
+                del self.parentId
             del self.zoneId
             del self.zoneId
 
 
     def isDeleted(self):
     def isDeleted(self):
@@ -155,8 +159,10 @@ class DistributedObjectAI(DirectObject.DirectObject):
         # does not include the quiet zone.
         # does not include the quiet zone.
         return 'DOLogicalChangeZone-%s' % self.doId
         return 'DOLogicalChangeZone-%s' % self.doId
     
     
-    def handleZoneChange(self, newZoneId, oldZoneId):
-        assert oldZoneId == self.zoneId
+    def handleZoneChange(self, newParentId, newZoneId, oldParentId, oldZoneId):
+        assert oldParentId == self.parentId
+        ##assert oldZoneId == self.zoneId
+        self.parentId = newParentId
         self.zoneId = newZoneId
         self.zoneId = newZoneId
         self.air.changeDOZoneInTables(self, newZoneId, oldZoneId)
         self.air.changeDOZoneInTables(self, newZoneId, oldZoneId)
         messenger.send(self.getZoneChangeEvent(), [newZoneId, oldZoneId])
         messenger.send(self.getZoneChangeEvent(), [newZoneId, oldZoneId])
@@ -187,19 +193,23 @@ class DistributedObjectAI(DirectObject.DirectObject):
         return self.air.getCollTrav(self.zoneId)
         return self.air.getCollTrav(self.zoneId)
 
 
     def sendUpdate(self, fieldName, args = []):
     def sendUpdate(self, fieldName, args = []):
+        assert self.notify.debugStateCall(self)
         if self.air:
         if self.air:
             self.air.sendUpdate(self, fieldName, args)
             self.air.sendUpdate(self, fieldName, args)
 
 
     def sendUpdateToAvatarId(self, avId, fieldName, args):
     def sendUpdateToAvatarId(self, avId, fieldName, args):
+        assert self.notify.debugStateCall(self)
         channelId = avId + 1
         channelId = avId + 1
         self.sendUpdateToChannel(channelId, fieldName, args)
         self.sendUpdateToChannel(channelId, fieldName, args)
 
 
     def sendUpdateToChannel(self, channelId, fieldName, args):
     def sendUpdateToChannel(self, channelId, fieldName, args):
+        assert self.notify.debugStateCall(self)
         if self.air:
         if self.air:
             self.air.sendUpdateToChannel(self, channelId, fieldName, args)
             self.air.sendUpdateToChannel(self, channelId, fieldName, args)
 
 
     def generateWithRequired(self, zoneId, optionalFields=[]):
     def generateWithRequired(self, zoneId, optionalFields=[]):
-        # have we already allocated a doId?
+        assert self.notify.debugStateCall(self)
+        # have we already allocated a doId?      
         if self.__preallocDoId:
         if self.__preallocDoId:
             self.__preallocDoId = 0
             self.__preallocDoId = 0
             return self.generateWithRequiredAndId(
             return self.generateWithRequiredAndId(
@@ -207,44 +217,80 @@ class DistributedObjectAI(DirectObject.DirectObject):
             
             
         # The repository is the one that really does the work
         # The repository is the one that really does the work
         self.air.generateWithRequired(self, zoneId, optionalFields)
         self.air.generateWithRequired(self, zoneId, optionalFields)
+        if wantOtpServer:
+            #HACK:
+            parentId = simbase.air.districtId
+            self.parentId = parentId
         self.zoneId = zoneId
         self.zoneId = zoneId
         self.generate()
         self.generate()
 
 
     # this is a special generate used for estates, or anything else that
     # this is a special generate used for estates, or anything else that
     # needs to have a hard coded doId as assigned by the server
     # needs to have a hard coded doId as assigned by the server
     def generateWithRequiredAndId(self, doId, zoneId, optionalFields=[]):
     def generateWithRequiredAndId(self, doId, zoneId, optionalFields=[]):
+        assert self.notify.debugStateCall(self)
         # have we already allocated a doId?
         # have we already allocated a doId?
         if self.__preallocDoId:
         if self.__preallocDoId:
+            assert doId == self.__preallocDoId
             self.__preallocDoId = 0
             self.__preallocDoId = 0
-            assert doId == self.doId
 
 
         # The repository is the one that really does the work
         # The repository is the one that really does the work
         self.air.generateWithRequiredAndId(self, doId, zoneId, optionalFields)
         self.air.generateWithRequiredAndId(self, doId, zoneId, optionalFields)
+        if wantOtpServer:
+            #HACK:
+            parentId = simbase.air.districtId
+            self.parentId = parentId
         self.zoneId = zoneId
         self.zoneId = zoneId
         self.generate()
         self.generate()
 
 
-    def generate(self):
-        # Inheritors should put functions that require self.zoneId or
-        # other networked info in this function.
-        assert(self.notify.debug('generate(): %s' % (self.doId)))
-        pass
+    if wantOtpServer:
+        def generateOtpObject(self, parentId, zoneId, optionalFields=[], doId=None):
+            assert self.notify.debugStateCall(self)
+            # have we already allocated a doId?
+            if self.__preallocDoId:
+                assert doId is None or doId == self.__preallocDoId
+                doId=self.__preallocDoId
+                self.__preallocDoId = 0
+                
+            # The repository is the one that really does the work
+            self.air.sendGenerateOtpObject(
+                    self, parentId, zoneId, optionalFields, doId=doId)
+            self.parentId = parentId
+            self.zoneId = zoneId
+            self.generate()
 
 
-    def sendGenerateWithRequired(self, repository, zoneId, optionalFields=[]):
+    def generate(self):
+        """
+        Inheritors should put functions that require self.zoneId or
+        other networked info in this function.
+        """
+        assert self.notify.debugStateCall(self)
+
+    if wantOtpServer:
+        def generateInit(self):
+            """
+            First generate (not from cache).
+            """
+            assert self.notify.debugStateCall(self)
+
+    def sendGenerateWithRequired(self, repository, parentId, zoneId, optionalFields=[]):
+        assert self.notify.debugStateCall(self)
+        if not wantOtpServer:
+            parentId = 0
         # Make the dclass do the hard work
         # Make the dclass do the hard work
-        dg = self.dclass.aiFormatGenerate(self, self.doId, zoneId,
-                                          repository.districtId,
-                                          repository.ourChannel,
-                                          optionalFields)
+        dg = self.dclass.aiFormatGenerate(
+                self, self.doId, parentId, zoneId,
+                repository.serverId,
+                repository.ourChannel,
+                optionalFields)
         repository.send(dg)
         repository.send(dg)
-        self.zoneId = zoneId
             
             
     def initFromServerResponse(self, valDict):
     def initFromServerResponse(self, valDict):
+        assert self.notify.debugStateCall(self)
         # This is a special method used for estates, etc., which get
         # This is a special method used for estates, etc., which get
         # their fields set from the database indirectly by way of the
         # their fields set from the database indirectly by way of the
         # AI.  The input parameter is a dictionary of field names to
         # AI.  The input parameter is a dictionary of field names to
         # datagrams that describes the initial field values from the
         # datagrams that describes the initial field values from the
         # database.
         # database.
-        assert(self.notify.debug("initFromServerResponse(%s)" % (valDict.keys(),)))
 
 
         dclass = self.dclass
         dclass = self.dclass
         for key, value in valDict.items():
         for key, value in valDict.items():
@@ -252,6 +298,7 @@ class DistributedObjectAI(DirectObject.DirectObject):
             dclass.directUpdate(self, key, value)
             dclass.directUpdate(self, key, value)
 
 
     def requestDelete(self):
     def requestDelete(self):
+        assert self.notify.debugStateCall(self)
         if not self.air:
         if not self.air:
             doId = "none"
             doId = "none"
             if hasattr(self, "doId"):
             if hasattr(self, "doId"):