aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
diff options
context:
space:
mode:
authorMelanie2010-04-19 07:00:40 +0100
committerMelanie2010-04-19 07:00:40 +0100
commit98cb4f74b265dfb8ca3eb8c8d3ad604249398df1 (patch)
tree1339d3707430a20662bdcd3eb4e9ef86abc6a4fd /OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
parentMerge branch 'master' into careminster-presence-refactor (diff)
parentAll scripts are now created suspended and are only unsuspended when the object (diff)
downloadopensim-SC_OLD-98cb4f74b265dfb8ca3eb8c8d3ad604249398df1.zip
opensim-SC_OLD-98cb4f74b265dfb8ca3eb8c8d3ad604249398df1.tar.gz
opensim-SC_OLD-98cb4f74b265dfb8ca3eb8c8d3ad604249398df1.tar.bz2
opensim-SC_OLD-98cb4f74b265dfb8ca3eb8c8d3ad604249398df1.tar.xz
Merge branch 'master' into careminster-presence-refactor
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs249
1 files changed, 131 insertions, 118 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index 6ecafd4..9ccc199 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
@@ -96,6 +96,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
96 private bool m_startedFromSavedState; 96 private bool m_startedFromSavedState;
97 private UUID m_CurrentStateHash; 97 private UUID m_CurrentStateHash;
98 private UUID m_RegionID; 98 private UUID m_RegionID;
99 private bool m_Suspended = true;
99 100
100 private Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> 101 private Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>
101 m_LineMap; 102 m_LineMap;
@@ -640,158 +641,160 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
640 /// <returns></returns> 641 /// <returns></returns>
641 public object EventProcessor() 642 public object EventProcessor()
642 { 643 {
644 EventParams data = null;
643 645
644 EventParams data = null; 646 lock (m_EventQueue)
645
646 lock (m_EventQueue)
647 {
648 lock (m_Script)
649 { 647 {
650 data = (EventParams) m_EventQueue.Dequeue(); 648 if (m_Suspended)
651 if (data == null) // Shouldn't happen 649 return 0;
650
651 lock (m_Script)
652 { 652 {
653 if ((m_EventQueue.Count > 0) && m_RunEvents && (!m_ShuttingDown)) 653 data = (EventParams) m_EventQueue.Dequeue();
654 if (data == null) // Shouldn't happen
654 { 655 {
655 m_CurrentResult = m_Engine.QueueEventHandler(this); 656 if ((m_EventQueue.Count > 0) && m_RunEvents && (!m_ShuttingDown))
657 {
658 m_CurrentResult = m_Engine.QueueEventHandler(this);
659 }
660 else
661 {
662 m_CurrentResult = null;
663 }
664 return 0;
656 } 665 }
657 else 666
667 if (data.EventName == "timer")
668 m_TimerQueued = false;
669 if (data.EventName == "control")
658 { 670 {
659 m_CurrentResult = null; 671 if (m_ControlEventsInQueue > 0)
672 m_ControlEventsInQueue--;
660 } 673 }
661 return 0; 674 if (data.EventName == "collision")
662 } 675 m_CollisionInQueue = false;
663
664 if (data.EventName == "timer")
665 m_TimerQueued = false;
666 if (data.EventName == "control")
667 {
668 if (m_ControlEventsInQueue > 0)
669 m_ControlEventsInQueue--;
670 } 676 }
671 if (data.EventName == "collision")
672 m_CollisionInQueue = false;
673 } 677 }
674 } 678 lock(m_Script)
675 lock(m_Script) 679 {
676 { 680
677 681 //m_log.DebugFormat("[XENGINE]: Processing event {0} for {1}", data.EventName, this);
678 //m_log.DebugFormat("[XENGINE]: Processing event {0} for {1}", data.EventName, this);
679 682
680 m_DetectParams = data.DetectParams; 683 m_DetectParams = data.DetectParams;
681 684
682 if (data.EventName == "state") // Hardcoded state change 685 if (data.EventName == "state") // Hardcoded state change
683 {
684// m_log.DebugFormat("[Script] Script {0}.{1} state set to {2}",
685// m_PrimName, m_ScriptName, data.Params[0].ToString());
686 m_State=data.Params[0].ToString();
687 AsyncCommandManager.RemoveScript(m_Engine,
688 m_LocalID, m_ItemID);
689
690 SceneObjectPart part = m_Engine.World.GetSceneObjectPart(
691 m_LocalID);
692 if (part != null)
693 {
694 part.SetScriptEvents(m_ItemID,
695 (int)m_Script.GetStateEventFlags(State));
696 }
697 }
698 else
699 {
700 if (m_Engine.World.PipeEventsForScript(m_LocalID) ||
701 data.EventName == "control") // Don't freeze avies!
702 { 686 {
687 // m_log.DebugFormat("[Script] Script {0}.{1} state set to {2}",
688 // m_PrimName, m_ScriptName, data.Params[0].ToString());
689 m_State=data.Params[0].ToString();
690 AsyncCommandManager.RemoveScript(m_Engine,
691 m_LocalID, m_ItemID);
692
703 SceneObjectPart part = m_Engine.World.GetSceneObjectPart( 693 SceneObjectPart part = m_Engine.World.GetSceneObjectPart(
704 m_LocalID); 694 m_LocalID);
705 // m_log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}", 695 if (part != null)
706 // m_PrimName, m_ScriptName, data.EventName, m_State); 696 {
707 697 part.SetScriptEvents(m_ItemID,
708 try 698 (int)m_Script.GetStateEventFlags(State));
699 }
700 }
701 else
702 {
703 if (m_Engine.World.PipeEventsForScript(m_LocalID) ||
704 data.EventName == "control") // Don't freeze avies!
709 { 705 {
710 m_CurrentEvent = data.EventName; 706 SceneObjectPart part = m_Engine.World.GetSceneObjectPart(
711 m_EventStart = DateTime.Now; 707 m_LocalID);
712 m_InEvent = true; 708 // m_log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}",
709 // m_PrimName, m_ScriptName, data.EventName, m_State);
713 710
714 m_Script.ExecuteEvent(State, data.EventName, data.Params); 711 try
712 {
713 m_CurrentEvent = data.EventName;
714 m_EventStart = DateTime.Now;
715 m_InEvent = true;
715 716
716 m_InEvent = false; 717 m_Script.ExecuteEvent(State, data.EventName, data.Params);
717 m_CurrentEvent = String.Empty;
718 718
719 if (m_SaveState) 719 m_InEvent = false;
720 { 720 m_CurrentEvent = String.Empty;
721 // This will be the very first event we deliver
722 // (state_entry) in default state
723 //
724 721
725 SaveState(m_Assembly); 722 if (m_SaveState)
723 {
724 // This will be the very first event we deliver
725 // (state_entry) in default state
726 //
726 727
727 m_SaveState = false; 728 SaveState(m_Assembly);
728 }
729 }
730 catch (Exception e)
731 {
732 // m_log.DebugFormat("[SCRIPT] Exception: {0}", e.Message);
733 m_InEvent = false;
734 m_CurrentEvent = String.Empty;
735 729
736 if ((!(e is TargetInvocationException) || (!(e.InnerException is SelfDeleteException) && !(e.InnerException is ScriptDeleteException))) && !(e is ThreadAbortException)) 730 m_SaveState = false;
731 }
732 }
733 catch (Exception e)
737 { 734 {
738 try 735 // m_log.DebugFormat("[SCRIPT] Exception: {0}", e.Message);
736 m_InEvent = false;
737 m_CurrentEvent = String.Empty;
738
739 if ((!(e is TargetInvocationException) || (!(e.InnerException is SelfDeleteException) && !(e.InnerException is ScriptDeleteException))) && !(e is ThreadAbortException))
739 { 740 {
740 // DISPLAY ERROR INWORLD 741 try
741 string text = FormatException(e); 742 {
742 743 // DISPLAY ERROR INWORLD
743 if (text.Length > 1000) 744 string text = FormatException(e);
744 text = text.Substring(0, 1000); 745
745 m_Engine.World.SimChat(Utils.StringToBytes(text), 746 if (text.Length > 1000)
746 ChatTypeEnum.DebugChannel, 2147483647, 747 text = text.Substring(0, 1000);
747 part.AbsolutePosition, 748 m_Engine.World.SimChat(Utils.StringToBytes(text),
748 part.Name, part.UUID, false); 749 ChatTypeEnum.DebugChannel, 2147483647,
750 part.AbsolutePosition,
751 part.Name, part.UUID, false);
752 }
753 catch (Exception)
754 {
755 }
756 // catch (Exception e2) // LEGIT: User Scripting
757 // {
758 // m_log.Error("[SCRIPT]: "+
759 // "Error displaying error in-world: " +
760 // e2.ToString());
761 // m_log.Error("[SCRIPT]: " +
762 // "Errormessage: Error compiling script:\r\n" +
763 // e.ToString());
764 // }
749 } 765 }
750 catch (Exception) 766 else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException))
751 { 767 {
768 m_InSelfDelete = true;
769 if (part != null && part.ParentGroup != null)
770 m_Engine.World.DeleteSceneObject(part.ParentGroup, false);
771 }
772 else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException))
773 {
774 m_InSelfDelete = true;
775 if (part != null && part.ParentGroup != null)
776 part.Inventory.RemoveInventoryItem(m_ItemID);
752 } 777 }
753 // catch (Exception e2) // LEGIT: User Scripting
754 // {
755 // m_log.Error("[SCRIPT]: "+
756 // "Error displaying error in-world: " +
757 // e2.ToString());
758 // m_log.Error("[SCRIPT]: " +
759 // "Errormessage: Error compiling script:\r\n" +
760 // e.ToString());
761 // }
762 }
763 else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException))
764 {
765 m_InSelfDelete = true;
766 if (part != null && part.ParentGroup != null)
767 m_Engine.World.DeleteSceneObject(part.ParentGroup, false);
768 }
769 else if ((e is TargetInvocationException) && (e.InnerException is ScriptDeleteException))
770 {
771 m_InSelfDelete = true;
772 if (part != null && part.ParentGroup != null)
773 part.Inventory.RemoveInventoryItem(m_ItemID);
774 } 778 }
775 } 779 }
776 } 780 }
777 }
778 781
779 lock (m_EventQueue) 782 lock (m_EventQueue)
780 {
781 if ((m_EventQueue.Count > 0) && m_RunEvents && (!m_ShuttingDown))
782 {
783 m_CurrentResult = m_Engine.QueueEventHandler(this);
784 }
785 else
786 { 783 {
787 m_CurrentResult = null; 784 if ((m_EventQueue.Count > 0) && m_RunEvents && (!m_ShuttingDown))
785 {
786 m_CurrentResult = m_Engine.QueueEventHandler(this);
787 }
788 else
789 {
790 m_CurrentResult = null;
791 }
788 } 792 }
789 }
790 793
791 m_DetectParams = null; 794 m_DetectParams = null;
792 795
793 return 0; 796 return 0;
794 } 797 }
795 } 798 }
796 799
797 public int EventTime() 800 public int EventTime()
@@ -1018,5 +1021,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
1018 { 1021 {
1019 get { return m_RegionID; } 1022 get { return m_RegionID; }
1020 } 1023 }
1024
1025 public void Suspend()
1026 {
1027 m_Suspended = true;
1028 }
1029
1030 public void Resume()
1031 {
1032 m_Suspended = false;
1033 }
1021 } 1034 }
1022} 1035}