From 37b07aa9ec1d4bb9c84eebc5f9d99b4d70d6d05e Mon Sep 17 00:00:00 2001 From: Melanie Date: Sun, 20 Dec 2009 16:44:31 +0000 Subject: [PATCH 1/4] Fix a case where an idle sim can eat 100% of a core --- OpenSim/Region/Framework/Scenes/Scene.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index eb284c12a4..f79eb5decb 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -1314,7 +1314,7 @@ namespace OpenSim.Region.Framework.Scenes maintc = Util.EnvironmentTickCountSubtract(maintc); maintc = (int)(m_timespan * 1000) - maintc; - if ((maintc < (m_timespan * 1000)) && maintc > 0) + if (maintc > 0) Thread.Sleep(maintc); // Tell the watchdog that this thread is still alive From f6ef48741303b6e19a5aa73de038b46e0ab409c5 Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 21 Dec 2009 06:29:23 +0000 Subject: [PATCH 2/4] Script State Fix: Step 1 Add Engine=xxx attribute and check for it's presence. Ignore state data written bby another engine --- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 9030a5c5a6..20dbbd4c8e 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -1266,6 +1266,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine XmlAttribute assetID = doc.CreateAttribute("", "Asset", ""); assetID.Value = instance.AssetID.ToString(); stateData.Attributes.Append(assetID); + XmlAttribute engineName = doc.CreateAttribute("", "Engine", ""); + engineName.Value = ScriptEngineName; + stateData.Attributes.Append(engineName); doc.AppendChild(stateData); // Add ... @@ -1388,6 +1391,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine XmlElement rootE = (XmlElement)rootL[0]; + if (rootE.GetAttribute("Engine") != ScriptEngineName) + return; + if (rootE.GetAttribute("UUID") != itemID.ToString()) return; From 83d8ba5775146da220b7e60d3779810db8a1eb5d Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 21 Dec 2009 06:41:10 +0000 Subject: [PATCH 3/4] Remove extra checking on the itemID of saved state, since it changes during rez from inventory. --- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 20dbbd4c8e..082c99bbe6 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -1394,10 +1394,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine if (rootE.GetAttribute("Engine") != ScriptEngineName) return; - if (rootE.GetAttribute("UUID") != itemID.ToString()) - return; - -// string assetID = rootE.GetAttribute("Asset"); +// On rez from inventory, that ID will have changed. It was only +// advisory anyway. So we don't check it anymore. +// +// if (rootE.GetAttribute("UUID") != itemID.ToString()) +// return; XmlNodeList stateL = rootE.GetElementsByTagName("ScriptState"); From 27453890d5a5d09e47c638ccef92f45b1ce360b2 Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 21 Dec 2009 10:26:52 +0000 Subject: [PATCH 4/4] Script State Fix: Part 2 Change the reader to wrap old-style definitions in new style wrappers. Change importer to not check irrelevant data that can't be reconstructed This removes the last bit of knowledge of XEngine's .state files from core. --- .../Framework/Interfaces/IScriptModule.cs | 2 +- .../Scenes/SceneObjectPartInventory.cs | 55 ++++++++++++++++--- .../Region/ScriptEngine/XEngine/XEngine.cs | 36 ++++++------ 3 files changed, 69 insertions(+), 24 deletions(-) diff --git a/OpenSim/Region/Framework/Interfaces/IScriptModule.cs b/OpenSim/Region/Framework/Interfaces/IScriptModule.cs index f11e5713d0..98efcbef57 100644 --- a/OpenSim/Region/Framework/Interfaces/IScriptModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IScriptModule.cs @@ -35,7 +35,7 @@ namespace OpenSim.Region.Framework.Interfaces string ScriptEngineName { get; } string GetXMLState(UUID itemID); - void SetXMLState(UUID itemID, string xml); + bool SetXMLState(UUID itemID, string xml); bool PostScriptEvent(UUID itemID, string name, Object[] args); bool PostObjectEvent(UUID itemID, string name, Object[] args); diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs index 22eedbab7d..47e4ad031c 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs @@ -26,6 +26,7 @@ */ using System; +using System.Xml; using System.IO; using System.Collections.Generic; using System.Reflection; @@ -283,15 +284,55 @@ namespace OpenSim.Region.Framework.Scenes private void RestoreSavedScriptState(UUID oldID, UUID newID) { + IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces(); + if (engines == null) // No engine at all + return; + if (m_part.ParentGroup.m_savedScriptState.ContainsKey(oldID)) { - string fpath = Path.Combine("ScriptEngines/"+m_part.ParentGroup.Scene.RegionInfo.RegionID.ToString(), - newID.ToString()+".state"); - FileStream fs = File.Create(fpath); - Byte[] buffer = enc.GetBytes(m_part.ParentGroup.m_savedScriptState[oldID]); - fs.Write(buffer,0,buffer.Length); - fs.Close(); - m_part.ParentGroup.m_savedScriptState.Remove(oldID); + XmlDocument doc = new XmlDocument(); + + doc.LoadXml(m_part.ParentGroup.m_savedScriptState[oldID]); + + ////////// CRUFT WARNING /////////////////////////////////// + // + // Old objects will have ... + // This format is XEngine ONLY + // + // New objects have ... + // This can be passed to any engine + // + XmlNode n = doc.SelectSingleNode("ScriptState"); + if (n != null) // Old format data + { + XmlDocument newDoc = new XmlDocument(); + + XmlElement rootN = newDoc.CreateElement("", "State", ""); + XmlAttribute uuidA = newDoc.CreateAttribute("", "UUID", ""); + uuidA.Value = oldID.ToString(); + rootN.Attributes.Append(uuidA); + XmlAttribute engineA = newDoc.CreateAttribute("", "Engine", ""); + engineA.Value = "XEngine"; + rootN.Attributes.Append(engineA); + + newDoc.AppendChild(rootN); + + XmlNode stateN = newDoc.ImportNode(n, true); + rootN.AppendChild(stateN); + + // This created document has only the minimun data + // necessary for XEngine to parse it successfully + + m_part.ParentGroup.m_savedScriptState[oldID] = newDoc.OuterXml; + } + foreach (IScriptModule e in engines) + { + if (e != null) + { + if (e.SetXMLState(newID, m_part.ParentGroup.m_savedScriptState[oldID])) + break; + } + } } } diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 082c99bbe6..25a4cd69a5 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -1368,10 +1368,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine return false; } - public void SetXMLState(UUID itemID, string xml) + public bool SetXMLState(UUID itemID, string xml) { if (xml == String.Empty) - return; + return false; XmlDocument doc = new XmlDocument(); @@ -1382,17 +1382,17 @@ namespace OpenSim.Region.ScriptEngine.XEngine catch (Exception) { m_log.Error("[XEngine]: Exception decoding XML data from region transfer"); - return; + return false; } XmlNodeList rootL = doc.GetElementsByTagName("State"); if (rootL.Count < 1) - return; + return false; XmlElement rootE = (XmlElement)rootL[0]; if (rootE.GetAttribute("Engine") != ScriptEngineName) - return; + return false; // On rez from inventory, that ID will have changed. It was only // advisory anyway. So we don't check it anymore. @@ -1403,7 +1403,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine XmlNodeList stateL = rootE.GetElementsByTagName("ScriptState"); if (stateL.Count != 1) - return; + return false; XmlElement stateE = (XmlElement)stateL[0]; @@ -1412,7 +1412,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine XmlNodeList assemL = rootE.GetElementsByTagName("Assembly"); if (assemL.Count != 1) - return; + return false; XmlElement assemE = (XmlElement)assemL[0]; @@ -1452,19 +1452,23 @@ namespace OpenSim.Region.ScriptEngine.XEngine sfs.Close(); XmlNodeList mapL = rootE.GetElementsByTagName("LineMap"); - - XmlElement mapE = (XmlElement)mapL[0]; + if (mapL.Count > 0) + { + XmlElement mapE = (XmlElement)mapL[0]; - string mappath = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString()); - mappath = Path.Combine(mappath, mapE.GetAttribute("Filename")); + string mappath = Path.Combine("ScriptEngines", World.RegionInfo.RegionID.ToString()); + mappath = Path.Combine(mappath, mapE.GetAttribute("Filename")); - FileStream mfs = File.Create(mappath); - StreamWriter msw = new StreamWriter(mfs); + FileStream mfs = File.Create(mappath); + StreamWriter msw = new StreamWriter(mfs); - msw.Write(mapE.InnerText); + msw.Write(mapE.InnerText); - msw.Close(); - mfs.Close(); + msw.Close(); + mfs.Close(); + } + + return true; } } }