From 567f4c51f85e61205c8b1caaab207bc6f979f04f Mon Sep 17 00:00:00 2001
From: Melanie
Date: Thu, 2 Feb 2012 01:52:17 +0000
Subject: Improve reliability of script state saving by covering various saving
and loading scenarios which resulted in loss of continuity on item ids
---
OpenSim/Framework/TaskInventoryItem.cs | 11 +++++++++
.../Framework/Scenes/SceneObjectPartInventory.cs | 26 +++++++++++++---------
.../Scenes/Serialization/SceneObjectSerializer.cs | 5 +----
3 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/OpenSim/Framework/TaskInventoryItem.cs b/OpenSim/Framework/TaskInventoryItem.cs
index ba2a306..d4bbbfb 100644
--- a/OpenSim/Framework/TaskInventoryItem.cs
+++ b/OpenSim/Framework/TaskInventoryItem.cs
@@ -65,6 +65,7 @@ namespace OpenSim.Framework
private int _permsMask;
private int _type = 0;
private UUID _oldID;
+ private UUID _loadedID = UUID.Zero;
private bool _ownerChanged = false;
@@ -231,6 +232,15 @@ namespace OpenSim.Framework
}
}
+ public UUID LoadedItemID {
+ get {
+ return _loadedID;
+ }
+ set {
+ _loadedID = value;
+ }
+ }
+
public UUID LastOwnerID {
get {
return _lastOwnerID;
@@ -347,6 +357,7 @@ namespace OpenSim.Framework
/// The new part ID to which this item belongs
public void ResetIDs(UUID partID)
{
+ LoadedItemID = OldItemID;
OldItemID = ItemID;
ItemID = UUID.Random();
ParentPartID = partID;
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
index daddb90..0c36dcd 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs
@@ -307,14 +307,15 @@ namespace OpenSim.Region.Framework.Scenes
else
{
if (m_part.ParentGroup.m_savedScriptState != null)
- RestoreSavedScriptState(item.OldItemID, item.ItemID);
+ item.OldItemID = RestoreSavedScriptState(item.LoadedItemID, item.OldItemID, item.ItemID);
lock (m_items)
{
+ m_items[item.ItemID].OldItemID = item.OldItemID;
m_items[item.ItemID].PermsMask = 0;
m_items[item.ItemID].PermsGranter = UUID.Zero;
}
-
+
string script = Utils.BytesToString(asset.Data);
m_part.ParentGroup.Scene.EventManager.TriggerRezScript(
m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource);
@@ -324,17 +325,20 @@ namespace OpenSim.Region.Framework.Scenes
}
}
- private void RestoreSavedScriptState(UUID oldID, UUID newID)
+ private UUID RestoreSavedScriptState(UUID loadedID, UUID oldID, UUID newID)
{
IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces();
if (engines.Length == 0) // No engine at all
- return;
+ return oldID;
- if (m_part.ParentGroup.m_savedScriptState.ContainsKey(oldID))
+ UUID stateID = oldID;
+ if (!m_part.ParentGroup.m_savedScriptState.ContainsKey(oldID))
+ stateID = loadedID;
+ if (m_part.ParentGroup.m_savedScriptState.ContainsKey(stateID))
{
XmlDocument doc = new XmlDocument();
- doc.LoadXml(m_part.ParentGroup.m_savedScriptState[oldID]);
+ doc.LoadXml(m_part.ParentGroup.m_savedScriptState[stateID]);
////////// CRUFT WARNING ///////////////////////////////////
//
@@ -351,7 +355,7 @@ namespace OpenSim.Region.Framework.Scenes
XmlElement rootN = newDoc.CreateElement("", "State", "");
XmlAttribute uuidA = newDoc.CreateAttribute("", "UUID", "");
- uuidA.Value = oldID.ToString();
+ uuidA.Value = stateID.ToString();
rootN.Attributes.Append(uuidA);
XmlAttribute engineA = newDoc.CreateAttribute("", "Engine", "");
engineA.Value = "XEngine";
@@ -365,20 +369,22 @@ namespace OpenSim.Region.Framework.Scenes
// This created document has only the minimun data
// necessary for XEngine to parse it successfully
- m_part.ParentGroup.m_savedScriptState[oldID] = newDoc.OuterXml;
+ m_part.ParentGroup.m_savedScriptState[stateID] = newDoc.OuterXml;
}
foreach (IScriptModule e in engines)
{
if (e != null)
{
- if (e.SetXMLState(newID, m_part.ParentGroup.m_savedScriptState[oldID]))
+ if (e.SetXMLState(newID, m_part.ParentGroup.m_savedScriptState[stateID]))
break;
}
}
- m_part.ParentGroup.m_savedScriptState.Remove(oldID);
+ m_part.ParentGroup.m_savedScriptState.Remove(stateID);
}
+
+ return stateID;
}
///
diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs
index 3a08271..b54fcb7 100644
--- a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs
+++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs
@@ -794,10 +794,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
private static void ProcessTIOldItemID(TaskInventoryItem item, XmlTextReader reader)
{
- Util.ReadUUID(reader, "OldItemID");
- // On deserialization, the old item id MUST BE UUID.Zero!!!!!
- // Setting this to the saved value will BREAK script persistence!
- // item.OldItemID = Util.ReadUUID(reader, "OldItemID");
+ item.OldItemID = Util.ReadUUID(reader, "OldItemID");
}
private static void ProcessTILastOwnerID(TaskInventoryItem item, XmlTextReader reader)
--
cgit v1.1