AgentAssetTransactionsManager.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. //moved to a module, left here until the module is found to have no problems
  28. /*
  29. using System;
  30. using System.Collections.Generic;
  31. using libsecondlife;
  32. namespace OpenSim.Framework.Communications.Cache
  33. {
  34. /// <summary>
  35. /// Provider handlers for processing asset transactions originating from the agent. This encompasses
  36. /// clothing creation and update as well as asset uploads.
  37. /// </summary>
  38. public class AgentAssetTransactionsManager
  39. {
  40. private static readonly log4net.ILog m_log
  41. = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  42. // Fields
  43. public CommunicationsManager CommsManager;
  44. /// <summary>
  45. /// Each agent has its own singleton collection of transactions
  46. /// </summary>
  47. private Dictionary<LLUUID, AgentAssetTransactions> AgentTransactions =
  48. new Dictionary<LLUUID, AgentAssetTransactions>();
  49. /// <summary>
  50. /// Should we dump uploaded assets to the filesystem?
  51. /// </summary>
  52. private bool m_dumpAssetsToFile;
  53. public AgentAssetTransactionsManager(CommunicationsManager commsManager, bool dumpAssetsToFile)
  54. {
  55. CommsManager = commsManager;
  56. m_dumpAssetsToFile = dumpAssetsToFile;
  57. }
  58. /// <summary>
  59. /// Get the collection of asset transactions for the given user. If one does not already exist, it
  60. /// is created.
  61. /// </summary>
  62. /// <param name="userID"></param>
  63. /// <returns></returns>
  64. private AgentAssetTransactions GetUserTransactions(LLUUID userID)
  65. {
  66. lock (AgentTransactions)
  67. {
  68. if (!AgentTransactions.ContainsKey(userID))
  69. {
  70. AgentAssetTransactions transactions
  71. = new AgentAssetTransactions(userID, this, m_dumpAssetsToFile);
  72. AgentTransactions.Add(userID, transactions);
  73. }
  74. return AgentTransactions[userID];
  75. }
  76. }
  77. /// <summary>
  78. /// Remove the given agent asset transactions. This should be called when a client is departing
  79. /// from a scene (and hence won't be making any more transactions here).
  80. /// </summary>
  81. /// <param name="userID"></param>
  82. public void RemoveAgentAssetTransactions(LLUUID userID)
  83. {
  84. m_log.DebugFormat("Removing agent asset transactions structure for agent {0}", userID);
  85. lock (AgentTransactions)
  86. {
  87. AgentTransactions.Remove(userID);
  88. }
  89. }
  90. /// <summary>
  91. /// Create an inventory item from data that has been received through a transaction.
  92. ///
  93. /// This is called when new clothing or body parts are created. It may also be called in other
  94. /// situations.
  95. /// </summary>
  96. /// <param name="remoteClient"></param>
  97. /// <param name="transactionID"></param>
  98. /// <param name="folderID"></param>
  99. /// <param name="callbackID"></param>
  100. /// <param name="description"></param>
  101. /// <param name="name"></param>
  102. /// <param name="invType"></param>
  103. /// <param name="type"></param>
  104. /// <param name="wearableType"></param>
  105. /// <param name="nextOwnerMask"></param>
  106. public void HandleItemCreationFromTransaction(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID,
  107. uint callbackID, string description, string name, sbyte invType,
  108. sbyte type, byte wearableType, uint nextOwnerMask)
  109. {
  110. m_log.DebugFormat(
  111. "[TRANSACTIONS MANAGER] Called HandleItemCreationFromTransaction with item {0}", name);
  112. AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
  113. transactions.RequestCreateInventoryItem(
  114. remoteClient, transactionID, folderID, callbackID, description,
  115. name, invType, type, wearableType, nextOwnerMask);
  116. }
  117. /// <summary>
  118. /// Update an inventory item with data that has been received through a transaction.
  119. ///
  120. /// This is called when clothing or body parts are updated (for instance, with new textures or
  121. /// colours). It may also be called in other situations.
  122. /// </summary>
  123. /// <param name="remoteClient"></param>
  124. /// <param name="transactionID"></param>
  125. /// <param name="item"></param>
  126. public void HandleItemUpdateFromTransaction(IClientAPI remoteClient, LLUUID transactionID,
  127. InventoryItemBase item)
  128. {
  129. m_log.DebugFormat(
  130. "[TRANSACTIONS MANAGER] Called HandleItemUpdateFromTransaction with item {0}",
  131. item.inventoryName);
  132. AgentAssetTransactions transactions
  133. = CommsManager.TransactionsManager.GetUserTransactions(remoteClient.AgentId);
  134. transactions.RequestUpdateInventoryItem(remoteClient, transactionID, item);
  135. }
  136. /// <summary>
  137. /// Request that a client (agent) begin an asset transfer.
  138. /// </summary>
  139. /// <param name="remoteClient"></param>
  140. /// <param name="assetID"></param>
  141. /// <param name="transaction"></param>
  142. /// <param name="type"></param>
  143. /// <param name="data"></param></param>
  144. /// <param name="tempFile"></param>
  145. public void HandleUDPUploadRequest(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type,
  146. byte[] data, bool storeLocal, bool tempFile)
  147. {
  148. // Console.WriteLine("asset upload of " + assetID);
  149. AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
  150. AgentAssetTransactions.AssetXferUploader uploader = transactions.RequestXferUploader(transaction);
  151. if (uploader != null)
  152. {
  153. // Upload has already compelted uploading...
  154. if (uploader.Initialise(remoteClient, assetID, transaction, type, data, storeLocal, tempFile))
  155. {
  156. //[commenting out as this removal breaks uploads]
  157. /*lock (transactions.XferUploaders)
  158. {
  159. // XXX Weak ass way of doing this by directly manipulating this public dictionary, purely temporary
  160. transactions.XferUploaders.Remove(uploader.TransactionID);
  161. //m_log.InfoFormat("[ASSET TRANSACTIONS] Current uploaders: {0}", transactions.XferUploaders.Count);
  162. }*/
  163. /* }
  164. }
  165. }
  166. /// <summary>
  167. /// Handle asset transfer data packets received in response to the asset upload request in
  168. /// HandleUDPUploadRequest()
  169. /// </summary>
  170. /// <param name="remoteClient"></param>
  171. /// <param name="xferID"></param>
  172. /// <param name="packetID"></param>
  173. /// <param name="data"></param>
  174. public void HandleXfer(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data)
  175. {
  176. AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
  177. transactions.HandleXfer(xferID, packetID, data);
  178. }
  179. }
  180. }
  181. */