aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs102
1 files changed, 59 insertions, 43 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs
index 54a5ef5..a3cf9f7 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs
@@ -225,6 +225,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
225 225
226 #region Start/Stop/Reset script 226 #region Start/Stop/Reset script
227 227
228 Object startStopLock = new Object();
229
228 /// <summary> 230 /// <summary>
229 /// Fetches, loads and hooks up a script to an objects events 231 /// Fetches, loads and hooks up a script to an objects events
230 /// </summary> 232 /// </summary>
@@ -259,76 +261,83 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
259 StartScript(localID, itemID, script); 261 StartScript(localID, itemID, script);
260 } 262 }
261 263
264 // Create a new instance of the compiler (reuse)
265 Compiler.LSL.Compiler LSLCompiler = new Compiler.LSL.Compiler();
262 private void _StartScript(uint localID, LLUUID itemID, string Script) 266 private void _StartScript(uint localID, LLUUID itemID, string Script)
263 { 267 {
264 //IScriptHost root = host.GetRoot(); 268 lock (startStopLock)
265 Console.WriteLine("ScriptManager StartScript: localID: " + localID + ", itemID: " + itemID); 269 {
270 //IScriptHost root = host.GetRoot();
271 Console.WriteLine("ScriptManager StartScript: localID: " + localID + ", itemID: " + itemID);
266 272
267 // We will initialize and start the script. 273 // We will initialize and start the script.
268 // It will be up to the script itself to hook up the correct events. 274 // It will be up to the script itself to hook up the correct events.
269 string ScriptSource = ""; 275 string ScriptSource = "";
270 276
271 SceneObjectPart m_host = World.GetSceneObjectPart(localID); 277 SceneObjectPart m_host = World.GetSceneObjectPart(localID);
272 278
273 try 279 try
274 { 280 {
275 // Create a new instance of the compiler (currently we don't want reuse) 281
276 Compiler.LSL.Compiler LSLCompiler = new Compiler.LSL.Compiler(); 282 // Compile (We assume LSL)
277 // Compile (We assume LSL) 283 ScriptSource = LSLCompiler.CompileFromLSLText(Script);
278 ScriptSource = LSLCompiler.CompileFromLSLText(Script); 284 //Console.WriteLine("Compilation of " + FileName + " done");
279 //Console.WriteLine("Compilation of " + FileName + " done"); 285 // * Insert yield into code
280 // * Insert yield into code 286 ScriptSource = ProcessYield(ScriptSource);
281 ScriptSource = ProcessYield(ScriptSource);
282 287
283 288
284#if DEBUG 289#if DEBUG
285 long before; 290 long before;
286 before = GC.GetTotalMemory(true); 291 before = GC.GetTotalMemory(true);
287#endif 292#endif
288 293
289 LSL_BaseClass CompiledScript; 294 LSL_BaseClass CompiledScript;
290 CompiledScript = m_scriptEngine.m_AppDomainManager.LoadScript(ScriptSource); 295 CompiledScript = m_scriptEngine.m_AppDomainManager.LoadScript(ScriptSource);
291 296
292#if DEBUG 297#if DEBUG
293 Console.WriteLine("Script " + itemID + " occupies {0} bytes", GC.GetTotalMemory(true) - before); 298 Console.WriteLine("Script " + itemID + " occupies {0} bytes", GC.GetTotalMemory(true) - before);
294#endif 299#endif
295 300
296 CompiledScript.SourceCode = ScriptSource; 301 CompiledScript.SourceCode = ScriptSource;
297 // Add it to our script memstruct 302 // Add it to our script memstruct
298 SetScript(localID, itemID, CompiledScript); 303 SetScript(localID, itemID, CompiledScript);
299 304
300 // We need to give (untrusted) assembly a private instance of BuiltIns 305 // We need to give (untrusted) assembly a private instance of BuiltIns
301 // this private copy will contain Read-Only FullitemID so that it can bring that on to the server whenever needed. 306 // this private copy will contain Read-Only FullitemID so that it can bring that on to the server whenever needed.
302 307
303 308
304 LSL_BuiltIn_Commands LSLB = new LSL_BuiltIn_Commands(m_scriptEngine, m_host, localID, itemID); 309 LSL_BuiltIn_Commands LSLB = new LSL_BuiltIn_Commands(m_scriptEngine, m_host, localID, itemID);
305 310
306 // Start the script - giving it BuiltIns 311 // Start the script - giving it BuiltIns
307 CompiledScript.Start(LSLB); 312 CompiledScript.Start(LSLB);
308 313
309 // Fire the first start-event 314 // Fire the first start-event
310 m_scriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "state_entry", new object[] {}); 315 m_scriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "state_entry", new object[] { });
311 }
312 catch (Exception e)
313 {
314 //m_scriptEngine.Log.Error("ScriptEngine", "Error compiling script: " + e.ToString());
315 try
316 {
317 // DISPLAY ERROR INWORLD
318 string text = "Error compiling script:\r\n" + e.Message.ToString();
319 if (text.Length > 1500)
320 text = text.Substring(0, 1500);
321 World.SimChat(Helpers.StringToField(text), 1, 0, m_host.AbsolutePosition, m_host.Name, m_host.UUID);
322 } 316 }
323 catch (Exception e2) 317 catch (Exception e)
324 { 318 {
325 m_scriptEngine.Log.Error("ScriptEngine", "Error displaying error in-world: " + e2.ToString()); 319 //m_scriptEngine.Log.Error("ScriptEngine", "Error compiling script: " + e.ToString());
320 try
321 {
322 // DISPLAY ERROR INWORLD
323 string text = "Error compiling script:\r\n" + e.Message.ToString();
324 if (text.Length > 1500)
325 text = text.Substring(0, 1500);
326 World.SimChat(Helpers.StringToField(text), 1, 0, m_host.AbsolutePosition, m_host.Name, m_host.UUID);
327 }
328 catch (Exception e2)
329 {
330 m_scriptEngine.Log.Error("ScriptEngine", "Error displaying error in-world: " + e2.ToString());
331 m_scriptEngine.Log.Error("ScriptEngine", "Errormessage: Error compiling script:\r\n" + e.Message.ToString());
332 }
326 } 333 }
327 } 334 }
328 } 335 }
329 336
330 private void _StopScript(uint localID, LLUUID itemID) 337 private void _StopScript(uint localID, LLUUID itemID)
331 { 338 {
339 lock (startStopLock)
340 {
332 // Stop script 341 // Stop script
333 Console.WriteLine("Stop script localID: " + localID + " LLUID: " + itemID.ToString()); 342 Console.WriteLine("Stop script localID: " + localID + " LLUID: " + itemID.ToString());
334 343
@@ -361,6 +370,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
361 ": " + e.ToString()); 370 ": " + e.ToString());
362 } 371 }
363 } 372 }
373 }
364 374
365 private string ProcessYield(string FileName) 375 private string ProcessYield(string FileName)
366 { 376 {
@@ -382,12 +392,18 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine
382 /// <param name="args">Arguments to pass to function</param> 392 /// <param name="args">Arguments to pass to function</param>
383 internal void ExecuteEvent(uint localID, LLUUID itemID, string FunctionName, object[] args) 393 internal void ExecuteEvent(uint localID, LLUUID itemID, string FunctionName, object[] args)
384 { 394 {
395#if DEBUG
396 Console.WriteLine("ScriptEngine: Inside ExecuteEvent for event " + FunctionName);
397#endif
385 // Execute a function in the script 398 // Execute a function in the script
386 //m_scriptEngine.Log.Verbose("ScriptEngine", "Executing Function localID: " + localID + ", itemID: " + itemID + ", FunctionName: " + FunctionName); 399 //m_scriptEngine.Log.Verbose("ScriptEngine", "Executing Function localID: " + localID + ", itemID: " + itemID + ", FunctionName: " + FunctionName);
387 LSL_BaseClass Script = m_scriptEngine.m_ScriptManager.GetScript(localID, itemID); 400 LSL_BaseClass Script = m_scriptEngine.m_ScriptManager.GetScript(localID, itemID);
388 if (Script == null) 401 if (Script == null)
389 return; 402 return;
390 403
404#if DEBUG
405 Console.WriteLine("ScriptEngine: Executing event: " + FunctionName);
406#endif
391 // Must be done in correct AppDomain, so leaving it up to the script itself 407 // Must be done in correct AppDomain, so leaving it up to the script itself
392 Script.Exec.ExecuteEvent(FunctionName, args); 408 Script.Exec.ExecuteEvent(FunctionName, args);
393 } 409 }