aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs60
1 files changed, 43 insertions, 17 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs
index 8b5e3e3..5606287 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs
@@ -31,6 +31,7 @@ using System.Collections.Generic;
31using System.Text; 31using System.Text;
32using System.Threading; 32using System.Threading;
33using System.Reflection; 33using System.Reflection;
34using OpenSim.Region.Environment.Scenes;
34using OpenSim.Region.Environment.Scenes.Scripting; 35using OpenSim.Region.Environment.Scenes.Scripting;
35 36
36namespace OpenSim.Region.ScriptEngine.DotNetEngine 37namespace OpenSim.Region.ScriptEngine.DotNetEngine
@@ -40,19 +41,26 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
40 /// Compiles them if necessary 41 /// Compiles them if necessary
41 /// Execute functions for EventQueueManager 42 /// Execute functions for EventQueueManager
42 /// </summary> 43 /// </summary>
43 class ScriptManager 44 public class ScriptManager
44 { 45 {
45 46
46 private ScriptEngine myScriptEngine; 47 private ScriptEngine m_scriptEngine;
47 public ScriptManager(ScriptEngine _ScriptEngine) 48 public ScriptManager(ScriptEngine scriptEngine)
48 { 49 {
49 myScriptEngine = _ScriptEngine; 50 m_scriptEngine = scriptEngine;
50 myScriptEngine.m_logger.Verbose("ScriptEngine", "ScriptManager Start"); 51 m_scriptEngine.Log.Verbose("ScriptEngine", "ScriptManager Start");
51 } 52 }
52 53
53 54
54 // Object<string, Script<string, script>> 55 // Object<string, Script<string, script>>
55 internal Dictionary<string, Dictionary<string, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass>> Scripts = new Dictionary<string, Dictionary<string, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass>>(); 56 internal Dictionary<string, Dictionary<string, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass>> Scripts = new Dictionary<string, Dictionary<string, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass>>();
57 public Scene World
58 {
59 get
60 {
61 return m_scriptEngine.World;
62 }
63 }
56 64
57 65
58 internal Dictionary<string, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass>.KeyCollection GetScriptKeys(string ObjectID) 66 internal Dictionary<string, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass>.KeyCollection GetScriptKeys(string ObjectID)
@@ -88,7 +96,9 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
88 { 96 {
89 // Create object if it doesn't exist 97 // Create object if it doesn't exist
90 if (Scripts.ContainsKey(ObjectID) == false) 98 if (Scripts.ContainsKey(ObjectID) == false)
99 {
91 Scripts.Add(ObjectID, new Dictionary<string, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass>()); 100 Scripts.Add(ObjectID, new Dictionary<string, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass>());
101 }
92 102
93 // Delete script if it exists 103 // Delete script if it exists
94 Dictionary<string, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass> Obj; 104 Dictionary<string, OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass> Obj;
@@ -108,7 +118,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
108 /// <param name="ObjectID"></param> 118 /// <param name="ObjectID"></param>
109 public void StartScript(string ScriptID, string ObjectID) 119 public void StartScript(string ScriptID, string ObjectID)
110 { 120 {
111 myScriptEngine.m_logger.Verbose("ScriptEngine", "ScriptManager StartScript: ScriptID: " + ScriptID + ", ObjectID: " + ObjectID); 121 m_scriptEngine.Log.Verbose("ScriptEngine", "ScriptManager StartScript: ScriptID: " + ScriptID + ", ObjectID: " + ObjectID);
112 122
113 // We will initialize and start the script. 123 // We will initialize and start the script.
114 // It will be up to the script itself to hook up the correct events. 124 // It will be up to the script itself to hook up the correct events.
@@ -130,7 +140,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
130 case ".txt": 140 case ".txt":
131 case ".lsl": 141 case ".lsl":
132 case ".cs": 142 case ".cs":
133 myScriptEngine.m_logger.Verbose("ScriptEngine", "ScriptManager Script is CS/LSL, compiling to .Net Assembly"); 143 m_scriptEngine.Log.Verbose("ScriptEngine", "ScriptManager Script is CS/LSL, compiling to .Net Assembly");
134 // Create a new instance of the compiler (currently we don't want reuse) 144 // Create a new instance of the compiler (currently we don't want reuse)
135 OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.Compiler LSLCompiler = new OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.Compiler(); 145 OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.Compiler LSLCompiler = new OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.Compiler();
136 // Compile 146 // Compile
@@ -142,7 +152,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
142 152
143 153
144 154
145 myScriptEngine.m_logger.Verbose("ScriptEngine", "Compilation done"); 155 m_scriptEngine.Log.Verbose("ScriptEngine", "Compilation done");
146 // * Insert yield into code 156 // * Insert yield into code
147 FileName = ProcessYield(FileName); 157 FileName = ProcessYield(FileName);
148 158
@@ -152,7 +162,10 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
152 // * Load and start script, for now with dummy host 162 // * Load and start script, for now with dummy host
153 163
154 //OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName); 164 //OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName);
155 OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName, new NullScriptHost() ); 165 IScriptHost host = new NullScriptHost();
166 IScriptHost root = host;
167
168 OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = LoadAndInitAssembly(FreeAppDomain, FileName, host, root );
156 string FullScriptID = ScriptID + "." + ObjectID; 169 string FullScriptID = ScriptID + "." + ObjectID;
157 // Add it to our temporary active script keeper 170 // Add it to our temporary active script keeper
158 //Scripts.Add(FullScriptID, Script); 171 //Scripts.Add(FullScriptID, Script);
@@ -164,12 +177,12 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
164 // Start the script - giving it BuiltIns 177 // Start the script - giving it BuiltIns
165 //myScriptEngine.m_logger.Verbose("ScriptEngine", "ScriptManager initializing script, handing over private builtin command interface"); 178 //myScriptEngine.m_logger.Verbose("ScriptEngine", "ScriptManager initializing script, handing over private builtin command interface");
166 179
167 Script.Start(myScriptEngine.World, ScriptID); 180 Script.Start( ScriptID );
168 181
169 } 182 }
170 catch (Exception e) 183 catch (Exception e)
171 { 184 {
172 myScriptEngine.m_logger.Error("ScriptEngine", "Exception loading script \"" + FileName + "\": " + e.ToString()); 185 m_scriptEngine.Log.Error("ScriptEngine", "Exception loading script \"" + FileName + "\": " + e.ToString());
173 } 186 }
174 187
175 188
@@ -192,7 +205,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
192 /// <param name="FreeAppDomain">AppDomain to load script into</param> 205 /// <param name="FreeAppDomain">AppDomain to load script into</param>
193 /// <param name="FileName">FileName of script assembly (.dll)</param> 206 /// <param name="FileName">FileName of script assembly (.dll)</param>
194 /// <returns></returns> 207 /// <returns></returns>
195 private OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass LoadAndInitAssembly(AppDomain FreeAppDomain, string FileName, IScriptHost host) 208 private OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass LoadAndInitAssembly(AppDomain FreeAppDomain, string FileName, IScriptHost host, IScriptHost root)
196 { 209 {
197 //myScriptEngine.m_logger.Verbose("ScriptEngine", "ScriptManager Loading Assembly " + FileName); 210 //myScriptEngine.m_logger.Verbose("ScriptEngine", "ScriptManager Loading Assembly " + FileName);
198 // Load .Net Assembly (.dll) 211 // Load .Net Assembly (.dll)
@@ -231,7 +244,13 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
231 //{ 244 //{
232 //} 245 //}
233 246
234 object[] args = new object[] { host }; 247 // Create constructor arguments
248 object[] args = new object[]
249 {
250 this,
251 host,
252 root
253 };
235 254
236 return (OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass)Activator.CreateInstance(t, args ); 255 return (OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass)Activator.CreateInstance(t, args );
237 256
@@ -240,13 +259,13 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
240 259
241 internal void ExecuteFunction(string ObjectID, string ScriptID, string FunctionName, object[] args) 260 internal void ExecuteFunction(string ObjectID, string ScriptID, string FunctionName, object[] args)
242 { 261 {
243 myScriptEngine.m_logger.Verbose("ScriptEngine", "Executing Function ObjectID: " + ObjectID + ", ScriptID: " + ScriptID + ", FunctionName: " + FunctionName); 262 m_scriptEngine.Log.Verbose("ScriptEngine", "Executing Function ObjectID: " + ObjectID + ", ScriptID: " + ScriptID + ", FunctionName: " + FunctionName);
244 OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = myScriptEngine.myScriptManager.GetScript(ObjectID, ScriptID); 263 OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass Script = m_scriptEngine.myScriptManager.GetScript(ObjectID, ScriptID);
245 264
246 Type type = Script.GetType(); 265 Type type = Script.GetType();
247 266
248 267
249 myScriptEngine.m_logger.Verbose("ScriptEngine", "Invoke: \"" + Script.State + "_event_" + FunctionName + "\""); 268 m_scriptEngine.Log.Verbose("ScriptEngine", "Invoke: \"" + Script.State + "_event_" + FunctionName + "\"");
250 269
251 try 270 try
252 { 271 {
@@ -254,7 +273,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
254 } 273 }
255 catch (Exception e) 274 catch (Exception e)
256 { 275 {
257 myScriptEngine.m_logger.Error("ScriptEngine", "Exception attempting to executing script function: " + e.ToString()); 276 m_scriptEngine.Log.Error("ScriptEngine", "Exception attempting to executing script function: " + e.ToString());
258 } 277 }
259 278
260 279
@@ -265,5 +284,12 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
265 284
266 } 285 }
267 286
287 public string RegionName
288 {
289 get
290 {
291 return World.RegionInfo.RegionName;
292 }
293 }
268 } 294 }
269} 295}