diff options
Diffstat (limited to 'OpenSim')
3 files changed, 52 insertions, 9 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs index d35bfa8..08f9545 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs | |||
@@ -73,6 +73,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
73 | private string m_CurrentEvent = String.Empty; | 73 | private string m_CurrentEvent = String.Empty; |
74 | private bool m_InSelfDelete = false; | 74 | private bool m_InSelfDelete = false; |
75 | private int m_MaxScriptQueue; | 75 | private int m_MaxScriptQueue; |
76 | private bool m_SaveState = true; | ||
76 | 77 | ||
77 | private Dictionary<string,IScriptApi> m_Apis = new Dictionary<string,IScriptApi>(); | 78 | private Dictionary<string,IScriptApi> m_Apis = new Dictionary<string,IScriptApi>(); |
78 | 79 | ||
@@ -213,6 +214,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
213 | return; | 214 | return; |
214 | } | 215 | } |
215 | 216 | ||
217 | m_SaveState = true; | ||
218 | |||
216 | string savedState = Path.Combine(Path.GetDirectoryName(assembly), | 219 | string savedState = Path.Combine(Path.GetDirectoryName(assembly), |
217 | m_ItemID.ToString() + ".state"); | 220 | m_ItemID.ToString() + ".state"); |
218 | if (File.Exists(savedState)) | 221 | if (File.Exists(savedState)) |
@@ -257,6 +260,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
257 | // we get new rez events on sim restart, too | 260 | // we get new rez events on sim restart, too |
258 | // but if there is state, then we fire the change | 261 | // but if there is state, then we fire the change |
259 | // event | 262 | // event |
263 | |||
264 | // We loaded state, don't force a re-save | ||
265 | m_SaveState = false; | ||
266 | |||
260 | if (stateSource == StateSource.NewRez) | 267 | if (stateSource == StateSource.NewRez) |
261 | { | 268 | { |
262 | // m_Engine.Log.Debug("[Script] Posted changed(CHANGED_REGION_RESTART) to script"); | 269 | // m_Engine.Log.Debug("[Script] Posted changed(CHANGED_REGION_RESTART) to script"); |
@@ -487,6 +494,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
487 | 494 | ||
488 | m_InEvent = false; | 495 | m_InEvent = false; |
489 | m_CurrentEvent = String.Empty; | 496 | m_CurrentEvent = String.Empty; |
497 | |||
498 | if (m_SaveState) | ||
499 | { | ||
500 | // This will be the very first event we deliver | ||
501 | // (state_entry) in defualt state | ||
502 | // | ||
503 | |||
504 | SaveState(m_Assembly); | ||
505 | |||
506 | m_SaveState = false; | ||
507 | } | ||
490 | } | 508 | } |
491 | catch (Exception e) | 509 | catch (Exception e) |
492 | { | 510 | { |
@@ -589,6 +607,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
589 | m_State = "default"; | 607 | m_State = "default"; |
590 | if (running) | 608 | if (running) |
591 | Start(); | 609 | Start(); |
610 | m_SaveState = true; | ||
592 | PostEvent(new EventParams("state_entry", | 611 | PostEvent(new EventParams("state_entry", |
593 | new Object[0], new DetectParams[0])); | 612 | new Object[0], new DetectParams[0])); |
594 | } | 613 | } |
@@ -607,6 +626,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
607 | async.RemoveScript(m_LocalID, m_ItemID); | 626 | async.RemoveScript(m_LocalID, m_ItemID); |
608 | if (m_CurrentEvent != "state_entry") | 627 | if (m_CurrentEvent != "state_entry") |
609 | { | 628 | { |
629 | m_SaveState = true; | ||
610 | PostEvent(new EventParams("state_entry", | 630 | PostEvent(new EventParams("state_entry", |
611 | new Object[0], new DetectParams[0])); | 631 | new Object[0], new DetectParams[0])); |
612 | } | 632 | } |
@@ -640,6 +660,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
640 | 660 | ||
641 | public void SaveState(string assembly) | 661 | public void SaveState(string assembly) |
642 | { | 662 | { |
663 | // If we're currently in an event, just tell it to save upon return | ||
664 | // | ||
665 | if(m_InEvent) | ||
666 | { | ||
667 | m_SaveState = true; | ||
668 | return; | ||
669 | } | ||
670 | |||
643 | AsyncCommandManager async = (AsyncCommandManager)m_Engine.AsyncCommands; | 671 | AsyncCommandManager async = (AsyncCommandManager)m_Engine.AsyncCommands; |
644 | PluginData = async.GetSerializationData(m_ItemID); | 672 | PluginData = async.GetSerializationData(m_ItemID); |
645 | 673 | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs index bc9b174..a794f02 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptSerializer.cs | |||
@@ -56,9 +56,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
56 | { | 56 | { |
57 | bool running = instance.Running; | 57 | bool running = instance.Running; |
58 | 58 | ||
59 | if (running) | ||
60 | instance.Stop(50); | ||
61 | |||
62 | XmlDocument xmldoc = new XmlDocument(); | 59 | XmlDocument xmldoc = new XmlDocument(); |
63 | 60 | ||
64 | XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, | 61 | XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, |
@@ -182,9 +179,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance | |||
182 | 179 | ||
183 | rootElement.AppendChild(plugins); | 180 | rootElement.AppendChild(plugins); |
184 | 181 | ||
185 | if (running) | ||
186 | instance.Start(); | ||
187 | |||
188 | return xmldoc.InnerXml; | 182 | return xmldoc.InnerXml; |
189 | } | 183 | } |
190 | 184 | ||
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 485531d..303e5e4 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | |||
@@ -210,6 +210,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
210 | m_Scene.EventManager.OnScriptReset += OnScriptReset; | 210 | m_Scene.EventManager.OnScriptReset += OnScriptReset; |
211 | m_Scene.EventManager.OnStartScript += OnStartScript; | 211 | m_Scene.EventManager.OnStartScript += OnStartScript; |
212 | m_Scene.EventManager.OnStopScript += OnStopScript; | 212 | m_Scene.EventManager.OnStopScript += OnStopScript; |
213 | m_Scene.EventManager.OnShutdown += OnShutdown; | ||
213 | 214 | ||
214 | m_AsyncCommands = new AsyncCommandManager(this); | 215 | m_AsyncCommands = new AsyncCommandManager(this); |
215 | 216 | ||
@@ -247,7 +248,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
247 | Object[] p = (Object[])o; | 248 | Object[] p = (Object[])o; |
248 | int saveTime = (int)p[0]; | 249 | int saveTime = (int)p[0]; |
249 | 250 | ||
250 | System.Threading.Thread.Sleep(saveTime); | 251 | if (saveTime > 0) |
252 | System.Threading.Thread.Sleep(saveTime); | ||
251 | 253 | ||
252 | // m_log.Debug("[XEngine] Backing up script states"); | 254 | // m_log.Debug("[XEngine] Backing up script states"); |
253 | 255 | ||
@@ -275,8 +277,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
275 | 277 | ||
276 | instances.Clear(); | 278 | instances.Clear(); |
277 | 279 | ||
278 | m_ThreadPool.QueueWorkItem(new WorkItemCallback(this.DoBackup), | 280 | if (saveTime > 0) |
279 | new Object[] { saveTime }); | 281 | m_ThreadPool.QueueWorkItem(new WorkItemCallback(this.DoBackup), |
282 | new Object[] { saveTime }); | ||
280 | 283 | ||
281 | return 0; | 284 | return 0; |
282 | } | 285 | } |
@@ -840,5 +843,23 @@ namespace OpenSim.Region.ScriptEngine.XEngine | |||
840 | { | 843 | { |
841 | return GetScriptState(itemID); | 844 | return GetScriptState(itemID); |
842 | } | 845 | } |
846 | |||
847 | public void OnShutdown() | ||
848 | { | ||
849 | List<IScriptInstance> instances = new List<IScriptInstance>(); | ||
850 | |||
851 | lock (m_Scripts) | ||
852 | { | ||
853 | foreach (IScriptInstance instance in m_Scripts.Values) | ||
854 | instances.Add(instance); | ||
855 | } | ||
856 | |||
857 | foreach (IScriptInstance i in instances) | ||
858 | { | ||
859 | i.Stop(50); | ||
860 | } | ||
861 | |||
862 | DoBackup(new Object[] {0}); | ||
863 | } | ||
843 | } | 864 | } |
844 | } | 865 | } |