aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
diff options
context:
space:
mode:
authorJeff Ames2008-06-04 09:59:27 +0000
committerJeff Ames2008-06-04 09:59:27 +0000
commit4ec4e16c809cf86a63b736d2b7b6ad7291595a5f (patch)
treecfa896ef9057228171e2ee39c4807060101ba90b /OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
parent* If a ThreadAbortException reaches AuthUser() then let it pass through unmol... (diff)
downloadopensim-SC-4ec4e16c809cf86a63b736d2b7b6ad7291595a5f.zip
opensim-SC-4ec4e16c809cf86a63b736d2b7b6ad7291595a5f.tar.gz
opensim-SC-4ec4e16c809cf86a63b736d2b7b6ad7291595a5f.tar.bz2
opensim-SC-4ec4e16c809cf86a63b736d2b7b6ad7291595a5f.tar.xz
Formatting cleanup, minor refactoring, svn properties.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/XEngine/XEngine.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs420
1 files changed, 210 insertions, 210 deletions
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index cbcf5ea..0fe1f46 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -106,7 +106,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
106 106
107 m_ScriptConfig = configSource.Configs["XEngine"]; 107 m_ScriptConfig = configSource.Configs["XEngine"];
108 108
109 if(m_ScriptConfig == null) 109 if (m_ScriptConfig == null)
110 { 110 {
111 m_log.ErrorFormat("[XEngine] No script configuration found. Scripts disabled"); 111 m_log.ErrorFormat("[XEngine] No script configuration found. Scripts disabled");
112 return; 112 return;
@@ -126,7 +126,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
126 int saveTime = m_ScriptConfig.GetInt("SaveInterval", 300)*1000; 126 int saveTime = m_ScriptConfig.GetInt("SaveInterval", 300)*1000;
127 127
128 ThreadPriority prio = ThreadPriority.BelowNormal; 128 ThreadPriority prio = ThreadPriority.BelowNormal;
129 switch(priority) 129 switch (priority)
130 { 130 {
131 case "Lowest": 131 case "Lowest":
132 prio=ThreadPriority.Lowest; 132 prio=ThreadPriority.Lowest;
@@ -149,7 +149,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
149 break; 149 break;
150 } 150 }
151 151
152 lock(m_ScriptEngines) 152 lock (m_ScriptEngines)
153 { 153 {
154 m_ScriptEngines.Add(this); 154 m_ScriptEngines.Add(this);
155 } 155 }
@@ -166,17 +166,17 @@ namespace OpenSim.Region.ScriptEngine.XEngine
166 m_Scene.EventManager.OnRemoveScript += OnRemoveScript; 166 m_Scene.EventManager.OnRemoveScript += OnRemoveScript;
167 m_Scene.EventManager.OnScriptReset += OnScriptReset; 167 m_Scene.EventManager.OnScriptReset += OnScriptReset;
168 168
169 if(sleepTime > 0) 169 if (sleepTime > 0)
170 { 170 {
171 m_ThreadPool.QueueWorkItem(new WorkItemCallback( 171 m_ThreadPool.QueueWorkItem(new WorkItemCallback(
172 this.DoMaintenance), new Object[] 172 this.DoMaintenance), new Object[]
173 { sleepTime }); 173 { sleepTime });
174 } 174 }
175 175
176 if(saveTime > 0) 176 if (saveTime > 0)
177 { 177 {
178 m_ThreadPool.QueueWorkItem(new WorkItemCallback( 178 m_ThreadPool.QueueWorkItem(new WorkItemCallback(
179 this.DoBackup), new Object[] { saveTime }); 179 this.DoBackup), new Object[] { saveTime });
180 } 180 }
181 } 181 }
182 182
@@ -187,9 +187,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
187 187
188 public void Close() 188 public void Close()
189 { 189 {
190 lock(m_ScriptEngines) 190 lock (m_ScriptEngines)
191 { 191 {
192 if(m_ScriptEngines.Contains(this)) 192 if (m_ScriptEngines.Contains(this))
193 m_ScriptEngines.Remove(this); 193 m_ScriptEngines.Remove(this);
194 } 194 }
195 } 195 }
@@ -205,7 +205,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
205 205
206 List<XScriptInstance> instances = new List<XScriptInstance>(); 206 List<XScriptInstance> instances = new List<XScriptInstance>();
207 207
208 lock(m_Scripts) 208 lock (m_Scripts)
209 { 209 {
210 foreach (XScriptInstance instance in m_Scripts.Values) 210 foreach (XScriptInstance instance in m_Scripts.Values)
211 instances.Add(instance); 211 instances.Add(instance);
@@ -215,9 +215,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
215 { 215 {
216 string assembly = String.Empty; 216 string assembly = String.Empty;
217 217
218 lock(m_Scripts) 218 lock (m_Scripts)
219 { 219 {
220 if(!m_Assemblies.ContainsKey(i.AssetID)) 220 if (!m_Assemblies.ContainsKey(i.AssetID))
221 continue; 221 continue;
222 assembly = m_Assemblies[i.AssetID]; 222 assembly = m_Assemblies[i.AssetID];
223 } 223 }
@@ -240,10 +240,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine
240 240
241 foreach (XScriptInstance inst in m_Scripts.Values) 241 foreach (XScriptInstance inst in m_Scripts.Values)
242 { 242 {
243 if(inst.EventTime() > m_EventLimit) 243 if (inst.EventTime() > m_EventLimit)
244 { 244 {
245 inst.Stop(100); 245 inst.Stop(100);
246 if(!m_KillTimedOutScripts) 246 if (!m_KillTimedOutScripts)
247 inst.Start(); 247 inst.Start();
248 } 248 }
249 } 249 }
@@ -251,7 +251,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
251 System.Threading.Thread.Sleep(sleepTime); 251 System.Threading.Thread.Sleep(sleepTime);
252 252
253 m_ThreadPool.QueueWorkItem(new WorkItemCallback( 253 m_ThreadPool.QueueWorkItem(new WorkItemCallback(
254 this.DoMaintenance), new Object[] 254 this.DoMaintenance), new Object[]
255 { sleepTime }); 255 { sleepTime });
256 256
257 return 0; 257 return 0;
@@ -281,7 +281,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
281 public void OnRezScript(uint localID, LLUUID itemID, string script) 281 public void OnRezScript(uint localID, LLUUID itemID, string script)
282 { 282 {
283 m_ThreadPool.QueueWorkItem(new WorkItemCallback( 283 m_ThreadPool.QueueWorkItem(new WorkItemCallback(
284 this.DoOnRezScript), new Object[] 284 this.DoOnRezScript), new Object[]
285 { localID, itemID, script}); 285 { localID, itemID, script});
286 } 286 }
287 287
@@ -296,25 +296,25 @@ namespace OpenSim.Region.ScriptEngine.XEngine
296 // already have it. 296 // already have it.
297 297
298 SceneObjectPart part = m_Scene.GetSceneObjectPart(localID); 298 SceneObjectPart part = m_Scene.GetSceneObjectPart(localID);
299 if(part == null) 299 if (part == null)
300 return false; 300 return false;
301 301
302 TaskInventoryItem item = part.GetInventoryItem(itemID); 302 TaskInventoryItem item = part.GetInventoryItem(itemID);
303 if(item == null) 303 if (item == null)
304 return false; 304 return false;
305 305
306 LLUUID assetID=item.AssetID; 306 LLUUID assetID = item.AssetID;
307 307
308// m_log.DebugFormat("[XEngine] Compiling script {0} ({1})", 308// m_log.DebugFormat("[XEngine] Compiling script {0} ({1})",
309// item.Name, itemID.ToString()); 309// item.Name, itemID.ToString());
310 310
311 string assembly=""; 311 string assembly = "";
312 try 312 try
313 { 313 {
314 assembly=m_Compiler.PerformScriptCompile(script, 314 assembly = m_Compiler.PerformScriptCompile(script,
315 assetID.ToString()); 315 assetID.ToString());
316 m_log.DebugFormat("[XEngine] Loaded script {0}.{1}", 316 m_log.DebugFormat("[XEngine] Loaded script {0}.{1}",
317 part.ParentGroup.RootPart.Name, item.Name); 317 part.ParentGroup.RootPart.Name, item.Name);
318 } 318 }
319 catch (Exception e) 319 catch (Exception e)
320 { 320 {
@@ -325,9 +325,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
325 if (text.Length > 1400) 325 if (text.Length > 1400)
326 text = text.Substring(0, 1400); 326 text = text.Substring(0, 1400);
327 World.SimChat(Helpers.StringToField(text), 327 World.SimChat(Helpers.StringToField(text),
328 ChatTypeEnum.DebugChannel, 2147483647, 328 ChatTypeEnum.DebugChannel, 2147483647,
329 part.AbsolutePosition, 329 part.AbsolutePosition,
330 part.Name, part.UUID, false); 330 part.Name, part.UUID, false);
331 } 331 }
332 catch (Exception e2) // LEGIT: User Scripting 332 catch (Exception e2) // LEGIT: User Scripting
333 { 333 {
@@ -342,28 +342,28 @@ namespace OpenSim.Region.ScriptEngine.XEngine
342 return false; 342 return false;
343 } 343 }
344 344
345 lock(m_Scripts) 345 lock (m_Scripts)
346 { 346 {
347 // Create the object record 347 // Create the object record
348 348
349 if(!m_PrimObjects.ContainsKey(localID)) 349 if (!m_PrimObjects.ContainsKey(localID))
350 m_PrimObjects[localID] = new List<LLUUID>(); 350 m_PrimObjects[localID] = new List<LLUUID>();
351 351
352 if(!m_PrimObjects[localID].Contains(itemID)) 352 if (!m_PrimObjects[localID].Contains(itemID))
353 m_PrimObjects[localID].Add(itemID); 353 m_PrimObjects[localID].Add(itemID);
354 354
355 if(!m_Assemblies.ContainsKey(assetID)) 355 if (!m_Assemblies.ContainsKey(assetID))
356 m_Assemblies[assetID] = assembly; 356 m_Assemblies[assetID] = assembly;
357 357
358 if((!m_Scripts.ContainsKey(itemID)) || 358 if ((!m_Scripts.ContainsKey(itemID)) ||
359 (m_Scripts[itemID].AssetID != assetID)) 359 (m_Scripts[itemID].AssetID != assetID))
360 { 360 {
361 LLUUID appDomain=assetID; 361 LLUUID appDomain=assetID;
362 362
363 if(part.ParentGroup.RootPart.m_IsAttachment) 363 if (part.ParentGroup.RootPart.m_IsAttachment)
364 appDomain=part.ParentGroup.RootPart.UUID; 364 appDomain = part.ParentGroup.RootPart.UUID;
365 365
366 if(!m_AppDomains.ContainsKey(appDomain)) 366 if (!m_AppDomains.ContainsKey(appDomain))
367 { 367 {
368 try 368 try
369 { 369 {
@@ -373,16 +373,16 @@ namespace OpenSim.Region.ScriptEngine.XEngine
373// m_Scene.RegionInfo.RegionID.ToString()); 373// m_Scene.RegionInfo.RegionID.ToString());
374 374
375 Evidence baseEvidence = 375 Evidence baseEvidence =
376 AppDomain.CurrentDomain.Evidence; 376 AppDomain.CurrentDomain.Evidence;
377 Evidence evidence = new Evidence(baseEvidence); 377 Evidence evidence = new Evidence(baseEvidence);
378 378
379 m_AppDomains[appDomain] = 379 m_AppDomains[appDomain] =
380 AppDomain.CreateDomain( 380 AppDomain.CreateDomain(
381 m_Scene.RegionInfo.RegionID.ToString(), 381 m_Scene.RegionInfo.RegionID.ToString(),
382 evidence, appSetup); 382 evidence, appSetup);
383 383
384 m_AppDomains[appDomain].AssemblyResolve += 384 m_AppDomains[appDomain].AssemblyResolve +=
385 new ResolveEventHandler( 385 new ResolveEventHandler(
386 AssemblyResolver.OnAssemblyResolve); 386 AssemblyResolver.OnAssemblyResolve);
387 m_DomainScripts[appDomain] = new List<LLUUID>(); 387 m_DomainScripts[appDomain] = new List<LLUUID>();
388 } 388 }
@@ -394,10 +394,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
394 } 394 }
395 m_DomainScripts[appDomain].Add(itemID); 395 m_DomainScripts[appDomain].Add(itemID);
396 396
397
398 XScriptInstance instance = new XScriptInstance(this,localID, 397 XScriptInstance instance = new XScriptInstance(this,localID,
399 part.UUID, itemID, assetID, assembly, 398 part.UUID, itemID, assetID, assembly,
400 m_AppDomains[appDomain]); 399 m_AppDomains[appDomain]);
401 400
402 instance.AppDomain = appDomain; 401 instance.AppDomain = appDomain;
403 402
@@ -409,10 +408,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine
409 408
410 public void OnRemoveScript(uint localID, LLUUID itemID) 409 public void OnRemoveScript(uint localID, LLUUID itemID)
411 { 410 {
412 lock(m_Scripts) 411 lock (m_Scripts)
413 { 412 {
414 // Do we even have it? 413 // Do we even have it?
415 if(!m_Scripts.ContainsKey(itemID)) 414 if (!m_Scripts.ContainsKey(itemID))
416 return; 415 return;
417 416
418 m_ASYNCLSLCommandManager.RemoveScript(localID, itemID); 417 m_ASYNCLSLCommandManager.RemoveScript(localID, itemID);
@@ -424,27 +423,27 @@ namespace OpenSim.Region.ScriptEngine.XEngine
424 instance.Stop(0); 423 instance.Stop(0);
425 424
426 SceneObjectPart part = 425 SceneObjectPart part =
427 m_Scene.GetSceneObjectPart(localID); 426 m_Scene.GetSceneObjectPart(localID);
428 427
429 if(part != null) 428 if (part != null)
430 part.RemoveScriptEvents(itemID); 429 part.RemoveScriptEvents(itemID);
431 430
432 // Remove the script from it's prim 431 // Remove the script from it's prim
433 if(m_PrimObjects.ContainsKey(localID)) 432 if (m_PrimObjects.ContainsKey(localID))
434 { 433 {
435 // Remove inventory item record 434 // Remove inventory item record
436 if(m_PrimObjects[localID].Contains(itemID)) 435 if (m_PrimObjects[localID].Contains(itemID))
437 m_PrimObjects[localID].Remove(itemID); 436 m_PrimObjects[localID].Remove(itemID);
438 437
439 // If there are no more scripts, remove prim 438 // If there are no more scripts, remove prim
440 if(m_PrimObjects[localID].Count == 0) 439 if (m_PrimObjects[localID].Count == 0)
441 { 440 {
442 m_PrimObjects.Remove(localID); 441 m_PrimObjects.Remove(localID);
443 } 442 }
444 } 443 }
445 444
446 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID); 445 m_DomainScripts[instance.AppDomain].Remove(instance.ItemID);
447 if(m_DomainScripts[instance.AppDomain].Count == 0) 446 if (m_DomainScripts[instance.AppDomain].Count == 0)
448 { 447 {
449 m_DomainScripts.Remove(instance.AppDomain); 448 m_DomainScripts.Remove(instance.AppDomain);
450 UnloadAppDomain(instance.AppDomain); 449 UnloadAppDomain(instance.AppDomain);
@@ -467,7 +466,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
467 466
468 foreach (XScriptInstance i in m_Scripts.Values) 467 foreach (XScriptInstance i in m_Scripts.Values)
469 { 468 {
470 if(assetIDList.Contains(i.AssetID)) 469 if (assetIDList.Contains(i.AssetID))
471 assetIDList.Remove(i.AssetID); 470 assetIDList.Remove(i.AssetID);
472 } 471 }
473 472
@@ -476,11 +475,13 @@ namespace OpenSim.Region.ScriptEngine.XEngine
476// m_log.DebugFormat("[XEngine] Removing unreferenced assembly {0}", m_Assemblies[assetID]); 475// m_log.DebugFormat("[XEngine] Removing unreferenced assembly {0}", m_Assemblies[assetID]);
477 try 476 try
478 { 477 {
479 if(File.Exists(m_Assemblies[assetID])) 478 if (File.Exists(m_Assemblies[assetID]))
480 File.Delete(m_Assemblies[assetID]); 479 File.Delete(m_Assemblies[assetID]);
481 if(File.Exists(m_Assemblies[assetID]+".state")) 480
481 if (File.Exists(m_Assemblies[assetID]+".state"))
482 File.Delete(m_Assemblies[assetID]+".state"); 482 File.Delete(m_Assemblies[assetID]+".state");
483 if(File.Exists(m_Assemblies[assetID]+".mdb")) 483
484 if (File.Exists(m_Assemblies[assetID]+".mdb"))
484 File.Delete(m_Assemblies[assetID]+".mdb"); 485 File.Delete(m_Assemblies[assetID]+".mdb");
485 } 486 }
486 catch (Exception e) 487 catch (Exception e)
@@ -492,9 +493,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
492 493
493 private void UnloadAppDomain(LLUUID id) 494 private void UnloadAppDomain(LLUUID id)
494 { 495 {
495 if(m_AppDomains.ContainsKey(id)) 496 if (m_AppDomains.ContainsKey(id))
496 { 497 {
497 AppDomain domain=m_AppDomains[id]; 498 AppDomain domain = m_AppDomains[id];
498 m_AppDomains.Remove(id); 499 m_AppDomains.Remove(id);
499 500
500 AppDomain.Unload(domain); 501 AppDomain.Unload(domain);
@@ -507,10 +508,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine
507 // Start processing 508 // Start processing
508 // 509 //
509 private void StartEngine(int minThreads, int maxThreads, 510 private void StartEngine(int minThreads, int maxThreads,
510 int idleTimeout, ThreadPriority threadPriority, 511 int idleTimeout, ThreadPriority threadPriority,
511 int maxScriptQueue, int stackSize) 512 int maxScriptQueue, int stackSize)
512 { 513 {
513 m_MaxScriptQueue=maxScriptQueue; 514 m_MaxScriptQueue = maxScriptQueue;
514 515
515 STPStartInfo startInfo = new STPStartInfo(); 516 STPStartInfo startInfo = new STPStartInfo();
516 startInfo.IdleTimeout = idleTimeout; 517 startInfo.IdleTimeout = idleTimeout;
@@ -519,7 +520,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
519 startInfo.ThreadPriority = threadPriority; 520 startInfo.ThreadPriority = threadPriority;
520 startInfo.StackSize = stackSize; 521 startInfo.StackSize = stackSize;
521 startInfo.StartSuspended = true; 522 startInfo.StartSuspended = true;
522 523
523 m_ThreadPool = new SmartThreadPool(startInfo); 524 m_ThreadPool = new SmartThreadPool(startInfo);
524 } 525 }
525 526
@@ -529,7 +530,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
529 public IWorkItemResult QueueEventHandler(object parms) 530 public IWorkItemResult QueueEventHandler(object parms)
530 { 531 {
531 return m_ThreadPool.QueueWorkItem(new WorkItemCallback( 532 return m_ThreadPool.QueueWorkItem(new WorkItemCallback(
532 this.ProcessEventHandler), parms); 533 this.ProcessEventHandler), parms);
533 } 534 }
534 535
535 // 536 //
@@ -537,8 +538,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
537 // 538 //
538 private object ProcessEventHandler(object parms) 539 private object ProcessEventHandler(object parms)
539 { 540 {
540 XScriptInstance instance=(XScriptInstance)parms; 541 XScriptInstance instance = (XScriptInstance) parms;
541 542
542 return instance.EventProcessor(); 543 return instance.EventProcessor();
543 } 544 }
544 545
@@ -549,15 +550,15 @@ namespace OpenSim.Region.ScriptEngine.XEngine
549 { 550 {
550 bool result = false; 551 bool result = false;
551 552
552 if(!m_PrimObjects.ContainsKey(localID)) 553 if (!m_PrimObjects.ContainsKey(localID))
553 return false; 554 return false;
554 555
555 foreach (LLUUID itemID in m_PrimObjects[localID]) 556 foreach (LLUUID itemID in m_PrimObjects[localID])
556 { 557 {
557 if(m_Scripts.ContainsKey(itemID)) 558 if (m_Scripts.ContainsKey(itemID))
558 { 559 {
559 XScriptInstance instance = m_Scripts[itemID]; 560 XScriptInstance instance = m_Scripts[itemID];
560 if(instance != null) 561 if (instance != null)
561 { 562 {
562 instance.PostEvent(p); 563 instance.PostEvent(p);
563 result = true; 564 result = true;
@@ -572,10 +573,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine
572 // 573 //
573 public bool PostScriptEvent(LLUUID itemID, XEventParams p) 574 public bool PostScriptEvent(LLUUID itemID, XEventParams p)
574 { 575 {
575 if(m_Scripts.ContainsKey(itemID)) 576 if (m_Scripts.ContainsKey(itemID))
576 { 577 {
577 XScriptInstance instance = m_Scripts[itemID]; 578 XScriptInstance instance = m_Scripts[itemID];
578 if(instance != null) 579 if (instance != null)
579 instance.PostEvent(p); 580 instance.PostEvent(p);
580 return true; 581 return true;
581 } 582 }
@@ -583,25 +584,25 @@ namespace OpenSim.Region.ScriptEngine.XEngine
583 } 584 }
584 585
585 public Assembly OnAssemblyResolve(object sender, 586 public Assembly OnAssemblyResolve(object sender,
586 ResolveEventArgs args) 587 ResolveEventArgs args)
587 { 588 {
588 if(!(sender is System.AppDomain)) 589 if (!(sender is System.AppDomain))
589 return null; 590 return null;
590 591
591 string[] pathList=new string[] {"bin", "ScriptEngines", 592 string[] pathList = new string[] {"bin", "ScriptEngines",
592 Path.Combine("ScriptEngines", 593 Path.Combine("ScriptEngines",
593 m_Scene.RegionInfo.RegionID.ToString())}; 594 m_Scene.RegionInfo.RegionID.ToString())};
594 595
595 string assemblyName = args.Name; 596 string assemblyName = args.Name;
596 if(assemblyName.IndexOf(",") != -1) 597 if (assemblyName.IndexOf(",") != -1)
597 assemblyName=args.Name.Substring(0, args.Name.IndexOf(",")); 598 assemblyName = args.Name.Substring(0, args.Name.IndexOf(","));
598 599
599 foreach (string s in pathList) 600 foreach (string s in pathList)
600 { 601 {
601 string path=Path.Combine(Directory.GetCurrentDirectory(), 602 string path = Path.Combine(Directory.GetCurrentDirectory(),
602 Path.Combine(s, assemblyName))+".dll"; 603 Path.Combine(s, assemblyName))+".dll";
603 604
604 if(File.Exists(path)) 605 if (File.Exists(path))
605 return Assembly.LoadFrom(path); 606 return Assembly.LoadFrom(path);
606 } 607 }
607 608
@@ -611,9 +612,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
611 private XScriptInstance GetInstance(LLUUID itemID) 612 private XScriptInstance GetInstance(LLUUID itemID)
612 { 613 {
613 XScriptInstance instance; 614 XScriptInstance instance;
614 lock(m_Scripts) 615 lock (m_Scripts)
615 { 616 {
616 if(!m_Scripts.ContainsKey(itemID)) 617 if (!m_Scripts.ContainsKey(itemID))
617 return null; 618 return null;
618 instance = m_Scripts[itemID]; 619 instance = m_Scripts[itemID];
619 } 620 }
@@ -623,9 +624,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
623 public void SetScriptState(LLUUID itemID, bool running) 624 public void SetScriptState(LLUUID itemID, bool running)
624 { 625 {
625 XScriptInstance instance = GetInstance(itemID); 626 XScriptInstance instance = GetInstance(itemID);
626 if(instance != null) 627 if (instance != null)
627 { 628 {
628 if(running) 629 if (running)
629 instance.Start(); 630 instance.Start();
630 else 631 else
631 instance.Stop(500); 632 instance.Stop(500);
@@ -635,7 +636,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
635 public bool GetScriptState(LLUUID itemID) 636 public bool GetScriptState(LLUUID itemID)
636 { 637 {
637 XScriptInstance instance = GetInstance(itemID); 638 XScriptInstance instance = GetInstance(itemID);
638 if(instance != null) 639 if (instance != null)
639 return instance.Running; 640 return instance.Running;
640 return false; 641 return false;
641 } 642 }
@@ -643,14 +644,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine
643 public void ResetScript(LLUUID itemID) 644 public void ResetScript(LLUUID itemID)
644 { 645 {
645 XScriptInstance instance = GetInstance(itemID); 646 XScriptInstance instance = GetInstance(itemID);
646 if(instance != null) 647 if (instance != null)
647 instance.ResetScript(); 648 instance.ResetScript();
648 } 649 }
649 650
650 public XDetectParams GetDetectParams(LLUUID itemID, int idx) 651 public XDetectParams GetDetectParams(LLUUID itemID, int idx)
651 { 652 {
652 XScriptInstance instance = GetInstance(itemID); 653 XScriptInstance instance = GetInstance(itemID);
653 if(instance != null) 654 if (instance != null)
654 return instance.GetDetectParams(idx); 655 return instance.GetDetectParams(idx);
655 return new XDetectParams(); 656 return new XDetectParams();
656 } 657 }
@@ -658,7 +659,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
658 public LLUUID GetDetectID(LLUUID itemID, int idx) 659 public LLUUID GetDetectID(LLUUID itemID, int idx)
659 { 660 {
660 XScriptInstance instance = GetInstance(itemID); 661 XScriptInstance instance = GetInstance(itemID);
661 if(instance != null) 662 if (instance != null)
662 return instance.GetDetectID(idx); 663 return instance.GetDetectID(idx);
663 return LLUUID.Zero; 664 return LLUUID.Zero;
664 } 665 }
@@ -688,8 +689,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
688 { 689 {
689 private XEngine m_Engine; 690 private XEngine m_Engine;
690 private IWorkItemResult m_CurrentResult=null; 691 private IWorkItemResult m_CurrentResult=null;
691 private Queue m_EventQueue=new Queue(32); 692 private Queue m_EventQueue = new Queue(32);
692 private bool m_RunEvents=false; 693 private bool m_RunEvents = false;
693 private LLUUID m_ItemID; 694 private LLUUID m_ItemID;
694 private uint m_LocalID; 695 private uint m_LocalID;
695 private LLUUID m_ObjectID; 696 private LLUUID m_ObjectID;
@@ -765,7 +766,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
765 public XScriptInstance(XEngine engine, uint localID, LLUUID objectID, 766 public XScriptInstance(XEngine engine, uint localID, LLUUID objectID,
766 LLUUID itemID, LLUUID assetID, string assembly, AppDomain dom) 767 LLUUID itemID, LLUUID assetID, string assembly, AppDomain dom)
767 { 768 {
768 m_Engine=engine; 769 m_Engine = engine;
769 770
770 m_LocalID = localID; 771 m_LocalID = localID;
771 m_ObjectID = objectID; 772 m_ObjectID = objectID;
@@ -773,22 +774,22 @@ namespace OpenSim.Region.ScriptEngine.XEngine
773 m_AssetID = assetID; 774 m_AssetID = assetID;
774 775
775 SceneObjectPart part=engine.World.GetSceneObjectPart(localID); 776 SceneObjectPart part=engine.World.GetSceneObjectPart(localID);
776 if(part == null) 777 if (part == null)
777 { 778 {
778 engine.Log.Error("[XEngine] SceneObjectPart unavailable. Script NOT started."); 779 engine.Log.Error("[XEngine] SceneObjectPart unavailable. Script NOT started.");
779 return; 780 return;
780 } 781 }
781 782
782 m_LSLCommands = new LSL_ScriptCommands(engine, this, part, localID, 783 m_LSLCommands = new LSL_ScriptCommands(engine, this, part, localID,
783 itemID); 784 itemID);
784 m_OSSLCommands = new OSSL_ScriptCommands(engine, this, part, 785 m_OSSLCommands = new OSSL_ScriptCommands(engine, this, part,
785 localID, itemID); 786 localID, itemID);
786 787
787 try 788 try
788 { 789 {
789 m_Script = (IScript)dom.CreateInstanceAndUnwrap( 790 m_Script = (IScript)dom.CreateInstanceAndUnwrap(
790 Path.GetFileNameWithoutExtension(assembly), 791 Path.GetFileNameWithoutExtension(assembly),
791 "SecondLife.Script"); 792 "SecondLife.Script");
792 } 793 }
793 catch (Exception e) 794 catch (Exception e)
794 { 795 {
@@ -804,15 +805,15 @@ namespace OpenSim.Region.ScriptEngine.XEngine
804// m_Engine.Log.Debug("[XEngine] Script instance created"); 805// m_Engine.Log.Debug("[XEngine] Script instance created");
805 806
806 part.SetScriptEvents(m_ItemID, 807 part.SetScriptEvents(m_ItemID,
807 (int)m_Executor.GetStateEventFlags()); 808 (int)m_Executor.GetStateEventFlags());
808 } 809 }
809 catch (Exception e) 810 catch (Exception e)
810 { 811 {
811 m_Engine.Log.Error("Error loading script instance\n"+e.ToString()); 812 m_Engine.Log.Error("Error loading script instance\n"+e.ToString());
812 } 813 }
813 814
814 string savedState = assembly+".state"; 815 string savedState = assembly + ".state";
815 if(File.Exists(savedState)) 816 if (File.Exists(savedState))
816 { 817 {
817 string xml = String.Empty; 818 string xml = String.Empty;
818 819
@@ -820,44 +821,44 @@ namespace OpenSim.Region.ScriptEngine.XEngine
820 { 821 {
821 FileInfo fi = new FileInfo(savedState); 822 FileInfo fi = new FileInfo(savedState);
822 int size=(int)fi.Length; 823 int size=(int)fi.Length;
823 if(size < 130000) 824 if (size < 130000)
824 { 825 {
825 using (FileStream fs = File.Open(savedState, 826 using (FileStream fs = File.Open(savedState,
826 FileMode.Open, FileAccess.Read, FileShare.None)) 827 FileMode.Open, FileAccess.Read, FileShare.None))
827 { 828 {
828 System.Text.ASCIIEncoding enc = 829 System.Text.ASCIIEncoding enc =
829 new System.Text.ASCIIEncoding(); 830 new System.Text.ASCIIEncoding();
830 831
831 Byte[] data=new Byte[size]; 832 Byte[] data = new Byte[size];
832 fs.Read(data, 0, size); 833 fs.Read(data, 0, size);
833 834
834 xml=enc.GetString(data); 835 xml = enc.GetString(data);
835 836
836 ScriptSerializer.Deserialize(xml, this); 837 ScriptSerializer.Deserialize(xml, this);
837 838
838 m_Engine.m_ASYNCLSLCommandManager.CreateFromData( 839 m_Engine.m_ASYNCLSLCommandManager.CreateFromData(
839 m_LocalID, m_ItemID, m_ObjectID, 840 m_LocalID, m_ItemID, m_ObjectID,
840 PluginData); 841 PluginData);
841 } 842 }
842 } 843 }
843 else 844 else
844 { 845 {
845 m_Engine.Log.Error("Unable to load script state: Memory limit exceeded"); 846 m_Engine.Log.Error("Unable to load script state: Memory limit exceeded");
846 PostEvent(new XEventParams("state_entry", 847 PostEvent(new XEventParams("state_entry",
847 new Object[0], new XDetectParams[0])); 848 new Object[0], new XDetectParams[0]));
848 } 849 }
849 } 850 }
850 catch (Exception e) 851 catch (Exception e)
851 { 852 {
852 m_Engine.Log.ErrorFormat("Unable to load script state from xml: {0}\n"+e.ToString(), xml); 853 m_Engine.Log.ErrorFormat("Unable to load script state from xml: {0}\n"+e.ToString(), xml);
853 PostEvent(new XEventParams("state_entry", 854 PostEvent(new XEventParams("state_entry",
854 new Object[0], new XDetectParams[0])); 855 new Object[0], new XDetectParams[0]));
855 } 856 }
856 } 857 }
857 else 858 else
858 { 859 {
859 PostEvent(new XEventParams("state_entry", 860 PostEvent(new XEventParams("state_entry",
860 new Object[0], new XDetectParams[0])); 861 new Object[0], new XDetectParams[0]));
861 } 862 }
862 Start(); 863 Start();
863 } 864 }
@@ -868,23 +869,23 @@ namespace OpenSim.Region.ScriptEngine.XEngine
868 foreach (KeyValuePair<string, object> v in vars) 869 foreach (KeyValuePair<string, object> v in vars)
869 { 870 {
870 Console.WriteLine("Variable: {0} = '{1}'", v. Key, 871 Console.WriteLine("Variable: {0} = '{1}'", v. Key,
871 v.Value.ToString()); 872 v.Value.ToString());
872 } 873 }
873 } 874 }
874 875
875 public void Start() 876 public void Start()
876 { 877 {
877 lock(m_EventQueue) 878 lock (m_EventQueue)
878 { 879 {
879 if(Running) 880 if (Running)
880 return; 881 return;
881 882
882 m_RunEvents=true; 883 m_RunEvents = true;
883 884
884 if(m_EventQueue.Count > 0) 885 if (m_EventQueue.Count > 0)
885 { 886 {
886 if(m_CurrentResult == null) 887 if (m_CurrentResult == null)
887 m_CurrentResult=m_Engine.QueueEventHandler(this); 888 m_CurrentResult = m_Engine.QueueEventHandler(this);
888 } 889 }
889 } 890 }
890 } 891 }
@@ -893,36 +894,36 @@ namespace OpenSim.Region.ScriptEngine.XEngine
893 { 894 {
894 IWorkItemResult result; 895 IWorkItemResult result;
895 896
896 lock(m_EventQueue) 897 lock (m_EventQueue)
897 { 898 {
898 if(!Running) 899 if (!Running)
899 return true; 900 return true;
900 901
901 if(m_CurrentResult == null) 902 if (m_CurrentResult == null)
902 { 903 {
903 m_RunEvents=false; 904 m_RunEvents = false;
904 return true; 905 return true;
905 } 906 }
906 907
907 if(m_CurrentResult.Cancel()) 908 if (m_CurrentResult.Cancel())
908 { 909 {
909 m_CurrentResult=null; 910 m_CurrentResult = null;
910 m_RunEvents=false; 911 m_RunEvents = false;
911 return true; 912 return true;
912 } 913 }
913 914
914 result=m_CurrentResult; 915 result = m_CurrentResult;
915 m_RunEvents=false; 916 m_RunEvents = false;
916 } 917 }
917 918
918 if(SmartThreadPool.WaitAll(new IWorkItemResult[] {result}, new TimeSpan((long)timeout*100000), false)) 919 if (SmartThreadPool.WaitAll(new IWorkItemResult[] {result}, new TimeSpan((long)timeout * 100000), false))
919 { 920 {
920 return true; 921 return true;
921 } 922 }
922 923
923 lock(m_EventQueue) 924 lock (m_EventQueue)
924 { 925 {
925 if(m_CurrentResult != null) 926 if (m_CurrentResult != null)
926 m_CurrentResult.Abort(); 927 m_CurrentResult.Abort();
927 else 928 else
928 return true; 929 return true;
@@ -934,75 +935,75 @@ namespace OpenSim.Region.ScriptEngine.XEngine
934 public void SetState(string state) 935 public void SetState(string state)
935 { 936 {
936 PostEvent(new XEventParams("state_exit", new Object[0], 937 PostEvent(new XEventParams("state_exit", new Object[0],
937 new XDetectParams[0])); 938 new XDetectParams[0]));
938 PostEvent(new XEventParams("state", new Object[] { state }, 939 PostEvent(new XEventParams("state", new Object[] { state },
939 new XDetectParams[0])); 940 new XDetectParams[0]));
940 PostEvent(new XEventParams("state_entry", new Object[0], 941 PostEvent(new XEventParams("state_entry", new Object[0],
941 new XDetectParams[0])); 942 new XDetectParams[0]));
942 } 943 }
943 944
944 public void PostEvent(XEventParams data) 945 public void PostEvent(XEventParams data)
945 { 946 {
946 lock(m_EventQueue) 947 lock (m_EventQueue)
947 { 948 {
948 if(m_EventQueue.Count >= m_Engine.MaxScriptQueue) 949 if (m_EventQueue.Count >= m_Engine.MaxScriptQueue)
949 return; 950 return;
950 951
951 m_EventQueue.Enqueue(data); 952 m_EventQueue.Enqueue(data);
952 if(data.EventName == "timer") 953 if (data.EventName == "timer")
953 { 954 {
954 if(m_TimerQueued) 955 if (m_TimerQueued)
955 return; 956 return;
956 m_TimerQueued = true; 957 m_TimerQueued = true;
957 } 958 }
958 959
959 if(!m_RunEvents) 960 if (!m_RunEvents)
960 return; 961 return;
961 962
962 if(m_CurrentResult == null) 963 if (m_CurrentResult == null)
963 { 964 {
964 m_CurrentResult=m_Engine.QueueEventHandler(this); 965 m_CurrentResult = m_Engine.QueueEventHandler(this);
965 } 966 }
966 } 967 }
967 } 968 }
968 969
969 public object EventProcessor() 970 public object EventProcessor()
970 { 971 {
971 XEventParams data=null; 972 XEventParams data = null;
972 973
973 lock(m_EventQueue) 974 lock (m_EventQueue)
974 { 975 {
975 data=(XEventParams)m_EventQueue.Dequeue(); 976 data = (XEventParams) m_EventQueue.Dequeue();
976 if(data == null) // Shouldn't happen 977 if (data == null) // Shouldn't happen
977 { 978 {
978 m_CurrentResult=null; 979 m_CurrentResult = null;
979 return 0; 980 return 0;
980 } 981 }
981 if(data.EventName == "timer") 982 if (data.EventName == "timer")
982 m_TimerQueued = false; 983 m_TimerQueued = false;
983 } 984 }
984 985
985 m_DetectParams=data.DetectParams; 986 m_DetectParams = data.DetectParams;
986 987
987 if(data.EventName == "state") // Hardcoded state change 988 if (data.EventName == "state") // Hardcoded state change
988 { 989 {
989 m_State=data.Params[0].ToString(); 990 m_State=data.Params[0].ToString();
990 m_Engine.m_ASYNCLSLCommandManager.RemoveScript( 991 m_Engine.m_ASYNCLSLCommandManager.RemoveScript(
991 m_LocalID, m_ItemID); 992 m_LocalID, m_ItemID);
992 993
993 SceneObjectPart part=m_Engine.World.GetSceneObjectPart( 994 SceneObjectPart part = m_Engine.World.GetSceneObjectPart(
994 m_LocalID); 995 m_LocalID);
995 if(part != null) 996 if (part != null)
996 { 997 {
997 part.SetScriptEvents(m_ItemID, 998 part.SetScriptEvents(m_ItemID,
998 (int)m_Executor.GetStateEventFlags()); 999 (int)m_Executor.GetStateEventFlags());
999 } 1000 }
1000 } 1001 }
1001 else 1002 else
1002 { 1003 {
1003// m_Engine.Log.DebugFormat("[XEngine] Processed event {0}", data.EventName); 1004// m_Engine.Log.DebugFormat("[XEngine] Processed event {0}", data.EventName);
1004 SceneObjectPart part=m_Engine.World.GetSceneObjectPart( 1005 SceneObjectPart part = m_Engine.World.GetSceneObjectPart(
1005 m_LocalID); 1006 m_LocalID);
1006 try 1007 try
1007 { 1008 {
1008 m_EventStart = DateTime.Now; 1009 m_EventStart = DateTime.Now;
@@ -1013,21 +1014,21 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1013 catch (Exception e) 1014 catch (Exception e)
1014 { 1015 {
1015 m_InEvent = false; 1016 m_InEvent = false;
1016 if(e is System.Threading.ThreadAbortException) 1017 if (e is System.Threading.ThreadAbortException)
1017 { 1018 {
1018 lock(m_EventQueue) 1019 lock (m_EventQueue)
1019 { 1020 {
1020 if((m_EventQueue.Count > 0) && m_RunEvents) 1021 if ((m_EventQueue.Count > 0) && m_RunEvents)
1021 { 1022 {
1022 m_CurrentResult=m_Engine.QueueEventHandler(this); 1023 m_CurrentResult=m_Engine.QueueEventHandler(this);
1023 } 1024 }
1024 else 1025 else
1025 { 1026 {
1026 m_CurrentResult=null; 1027 m_CurrentResult = null;
1027 } 1028 }
1028 } 1029 }
1029 1030
1030 m_DetectParams=null; 1031 m_DetectParams = null;
1031 1032
1032 return 0; 1033 return 0;
1033 } 1034 }
@@ -1039,42 +1040,42 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1039 if (text.Length > 1400) 1040 if (text.Length > 1400)
1040 text = text.Substring(0, 1400); 1041 text = text.Substring(0, 1400);
1041 m_Engine.World.SimChat(Helpers.StringToField(text), 1042 m_Engine.World.SimChat(Helpers.StringToField(text),
1042 ChatTypeEnum.DebugChannel, 2147483647, 1043 ChatTypeEnum.DebugChannel, 2147483647,
1043 part.AbsolutePosition, 1044 part.AbsolutePosition,
1044 part.Name, part.UUID, false); 1045 part.Name, part.UUID, false);
1045 } 1046 }
1046 catch (Exception e2) // LEGIT: User Scripting 1047 catch (Exception e2) // LEGIT: User Scripting
1047 { 1048 {
1048 m_Engine.Log.Error("[XEngine]: "+ 1049 m_Engine.Log.Error("[XEngine]: "+
1049 "Error displaying error in-world: " + 1050 "Error displaying error in-world: " +
1050 e2.ToString()); 1051 e2.ToString());
1051 m_Engine.Log.Error("[XEngine]: " + 1052 m_Engine.Log.Error("[XEngine]: " +
1052 "Errormessage: Error compiling script:\r\n" + 1053 "Errormessage: Error compiling script:\r\n" +
1053 e.ToString()); 1054 e.ToString());
1054 } 1055 }
1055 } 1056 }
1056 } 1057 }
1057 1058
1058 lock(m_EventQueue) 1059 lock (m_EventQueue)
1059 { 1060 {
1060 if((m_EventQueue.Count > 0) && m_RunEvents) 1061 if ((m_EventQueue.Count > 0) && m_RunEvents)
1061 { 1062 {
1062 m_CurrentResult=m_Engine.QueueEventHandler(this); 1063 m_CurrentResult = m_Engine.QueueEventHandler(this);
1063 } 1064 }
1064 else 1065 else
1065 { 1066 {
1066 m_CurrentResult=null; 1067 m_CurrentResult = null;
1067 } 1068 }
1068 } 1069 }
1069 1070
1070 m_DetectParams=null; 1071 m_DetectParams = null;
1071 1072
1072 return 0; 1073 return 0;
1073 } 1074 }
1074 1075
1075 public int EventTime() 1076 public int EventTime()
1076 { 1077 {
1077 if(!m_InEvent) 1078 if (!m_InEvent)
1078 return 0; 1079 return 0;
1079 1080
1080 return (DateTime.Now - m_EventStart).Seconds; 1081 return (DateTime.Now - m_EventStart).Seconds;
@@ -1082,14 +1083,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1082 1083
1083 public void ResetScript() 1084 public void ResetScript()
1084 { 1085 {
1085 bool running=Running; 1086 bool running = Running;
1086 1087
1087 Stop(0); 1088 Stop(0);
1088 m_Engine.m_ASYNCLSLCommandManager.RemoveScript(m_LocalID, m_ItemID); 1089 m_Engine.m_ASYNCLSLCommandManager.RemoveScript(m_LocalID, m_ItemID);
1089 m_EventQueue.Clear(); 1090 m_EventQueue.Clear();
1090 m_Script.ResetVars(); 1091 m_Script.ResetVars();
1091 m_State = "default"; 1092 m_State = "default";
1092 if(running) 1093 if (running)
1093 Start(); 1094 Start();
1094 PostEvent(new XEventParams("state_entry", 1095 PostEvent(new XEventParams("state_entry",
1095 new Object[0], new XDetectParams[0])); 1096 new Object[0], new XDetectParams[0]));
@@ -1107,7 +1108,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1107 1108
1108 public XDetectParams GetDetectParams(int idx) 1109 public XDetectParams GetDetectParams(int idx)
1109 { 1110 {
1110 if(idx < 0 || idx >= m_DetectParams.Length) 1111 if (idx < 0 || idx >= m_DetectParams.Length)
1111 return new XDetectParams(); 1112 return new XDetectParams();
1112 1113
1113 return m_DetectParams[idx]; 1114 return m_DetectParams[idx];
@@ -1115,7 +1116,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1115 1116
1116 public LLUUID GetDetectID(int idx) 1117 public LLUUID GetDetectID(int idx)
1117 { 1118 {
1118 if(idx < 0 || idx >= m_DetectParams.Length) 1119 if (idx < 0 || idx >= m_DetectParams.Length)
1119 return LLUUID.Zero; 1120 return LLUUID.Zero;
1120 1121
1121 return m_DetectParams[idx].Key; 1122 return m_DetectParams[idx].Key;
@@ -1124,22 +1125,21 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1124 public void SaveState(string assembly) 1125 public void SaveState(string assembly)
1125 { 1126 {
1126 PluginData = 1127 PluginData =
1127 m_Engine.m_ASYNCLSLCommandManager.GetSerializationData( 1128 m_Engine.m_ASYNCLSLCommandManager.GetSerializationData(
1128 m_ItemID); 1129 m_ItemID);
1129 1130
1130 string xml=ScriptSerializer.Serialize(this); 1131 string xml = ScriptSerializer.Serialize(this);
1131 1132
1132 try 1133 try
1133 { 1134 {
1134 FileStream fs = File.Create(assembly+".state"); 1135 FileStream fs = File.Create(assembly + ".state");
1135 System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); 1136 System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
1136 Byte[] buf=enc.GetBytes(xml); 1137 Byte[] buf = enc.GetBytes(xml);
1137 fs.Write(buf, 0, buf.Length); 1138 fs.Write(buf, 0, buf.Length);
1138 fs.Close(); 1139 fs.Close();
1139 } 1140 }
1140 catch(Exception) 1141 catch(Exception)
1141 { 1142 {
1142 return;
1143 } 1143 }
1144 } 1144 }
1145 } 1145 }
@@ -1153,11 +1153,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1153 XmlDocument xmldoc = new XmlDocument(); 1153 XmlDocument xmldoc = new XmlDocument();
1154 1154
1155 XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, 1155 XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration,
1156 "", ""); 1156 "", "");
1157 xmldoc.AppendChild(xmlnode); 1157 xmldoc.AppendChild(xmlnode);
1158 1158
1159 XmlElement rootElement = xmldoc.CreateElement("", "ScriptState", 1159 XmlElement rootElement = xmldoc.CreateElement("", "ScriptState",
1160 ""); 1160 "");
1161 xmldoc.AppendChild(rootElement); 1161 xmldoc.AppendChild(rootElement);
1162 1162
1163 XmlElement state = xmldoc.CreateElement("", "State", ""); 1163 XmlElement state = xmldoc.CreateElement("", "State", "");
@@ -1171,15 +1171,15 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1171 1171
1172 foreach (KeyValuePair<string, Object> var in vars) 1172 foreach (KeyValuePair<string, Object> var in vars)
1173 WriteTypedValue(xmldoc, variables, "Variable", var.Key, 1173 WriteTypedValue(xmldoc, variables, "Variable", var.Key,
1174 var.Value); 1174 var.Value);
1175 1175
1176 rootElement.AppendChild(variables); 1176 rootElement.AppendChild(variables);
1177 1177
1178 XmlElement queue = xmldoc.CreateElement("", "Queue", ""); 1178 XmlElement queue = xmldoc.CreateElement("", "Queue", "");
1179 1179
1180 int count = instance.EventQueue.Count; 1180 int count = instance.EventQueue.Count;
1181 1181
1182 while(count > 0) 1182 while (count > 0)
1183 { 1183 {
1184 XEventParams ep = (XEventParams)instance.EventQueue.Dequeue(); 1184 XEventParams ep = (XEventParams)instance.EventQueue.Dequeue();
1185 instance.EventQueue.Enqueue(ep); 1185 instance.EventQueue.Enqueue(ep);
@@ -1187,8 +1187,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1187 1187
1188 XmlElement item = xmldoc.CreateElement("", "Item", ""); 1188 XmlElement item = xmldoc.CreateElement("", "Item", "");
1189 XmlAttribute itemEvent = xmldoc.CreateAttribute("", "event", 1189 XmlAttribute itemEvent = xmldoc.CreateAttribute("", "event",
1190 ""); 1190 "");
1191 itemEvent.Value=ep.EventName; 1191 itemEvent.Value = ep.EventName;
1192 item.Attributes.Append(itemEvent); 1192 item.Attributes.Append(itemEvent);
1193 1193
1194 XmlElement parms = xmldoc.CreateElement("", "Params", ""); 1194 XmlElement parms = xmldoc.CreateElement("", "Params", "");
@@ -1203,12 +1203,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1203 foreach (XDetectParams det in ep.DetectParams) 1203 foreach (XDetectParams det in ep.DetectParams)
1204 { 1204 {
1205 XmlElement objectElem = xmldoc.CreateElement("", "Object", 1205 XmlElement objectElem = xmldoc.CreateElement("", "Object",
1206 ""); 1206 "");
1207 XmlAttribute pos = xmldoc.CreateAttribute("", "pos", ""); 1207 XmlAttribute pos = xmldoc.CreateAttribute("", "pos", "");
1208 pos.Value=det.OffsetPos.ToString(); 1208 pos.Value = det.OffsetPos.ToString();
1209 objectElem.Attributes.Append(pos); 1209 objectElem.Attributes.Append(pos);
1210 objectElem.AppendChild( 1210 objectElem.AppendChild(
1211 xmldoc.CreateTextNode(det.Key.ToString())); 1211 xmldoc.CreateTextNode(det.Key.ToString()));
1212 1212
1213 detect.AppendChild(objectElem); 1213 detect.AppendChild(objectElem);
1214 } 1214 }
@@ -1221,9 +1221,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1221 rootElement.AppendChild(queue); 1221 rootElement.AppendChild(queue);
1222 1222
1223 XmlNode plugins = xmldoc.CreateElement("", "Plugins", ""); 1223 XmlNode plugins = xmldoc.CreateElement("", "Plugins", "");
1224 if(instance.PluginData.Length > 0) 1224 if (instance.PluginData.Length > 0)
1225 DumpList(xmldoc, plugins, 1225 DumpList(xmldoc, plugins,
1226 new LSL_Types.list(instance.PluginData)); 1226 new LSL_Types.list(instance.PluginData));
1227 1227
1228 rootElement.AppendChild(plugins); 1228 rootElement.AppendChild(plugins);
1229 1229
@@ -1241,22 +1241,22 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1241 instance.PluginData = new Object[0]; 1241 instance.PluginData = new Object[0];
1242 1242
1243 doc.LoadXml(xml); 1243 doc.LoadXml(xml);
1244 1244
1245 XmlNodeList rootL = doc.GetElementsByTagName("ScriptState"); 1245 XmlNodeList rootL = doc.GetElementsByTagName("ScriptState");
1246 if(rootL.Count != 1) 1246 if (rootL.Count != 1)
1247 { 1247 {
1248 return; 1248 return;
1249 } 1249 }
1250 XmlNode rootNode = rootL[0]; 1250 XmlNode rootNode = rootL[0];
1251 1251
1252 if(rootNode != null) 1252 if (rootNode != null)
1253 { 1253 {
1254 object varValue; 1254 object varValue;
1255 XmlNodeList partL = rootNode.ChildNodes; 1255 XmlNodeList partL = rootNode.ChildNodes;
1256 1256
1257 foreach (XmlNode part in partL) 1257 foreach (XmlNode part in partL)
1258 { 1258 {
1259 switch(part.Name) 1259 switch (part.Name)
1260 { 1260 {
1261 case "State": 1261 case "State":
1262 instance.State=part.InnerText; 1262 instance.State=part.InnerText;
@@ -1268,7 +1268,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1268 string varName; 1268 string varName;
1269 varValue=ReadTypedValue(var, out varName); 1269 varValue=ReadTypedValue(var, out varName);
1270 1270
1271 if(vars.ContainsKey(varName)) 1271 if (vars.ContainsKey(varName))
1272 vars[varName] = varValue; 1272 vars[varName] = varValue;
1273 } 1273 }
1274 instance.SetVars(vars); 1274 instance.SetVars(vars);
@@ -1286,7 +1286,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1286 XmlNodeList eventL = item.ChildNodes; 1286 XmlNodeList eventL = item.ChildNodes;
1287 foreach (XmlNode evt in eventL) 1287 foreach (XmlNode evt in eventL)
1288 { 1288 {
1289 switch(evt.Name) 1289 switch (evt.Name)
1290 { 1290 {
1291 case "Params": 1291 case "Params":
1292 XmlNodeList prms = evt.ChildNodes; 1292 XmlNodeList prms = evt.ChildNodes;
@@ -1342,7 +1342,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1342 List<Object> olist = new List<Object>(); 1342 List<Object> olist = new List<Object>();
1343 1343
1344 XmlNodeList itemL = parent.ChildNodes; 1344 XmlNodeList itemL = parent.ChildNodes;
1345 foreach(XmlNode item in itemL) 1345 foreach (XmlNode item in itemL)
1346 olist.Add(ReadTypedValue(item)); 1346 olist.Add(ReadTypedValue(item));
1347 1347
1348 return new LSL_Types.list(olist.ToArray()); 1348 return new LSL_Types.list(olist.ToArray());
@@ -1355,14 +1355,14 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1355 XmlAttribute typ = doc.CreateAttribute("", "type", ""); 1355 XmlAttribute typ = doc.CreateAttribute("", "type", "");
1356 XmlNode n = doc.CreateElement("", tag, ""); 1356 XmlNode n = doc.CreateElement("", tag, "");
1357 1357
1358 if(value is LSL_Types.list) 1358 if (value is LSL_Types.list)
1359 { 1359 {
1360 typ.Value = "list"; 1360 typ.Value = "list";
1361 n.Attributes.Append(typ); 1361 n.Attributes.Append(typ);
1362 1362
1363 DumpList(doc, n, (LSL_Types.list) value); 1363 DumpList(doc, n, (LSL_Types.list) value);
1364 1364
1365 if(name != String.Empty) 1365 if (name != String.Empty)
1366 { 1366 {
1367 XmlAttribute nam = doc.CreateAttribute("", "name", ""); 1367 XmlAttribute nam = doc.CreateAttribute("", "name", "");
1368 nam.Value = name; 1368 nam.Value = name;
@@ -1377,7 +1377,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1377 1377
1378 typ.Value = t.ToString(); 1378 typ.Value = t.ToString();
1379 n.Attributes.Append(typ); 1379 n.Attributes.Append(typ);
1380 if(name != String.Empty) 1380 if (name != String.Empty)
1381 { 1381 {
1382 XmlAttribute nam = doc.CreateAttribute("", "name", ""); 1382 XmlAttribute nam = doc.CreateAttribute("", "name", "");
1383 nam.Value = name; 1383 nam.Value = name;
@@ -1401,31 +1401,31 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1401 1401
1402 string itemType = tag.Attributes.GetNamedItem("type").Value; 1402 string itemType = tag.Attributes.GetNamedItem("type").Value;
1403 1403
1404 if(itemType == "list") 1404 if (itemType == "list")
1405 return ReadList(tag); 1405 return ReadList(tag);
1406 1406
1407 if(itemType == "libsecondlife.LLUUID") 1407 if (itemType == "libsecondlife.LLUUID")
1408 { 1408 {
1409 LLUUID val = new LLUUID(); 1409 LLUUID val = new LLUUID();
1410 LLUUID.TryParse(tag.InnerText, out val); 1410 LLUUID.TryParse(tag.InnerText, out val);
1411 1411
1412 return val; 1412 return val;
1413 } 1413 }
1414 1414
1415 Type itemT = Type.GetType(itemType); 1415 Type itemT = Type.GetType(itemType);
1416 if(itemT == null) 1416 if (itemT == null)
1417 { 1417 {
1418 Object[] args = 1418 Object[] args =
1419 new Object[] { tag.InnerText }; 1419 new Object[] { tag.InnerText };
1420 1420
1421 assembly = itemType+", OpenSim.Region.ScriptEngine.XEngine.Script"; 1421 assembly = itemType+", OpenSim.Region.ScriptEngine.XEngine.Script";
1422 itemT = Type.GetType(assembly); 1422 itemT = Type.GetType(assembly);
1423 if(itemT == null) 1423 if (itemT == null)
1424 return null; 1424 return null;
1425 1425
1426 varValue = Activator.CreateInstance(itemT, args); 1426 varValue = Activator.CreateInstance(itemT, args);
1427 1427
1428 if(varValue == null) 1428 if (varValue == null)
1429 return null; 1429 return null;
1430 } 1430 }
1431 else 1431 else