From 59da146e9dd678aea2e0bd3e16ef178c183754a0 Mon Sep 17 00:00:00 2001
From: Oren Hurvitz
Date: Fri, 7 Aug 2015 16:35:32 +0300
Subject: When the user stops a script, have it remain stopped
Previously the script state was never saved for a !Running script, so upon region restart the script would be Running again.
The use of the 'StayStopped' flag is needed because all scripts are automatically stopped when the region shuts down, but in that case we shouldn't save in their state that they're !Running.
---
.../ScriptEngine/Interfaces/IScriptInstance.cs | 5 +++++
.../ScriptEngine/Shared/Instance/ScriptInstance.cs | 21 ++++++++++++++++++---
OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 5 +++++
3 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs
index f695eba..16641f7 100644
--- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptInstance.cs
@@ -93,6 +93,11 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
bool ShuttingDown { get; set; }
///
+ /// When stopping the script: should it remain stopped permanently (i.e., save !Running in its state)?
+ ///
+ bool StayStopped { get; set; }
+
+ ///
/// Script state
///
string State { get; set; }
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index c6512ba..6541256 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
@@ -126,7 +126,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
}
}
- public bool Running { get; set; }
+ public bool Running
+ {
+ get { return m_running; }
+
+ set
+ {
+ m_running = value;
+ if (m_running)
+ StayStopped = false;
+ }
+ }
+ private bool m_running;
public bool Suspended
{
@@ -158,6 +169,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
public string State { get; set; }
+ public bool StayStopped { get; set; }
+
public IScriptEngine Engine { get; private set; }
public UUID AppDomain { get; set; }
@@ -1077,7 +1090,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
public void SaveState()
{
- if (!Running)
+ if (!Running && !StayStopped)
return;
// We cannot call this inside the EventQueue lock since it will currently take AsyncCommandManager.staticLock.
@@ -1089,7 +1102,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
lock (EventQueue)
{
// Check again to avoid a race with a thread in Stop()
- if (!Running)
+ if (!Running && !StayStopped)
return;
// If we're currently in an event, just tell it to save upon return
@@ -1130,6 +1143,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
//}
m_CurrentStateHash = hash;
}
+
+ StayStopped = false;
}
}
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 5071884..62bf803 100755
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -699,6 +699,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
{
if (instance.Running)
{
+ instance.StayStopped = true; // the script was stopped explicitly
+
instance.Stop(0);
SceneObjectPart sop = m_Scene.GetSceneObjectPart(instance.ObjectID);
@@ -1914,6 +1916,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine
if (instance != null)
{
+ lock (instance.EventQueue)
+ instance.StayStopped = true; // the script was stopped explicitly
+
instance.Stop(m_WaitForEventCompletionOnScriptStop);
}
else
--
cgit v1.1