From 8f58a9a107047bf9d9aff4d8c25171acaa8e9805 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Mon, 3 Dec 2007 20:06:01 +0000 Subject: From Justin Casey (IBM) While exploring what it would take to get the 'new script' button working, I encountered the fact, some way down in the rabbit hole, that if a user renamed an item in their inventory and logged out (without a restart of the simulator), on log in the new name was not preserved. As far as I can see, this was because any updates which didn't occur inside a transaction were ignored by opensim. This patch pays attention to those changes. It generates a new asset when an item is updated and changes the user's inventory properties appropriately. I believe this behaviour is in line with the copy-on-write semantics used in the Second Life protocol - perhaps it could be optimized if we knew for sure that the only copy of the object was in the user's inventory. This also means that if you rename an item (e.g. a script) before you drag it into an object's inventory, the inventory will receive the item's most recent name and description. --- .../Region/Environment/Scenes/Scene.Inventory.cs | 119 +++++++++++++++------ OpenSim/Region/Environment/Scenes/Scene.cs | 2 +- 2 files changed, 88 insertions(+), 33 deletions(-) (limited to 'OpenSim/Region/Environment/Scenes') diff --git a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs index 1ea8d5a..5976fdc 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs @@ -106,53 +106,108 @@ namespace OpenSim.Region.Environment.Scenes return LLUUID.Zero; } - public void UDPUpdateInventoryItemAsset(IClientAPI remoteClient, LLUUID transactionID, LLUUID assetID, - LLUUID itemID) - { - CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId); - if (userInfo != null) + /// + /// Update an item which is either already in the client's inventory or is within + /// a transaction + /// + /// + /// The transaction ID. If this is LLUUID.Zero we will + /// assume that we are not in a transaction + /// The ID of the updated item + /// The name of the updated item + /// The description of the updated item + /// The permissions of the updated item + public void UpdateInventoryItemAsset(IClientAPI remoteClient, LLUUID transactionID, + LLUUID itemID, string name, string description, + uint nextOwnerMask) + { + CachedUserInfo userInfo + = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId); + + if (userInfo != null && userInfo.RootFolder != null) { - if (userInfo.RootFolder != null) + InventoryItemBase item = userInfo.RootFolder.HasItem(itemID); + if (item != null) { - InventoryItemBase item = userInfo.RootFolder.HasItem(itemID); - if (item != null) + AssetBase asset = null; + bool addAsset = false; + + // If we're not inside a transaction and an existing asset is attached + // to the update item, then we need to create a new asset for the new details + if (LLUUID.Zero == transactionID) + { + asset = AssetCache.GetAsset(item.assetID); + + if (asset != null) + { + // to update an item we need to create a new asset + // it's possible that this could be optimized to an update if we knew + // that the owner's inventory had the only copy of the item (I believe + // we're using copy on write semantics). + item.inventoryName = asset.Name = name; + item.inventoryDescription = asset.Description = description; + item.inventoryNextPermissions = nextOwnerMask; + item.assetID = asset.FullID = LLUUID.Random(); + + addAsset = true; + } + else + { + OpenSim.Framework.Console.MainLog.Instance.Warn( + "Asset ID " + item.assetID + " not found for item ID " + itemID + + " named " + item.inventoryName + " for an inventory item update."); + return; + } + } + else { - AgentAssetTransactions transactions = - CommsManager.TransactionsManager.GetUserTransActions(remoteClient.AgentId); + AgentAssetTransactions transactions + = CommsManager.TransactionsManager.GetUserTransActions(remoteClient.AgentId); + if (transactions != null) { - AssetBase asset = null; - bool addToCache = false; - + LLUUID assetID = transactionID.Combine(remoteClient.SecureSessionId); asset = AssetCache.GetAsset(assetID); + if (asset == null) { asset = transactions.GetTransactionAsset(transactionID); - addToCache = true; } - - if (asset != null) + + if (asset != null && asset.FullID == assetID) { - if (asset.FullID == assetID) - { - asset.Name = item.inventoryName; - asset.Description = item.inventoryDescription; - asset.InvType = (sbyte) item.invType; - asset.Type = (sbyte) item.assetType; - item.assetID = asset.FullID; - - if (addToCache) - { - AssetCache.AddAsset(asset); - } - - userInfo.UpdateItem(remoteClient.AgentId, item); - } + asset.Name = item.inventoryName; + asset.Description = item.inventoryDescription; + asset.InvType = (sbyte) item.invType; + asset.Type = (sbyte) item.assetType; + item.assetID = asset.FullID; + + addAsset = true; } } } + + if (asset != null) + { + if (addAsset) + { + AssetCache.AddAsset(asset); + } + + userInfo.UpdateItem(remoteClient.AgentId, item); + } + } + else + { + OpenSim.Framework.Console.MainLog.Instance.Warn( + "Item ID " + itemID + " not found for an inventory item update."); } } + else + { + OpenSim.Framework.Console.MainLog.Instance.Warn( + "Agent ID " + remoteClient.AgentId + " not found for an inventory item update."); + } } public void CopyInventoryItem(IClientAPI remoteClient, uint callbackID, LLUUID oldAgentID, LLUUID oldItemID, LLUUID newFolderID, string newName) @@ -507,4 +562,4 @@ namespace OpenSim.Region.Environment.Scenes rootPart.ScheduleFullUpdate(); } } -} \ No newline at end of file +} diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 09ecae0..8fc04c4 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -989,7 +989,7 @@ namespace OpenSim.Region.Environment.Scenes client.OnFetchInventoryDescendents += CommsManager.UserProfileCacheService.HandleFecthInventoryDescendents; client.OnRequestTaskInventory += RequestTaskInventory; client.OnFetchInventory += CommsManager.UserProfileCacheService.HandleFetchInventory; - client.OnUpdateInventoryItem += UDPUpdateInventoryItemAsset; + client.OnUpdateInventoryItem += UpdateInventoryItemAsset; client.OnCopyInventoryItem += CopyInventoryItem; client.OnAssetUploadRequest += CommsManager.TransactionsManager.HandleUDPUploadRequest; client.OnXferReceive += CommsManager.TransactionsManager.HandleXfer; -- cgit v1.1