AgentAssetTransactionsManager.cs 10 KB

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