aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Instance
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Instance')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs173
1 files changed, 97 insertions, 76 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index bf19a42..a2ac9c5 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
@@ -230,13 +231,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
230 ItemID = ScriptTask.ItemID; 231 ItemID = ScriptTask.ItemID;
231 AssetID = ScriptTask.AssetID; 232 AssetID = ScriptTask.AssetID;
232 } 233 }
234 LocalID = part.LocalId;
233 235
234 PrimName = part.ParentGroup.Name; 236 PrimName = part.ParentGroup.Name;
235 StartParam = startParam; 237 StartParam = startParam;
236 m_MaxScriptQueue = maxScriptQueue; 238 m_MaxScriptQueue = maxScriptQueue;
237 m_postOnRez = postOnRez; 239 m_postOnRez = postOnRez;
238 m_AttachedAvatar = Part.ParentGroup.AttachedAvatar; 240 m_AttachedAvatar = part.ParentGroup.AttachedAvatar;
239 m_RegionID = Part.ParentGroup.Scene.RegionInfo.RegionID; 241 m_RegionID = part.ParentGroup.Scene.RegionInfo.RegionID;
240 242
241 if (Engine.Config.GetString("ScriptStopStrategy", "abort") == "co-op") 243 if (Engine.Config.GetString("ScriptStopStrategy", "abort") == "co-op")
242 { 244 {
@@ -481,27 +483,34 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
481 PostEvent(new EventParams("attach", 483 PostEvent(new EventParams("attach",
482 new object[] { new LSL_Types.LSLString(m_AttachedAvatar.ToString()) }, new DetectParams[0])); 484 new object[] { new LSL_Types.LSLString(m_AttachedAvatar.ToString()) }, new DetectParams[0]));
483 } 485 }
486
484 } 487 }
485 } 488 }
486 489
487 private void ReleaseControls() 490 private void ReleaseControls()
488 { 491 {
489 int permsMask; 492 SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
490 UUID permsGranter; 493
491 lock (Part.TaskInventory) 494 if (part != null)
492 { 495 {
493 if (!Part.TaskInventory.ContainsKey(ItemID)) 496 int permsMask;
497 UUID permsGranter;
498 part.TaskInventory.LockItemsForRead(true);
499 if (!part.TaskInventory.ContainsKey(ItemID))
500 {
501 part.TaskInventory.LockItemsForRead(false);
494 return; 502 return;
503 }
504 permsGranter = part.TaskInventory[ItemID].PermsGranter;
505 permsMask = part.TaskInventory[ItemID].PermsMask;
506 part.TaskInventory.LockItemsForRead(false);
495 507
496 permsGranter = Part.TaskInventory[ItemID].PermsGranter; 508 if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0)
497 permsMask = Part.TaskInventory[ItemID].PermsMask; 509 {
498 } 510 ScenePresence presence = Engine.World.GetScenePresence(permsGranter);
499 511 if (presence != null)
500 if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) 512 presence.UnRegisterControlEventsToScript(LocalID, ItemID);
501 { 513 }
502 ScenePresence presence = Engine.World.GetScenePresence(permsGranter);
503 if (presence != null)
504 presence.UnRegisterControlEventsToScript(LocalID, ItemID);
505 } 514 }
506 } 515 }
507 516
@@ -650,6 +659,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
650 return true; 659 return true;
651 } 660 }
652 661
662 [DebuggerNonUserCode] //Prevents the debugger from farting in this function
653 public void SetState(string state) 663 public void SetState(string state)
654 { 664 {
655 if (state == State) 665 if (state == State)
@@ -661,7 +671,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
661 new DetectParams[0])); 671 new DetectParams[0]));
662 PostEvent(new EventParams("state_entry", new Object[0], 672 PostEvent(new EventParams("state_entry", new Object[0],
663 new DetectParams[0])); 673 new DetectParams[0]));
664 674
665 throw new EventAbortException(); 675 throw new EventAbortException();
666 } 676 }
667 677
@@ -751,57 +761,60 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
751 /// <returns></returns> 761 /// <returns></returns>
752 public object EventProcessor() 762 public object EventProcessor()
753 { 763 {
764 EventParams data = null;
754 // We check here as the thread stopping this instance from running may itself hold the m_Script lock. 765 // We check here as the thread stopping this instance from running may itself hold the m_Script lock.
755 if (!Running) 766 if (!Running)
756 return 0; 767 return 0;
757 768
758 lock (m_Script)
759 {
760// m_log.DebugFormat("[XEngine]: EventProcessor() invoked for {0}.{1}", PrimName, ScriptName); 769// m_log.DebugFormat("[XEngine]: EventProcessor() invoked for {0}.{1}", PrimName, ScriptName);
761 770
762 if (Suspended) 771 if (Suspended)
763 return 0; 772 return 0;
764
765 EventParams data = null;
766 773
767 lock (EventQueue) 774 lock (EventQueue)
775 {
776 data = (EventParams) EventQueue.Dequeue();
777 if (data == null) // Shouldn't happen
768 { 778 {
769 data = (EventParams)EventQueue.Dequeue(); 779 if (EventQueue.Count > 0 && Running && !ShuttingDown)
770 if (data == null) // Shouldn't happen
771 { 780 {
772 if (EventQueue.Count > 0 && Running && !ShuttingDown) 781 m_CurrentWorkItem = Engine.QueueEventHandler(this);
773 {
774 m_CurrentWorkItem = Engine.QueueEventHandler(this);
775 }
776 else
777 {
778 m_CurrentWorkItem = null;
779 }
780 return 0;
781 } 782 }
782 783 else
783 if (data.EventName == "timer")
784 m_TimerQueued = false;
785 if (data.EventName == "control")
786 { 784 {
787 if (m_ControlEventsInQueue > 0) 785 m_CurrentWorkItem = null;
788 m_ControlEventsInQueue--;
789 } 786 }
790 if (data.EventName == "collision") 787 return 0;
791 m_CollisionInQueue = false;
792 } 788 }
793 789
790 if (data.EventName == "timer")
791 m_TimerQueued = false;
792 if (data.EventName == "control")
793 {
794 if (m_ControlEventsInQueue > 0)
795 m_ControlEventsInQueue--;
796 }
797 if (data.EventName == "collision")
798 m_CollisionInQueue = false;
799 }
800
801 lock(m_Script)
802 {
803
804// m_log.DebugFormat("[XEngine]: Processing event {0} for {1}", data.EventName, this);
805 SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
806
794 if (DebugLevel >= 2) 807 if (DebugLevel >= 2)
795 m_log.DebugFormat( 808 m_log.DebugFormat(
796 "[SCRIPT INSTANCE]: Processing event {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}", 809 "[SCRIPT INSTANCE]: Processing event {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}",
797 data.EventName, 810 data.EventName,
798 ScriptName, 811 ScriptName,
799 Part.Name, 812 part.Name,
800 Part.LocalId, 813 part.LocalId,
801 Part.ParentGroup.Name, 814 part.ParentGroup.Name,
802 Part.ParentGroup.UUID, 815 part.ParentGroup.UUID,
803 Part.AbsolutePosition, 816 part.AbsolutePosition,
804 Part.ParentGroup.Scene.Name); 817 part.ParentGroup.Scene.Name);
805 818
806 m_DetectParams = data.DetectParams; 819 m_DetectParams = data.DetectParams;
807 820
@@ -814,17 +827,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
814 "[SCRIPT INSTANCE]: Changing state to {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}", 827 "[SCRIPT INSTANCE]: Changing state to {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}",
815 State, 828 State,
816 ScriptName, 829 ScriptName,
817 Part.Name, 830 part.Name,
818 Part.LocalId, 831 part.LocalId,
819 Part.ParentGroup.Name, 832 part.ParentGroup.Name,
820 Part.ParentGroup.UUID, 833 part.ParentGroup.UUID,
821 Part.AbsolutePosition, 834 part.AbsolutePosition,
822 Part.ParentGroup.Scene.Name); 835 part.ParentGroup.Scene.Name);
823 836
824 AsyncCommandManager.RemoveScript(Engine, 837 AsyncCommandManager.RemoveScript(Engine,
825 LocalID, ItemID); 838 LocalID, ItemID);
826 839
827 Part.SetScriptEvents(ItemID, (int)m_Script.GetStateEventFlags(State)); 840 if (part != null)
841 {
842 part.SetScriptEvents(ItemID,
843 (int)m_Script.GetStateEventFlags(State));
844 }
828 } 845 }
829 else 846 else
830 { 847 {
@@ -887,17 +904,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
887 text = text.Substring(0, 1000); 904 text = text.Substring(0, 1000);
888 Engine.World.SimChat(Utils.StringToBytes(text), 905 Engine.World.SimChat(Utils.StringToBytes(text),
889 ChatTypeEnum.DebugChannel, 2147483647, 906 ChatTypeEnum.DebugChannel, 2147483647,
890 Part.AbsolutePosition, 907 part.AbsolutePosition,
891 Part.Name, Part.UUID, false); 908 part.Name, part.UUID, false);
892 909
893 910
894 m_log.DebugFormat( 911 m_log.DebugFormat(
895 "[SCRIPT INSTANCE]: Runtime error in script {0}, part {1} {2} at {3} in {4}, displayed error {5}, actual exception {6}", 912 "[SCRIPT INSTANCE]: Runtime error in script {0}, part {1} {2} at {3} in {4}, displayed error {5}, actual exception {6}",
896 ScriptName, 913 ScriptName,
897 PrimName, 914 PrimName,
898 Part.UUID, 915 part.UUID,
899 Part.AbsolutePosition, 916 part.AbsolutePosition,
900 Part.ParentGroup.Scene.Name, 917 part.ParentGroup.Scene.Name,
901 text.Replace("\n", "\\n"), 918 text.Replace("\n", "\\n"),
902 e.InnerException); 919 e.InnerException);
903 } 920 }
@@ -917,12 +934,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
917 else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException)) 934 else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException))
918 { 935 {
919 m_InSelfDelete = true; 936 m_InSelfDelete = true;
920 Engine.World.DeleteSceneObject(Part.ParentGroup, false); 937 if (part != null)
938 Engine.World.DeleteSceneObject(part.ParentGroup, false);
921 } 939 }
922 else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException)) 940 else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException))
923 { 941 {
924 m_InSelfDelete = true; 942 m_InSelfDelete = true;
925 Part.Inventory.RemoveInventoryItem(ItemID); 943 if (part != null)
944 part.Inventory.RemoveInventoryItem(ItemID);
926 } 945 }
927 else if ((e is TargetInvocationException) && (e.InnerException is ScriptCoopStopException)) 946 else if ((e is TargetInvocationException) && (e.InnerException is ScriptCoopStopException))
928 { 947 {
@@ -976,14 +995,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
976 ReleaseControls(); 995 ReleaseControls();
977 996
978 Stop(timeout); 997 Stop(timeout);
979 Part.Inventory.GetInventoryItem(ItemID).PermsMask = 0; 998 SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
980 Part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero; 999 part.Inventory.GetInventoryItem(ItemID).PermsMask = 0;
1000 part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero;
1001 part.CollisionSound = UUID.Zero;
981 AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID); 1002 AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID);
982 EventQueue.Clear(); 1003 EventQueue.Clear();
983 m_Script.ResetVars(); 1004 m_Script.ResetVars();
984 State = "default"; 1005 State = "default";
985 1006
986 Part.SetScriptEvents(ItemID, 1007 part.SetScriptEvents(ItemID,
987 (int)m_Script.GetStateEventFlags(State)); 1008 (int)m_Script.GetStateEventFlags(State));
988 if (running) 1009 if (running)
989 Start(); 1010 Start();
@@ -992,6 +1013,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
992 new Object[0], new DetectParams[0])); 1013 new Object[0], new DetectParams[0]));
993 } 1014 }
994 1015
1016 [DebuggerNonUserCode] //Stops the VS debugger from farting in this function
995 public void ApiResetScript() 1017 public void ApiResetScript()
996 { 1018 {
997 // bool running = Running; 1019 // bool running = Running;
@@ -1000,15 +1022,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
1000 ReleaseControls(); 1022 ReleaseControls();
1001 1023
1002 m_Script.ResetVars(); 1024 m_Script.ResetVars();
1003 Part.Inventory.GetInventoryItem(ItemID).PermsMask = 0; 1025 SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID);
1004 Part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero; 1026 part.Inventory.GetInventoryItem(ItemID).PermsMask = 0;
1027 part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero;
1028 part.CollisionSound = UUID.Zero;
1005 AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID); 1029 AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID);
1006 1030
1007 EventQueue.Clear(); 1031 EventQueue.Clear();
1008 m_Script.ResetVars(); 1032 m_Script.ResetVars();
1009 State = "default"; 1033 State = "default";
1010 1034
1011 Part.SetScriptEvents(ItemID, 1035 part.SetScriptEvents(ItemID,
1012 (int)m_Script.GetStateEventFlags(State)); 1036 (int)m_Script.GetStateEventFlags(State));
1013 1037
1014 if (m_CurrentEvent != "state_entry") 1038 if (m_CurrentEvent != "state_entry")
@@ -1022,10 +1046,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
1022 1046
1023 public Dictionary<string, object> GetVars() 1047 public Dictionary<string, object> GetVars()
1024 { 1048 {
1025 if (m_Script != null) 1049 return m_Script.GetVars();
1026 return m_Script.GetVars();
1027 else
1028 return new Dictionary<string, object>();
1029 } 1050 }
1030 1051
1031 public void SetVars(Dictionary<string, object> vars) 1052 public void SetVars(Dictionary<string, object> vars)