Improve reliability of script state saving by covering various saving

and loading scenarios which resulted in loss of continuity on item ids
iar_mods
Melanie 2012-02-02 01:52:17 +00:00
parent 003bd9f1b3
commit 567f4c51f8
3 changed files with 28 additions and 14 deletions

View File

@ -65,6 +65,7 @@ namespace OpenSim.Framework
private int _permsMask; private int _permsMask;
private int _type = 0; private int _type = 0;
private UUID _oldID; private UUID _oldID;
private UUID _loadedID = UUID.Zero;
private bool _ownerChanged = false; private bool _ownerChanged = false;
@ -231,6 +232,15 @@ namespace OpenSim.Framework
} }
} }
public UUID LoadedItemID {
get {
return _loadedID;
}
set {
_loadedID = value;
}
}
public UUID LastOwnerID { public UUID LastOwnerID {
get { get {
return _lastOwnerID; return _lastOwnerID;
@ -347,6 +357,7 @@ namespace OpenSim.Framework
/// <param name="partID">The new part ID to which this item belongs</param> /// <param name="partID">The new part ID to which this item belongs</param>
public void ResetIDs(UUID partID) public void ResetIDs(UUID partID)
{ {
LoadedItemID = OldItemID;
OldItemID = ItemID; OldItemID = ItemID;
ItemID = UUID.Random(); ItemID = UUID.Random();
ParentPartID = partID; ParentPartID = partID;

View File

@ -307,10 +307,11 @@ namespace OpenSim.Region.Framework.Scenes
else else
{ {
if (m_part.ParentGroup.m_savedScriptState != null) if (m_part.ParentGroup.m_savedScriptState != null)
RestoreSavedScriptState(item.OldItemID, item.ItemID); item.OldItemID = RestoreSavedScriptState(item.LoadedItemID, item.OldItemID, item.ItemID);
lock (m_items) lock (m_items)
{ {
m_items[item.ItemID].OldItemID = item.OldItemID;
m_items[item.ItemID].PermsMask = 0; m_items[item.ItemID].PermsMask = 0;
m_items[item.ItemID].PermsGranter = UUID.Zero; m_items[item.ItemID].PermsGranter = UUID.Zero;
} }
@ -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<IScriptModule>(); IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces<IScriptModule>();
if (engines.Length == 0) // No engine at all 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(); XmlDocument doc = new XmlDocument();
doc.LoadXml(m_part.ParentGroup.m_savedScriptState[oldID]); doc.LoadXml(m_part.ParentGroup.m_savedScriptState[stateID]);
////////// CRUFT WARNING /////////////////////////////////// ////////// CRUFT WARNING ///////////////////////////////////
// //
@ -351,7 +355,7 @@ namespace OpenSim.Region.Framework.Scenes
XmlElement rootN = newDoc.CreateElement("", "State", ""); XmlElement rootN = newDoc.CreateElement("", "State", "");
XmlAttribute uuidA = newDoc.CreateAttribute("", "UUID", ""); XmlAttribute uuidA = newDoc.CreateAttribute("", "UUID", "");
uuidA.Value = oldID.ToString(); uuidA.Value = stateID.ToString();
rootN.Attributes.Append(uuidA); rootN.Attributes.Append(uuidA);
XmlAttribute engineA = newDoc.CreateAttribute("", "Engine", ""); XmlAttribute engineA = newDoc.CreateAttribute("", "Engine", "");
engineA.Value = "XEngine"; engineA.Value = "XEngine";
@ -365,20 +369,22 @@ namespace OpenSim.Region.Framework.Scenes
// This created document has only the minimun data // This created document has only the minimun data
// necessary for XEngine to parse it successfully // 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) foreach (IScriptModule e in engines)
{ {
if (e != null) if (e != null)
{ {
if (e.SetXMLState(newID, m_part.ParentGroup.m_savedScriptState[oldID])) if (e.SetXMLState(newID, m_part.ParentGroup.m_savedScriptState[stateID]))
break; break;
} }
} }
m_part.ParentGroup.m_savedScriptState.Remove(oldID); m_part.ParentGroup.m_savedScriptState.Remove(stateID);
} }
return stateID;
} }
/// <summary> /// <summary>

View File

@ -794,10 +794,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
private static void ProcessTIOldItemID(TaskInventoryItem item, XmlTextReader reader) private static void ProcessTIOldItemID(TaskInventoryItem item, XmlTextReader reader)
{ {
Util.ReadUUID(reader, "OldItemID"); item.OldItemID = 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");
} }
private static void ProcessTILastOwnerID(TaskInventoryItem item, XmlTextReader reader) private static void ProcessTILastOwnerID(TaskInventoryItem item, XmlTextReader reader)