AgentAssetTransactionsManager.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 OpenSimulator 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. //using System.Reflection;
  28. //using log4net;
  29. namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
  30. {
  31. /*
  32. public class AgentAssetTransactionsManager
  33. {
  34. //private static readonly ILog m_log
  35. // = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  36. /// <summary>
  37. /// Each agent has its own singleton collection of transactions
  38. /// </summary>
  39. private Dictionary<UUID, AgentAssetTransactions> AgentTransactions =
  40. new Dictionary<UUID, AgentAssetTransactions>();
  41. /// <summary>
  42. /// Should we dump uploaded assets to the filesystem?
  43. /// </summary>
  44. private bool m_dumpAssetsToFile;
  45. public Scene MyScene;
  46. public AgentAssetTransactionsManager(Scene scene, bool dumpAssetsToFile)
  47. {
  48. MyScene = scene;
  49. m_dumpAssetsToFile = dumpAssetsToFile;
  50. }
  51. /// <summary>
  52. /// Get the collection of asset transactions for the given user. If one does not already exist, it
  53. /// is created.
  54. /// </summary>
  55. /// <param name="userID"></param>
  56. /// <returns></returns>
  57. private AgentAssetTransactions GetUserTransactions(UUID userID)
  58. {
  59. lock (AgentTransactions)
  60. {
  61. if (!AgentTransactions.ContainsKey(userID))
  62. {
  63. AgentAssetTransactions transactions = null;
  64. //= new AgentAssetTransactions(userID, this, m_dumpAssetsToFile);
  65. AgentTransactions.Add(userID, transactions);
  66. }
  67. return AgentTransactions[userID];
  68. }
  69. }
  70. /// <summary>
  71. /// Remove the given agent asset transactions. This should be called when a client is departing
  72. /// from a scene (and hence won't be making any more transactions here).
  73. /// </summary>
  74. /// <param name="userID"></param>
  75. public void RemoveAgentAssetTransactions(UUID userID)
  76. {
  77. // m_log.DebugFormat("Removing agent asset transactions structure for agent {0}", userID);
  78. lock (AgentTransactions)
  79. {
  80. AgentTransactions.Remove(userID);
  81. }
  82. }
  83. /// <summary>
  84. /// Create an inventory item from data that has been received through a transaction.
  85. ///
  86. /// This is called when new clothing or body parts are created. It may also be called in other
  87. /// situations.
  88. /// </summary>
  89. /// <param name="remoteClient"></param>
  90. /// <param name="transactionID"></param>
  91. /// <param name="folderID"></param>
  92. /// <param name="callbackID"></param>
  93. /// <param name="description"></param>
  94. /// <param name="name"></param>
  95. /// <param name="invType"></param>
  96. /// <param name="type"></param>
  97. /// <param name="wearableType"></param>
  98. /// <param name="nextOwnerMask"></param>
  99. public void HandleItemCreationFromTransaction(IClientAPI remoteClient, UUID transactionID, UUID folderID,
  100. uint callbackID, string description, string name, sbyte invType,
  101. sbyte type, byte wearableType, uint nextOwnerMask)
  102. {
  103. // m_log.DebugFormat(
  104. // "[TRANSACTIONS MANAGER] Called HandleItemCreationFromTransaction with item {0}", name);
  105. AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
  106. transactions.RequestCreateInventoryItem(
  107. remoteClient, transactionID, folderID, callbackID, description,
  108. name, invType, type, wearableType, nextOwnerMask);
  109. }
  110. /// <summary>
  111. /// Update an inventory item with data that has been received through a transaction.
  112. ///
  113. /// This is called when clothing or body parts are updated (for instance, with new textures or
  114. /// colours). It may also be called in other situations.
  115. /// </summary>
  116. /// <param name="remoteClient"></param>
  117. /// <param name="transactionID"></param>
  118. /// <param name="item"></param>
  119. public void HandleItemUpdateFromTransaction(IClientAPI remoteClient, UUID transactionID,
  120. InventoryItemBase item)
  121. {
  122. // m_log.DebugFormat(
  123. // "[TRANSACTIONS MANAGER] Called HandleItemUpdateFromTransaction with item {0}",
  124. // item.Name);
  125. AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
  126. transactions.RequestUpdateInventoryItem(remoteClient, transactionID, item);
  127. }
  128. /// <summary>
  129. /// Update a task inventory item with data that has been received through a transaction.
  130. ///
  131. /// This is currently called when, for instance, a notecard in a prim is saved. The data is sent
  132. /// up through a single AssetUploadRequest. A subsequent UpdateTaskInventory then references the transaction
  133. /// and comes through this method.
  134. /// </summary>
  135. /// <param name="remoteClient"></param>
  136. /// <param name="transactionID"></param>
  137. /// <param name="item"></param>
  138. public void HandleTaskItemUpdateFromTransaction(
  139. IClientAPI remoteClient, SceneObjectPart part, UUID transactionID, TaskInventoryItem item)
  140. {
  141. // m_log.DebugFormat(
  142. // "[TRANSACTIONS MANAGER] Called HandleTaskItemUpdateFromTransaction with item {0}",
  143. // item.Name);
  144. AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
  145. transactions.RequestUpdateTaskInventoryItem(remoteClient, part, transactionID, item);
  146. }
  147. /// <summary>
  148. /// Request that a client (agent) begin an asset transfer.
  149. /// </summary>
  150. /// <param name="remoteClient"></param>
  151. /// <param name="assetID"></param>
  152. /// <param name="transaction"></param>
  153. /// <param name="type"></param>
  154. /// <param name="data"></param></param>
  155. /// <param name="tempFile"></param>
  156. public void HandleUDPUploadRequest(IClientAPI remoteClient, UUID assetID, UUID transaction, sbyte type,
  157. byte[] data, bool storeLocal, bool tempFile)
  158. {
  159. //m_log.Debug("HandleUDPUploadRequest - assetID: " + assetID.ToString() + " transaction: " + transaction.ToString() + " type: " + type.ToString() + " storelocal: " + storeLocal + " tempFile: " + tempFile);
  160. if (((AssetType)type == AssetType.Texture ||
  161. (AssetType)type == AssetType.Sound ||
  162. (AssetType)type == AssetType.TextureTGA ||
  163. (AssetType)type == AssetType.Animation) &&
  164. tempFile == false)
  165. {
  166. Scene scene = (Scene)remoteClient.Scene;
  167. IMoneyModule mm = scene.RequestModuleInterface<IMoneyModule>();
  168. if (mm != null)
  169. {
  170. if (!mm.UploadCovered(remoteClient))
  171. {
  172. remoteClient.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false);
  173. return;
  174. }
  175. }
  176. }
  177. //m_log.Debug("asset upload of " + assetID);
  178. AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
  179. AssetXferUploader uploader = transactions.RequestXferUploader(transaction);
  180. if (uploader != null)
  181. {
  182. uploader.Initialise(remoteClient, assetID, transaction, type, data, storeLocal, tempFile);
  183. }
  184. }
  185. /// <summary>
  186. /// Handle asset transfer data packets received in response to the asset upload request in
  187. /// HandleUDPUploadRequest()
  188. /// </summary>
  189. /// <param name="remoteClient"></param>
  190. /// <param name="xferID"></param>
  191. /// <param name="packetID"></param>
  192. /// <param name="data"></param>
  193. public void HandleXfer(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data)
  194. {
  195. //m_log.Debug("xferID: " + xferID + " packetID: " + packetID + " data!");
  196. AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
  197. transactions.HandleXfer(xferID, packetID, data);
  198. }
  199. }
  200. */
  201. }