From c271bbcc8af1549666f6a5299a4b9ab9cf1c86d9 Mon Sep 17 00:00:00 2001 From: Melanie Date: Sat, 8 Jan 2011 16:44:28 +0100 Subject: Preserve the script running flag when copying an object. --- OpenSim/Framework/TaskInventoryItem.cs | 12 ++++++++ .../Region/Framework/Interfaces/IScriptModule.cs | 2 ++ .../Framework/Scenes/SceneObjectPartInventory.cs | 34 ++++++++++++++++++++++ OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 12 ++++++++ 4 files changed, 60 insertions(+) (limited to 'OpenSim') diff --git a/OpenSim/Framework/TaskInventoryItem.cs b/OpenSim/Framework/TaskInventoryItem.cs index 248502e..be2b8c8 100644 --- a/OpenSim/Framework/TaskInventoryItem.cs +++ b/OpenSim/Framework/TaskInventoryItem.cs @@ -124,6 +124,9 @@ namespace OpenSim.Framework private UUID _oldID = UUID.Zero; private bool _ownerChanged = false; + + // This used ONLY during copy. It can't be relied on at other times! + private bool _scriptRunning = true; public UUID AssetID { get { @@ -387,6 +390,15 @@ namespace OpenSim.Framework } } + public bool ScriptRunning { + get { + return _scriptRunning; + } + set { + _scriptRunning = value; + } + } + // See ICloneable #region ICloneable Members diff --git a/OpenSim/Region/Framework/Interfaces/IScriptModule.cs b/OpenSim/Region/Framework/Interfaces/IScriptModule.cs index fecdd1b..4a3c634 100644 --- a/OpenSim/Region/Framework/Interfaces/IScriptModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IScriptModule.cs @@ -50,5 +50,7 @@ namespace OpenSim.Region.Framework.Interfaces void ResumeScript(UUID itemID); ArrayList GetScriptErrors(UUID itemID); + + bool HasScript(UUID itemID, out bool running); } } diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs index 5a39941..6c56dc3 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs @@ -94,6 +94,7 @@ namespace OpenSim.Region.Framework.Scenes { m_items = value; m_inventorySerial++; + QueryScriptStates(); } } @@ -226,6 +227,36 @@ namespace OpenSim.Region.Framework.Scenes m_items.LockItemsForWrite(false); } + private void QueryScriptStates() + { + if (m_part == null || m_part.ParentGroup == null) + return; + + IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces(); + if (engines == null) // No engine at all + return; + + Items.LockItemsForRead(true); + foreach (TaskInventoryItem item in Items.Values) + { + if (item.InvType == (int)InventoryType.LSL) + { + foreach (IScriptModule e in engines) + { + bool running; + + if (e.HasScript(item.ItemID, out running)) + { + item.ScriptRunning = running; + break; + } + } + } + } + + Items.LockItemsForRead(false); + } + /// /// Start all the scripts contained in this prim's inventory /// @@ -349,6 +380,9 @@ namespace OpenSim.Region.Framework.Scenes m_part.ParentGroup.Scene.EventManager.TriggerRezScript( m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource); StoreScriptErrors(item.ItemID, null); + if (!item.ScriptRunning) + m_part.ParentGroup.Scene.EventManager.TriggerStopScript( + m_part.LocalId, item.ItemID); m_part.ParentGroup.AddActiveScriptCount(1); m_part.ScheduleFullUpdate(); } diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 35cc65b..6bdd4c8 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -1695,5 +1695,17 @@ namespace OpenSim.Region.ScriptEngine.XEngine instance.Resume(); } + + public bool HasScript(UUID itemID, out bool running) + { + running = true; + + IScriptInstance instance = GetInstance(itemID); + if (instance == null) + return false; + + running = instance.Running; + return true; + } } } -- cgit v1.1