From 7ee1f3dff64144050cc0f0f5e9e89fe68ccc0ae0 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Fri, 26 Sep 2008 14:28:24 +0000 Subject: * Implment task inventory item asset update for the old non CAPS transaction system * This means that saving notecards in prim inventories should now work. * Not the nicest code in the world - the transactions system is pretty fugly right now * PLEASE NOTE: Currently, the prim will not repersist until up to 15 seconds after it is unselected. * What we really need is a proper mechanism so that any prim updates still waiting when the simulator is quit are performed before exit. --- .../AssetTransaction/AgentAssetsTransactions.cs | 52 +++++++++++++++------ .../AssetTransaction/AssetTransactionModule.cs | 53 ++++++++++++++++------ 2 files changed, 75 insertions(+), 30 deletions(-) (limited to 'OpenSim/Region/Environment/Modules/Agent/AssetTransaction') diff --git a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetsTransactions.cs b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetsTransactions.cs index c46c4a4..b32d199 100644 --- a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetsTransactions.cs +++ b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetsTransactions.cs @@ -28,10 +28,13 @@ using System; using System.Collections.Generic; using System.IO; +using System.Reflection; +using log4net; using OpenMetaverse; using OpenMetaverse.Packets; using OpenSim.Framework; using OpenSim.Framework.Communications.Cache; +using OpenSim.Region.Environment.Scenes; namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction { @@ -74,9 +77,7 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction } public void HandleXfer(ulong xferID, uint packetID, byte[] data) - { - // AssetXferUploader uploaderFound = null; - + { lock (XferUploaders) { foreach (AssetXferUploader uploader in XferUploaders.Values) @@ -110,6 +111,15 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction XferUploaders[transactionID].RequestUpdateInventoryItem(remoteClient, transactionID, item); } } + + public void RequestUpdateTaskInventoryItem( + IClientAPI remoteClient, SceneObjectPart part, UUID transactionID, TaskInventoryItem item) + { + if (XferUploaders.ContainsKey(transactionID)) + { + XferUploaders[transactionID].RequestUpdateTaskInventoryItem(remoteClient, part, transactionID, item); + } + } /// /// Get an uploaded asset. If the data is successfully retrieved, the transaction will be removed. @@ -140,6 +150,8 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction public class AssetXferUploader { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + // Fields public bool AddToInventory; public AssetBase Asset; @@ -225,6 +237,7 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction TransactionID = transaction; m_storeLocal = storeLocal; + if (Asset.Data.Length > 2) { SendCompleteMessage(); @@ -251,7 +264,6 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction ourClient.SendAssetUploadCompleteMessage(Asset.Type, true, Asset.FullID); - m_finished = true; if (m_createItem) { @@ -262,7 +274,7 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset); } - // Console.WriteLine("upload complete "+ this.TransactionID); + m_log.DebugFormat("[ASSET TRANSACTIONS]: Uploaded asset data for transaction {0}", TransactionID); if (m_dumpAssetToFile) { @@ -274,15 +286,6 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction } } - ///Left this in and commented in case there are unforseen issues - //private void SaveAssetToFile(string filename, byte[] data) - //{ - // FileStream fs = File.Create(filename); - // BinaryWriter bw = new BinaryWriter(fs); - // bw.Write(data); - // bw.Close(); - // fs.Close(); - //} private void SaveAssetToFile(string filename, byte[] data) { string assetPath = "UserAssets"; @@ -314,6 +317,7 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction Asset.Description = description; Asset.Type = type; m_createItem = true; + if (m_finished) { DoCreateItem(); @@ -359,7 +363,25 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction } } } - + + public void RequestUpdateTaskInventoryItem( + IClientAPI remoteClient, SceneObjectPart part, UUID transactionID, TaskInventoryItem item) + { + m_log.DebugFormat( + "[ASSET TRANSACTIONS]: Updating task item {0} in {1} with asset in transaction {2}", + item.Name, part.Name, transactionID); + + Asset.Name = item.Name; + Asset.Description = item.Description; + Asset.Type = (sbyte) item.Type; + item.AssetID = Asset.FullID; + + m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset); + + if (part.UpdateInventoryItem(item)) + part.GetProperties(remoteClient); + } + private void DoCreateItem() { //really need to fix this call, if lbsa71 saw this he would die. diff --git a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs index e6e27be..56ca1a1 100644 --- a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs +++ b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs @@ -61,11 +61,16 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction wearableType, nextOwnerMask); } - public void HandleItemUpdateFromTransaction(IClientAPI remoteClient, UUID transactionID, - InventoryItemBase item) + public void HandleItemUpdateFromTransaction(IClientAPI remoteClient, UUID transactionID, InventoryItemBase item) { m_transactionManager.HandleItemUpdateFromTransaction(remoteClient, transactionID, item); } + + public void HandleTaskItemUpdateFromTransaction( + IClientAPI remoteClient, SceneObjectPart part, UUID transactionID, TaskInventoryItem item) + { + m_transactionManager.HandleTaskItemUpdateFromTransaction(remoteClient, part, transactionID, item); + } public void RemoveAgentAssetTransactions(UUID userID) { @@ -141,8 +146,6 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - // Fields - /// /// Each agent has its own singleton collection of transactions /// @@ -218,8 +221,8 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction uint callbackID, string description, string name, sbyte invType, sbyte type, byte wearableType, uint nextOwnerMask) { - m_log.DebugFormat( - "[TRANSACTIONS MANAGER] Called HandleItemCreationFromTransaction with item {0}", name); +// m_log.DebugFormat( +// "[TRANSACTIONS MANAGER] Called HandleItemCreationFromTransaction with item {0}", name); AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); @@ -240,15 +243,36 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction public void HandleItemUpdateFromTransaction(IClientAPI remoteClient, UUID transactionID, InventoryItemBase item) { - m_log.DebugFormat( - "[TRANSACTIONS MANAGER] Called HandleItemUpdateFromTransaction with item {0}", - item.Name); +// m_log.DebugFormat( +// "[TRANSACTIONS MANAGER] Called HandleItemUpdateFromTransaction with item {0}", +// item.Name); - AgentAssetTransactions transactions - = GetUserTransactions(remoteClient.AgentId); + AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); transactions.RequestUpdateInventoryItem(remoteClient, transactionID, item); } + + /// + /// Update a task inventory item with data that has been received through a transaction. + /// + /// This is currently called when, for instance, a notecard in a prim is saved. The data is sent + /// up through a single AssetUploadRequest. A subsequent UpdateTaskInventory then references the transaction + /// and comes through this method. + /// + /// + /// + /// + public void HandleTaskItemUpdateFromTransaction( + IClientAPI remoteClient, SceneObjectPart part, UUID transactionID, TaskInventoryItem item) + { +// m_log.DebugFormat( +// "[TRANSACTIONS MANAGER] Called HandleTaskItemUpdateFromTransaction with item {0}", +// item.Name); + + AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); + + transactions.RequestUpdateTaskInventoryItem(remoteClient, part, transactionID, item); + } /// /// Request that a client (agent) begin an asset transfer. @@ -270,6 +294,7 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction { Scene scene = (Scene)remoteClient.Scene; IMoneyModule mm = scene.RequestModuleInterface(); + if (mm != null) { if (!mm.UploadCovered(remoteClient)) @@ -280,15 +305,13 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction } } - // Console.WriteLine("asset upload of " + assetID); + //Console.WriteLine("asset upload of " + assetID); AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); AgentAssetTransactions.AssetXferUploader uploader = transactions.RequestXferUploader(transaction); if (uploader != null) { - if (uploader.Initialise(remoteClient, assetID, transaction, type, data, storeLocal, tempFile)) - { - } + uploader.Initialise(remoteClient, assetID, transaction, type, data, storeLocal, tempFile); } } -- cgit v1.1