diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs | 175 |
1 files changed, 98 insertions, 77 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index 6264f5d..275b608 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs | |||
@@ -30,6 +30,7 @@ using System.Collections; | |||
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Globalization; | 31 | using System.Globalization; |
32 | using System.IO; | 32 | using System.IO; |
33 | using System.Diagnostics; //for [DebuggerNonUserCode] | ||
33 | using System.Reflection; | 34 | using System.Reflection; |
34 | using System.Runtime.Remoting; | 35 | using System.Runtime.Remoting; |
35 | using System.Runtime.Remoting.Lifetime; | 36 | using 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 | ||
@@ -656,6 +665,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
656 | return true; | 665 | return true; |
657 | } | 666 | } |
658 | 667 | ||
668 | [DebuggerNonUserCode] //Prevents the debugger from farting in this function | ||
659 | public void SetState(string state) | 669 | public void SetState(string state) |
660 | { | 670 | { |
661 | if (state == State) | 671 | if (state == State) |
@@ -667,7 +677,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
667 | new DetectParams[0])); | 677 | new DetectParams[0])); |
668 | PostEvent(new EventParams("state_entry", new Object[0], | 678 | PostEvent(new EventParams("state_entry", new Object[0], |
669 | new DetectParams[0])); | 679 | new DetectParams[0])); |
670 | 680 | ||
671 | throw new EventAbortException(); | 681 | throw new EventAbortException(); |
672 | } | 682 | } |
673 | 683 | ||
@@ -757,57 +767,60 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
757 | /// <returns></returns> | 767 | /// <returns></returns> |
758 | public object EventProcessor() | 768 | public object EventProcessor() |
759 | { | 769 | { |
770 | EventParams data = null; | ||
760 | // We check here as the thread stopping this instance from running may itself hold the m_Script lock. | 771 | // We check here as the thread stopping this instance from running may itself hold the m_Script lock. |
761 | if (!Running) | 772 | if (!Running) |
762 | return 0; | 773 | return 0; |
763 | 774 | ||
764 | lock (m_Script) | ||
765 | { | ||
766 | // m_log.DebugFormat("[XEngine]: EventProcessor() invoked for {0}.{1}", PrimName, ScriptName); | 775 | // m_log.DebugFormat("[XEngine]: EventProcessor() invoked for {0}.{1}", PrimName, ScriptName); |
767 | 776 | ||
768 | if (Suspended) | 777 | if (Suspended) |
769 | return 0; | 778 | return 0; |
770 | |||
771 | EventParams data = null; | ||
772 | 779 | ||
773 | lock (EventQueue) | 780 | lock (EventQueue) |
781 | { | ||
782 | data = (EventParams) EventQueue.Dequeue(); | ||
783 | if (data == null) // Shouldn't happen | ||
774 | { | 784 | { |
775 | data = (EventParams)EventQueue.Dequeue(); | 785 | if (EventQueue.Count > 0 && Running && !ShuttingDown) |
776 | if (data == null) // Shouldn't happen | ||
777 | { | 786 | { |
778 | if (EventQueue.Count > 0 && Running && !ShuttingDown) | 787 | m_CurrentWorkItem = Engine.QueueEventHandler(this); |
779 | { | ||
780 | m_CurrentWorkItem = Engine.QueueEventHandler(this); | ||
781 | } | ||
782 | else | ||
783 | { | ||
784 | m_CurrentWorkItem = null; | ||
785 | } | ||
786 | return 0; | ||
787 | } | 788 | } |
788 | 789 | else | |
789 | if (data.EventName == "timer") | ||
790 | m_TimerQueued = false; | ||
791 | if (data.EventName == "control") | ||
792 | { | 790 | { |
793 | if (m_ControlEventsInQueue > 0) | 791 | m_CurrentWorkItem = null; |
794 | m_ControlEventsInQueue--; | ||
795 | } | 792 | } |
796 | if (data.EventName == "collision") | 793 | return 0; |
797 | m_CollisionInQueue = false; | ||
798 | } | 794 | } |
799 | 795 | ||
796 | if (data.EventName == "timer") | ||
797 | m_TimerQueued = false; | ||
798 | if (data.EventName == "control") | ||
799 | { | ||
800 | if (m_ControlEventsInQueue > 0) | ||
801 | m_ControlEventsInQueue--; | ||
802 | } | ||
803 | if (data.EventName == "collision") | ||
804 | m_CollisionInQueue = false; | ||
805 | } | ||
806 | |||
807 | lock(m_Script) | ||
808 | { | ||
809 | |||
810 | // m_log.DebugFormat("[XEngine]: Processing event {0} for {1}", data.EventName, this); | ||
811 | SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID); | ||
812 | |||
800 | if (DebugLevel >= 2) | 813 | if (DebugLevel >= 2) |
801 | m_log.DebugFormat( | 814 | m_log.DebugFormat( |
802 | "[SCRIPT INSTANCE]: Processing event {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}", | 815 | "[SCRIPT INSTANCE]: Processing event {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}", |
803 | data.EventName, | 816 | data.EventName, |
804 | ScriptName, | 817 | ScriptName, |
805 | Part.Name, | 818 | part.Name, |
806 | Part.LocalId, | 819 | part.LocalId, |
807 | Part.ParentGroup.Name, | 820 | part.ParentGroup.Name, |
808 | Part.ParentGroup.UUID, | 821 | part.ParentGroup.UUID, |
809 | Part.AbsolutePosition, | 822 | part.AbsolutePosition, |
810 | Part.ParentGroup.Scene.Name); | 823 | part.ParentGroup.Scene.Name); |
811 | 824 | ||
812 | m_DetectParams = data.DetectParams; | 825 | m_DetectParams = data.DetectParams; |
813 | 826 | ||
@@ -820,17 +833,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
820 | "[SCRIPT INSTANCE]: Changing state to {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}", | 833 | "[SCRIPT INSTANCE]: Changing state to {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}", |
821 | State, | 834 | State, |
822 | ScriptName, | 835 | ScriptName, |
823 | Part.Name, | 836 | part.Name, |
824 | Part.LocalId, | 837 | part.LocalId, |
825 | Part.ParentGroup.Name, | 838 | part.ParentGroup.Name, |
826 | Part.ParentGroup.UUID, | 839 | part.ParentGroup.UUID, |
827 | Part.AbsolutePosition, | 840 | part.AbsolutePosition, |
828 | Part.ParentGroup.Scene.Name); | 841 | part.ParentGroup.Scene.Name); |
829 | 842 | ||
830 | AsyncCommandManager.RemoveScript(Engine, | 843 | AsyncCommandManager.RemoveScript(Engine, |
831 | LocalID, ItemID); | 844 | LocalID, ItemID); |
832 | 845 | ||
833 | Part.SetScriptEvents(ItemID, (int)m_Script.GetStateEventFlags(State)); | 846 | if (part != null) |
847 | { | ||
848 | part.SetScriptEvents(ItemID, | ||
849 | (int)m_Script.GetStateEventFlags(State)); | ||
850 | } | ||
834 | } | 851 | } |
835 | else | 852 | else |
836 | { | 853 | { |
@@ -893,17 +910,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
893 | text = text.Substring(0, 1000); | 910 | text = text.Substring(0, 1000); |
894 | Engine.World.SimChat(Utils.StringToBytes(text), | 911 | Engine.World.SimChat(Utils.StringToBytes(text), |
895 | ChatTypeEnum.DebugChannel, 2147483647, | 912 | ChatTypeEnum.DebugChannel, 2147483647, |
896 | Part.AbsolutePosition, | 913 | part.AbsolutePosition, |
897 | Part.Name, Part.UUID, false); | 914 | part.Name, part.UUID, false); |
898 | 915 | ||
899 | 916 | ||
900 | m_log.DebugFormat( | 917 | m_log.DebugFormat( |
901 | "[SCRIPT INSTANCE]: Runtime error in script {0}, part {1} {2} at {3} in {4}, displayed error {5}, actual exception {6}", | 918 | "[SCRIPT INSTANCE]: Runtime error in script {0}, part {1} {2} at {3} in {4}, displayed error {5}, actual exception {6}", |
902 | ScriptName, | 919 | ScriptName, |
903 | PrimName, | 920 | PrimName, |
904 | Part.UUID, | 921 | part.UUID, |
905 | Part.AbsolutePosition, | 922 | part.AbsolutePosition, |
906 | Part.ParentGroup.Scene.Name, | 923 | part.ParentGroup.Scene.Name, |
907 | text.Replace("\n", "\\n"), | 924 | text.Replace("\n", "\\n"), |
908 | e.InnerException); | 925 | e.InnerException); |
909 | } | 926 | } |
@@ -923,12 +940,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
923 | else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException)) | 940 | else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException)) |
924 | { | 941 | { |
925 | m_InSelfDelete = true; | 942 | m_InSelfDelete = true; |
926 | Engine.World.DeleteSceneObject(Part.ParentGroup, false); | 943 | if (part != null) |
944 | Engine.World.DeleteSceneObject(part.ParentGroup, false); | ||
927 | } | 945 | } |
928 | else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException)) | 946 | else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException)) |
929 | { | 947 | { |
930 | m_InSelfDelete = true; | 948 | m_InSelfDelete = true; |
931 | Part.Inventory.RemoveInventoryItem(ItemID); | 949 | if (part != null) |
950 | part.Inventory.RemoveInventoryItem(ItemID); | ||
932 | } | 951 | } |
933 | else if ((e is TargetInvocationException) && (e.InnerException is ScriptCoopStopException)) | 952 | else if ((e is TargetInvocationException) && (e.InnerException is ScriptCoopStopException)) |
934 | { | 953 | { |
@@ -982,14 +1001,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
982 | ReleaseControls(); | 1001 | ReleaseControls(); |
983 | 1002 | ||
984 | Stop(timeout); | 1003 | Stop(timeout); |
985 | Part.Inventory.GetInventoryItem(ItemID).PermsMask = 0; | 1004 | SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID); |
986 | Part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero; | 1005 | part.Inventory.GetInventoryItem(ItemID).PermsMask = 0; |
1006 | part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero; | ||
1007 | part.CollisionSound = UUID.Zero; | ||
987 | AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID); | 1008 | AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID); |
988 | EventQueue.Clear(); | 1009 | EventQueue.Clear(); |
989 | m_Script.ResetVars(); | 1010 | m_Script.ResetVars(); |
990 | State = "default"; | 1011 | State = "default"; |
991 | 1012 | ||
992 | Part.SetScriptEvents(ItemID, | 1013 | part.SetScriptEvents(ItemID, |
993 | (int)m_Script.GetStateEventFlags(State)); | 1014 | (int)m_Script.GetStateEventFlags(State)); |
994 | if (running) | 1015 | if (running) |
995 | Start(); | 1016 | Start(); |
@@ -998,6 +1019,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
998 | new Object[0], new DetectParams[0])); | 1019 | new Object[0], new DetectParams[0])); |
999 | } | 1020 | } |
1000 | 1021 | ||
1022 | [DebuggerNonUserCode] //Stops the VS debugger from farting in this function | ||
1001 | public void ApiResetScript() | 1023 | public void ApiResetScript() |
1002 | { | 1024 | { |
1003 | // bool running = Running; | 1025 | // bool running = Running; |
@@ -1006,15 +1028,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
1006 | ReleaseControls(); | 1028 | ReleaseControls(); |
1007 | 1029 | ||
1008 | m_Script.ResetVars(); | 1030 | m_Script.ResetVars(); |
1009 | Part.Inventory.GetInventoryItem(ItemID).PermsMask = 0; | 1031 | SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID); |
1010 | Part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero; | 1032 | part.Inventory.GetInventoryItem(ItemID).PermsMask = 0; |
1033 | part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero; | ||
1034 | part.CollisionSound = UUID.Zero; | ||
1011 | AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID); | 1035 | AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID); |
1012 | 1036 | ||
1013 | EventQueue.Clear(); | 1037 | EventQueue.Clear(); |
1014 | m_Script.ResetVars(); | 1038 | m_Script.ResetVars(); |
1015 | State = "default"; | 1039 | State = "default"; |
1016 | 1040 | ||
1017 | Part.SetScriptEvents(ItemID, | 1041 | part.SetScriptEvents(ItemID, |
1018 | (int)m_Script.GetStateEventFlags(State)); | 1042 | (int)m_Script.GetStateEventFlags(State)); |
1019 | 1043 | ||
1020 | if (m_CurrentEvent != "state_entry") | 1044 | if (m_CurrentEvent != "state_entry") |
@@ -1028,10 +1052,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
1028 | 1052 | ||
1029 | public Dictionary<string, object> GetVars() | 1053 | public Dictionary<string, object> GetVars() |
1030 | { | 1054 | { |
1031 | if (m_Script != null) | 1055 | return m_Script.GetVars(); |
1032 | return m_Script.GetVars(); | ||
1033 | else | ||
1034 | return new Dictionary<string, object>(); | ||
1035 | } | 1056 | } |
1036 | 1057 | ||
1037 | public void SetVars(Dictionary<string, object> vars) | 1058 | public void SetVars(Dictionary<string, object> vars) |
@@ -1220,4 +1241,4 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
1220 | return null; | 1241 | return null; |
1221 | } | 1242 | } |
1222 | } | 1243 | } |
1223 | } \ No newline at end of file | 1244 | } |