From 2f84f2171fb7e17f6c336a4e6db9a04ad822704a Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 21 Dec 2010 20:47:00 +0000 Subject: [PATCH] Make prim inventories a bit more sane --- .../Framework/Interfaces/IEntityInventory.cs | 7 -- .../Framework/Scenes/Scene.Inventory.cs | 23 ++---- .../Scenes/SceneObjectGroup.Inventory.cs | 43 ----------- .../Scenes/SceneObjectPartInventory.cs | 76 ++++++++----------- 4 files changed, 39 insertions(+), 110 deletions(-) diff --git a/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs b/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs index ed40da9609..4b17b9a71f 100644 --- a/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs +++ b/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs @@ -195,13 +195,6 @@ namespace OpenSim.Region.Framework.Interfaces /// in this prim's inventory. int RemoveInventoryItem(UUID itemID); - /// - /// Return the name with which a client can request a xfer of this prim's inventory metadata - /// - string GetInventoryFileName(); - - bool GetInventoryFileName(IClientAPI client, uint localID); - /// /// Serialize all the metadata for the items in this prim's inventory ready for sending to the client /// diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index a1f1ea5489..47c574a2e4 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -951,23 +951,12 @@ namespace OpenSim.Region.Framework.Scenes /// public void RequestTaskInventory(IClientAPI remoteClient, uint primLocalID) { - SceneObjectGroup group = GetGroupByPrim(primLocalID); - if (group != null) - { - bool fileChange = group.GetPartInventoryFileName(remoteClient, primLocalID); - if (fileChange) - { - if (XferManager != null) - { - group.RequestInventoryFile(remoteClient, primLocalID, XferManager); - } - } - } - else - { - m_log.ErrorFormat( - "[PRIM INVENTORY]: Inventory requested of prim {0} which doesn't exist", primLocalID); - } + SceneObjectPart part = GetSceneObjectPart(primLocalID); + if (part == null) + return; + + if (XferManager != null) + part.Inventory.RequestInventoryFile(remoteClient, XferManager); } /// diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs index 6cc7231502..50521c45ab 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.Inventory.cs @@ -76,49 +76,6 @@ namespace OpenSim.Region.Framework.Scenes parts[i].Inventory.RemoveScriptInstances(sceneObjectBeingDeleted); } - /// - /// - /// - /// - /// - public bool GetPartInventoryFileName(IClientAPI remoteClient, uint localID) - { - SceneObjectPart part = GetChildPart(localID); - if (part != null) - { - return part.Inventory.GetInventoryFileName(remoteClient, localID); - } - else - { - m_log.ErrorFormat( - "[PRIM INVENTORY]: " + - "Couldn't find part {0} in object group {1}, {2} to retreive prim inventory", - localID, Name, UUID); - } - return false; - } - - /// - /// Return serialized inventory metadata for the given constituent prim - /// - /// - /// - public void RequestInventoryFile(IClientAPI client, uint localID, IXfer xferManager) - { - SceneObjectPart part = GetChildPart(localID); - if (part != null) - { - part.Inventory.RequestInventoryFile(client, xferManager); - } - else - { - m_log.ErrorFormat( - "[PRIM INVENTORY]: " + - "Couldn't find part {0} in object group {1}, {2} to request inventory data", - localID, Name, UUID); - } - } - /// /// Add an inventory item to a prim in this group. /// diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs index 8fcfcc5e75..74b4e54016 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs @@ -46,6 +46,7 @@ namespace OpenSim.Region.Framework.Scenes private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private string m_inventoryFileName = String.Empty; + private byte[] m_inventoryFileData = new byte[0]; private int m_inventoryFileNameSerial = 0; private Dictionary m_scriptErrors = new Dictionary(); @@ -930,39 +931,16 @@ namespace OpenSim.Region.Framework.Scenes return -1; } - public string GetInventoryFileName() + private bool CreateInventoryFileName() { - if (m_inventoryFileName == String.Empty) - m_inventoryFileName = "inventory_" + UUID.Random().ToString() + ".tmp"; - if (m_inventoryFileNameSerial < m_inventorySerial) + if (m_inventoryFileName == String.Empty || + m_inventoryFileNameSerial < m_inventorySerial) { m_inventoryFileName = "inventory_" + UUID.Random().ToString() + ".tmp"; - } - return m_inventoryFileName; - } - - /// - /// Return the name with which a client can request a xfer of this prim's inventory metadata - /// - /// - /// - public bool GetInventoryFileName(IClientAPI client, uint localID) - { -// m_log.DebugFormat( -// "[PRIM INVENTORY]: Received request from client {0} for inventory file name of {1}, {2}", -// client.AgentId, Name, UUID); - - if (m_inventorySerial > 0) - { - client.SendTaskInventory(m_part.UUID, (short)m_inventorySerial, - Utils.StringToBytes(GetInventoryFileName())); return true; } - else - { - client.SendTaskInventory(m_part.UUID, 0, new byte[0]); - return false; - } + + return false; } /// @@ -971,19 +949,34 @@ namespace OpenSim.Region.Framework.Scenes /// public void RequestInventoryFile(IClientAPI client, IXfer xferManager) { - byte[] fileData = new byte[0]; + bool changed = CreateInventoryFileName(); - // Confusingly, the folder item has to be the object id, while the 'parent id' has to be zero. This matches - // what appears to happen in the Second Life protocol. If this isn't the case. then various functionality - // isn't available (such as drag from prim inventory to agent inventory) InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero); - bool includeAssets = false; - if (m_part.ParentGroup.Scene.Permissions.CanEditObjectInventory(m_part.UUID, client.AgentId)) - includeAssets = true; - lock (m_items) { + if (m_inventorySerial == 0) // No inventory + { + client.SendTaskInventory(m_part.UUID, 0, new byte[0]); + return; + } + + client.SendTaskInventory(m_part.UUID, (short)m_inventorySerial, + Util.StringToBytes256(m_inventoryFileName)); + + if (!changed) + { + if (m_inventoryFileData.Length > 2) + { + xferManager.AddNewFile(m_inventoryFileName, + m_inventoryFileData); + } + } + + bool includeAssets = false; + if (m_part.ParentGroup.Scene.Permissions.CanEditObjectInventory(m_part.UUID, client.AgentId)) + includeAssets = true; + foreach (TaskInventoryItem item in m_items.Values) { UUID ownerID = item.OwnerID; @@ -1032,17 +1025,14 @@ namespace OpenSim.Region.Framework.Scenes invString.AddSectionEnd(); } } + int count = m_items.Count; - m_items.LockItemsForRead(false); - fileData = Utils.StringToBytes(invString.BuildString); + m_inventoryFileData = Utils.StringToBytes(invString.BuildString); - //m_log.Debug(Utils.BytesToString(fileData)); - //m_log.Debug("[PRIM INVENTORY]: RequestInventoryFile fileData: " + Utils.BytesToString(fileData)); - - if (fileData.Length > 2) + if (m_inventoryFileData.Length > 2) { - xferManager.AddNewFile(m_inventoryFileName, fileData); + xferManager.AddNewFile(m_inventoryFileName, m_inventoryFileData); } }