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