diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs | 172 |
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 887a317..8da06d1 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 | ||
@@ -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 | { |
@@ -481,27 +482,34 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
481 | PostEvent(new EventParams("attach", | 482 | PostEvent(new EventParams("attach", |
482 | new object[] { new LSL_Types.LSLString(m_AttachedAvatar.ToString()) }, new DetectParams[0])); | 483 | new object[] { new LSL_Types.LSLString(m_AttachedAvatar.ToString()) }, new DetectParams[0])); |
483 | } | 484 | } |
485 | |||
484 | } | 486 | } |
485 | } | 487 | } |
486 | 488 | ||
487 | private void ReleaseControls() | 489 | private void ReleaseControls() |
488 | { | 490 | { |
489 | int permsMask; | 491 | SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID); |
490 | UUID permsGranter; | 492 | |
491 | lock (Part.TaskInventory) | 493 | if (part != null) |
492 | { | 494 | { |
493 | if (!Part.TaskInventory.ContainsKey(ItemID)) | 495 | int permsMask; |
496 | UUID permsGranter; | ||
497 | part.TaskInventory.LockItemsForRead(true); | ||
498 | if (!part.TaskInventory.ContainsKey(ItemID)) | ||
499 | { | ||
500 | part.TaskInventory.LockItemsForRead(false); | ||
494 | return; | 501 | return; |
502 | } | ||
503 | permsGranter = part.TaskInventory[ItemID].PermsGranter; | ||
504 | permsMask = part.TaskInventory[ItemID].PermsMask; | ||
505 | part.TaskInventory.LockItemsForRead(false); | ||
495 | 506 | ||
496 | permsGranter = Part.TaskInventory[ItemID].PermsGranter; | 507 | if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) |
497 | permsMask = Part.TaskInventory[ItemID].PermsMask; | 508 | { |
498 | } | 509 | ScenePresence presence = Engine.World.GetScenePresence(permsGranter); |
499 | 510 | if (presence != null) | |
500 | if ((permsMask & ScriptBaseClass.PERMISSION_TAKE_CONTROLS) != 0) | 511 | presence.UnRegisterControlEventsToScript(LocalID, ItemID); |
501 | { | 512 | } |
502 | ScenePresence presence = Engine.World.GetScenePresence(permsGranter); | ||
503 | if (presence != null) | ||
504 | presence.UnRegisterControlEventsToScript(LocalID, ItemID); | ||
505 | } | 513 | } |
506 | } | 514 | } |
507 | 515 | ||
@@ -656,6 +664,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
656 | return true; | 664 | return true; |
657 | } | 665 | } |
658 | 666 | ||
667 | [DebuggerNonUserCode] //Prevents the debugger from farting in this function | ||
659 | public void SetState(string state) | 668 | public void SetState(string state) |
660 | { | 669 | { |
661 | if (state == State) | 670 | if (state == State) |
@@ -667,7 +676,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
667 | new DetectParams[0])); | 676 | new DetectParams[0])); |
668 | PostEvent(new EventParams("state_entry", new Object[0], | 677 | PostEvent(new EventParams("state_entry", new Object[0], |
669 | new DetectParams[0])); | 678 | new DetectParams[0])); |
670 | 679 | ||
671 | throw new EventAbortException(); | 680 | throw new EventAbortException(); |
672 | } | 681 | } |
673 | 682 | ||
@@ -757,57 +766,60 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
757 | /// <returns></returns> | 766 | /// <returns></returns> |
758 | public object EventProcessor() | 767 | public object EventProcessor() |
759 | { | 768 | { |
769 | EventParams data = null; | ||
760 | // We check here as the thread stopping this instance from running may itself hold the m_Script lock. | 770 | // We check here as the thread stopping this instance from running may itself hold the m_Script lock. |
761 | if (!Running) | 771 | if (!Running) |
762 | return 0; | 772 | return 0; |
763 | 773 | ||
764 | lock (m_Script) | ||
765 | { | ||
766 | // m_log.DebugFormat("[XEngine]: EventProcessor() invoked for {0}.{1}", PrimName, ScriptName); | 774 | // m_log.DebugFormat("[XEngine]: EventProcessor() invoked for {0}.{1}", PrimName, ScriptName); |
767 | 775 | ||
768 | if (Suspended) | 776 | if (Suspended) |
769 | return 0; | 777 | return 0; |
770 | |||
771 | EventParams data = null; | ||
772 | 778 | ||
773 | lock (EventQueue) | 779 | lock (EventQueue) |
780 | { | ||
781 | data = (EventParams) EventQueue.Dequeue(); | ||
782 | if (data == null) // Shouldn't happen | ||
774 | { | 783 | { |
775 | data = (EventParams)EventQueue.Dequeue(); | 784 | if (EventQueue.Count > 0 && Running && !ShuttingDown) |
776 | if (data == null) // Shouldn't happen | ||
777 | { | 785 | { |
778 | if (EventQueue.Count > 0 && Running && !ShuttingDown) | 786 | 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 | } | 787 | } |
788 | 788 | else | |
789 | if (data.EventName == "timer") | ||
790 | m_TimerQueued = false; | ||
791 | if (data.EventName == "control") | ||
792 | { | 789 | { |
793 | if (m_ControlEventsInQueue > 0) | 790 | m_CurrentWorkItem = null; |
794 | m_ControlEventsInQueue--; | ||
795 | } | 791 | } |
796 | if (data.EventName == "collision") | 792 | return 0; |
797 | m_CollisionInQueue = false; | ||
798 | } | 793 | } |
799 | 794 | ||
795 | if (data.EventName == "timer") | ||
796 | m_TimerQueued = false; | ||
797 | if (data.EventName == "control") | ||
798 | { | ||
799 | if (m_ControlEventsInQueue > 0) | ||
800 | m_ControlEventsInQueue--; | ||
801 | } | ||
802 | if (data.EventName == "collision") | ||
803 | m_CollisionInQueue = false; | ||
804 | } | ||
805 | |||
806 | lock(m_Script) | ||
807 | { | ||
808 | |||
809 | // m_log.DebugFormat("[XEngine]: Processing event {0} for {1}", data.EventName, this); | ||
810 | SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID); | ||
811 | |||
800 | if (DebugLevel >= 2) | 812 | if (DebugLevel >= 2) |
801 | m_log.DebugFormat( | 813 | m_log.DebugFormat( |
802 | "[SCRIPT INSTANCE]: Processing event {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}", | 814 | "[SCRIPT INSTANCE]: Processing event {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}", |
803 | data.EventName, | 815 | data.EventName, |
804 | ScriptName, | 816 | ScriptName, |
805 | Part.Name, | 817 | part.Name, |
806 | Part.LocalId, | 818 | part.LocalId, |
807 | Part.ParentGroup.Name, | 819 | part.ParentGroup.Name, |
808 | Part.ParentGroup.UUID, | 820 | part.ParentGroup.UUID, |
809 | Part.AbsolutePosition, | 821 | part.AbsolutePosition, |
810 | Part.ParentGroup.Scene.Name); | 822 | part.ParentGroup.Scene.Name); |
811 | 823 | ||
812 | m_DetectParams = data.DetectParams; | 824 | m_DetectParams = data.DetectParams; |
813 | 825 | ||
@@ -820,17 +832,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
820 | "[SCRIPT INSTANCE]: Changing state to {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}", | 832 | "[SCRIPT INSTANCE]: Changing state to {0} for {1}/{2}({3})/{4}({5}) @ {6}/{7}", |
821 | State, | 833 | State, |
822 | ScriptName, | 834 | ScriptName, |
823 | Part.Name, | 835 | part.Name, |
824 | Part.LocalId, | 836 | part.LocalId, |
825 | Part.ParentGroup.Name, | 837 | part.ParentGroup.Name, |
826 | Part.ParentGroup.UUID, | 838 | part.ParentGroup.UUID, |
827 | Part.AbsolutePosition, | 839 | part.AbsolutePosition, |
828 | Part.ParentGroup.Scene.Name); | 840 | part.ParentGroup.Scene.Name); |
829 | 841 | ||
830 | AsyncCommandManager.RemoveScript(Engine, | 842 | AsyncCommandManager.RemoveScript(Engine, |
831 | LocalID, ItemID); | 843 | LocalID, ItemID); |
832 | 844 | ||
833 | Part.SetScriptEvents(ItemID, (int)m_Script.GetStateEventFlags(State)); | 845 | if (part != null) |
846 | { | ||
847 | part.SetScriptEvents(ItemID, | ||
848 | (int)m_Script.GetStateEventFlags(State)); | ||
849 | } | ||
834 | } | 850 | } |
835 | else | 851 | else |
836 | { | 852 | { |
@@ -893,17 +909,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
893 | text = text.Substring(0, 1000); | 909 | text = text.Substring(0, 1000); |
894 | Engine.World.SimChat(Utils.StringToBytes(text), | 910 | Engine.World.SimChat(Utils.StringToBytes(text), |
895 | ChatTypeEnum.DebugChannel, 2147483647, | 911 | ChatTypeEnum.DebugChannel, 2147483647, |
896 | Part.AbsolutePosition, | 912 | part.AbsolutePosition, |
897 | Part.Name, Part.UUID, false); | 913 | part.Name, part.UUID, false); |
898 | 914 | ||
899 | 915 | ||
900 | m_log.DebugFormat( | 916 | m_log.DebugFormat( |
901 | "[SCRIPT INSTANCE]: Runtime error in script {0}, part {1} {2} at {3} in {4}, displayed error {5}, actual exception {6}", | 917 | "[SCRIPT INSTANCE]: Runtime error in script {0}, part {1} {2} at {3} in {4}, displayed error {5}, actual exception {6}", |
902 | ScriptName, | 918 | ScriptName, |
903 | PrimName, | 919 | PrimName, |
904 | Part.UUID, | 920 | part.UUID, |
905 | Part.AbsolutePosition, | 921 | part.AbsolutePosition, |
906 | Part.ParentGroup.Scene.Name, | 922 | part.ParentGroup.Scene.Name, |
907 | text.Replace("\n", "\\n"), | 923 | text.Replace("\n", "\\n"), |
908 | e.InnerException); | 924 | e.InnerException); |
909 | } | 925 | } |
@@ -923,12 +939,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
923 | else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException)) | 939 | else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException)) |
924 | { | 940 | { |
925 | m_InSelfDelete = true; | 941 | m_InSelfDelete = true; |
926 | Engine.World.DeleteSceneObject(Part.ParentGroup, false); | 942 | if (part != null) |
943 | Engine.World.DeleteSceneObject(part.ParentGroup, false); | ||
927 | } | 944 | } |
928 | else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException)) | 945 | else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException)) |
929 | { | 946 | { |
930 | m_InSelfDelete = true; | 947 | m_InSelfDelete = true; |
931 | Part.Inventory.RemoveInventoryItem(ItemID); | 948 | if (part != null) |
949 | part.Inventory.RemoveInventoryItem(ItemID); | ||
932 | } | 950 | } |
933 | else if ((e is TargetInvocationException) && (e.InnerException is ScriptCoopStopException)) | 951 | else if ((e is TargetInvocationException) && (e.InnerException is ScriptCoopStopException)) |
934 | { | 952 | { |
@@ -982,14 +1000,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
982 | ReleaseControls(); | 1000 | ReleaseControls(); |
983 | 1001 | ||
984 | Stop(timeout); | 1002 | Stop(timeout); |
985 | Part.Inventory.GetInventoryItem(ItemID).PermsMask = 0; | 1003 | SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID); |
986 | Part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero; | 1004 | part.Inventory.GetInventoryItem(ItemID).PermsMask = 0; |
1005 | part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero; | ||
1006 | part.CollisionSound = UUID.Zero; | ||
987 | AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID); | 1007 | AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID); |
988 | EventQueue.Clear(); | 1008 | EventQueue.Clear(); |
989 | m_Script.ResetVars(); | 1009 | m_Script.ResetVars(); |
990 | State = "default"; | 1010 | State = "default"; |
991 | 1011 | ||
992 | Part.SetScriptEvents(ItemID, | 1012 | part.SetScriptEvents(ItemID, |
993 | (int)m_Script.GetStateEventFlags(State)); | 1013 | (int)m_Script.GetStateEventFlags(State)); |
994 | if (running) | 1014 | if (running) |
995 | Start(); | 1015 | Start(); |
@@ -998,6 +1018,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
998 | new Object[0], new DetectParams[0])); | 1018 | new Object[0], new DetectParams[0])); |
999 | } | 1019 | } |
1000 | 1020 | ||
1021 | [DebuggerNonUserCode] //Stops the VS debugger from farting in this function | ||
1001 | public void ApiResetScript() | 1022 | public void ApiResetScript() |
1002 | { | 1023 | { |
1003 | // bool running = Running; | 1024 | // bool running = Running; |
@@ -1006,15 +1027,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
1006 | ReleaseControls(); | 1027 | ReleaseControls(); |
1007 | 1028 | ||
1008 | m_Script.ResetVars(); | 1029 | m_Script.ResetVars(); |
1009 | Part.Inventory.GetInventoryItem(ItemID).PermsMask = 0; | 1030 | SceneObjectPart part = Engine.World.GetSceneObjectPart(LocalID); |
1010 | Part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero; | 1031 | part.Inventory.GetInventoryItem(ItemID).PermsMask = 0; |
1032 | part.Inventory.GetInventoryItem(ItemID).PermsGranter = UUID.Zero; | ||
1033 | part.CollisionSound = UUID.Zero; | ||
1011 | AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID); | 1034 | AsyncCommandManager.RemoveScript(Engine, LocalID, ItemID); |
1012 | 1035 | ||
1013 | EventQueue.Clear(); | 1036 | EventQueue.Clear(); |
1014 | m_Script.ResetVars(); | 1037 | m_Script.ResetVars(); |
1015 | State = "default"; | 1038 | State = "default"; |
1016 | 1039 | ||
1017 | Part.SetScriptEvents(ItemID, | 1040 | part.SetScriptEvents(ItemID, |
1018 | (int)m_Script.GetStateEventFlags(State)); | 1041 | (int)m_Script.GetStateEventFlags(State)); |
1019 | 1042 | ||
1020 | if (m_CurrentEvent != "state_entry") | 1043 | if (m_CurrentEvent != "state_entry") |
@@ -1028,10 +1051,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
1028 | 1051 | ||
1029 | public Dictionary<string, object> GetVars() | 1052 | public Dictionary<string, object> GetVars() |
1030 | { | 1053 | { |
1031 | if (m_Script != null) | 1054 | return m_Script.GetVars(); |
1032 | return m_Script.GetVars(); | ||
1033 | else | ||
1034 | return new Dictionary<string, object>(); | ||
1035 | } | 1055 | } |
1036 | 1056 | ||
1037 | public void SetVars(Dictionary<string, object> vars) | 1057 | public void SetVars(Dictionary<string, object> vars) |