aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs172
1 files changed, 96 insertions, 76 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index 75aea2b..a869a6a 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
@@ -30,6 +30,7 @@ using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Globalization; 31using System.Globalization;
32using System.IO; 32using System.IO;
33using System.Diagnostics; //for [DebuggerNonUserCode]
33using System.Reflection; 34using System.Reflection;
34using System.Runtime.Remoting; 35using System.Runtime.Remoting;
35using System.Runtime.Remoting.Lifetime; 36using System.Runtime.Remoting.Lifetime;
@@ -165,13 +166,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
165 166
166 public UUID ItemID { get; private set; } 167 public UUID ItemID { get; private set; }
167 168
168 public UUID ObjectID { get { return Part.UUID; } } 169 public UUID ObjectID { get; private set; }
169 170
170 public uint LocalID { get { return Part.LocalId; } } 171 public uint LocalID { get; private set; }
171 172
172 public UUID RootObjectID { get { return Part.ParentGroup.UUID; } } 173 public UUID RootObjectID { get; private set; }
173 174
174 public uint RootLocalID { get { return Part.ParentGroup.LocalId; } } 175 public uint RootLocalID { get; private set; }
175 176
176 public UUID AssetID { get; private set; } 177 public UUID AssetID { get; private set; }
177 178
@@ -235,8 +236,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
235 StartParam = startParam; 236 StartParam = startParam;
236 m_MaxScriptQueue = maxScriptQueue; 237 m_MaxScriptQueue = maxScriptQueue;
237 m_postOnRez = postOnRez; 238 m_postOnRez = postOnRez;
238 m_AttachedAvatar = Part.ParentGroup.AttachedAvatar; 239 m_AttachedAvatar = part.ParentGroup.AttachedAvatar;
239 m_RegionID = Part.ParentGroup.Scene.RegionInfo.RegionID; 240 m_RegionID = part.ParentGroup.Scene.RegionInfo.RegionID;
240 241
241 if (Engine.Config.GetString("ScriptStopStrategy", "abort") == "co-op") 242 if (Engine.Config.GetString("ScriptStopStrategy", "abort") == "co-op")
242 { 243 {
@@ -433,27 +434,34 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
433 PostEvent(new EventParams("attach", 434 PostEvent(new EventParams("attach",
434 new object[] { new LSL_Types.LSLString(m_AttachedAvatar.ToString()) }, new DetectParams[0])); 435 new object[] { new LSL_Types.LSLString(m_AttachedAvatar.ToString()) }, new DetectParams[0]));
435 } 436 }
437
436 } 438 }
437 } 439 }
438 440
439 private void ReleaseControls() 441 private void ReleaseControls()
440 { 442 {
441 int permsMask; 443 SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
442 UUID permsGranter; 444
443 lock (Part.TaskInventory) 445 if (part != null)
444 { 446 {
445 if (!Part.TaskInventory.ContainsKey(ItemID)) 447 int permsMask;
448 UUID permsGranter;
449 part.TaskInventory.LockItemsForRead(true);
450 if (!part.TaskInventory.ContainsKey(ItemID))
451 {
452 part.TaskInventory.LockItemsForRead(false);
446 return; 453 return;
454 }
455 permsGranter = part.TaskInventory[ItemID].PermsGranter;
456 permsMask = part.TaskInventory[ItemID].PermsMask;
457 part.TaskInventory.LockItemsForRead(false);
447 458
448 permsGranter = Part.TaskInventory[ItemID].PermsGranter; 459 if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
449 permsMask = Part.TaskInventory[ItemID].PermsMask; 460 {
450 } 461 ScenePresence presence = Engine.World.GetScenePresence(permsGranter);
451 462 if (presence != null)
452 if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 463 presence.UnRegisterControlEventsToScript(LocalID, ItemID);
453 { 464 }
454 ScenePresence presence = Engine.World.GetScenePresence(permsGranter);
455 if (presence != null)
456 presence.UnRegisterControlEventsToScript(LocalID, ItemID);
457 } 465 }
458 } 466 }
459 467
@@ -600,6 +608,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
600 return true; 608 return true;
601 } 609 }
602 610
611 [DebuggerNonUserCode] //Prevents the debugger from farting in this function
603 public void SetState(string state) 612 public void SetState(string state)
604 { 613 {
605 if (state == State) 614 if (state == State)
@@ -611,7 +620,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
611 new DetectParams[0])); 620 new DetectParams[0]));
612 PostEvent(new EventParams("state_entry", new Object[0], 621 PostEvent(new EventParams("state_entry", new Object[0],
613 new DetectParams[0])); 622 new DetectParams[0]));
614 623
615 throw new EventAbortException(); 624 throw new EventAbortException();
616 } 625 }
617 626
@@ -701,57 +710,60 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
701 /// <returns></returns> 710 /// <returns></returns>
702 public object EventProcessor() 711 public object EventProcessor()
703 { 712 {
713 EventParams data = null;
704 // We check here as the thread stopping this instance from running may itself hold the m_Script lock. 714 // We check here as the thread stopping this instance from running may itself hold the m_Script lock.
705 if (!Running) 715 if (!Running)
706 return 0; 716 return 0;
707 717
708 lock (m_Script)
709 {
710// m_log.DebugFormat("[XEngine]: EventProcessor() invoked for {0}.{1}", PrimName, ScriptName); 718// m_log.DebugFormat("[XEngine]: EventProcessor() invoked for {0}.{1}", PrimName, ScriptName);
711 719
712 if (Suspended) 720 if (Suspended)
713 return 0; 721 return 0;
714
715 EventParams data = null;
716 722
717 lock (EventQueue) 723 lock (EventQueue)
724 {
725 data = (EventParams) EventQueue.Dequeue();
726 if (data == null) // Shouldn't happen
718 { 727 {
719 data = (EventParams)EventQueue.Dequeue(); 728 if (EventQueue.Count > 0 && Running && !ShuttingDown)
720 if (data == null) // Shouldn't happen
721 { 729 {
722 if (EventQueue.Count > 0 && Running && !ShuttingDown) 730 m_CurrentWorkItem = Engine.QueueEventHandler(this);
723 {
724 m_CurrentWorkItem = Engine.QueueEventHandler(this);
725 }
726 else
727 {
728 m_CurrentWorkItem = null;
729 }
730 return 0;
731 } 731 }
732 732 else
733 if (data.EventName == "timer")
734 m_TimerQueued = false;
735 if (data.EventName == "control")
736 { 733 {
737 if (m_ControlEventsInQueue > 0) 734 m_CurrentWorkItem = null;
738 m_ControlEventsInQueue--;
739 } 735 }
740 if (data.EventName == "collision") 736 return 0;
741 m_CollisionInQueue = false;
742 } 737 }
743 738
739 if (data.EventName == "timer")
740 m_TimerQueued = false;
741 if (data.EventName == "control")
742 {
743 if (m_ControlEventsInQueue > 0)
744 m_ControlEventsInQueue--;
745 }
746 if (data.EventName == "collision")
747 m_CollisionInQueue = false;
748 }
749
750 lock(m_Script)
751 {
752
753// m_log.DebugFormat("[XEngine]: Processing event {0} for {1}", data.EventName, this);
754 SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
755
744 if (DebugLevel >= 2) 756 if (DebugLevel >= 2)
745 m_log.DebugFormat( 757 m_log.DebugFormat(
746 "[SCRIPT INSTANCE]: Processing event {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}", 758 "[SCRIPT INSTANCE]: Processing event {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}",
747 data.EventName, 759 data.EventName,
748 ScriptName, 760 ScriptName,
749 Part.Name, 761 part.Name,
750 Part.LocalId, 762 part.LocalId,
751 Part.ParentGroup.Name, 763 part.ParentGroup.Name,
752 Part.ParentGroup.UUID, 764 part.ParentGroup.UUID,
753 Part.AbsolutePosition, 765 part.AbsolutePosition,
754 Part.ParentGroup.Scene.Name); 766 part.ParentGroup.Scene.Name);
755 767
756 m_DetectParams = data.DetectParams; 768 m_DetectParams = data.DetectParams;
757 769
@@ -764,17 +776,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
764 "[SCRIPT INSTANCE]: Changing state to {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}", 776 "[SCRIPT INSTANCE]: Changing state to {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}",
765 State, 777 State,
766 ScriptName, 778 ScriptName,
767 Part.Name, 779 part.Name,
768 Part.LocalId, 780 part.LocalId,
769 Part.ParentGroup.Name, 781 part.ParentGroup.Name,
770 Part.ParentGroup.UUID, 782 part.ParentGroup.UUID,
771 Part.AbsolutePosition, 783 part.AbsolutePosition,
772 Part.ParentGroup.Scene.Name); 784 part.ParentGroup.Scene.Name);
773 785
774 AsyncCommandManager.RemoveScript(Engine, 786 AsyncCommandManager.RemoveScript(Engine,
775 LocalID, ItemID); 787 LocalID, ItemID);
776 788
777 Part.SetScriptEvents(ItemID, (int)m_Script.GetStateEventFlags(State)); 789 if (part != null)
790 {
791 part.SetScriptEvents(ItemID,
792 (int)m_Script.GetStateEventFlags(State));
793 }
778 } 794 }
779 else 795 else
780 { 796 {
@@ -837,17 +853,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
837 text = text.Substring(0, 1000); 853 text = text.Substring(0, 1000);
838 Engine.World.SimChat(Utils.StringToBytes(text), 854 Engine.World.SimChat(Utils.StringToBytes(text),
839 ChatTypeEnum.DebugChannel, 2147483647, 855 ChatTypeEnum.DebugChannel, 2147483647,
840 Part.AbsolutePosition, 856 part.AbsolutePosition,
841 Part.Name, Part.UUID, false); 857 part.Name, part.UUID, false);
842 858
843 859
844 m_log.DebugFormat( 860 m_log.DebugFormat(
845 "[SCRIPT INSTANCE]: Runtime error in script {0}, part {1} {2} at {3} in {4}, displayed error {5}, actual exception {6}", 861 "[SCRIPT INSTANCE]: Runtime error in script {0}, part {1} {2} at {3} in {4}, displayed error {5}, actual exception {6}",
846 ScriptName, 862 ScriptName,
847 PrimName, 863 PrimName,
848 Part.UUID, 864 part.UUID,
849 Part.AbsolutePosition, 865 part.AbsolutePosition,
850 Part.ParentGroup.Scene.Name, 866 part.ParentGroup.Scene.Name,
851 text.Replace("\n", "\\n"), 867 text.Replace("\n", "\\n"),
852 e.InnerException); 868 e.InnerException);
853 } 869 }
@@ -867,12 +883,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
867 else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException)) 883 else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException))
868 { 884 {
869 m_InSelfDelete = true; 885 m_InSelfDelete = true;
870 Engine.World.DeleteSceneObject(Part.ParentGroup, false); 886 if (part != null)
887 Engine.World.DeleteSceneObject(part.ParentGroup, false);
871 } 888 }
872 else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException)) 889 else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException))
873 { 890 {
874 m_InSelfDelete = true; 891 m_InSelfDelete = true;
875 Part.Inventory.RemoveInventoryItem(ItemID); 892 if (part != null)
893 part.Inventory.RemoveInventoryItem(ItemID);
876 } 894 }
877 else if ((e is TargetInvocationException) && (e.InnerException is ScriptCoopStopException)) 895 else if ((e is TargetInvocationException) && (e.InnerException is ScriptCoopStopException))
878 { 896 {
@@ -925,14 +943,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
925 ReleaseControls(); 943 ReleaseControls();
926 944
927 Stop(timeout); 945 Stop(timeout);
928 Part.Inventory.GetInventoryItem(ItemID).PermsMask = 0; 946 SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
929 Part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero; 947 part.Inventory.GetInventoryItem(ItemID).PermsMask = 0;
948 part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero;
949 part.CollisionSound = UUID.Zero;
930 AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID); 950 AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID);
931 EventQueue.Clear(); 951 EventQueue.Clear();
932 m_Script.ResetVars(); 952 m_Script.ResetVars();
933 State = "default"; 953 State = "default";
934 954
935 Part.SetScriptEvents(ItemID, 955 part.SetScriptEvents(ItemID,
936 (int)m_Script.GetStateEventFlags(State)); 956 (int)m_Script.GetStateEventFlags(State));
937 if (running) 957 if (running)
938 Start(); 958 Start();
@@ -941,6 +961,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
941 new Object[0], new DetectParams[0])); 961 new Object[0], new DetectParams[0]));
942 } 962 }
943 963
964 [DebuggerNonUserCode] //Stops the VS debugger from farting in this function
944 public void ApiResetScript() 965 public void ApiResetScript()
945 { 966 {
946 // bool running = Running; 967 // bool running = Running;
@@ -949,15 +970,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
949 ReleaseControls(); 970 ReleaseControls();
950 971
951 m_Script.ResetVars(); 972 m_Script.ResetVars();
952 Part.Inventory.GetInventoryItem(ItemID).PermsMask = 0; 973 SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
953 Part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero; 974 part.Inventory.GetInventoryItem(ItemID).PermsMask = 0;
975 part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero;
976 part.CollisionSound = UUID.Zero;
954 AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID); 977 AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID);
955 978
956 EventQueue.Clear(); 979 EventQueue.Clear();
957 m_Script.ResetVars(); 980 m_Script.ResetVars();
958 State = "default"; 981 State = "default";
959 982
960 Part.SetScriptEvents(ItemID, 983 part.SetScriptEvents(ItemID,
961 (int)m_Script.GetStateEventFlags(State)); 984 (int)m_Script.GetStateEventFlags(State));
962 985
963 if (m_CurrentEvent != "state_entry") 986 if (m_CurrentEvent != "state_entry")
@@ -971,10 +994,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
971 994
972 public Dictionary<string, object> GetVars() 995 public Dictionary<string, object> GetVars()
973 { 996 {
974 if (m_Script != null) 997 return m_Script.GetVars();
975 return m_Script.GetVars();
976 else
977 return new Dictionary<string, object>();
978 } 998 }
979 999
980 public void SetVars(Dictionary<string, object> vars) 1000 public void SetVars(Dictionary<string, object> vars)