From 396c40dcb04dad9f6ddff8a83664e66d7f231c43 Mon Sep 17 00:00:00 2001 From: Zachary Pavlov Date: Tue, 5 Feb 2008 00:10:51 +0000 Subject: [PATCH] new ~ud support --- direct/src/distributed/DistributedObject.py | 3 ++ direct/src/distributed/DistributedObjectAI.py | 4 ++ .../distributed/DistributedObjectGlobal.py | 1 + .../distributed/DistributedObjectGlobalUD.py | 43 +++++++++++++++++++ direct/src/distributed/DistributedObjectUD.py | 3 ++ 5 files changed, 54 insertions(+) diff --git a/direct/src/distributed/DistributedObject.py b/direct/src/distributed/DistributedObject.py index 6667422102..78f13ee3ef 100644 --- a/direct/src/distributed/DistributedObject.py +++ b/direct/src/distributed/DistributedObject.py @@ -466,3 +466,6 @@ class DistributedObject(DistributedObjectBase): def isGridParent(self): # If this distributed object is a DistributedGrid return 1. 0 by default return 0 + + def execCommand(self, string, mwMgrId, avId, zoneId): + pass diff --git a/direct/src/distributed/DistributedObjectAI.py b/direct/src/distributed/DistributedObjectAI.py index c8966c72e7..1691b43897 100644 --- a/direct/src/distributed/DistributedObjectAI.py +++ b/direct/src/distributed/DistributedObjectAI.py @@ -555,3 +555,7 @@ class DistributedObjectAI(DistributedObjectBase): def isGridParent(self): # If this distributed object is a DistributedGrid return 1. 0 by default return 0 + + def execCommand(self, string, mwMgrId, avId, zoneId): + pass + diff --git a/direct/src/distributed/DistributedObjectGlobal.py b/direct/src/distributed/DistributedObjectGlobal.py index 0298f19d5f..6414f70990 100755 --- a/direct/src/distributed/DistributedObjectGlobal.py +++ b/direct/src/distributed/DistributedObjectGlobal.py @@ -21,3 +21,4 @@ class DistributedObjectGlobal(DistributedObject): DistributedObject.__init__(self, cr) self.parentId = 0 self.zoneId = 0 + diff --git a/direct/src/distributed/DistributedObjectGlobalUD.py b/direct/src/distributed/DistributedObjectGlobalUD.py index b860f8cf8f..b3cc8669ae 100755 --- a/direct/src/distributed/DistributedObjectGlobalUD.py +++ b/direct/src/distributed/DistributedObjectGlobalUD.py @@ -3,6 +3,7 @@ from DistributedObjectUD import DistributedObjectUD from direct.directnotify.DirectNotifyGlobal import directNotify +import sys class DistributedObjectGlobalUD(DistributedObjectUD): notify = directNotify.newCategory('DistributedObjectGlobalUD') @@ -12,6 +13,7 @@ class DistributedObjectGlobalUD(DistributedObjectUD): def __init__(self, air): DistributedObjectUD.__init__(self, air) + self.ExecNamespace = {"self":self} def announceGenerate(self): self.air.registerForChannel(self.doId) @@ -21,3 +23,44 @@ class DistributedObjectGlobalUD(DistributedObjectUD): self.air.unregisterForChannel(self.doId) ## self.air.removeDOFromTables(self) DistributedObjectUD.delete(self) + + def execCommand(self, command, mwMgrId, avId, zoneId): + text = self.__execMessage(command) + print text + dclass = uber.air.dclassesByName.get("PiratesMagicWordManagerAI") + dg = dclass.aiFormatUpdate( + "setMagicWordResponse", mwMgrId, (1<<32)+avId, uber.air.ourChannel, [text]) + uber.air.send(dg) + + def __execMessage(self, message): + if not self.ExecNamespace: + # Import some useful variables into the ExecNamespace initially. + exec 'from pandac.PandaModules import *' in globals(), self.ExecNamespace + #self.importExecNamespace() + + # Now try to evaluate the expression using ChatInputNormal.ExecNamespace as + # the local namespace. + try: + return str(eval(message, globals(), self.ExecNamespace)) + + except SyntaxError: + # Maybe it's only a statement, like "x = 1", or + # "import math". These aren't expressions, so eval() + # fails, but they can be exec'ed. + try: + exec message in globals(), self.ExecNamespace + return 'ok' + except: + exception = sys.exc_info()[0] + extraInfo = sys.exc_info()[1] + if extraInfo: + return str(extraInfo) + else: + return str(exception) + except: + exception = sys.exc_info()[0] + extraInfo = sys.exc_info()[1] + if extraInfo: + return str(extraInfo) + else: + return str(exception) diff --git a/direct/src/distributed/DistributedObjectUD.py b/direct/src/distributed/DistributedObjectUD.py index f2dcdf9126..1daa9801ee 100755 --- a/direct/src/distributed/DistributedObjectUD.py +++ b/direct/src/distributed/DistributedObjectUD.py @@ -488,3 +488,6 @@ class DistributedObjectUD(DistributedObjectBase): def isGridParent(self): # If this distributed object is a DistributedGrid return 1. 0 by default return 0 + + def execCommand(self, string, mwMgrId, avId, zoneId): + pass