comparison orpg/networking/server_plugins.py @ 96:65c1604e7949 alpha

Traipse Alpha 'OpenRPG' {090924-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary: 00: Update forwards to the 090909-02 Server code that now works. New default Lobby Map, designed for Traipse. Feel free to change it. Updates to Server GUI: * Admin can Ban from Backend. * Prework to modify Ban List in back end. * Server GUI finds your Lobby Name * New users default as Lurker unless a Role is set New Addition to Chat Die Roll commands. Math Ordering. Ex. [(X+Y)dZ]. Currently does pairs only, no nesting either. Cleaner TraipseSuiteAttention portability and clean up in Main (Beta!)
author sirebral
date Thu, 24 Sep 2009 02:05:08 -0500
parents d1aff41c031b
children 06f10429eedc
comparison
equal deleted inserted replaced
95:af6bf998f425 96:65c1604e7949
22 self.__ptype = ptype 22 self.__ptype = ptype
23 self.__plugins = {} 23 self.__plugins = {}
24 24
25 def initBase(self): 25 def initBase(self):
26 self._startPlugins() 26 self._startPlugins()
27
28 27
29 #Methods 28 #Methods
30 def _startPlugins(self): 29 def _startPlugins(self):
31 autoload = [] 30 autoload = []
32 #Fill autoload from some file with the Plugin Names 31 #Fill autoload from some file with the Plugin Names
58 57
59 #Now Load it 58 #Now Load it
60 self._load(pluginData) 59 self._load(pluginData)
61 60
62 #Write to the autoload file for this plugin 61 #Write to the autoload file for this plugin
63
64 self.__plugins[pluginName].Activated = True 62 self.__plugins[pluginName].Activated = True
65 self.__plugins[pluginName].start() 63 self.__plugins[pluginName].start()
66 64
67 def deactivatePugin(self, pluginData): 65 def deactivatePugin(self, pluginData):
68 if not self.__plugins.has_key(pluginName): 66 if not self.__plugins.has_key(pluginName):
69 #Print some error about invalid plugin 67 #Print some error about invalid plugin
70 return 68 return
69
71 pluginData = self.__plugins[pluginName] 70 pluginData = self.__plugins[pluginName]
72
73 self.__plugins[pluginName].stop() 71 self.__plugins[pluginName].stop()
74 72
75 #Unload it 73 #Unload it
76 self._unload(pluginData) 74 self._unload(pluginData)
77
78 #Remove this plugin from the autoload file 75 #Remove this plugin from the autoload file
79 76
80 #Private Methods 77 #Private Methods
81 def _findModule(self, pluginFile): 78 def _findModule(self, pluginFile):
82 s1 = pluginFile.split(os.sep) 79 s1 = pluginFile.split(os.sep)
83 s2 = s1[-1].split('.') 80 s2 = s1[-1].split('.')
84 return ('plugins.' + self.__ptype + '.' + s2[0], s2[0]) 81 return ('plugins.' + self.__ptype + '.' + s2[0], s2[0])
85 82
86 def _unload(self, pluginData): 83 def _unload(self, pluginData):
87 self.__plugins[pluginData.Name] = PluginData(pluginData.Name, pluginData.File, pluginData.Author, pluginData.Help) 84 self.__plugins[pluginData.Name] = PluginData(pluginData.Name,
85 pluginData.File,
86 pluginData.Author,
87 pluginData.Help)
88 unload = [] 88 unload = []
89 mod = self._findModule(pluginData.File)[0] 89 mod = self._findModule(pluginData.File)[0]
90 for key, module in sys.modules.iteritems(): 90 for key, module in sys.modules.iteritems():
91 if str(module).find(mod) > -1: 91 if str(module).find(mod) > -1:
92 unload.append(key) 92 unload.append(key)
113 def _getPlugins(self): 113 def _getPlugins(self):
114 return self.__plugins 114 return self.__plugins
115 115
116 def _getType(self): 116 def _getType(self):
117 return self.__ptype 117 return self.__ptype
118
119
120 #Properties 118 #Properties
121 Plugins = property(_getPlugins, None) 119 Plugins = property(_getPlugins, None)
122 Type = property(_getType, None) 120 Type = property(_getType, None)
123 121
124 class ServerPluginsClass(BasePluginsClass): 122 class ServerPluginsClass(BasePluginsClass):
130 self.initBase() 128 self.initBase()
131 129
132 def preParseIncoming(self, xml_dom, data): 130 def preParseIncoming(self, xml_dom, data):
133 sent = True 131 sent = True
134 errmsg = "" 132 errmsg = ""
135
136 for pluginName, pluginData in self.Plugins.iteritems(): 133 for pluginName, pluginData in self.Plugins.iteritems():
137 if pluginData.Activated: 134 if pluginData.Activated:
138 xml_dom, data = pluginData.preParseIncoming(xml_dom, data) 135 xml_dom, data = pluginData.preParseIncoming(xml_dom, data)
139
140 return xml_dom, data 136 return xml_dom, data
141 137
142 def postParseIncoming(self, data): 138 def postParseIncoming(self, data):
143 for pluginName, pluginData in self.Plugins.iteritems(): 139 for pluginName, pluginData in self.Plugins.iteritems():
144 if pluginData.Activated: 140 if pluginData.Activated:
145 data = pluginData.postParseIncoming(data) 141 data = pluginData.postParseIncoming(data)
146
147 return data 142 return data
148 143
149 def getPlayer(self): 144 def getPlayer(self):
150 players = [] 145 players = []
151 for pluginName, pluginData in self.Plugins.iteritems(): 146 for pluginName, pluginData in self.Plugins.iteritems():
152 if pluginData.Activated: 147 if pluginData.Activated:
153 playerName = pluginData.addPlayer(data) 148 playerName = pluginData.addPlayer(data)
154 players.append(playerName) 149 players.append(playerName)
155
156 return players 150 return players
157 151
158 def setPlayer(self, playerData): 152 def setPlayer(self, playerData):
159 players = [] 153 players = []
160 for pluginName, pluginData in self.Plugins.iteritems(): 154 for pluginName, pluginData in self.Plugins.iteritems():
161 if pluginData.Activated: 155 if pluginData.Activated:
162 playerName = pluginData.addPlayer(data) 156 playerName = pluginData.addPlayer(data)
163 players.append(playerName) 157 players.append(playerName)
164
165 return 158 return
166 159
167 def preParseOutgoing(self): 160 def preParseOutgoing(self):
168 data = [] 161 data = []
169 for pluginName, pluginData in self.Plugins.iteritems(): 162 for pluginName, pluginData in self.Plugins.iteritems():
170 if pluginData.Activated: 163 if pluginData.Activated:
171 xml = pluginData.preParseOutgoing() 164 xml = pluginData.preParseOutgoing()
172 for msg in xml: 165 for msg in xml:
173 data.append(msg) 166 data.append(msg)
174
175 return data 167 return data
176 168
177 def postParseOutgoing(self): 169 def postParseOutgoing(self):
178 data = [] 170 data = []
179 for pluginName, pluginData in self.Plugins.iteritems(): 171 for pluginName, pluginData in self.Plugins.iteritems():
180 if pluginData.Activated: 172 if pluginData.Activated:
181 xml = pluginData.postParseOutgoing() 173 xml = pluginData.postParseOutgoing()
182 for msg in xml: 174 for msg in xml:
183 data.append(msg) 175 data.append(msg)
184
185 return data 176 return data
186 177
187 __key = _SingletonKey() 178 __key = _SingletonKey()
188 ServerPlugins = ServerPluginsClass(__key) 179 ServerPlugins = ServerPluginsClass(__key)