From 8f58a9a107047bf9d9aff4d8c25171acaa8e9805 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Mon, 3 Dec 2007 20:06:01 +0000 Subject: [PATCH] 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. --- OpenSim/Framework/IClientAPI.cs | 11 +- OpenSim/Region/ClientStack/ClientView.cs | 32 +++-- .../Environment/Scenes/Scene.Inventory.cs | 119 +++++++++++++----- OpenSim/Region/Environment/Scenes/Scene.cs | 2 +- .../Examples/SimpleApp/MyNpcCharacter.cs | 7 +- 5 files changed, 120 insertions(+), 51 deletions(-) diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs index a3177f70e3..68a059157f 100644 --- a/OpenSim/Framework/IClientAPI.cs +++ b/OpenSim/Framework/IClientAPI.cs @@ -310,8 +310,9 @@ namespace OpenSim.Framework public delegate void RequestTaskInventory(IClientAPI remoteClient, uint localID); - public delegate void UpdateInventoryItemTransaction( - IClientAPI remoteClient, LLUUID transactionID, LLUUID assetID, LLUUID itemID); + public delegate void UpdateInventoryItem( + IClientAPI remoteClient, LLUUID transactionID, LLUUID itemID, string name, string description, + uint nextOwnerMask); public delegate void CopyInventoryItem( IClientAPI remoteClient, uint callbackID, LLUUID oldAgentID, LLUUID oldItemID, LLUUID newFolderID, string newName); @@ -392,7 +393,7 @@ namespace OpenSim.Framework event FetchInventoryDescendents OnFetchInventoryDescendents; event FetchInventory OnFetchInventory; event RequestTaskInventory OnRequestTaskInventory; - event UpdateInventoryItemTransaction OnUpdateInventoryItem; + event UpdateInventoryItem OnUpdateInventoryItem; event CopyInventoryItem OnCopyInventoryItem; event UDPAssetUploadRequest OnAssetUploadRequest; event XferReceive OnXferReceive; @@ -417,6 +418,8 @@ namespace OpenSim.Framework LLUUID AgentId { get; } LLUUID SessionId { get; } + + LLUUID SecureSessionId { get; } string FirstName { get; } @@ -481,7 +484,7 @@ namespace OpenSim.Framework /// /// Tell the client that we have created the item it requested. /// - /// + /// void SendInventoryItemCreateUpdate(InventoryItemBase Item); void SendRemoveInventoryItem(LLUUID itemID); diff --git a/OpenSim/Region/ClientStack/ClientView.cs b/OpenSim/Region/ClientStack/ClientView.cs index f04a70a20b..1c16a95c7c 100644 --- a/OpenSim/Region/ClientStack/ClientView.cs +++ b/OpenSim/Region/ClientStack/ClientView.cs @@ -59,7 +59,14 @@ namespace OpenSim.Region.ClientStack //local handlers for this instance private LLUUID m_sessionId; - public LLUUID SecureSessionID = LLUUID.Zero; + + private LLUUID m_secureSessionId = LLUUID.Zero; + + public LLUUID SecureSessionId + { + get { return m_secureSessionId; } + } + public string firstName; public string lastName; private UseCircuitCodePacket cirpack; @@ -540,7 +547,7 @@ namespace OpenSim.Region.ClientStack if (sessionInfo.LoginInfo.SecureSession != LLUUID.Zero) { - SecureSessionID = sessionInfo.LoginInfo.SecureSession; + m_secureSessionId = sessionInfo.LoginInfo.SecureSession; } InitNewClient(); @@ -615,7 +622,7 @@ namespace OpenSim.Region.ClientStack public event FetchInventoryDescendents OnFetchInventoryDescendents; public event FetchInventory OnFetchInventory; public event RequestTaskInventory OnRequestTaskInventory; - public event UpdateInventoryItemTransaction OnUpdateInventoryItem; + public event UpdateInventoryItem OnUpdateInventoryItem; public event CopyInventoryItem OnCopyInventoryItem; public event UDPAssetUploadRequest OnAssetUploadRequest; public event XferReceive OnXferReceive; @@ -888,7 +895,7 @@ namespace OpenSim.Region.ClientStack AgentCircuitData agentData = new AgentCircuitData(); agentData.AgentID = AgentId; agentData.SessionID = m_sessionId; - agentData.SecureSessionID = SecureSessionID; + agentData.SecureSessionID = SecureSessionId; agentData.circuitcode = m_circuitCode; agentData.child = false; agentData.firstname = firstName; @@ -2953,10 +2960,10 @@ namespace OpenSim.Region.ClientStack case PacketType.AssetUploadRequest: AssetUploadRequestPacket request = (AssetUploadRequestPacket) Pack; // Console.WriteLine("upload request " + Pack.ToString()); - // Console.WriteLine("upload request was for assetid: " + request.AssetBlock.TransactionID.Combine(this.SecureSessionID).ToStringHyphenated()); + // Console.WriteLine("upload request was for assetid: " + request.AssetBlock.TransactionID.Combine(this.SecureSessionId).ToStringHyphenated()); if (OnAssetUploadRequest != null) { - OnAssetUploadRequest(this, request.AssetBlock.TransactionID.Combine(SecureSessionID), + OnAssetUploadRequest(this, request.AssetBlock.TransactionID.Combine(SecureSessionId), request.AssetBlock.TransactionID, request.AssetBlock.Type, request.AssetBlock.AssetData, request.AssetBlock.StoreLocal); } @@ -3033,12 +3040,11 @@ namespace OpenSim.Region.ClientStack { for (int i = 0; i < update.InventoryData.Length; i++) { - if (update.InventoryData[i].TransactionID != LLUUID.Zero) - { - OnUpdateInventoryItem(this, update.InventoryData[i].TransactionID, - update.InventoryData[i].TransactionID.Combine(SecureSessionID), - update.InventoryData[i].ItemID); - } + OnUpdateInventoryItem(this, update.InventoryData[i].TransactionID, + update.InventoryData[i].ItemID, + Util.FieldToString(update.InventoryData[i].Name), + Util.FieldToString(update.InventoryData[i].Description), + update.InventoryData[i].NextOwnerMask); } } //Console.WriteLine(Pack.ToString()); @@ -3046,7 +3052,7 @@ namespace OpenSim.Region.ClientStack { if (update.InventoryData[i].TransactionID != LLUUID.Zero) { - AssetBase asset = m_assetCache.GetAsset(update.InventoryData[i].TransactionID.Combine(this.SecureSessionID)); + AssetBase asset = m_assetCache.GetAsset(update.InventoryData[i].TransactionID.Combine(this.SecureSessionId)); if (asset != null) { // Console.WriteLine("updating inventory item, found asset" + asset.FullID.ToStringHyphenated() + " already in cache"); diff --git a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs index 1ea8d5a136..5976fdc314 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs @@ -106,52 +106,107 @@ 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) { - AgentAssetTransactions transactions = - CommsManager.TransactionsManager.GetUserTransActions(remoteClient.AgentId); + 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); + 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."); } } @@ -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 09ecae07a7..8fc04c4f33 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; diff --git a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs index 6887debaed..69cf7b32bc 100644 --- a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs +++ b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs @@ -108,7 +108,7 @@ namespace SimpleApp public event FetchInventoryDescendents OnFetchInventoryDescendents; public event FetchInventory OnFetchInventory; public event RequestTaskInventory OnRequestTaskInventory; - public event UpdateInventoryItemTransaction OnUpdateInventoryItem; + public event UpdateInventoryItem OnUpdateInventoryItem; public event CopyInventoryItem OnCopyInventoryItem; public event UDPAssetUploadRequest OnAssetUploadRequest; public event XferReceive OnXferReceive; @@ -157,6 +157,11 @@ namespace SimpleApp { get { return LLUUID.Zero; } } + + public LLUUID SecureSessionId + { + get { return LLUUID.Zero; } + } public virtual string FirstName {