AgentAssetsTransactions.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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.Collections.Generic;
  28. using System.Reflection;
  29. using log4net;
  30. using OpenMetaverse;
  31. using OpenSim.Framework;
  32. using OpenSim.Region.Framework.Scenes;
  33. using OpenSim.Services.Interfaces;
  34. using OpenSim.Region.Framework.Interfaces;
  35. namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
  36. {
  37. /// <summary>
  38. /// Manage asset transactions for a single agent.
  39. /// </summary>
  40. public class AgentAssetTransactions
  41. {
  42. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  43. // Fields
  44. private bool m_dumpAssetsToFile;
  45. private Scene m_Scene;
  46. private Dictionary<UUID, AssetXferUploader> XferUploaders = new Dictionary<UUID, AssetXferUploader>();
  47. // Methods
  48. public AgentAssetTransactions(UUID agentID, Scene scene,
  49. bool dumpAssetsToFile)
  50. {
  51. m_Scene = scene;
  52. m_dumpAssetsToFile = dumpAssetsToFile;
  53. }
  54. /// <summary>
  55. /// Return the xfer uploader for the given transaction.
  56. /// </summary>
  57. /// <remarks>
  58. /// If an uploader does not already exist for this transaction then it is created, otherwise the existing
  59. /// uploader is returned.
  60. /// </remarks>
  61. /// <param name="transactionID"></param>
  62. /// <returns>The asset xfer uploader</returns>
  63. public AssetXferUploader RequestXferUploader(UUID transactionID)
  64. {
  65. AssetXferUploader uploader;
  66. lock (XferUploaders)
  67. {
  68. if (!XferUploaders.ContainsKey(transactionID))
  69. {
  70. uploader = new AssetXferUploader(this, m_Scene, transactionID, m_dumpAssetsToFile);
  71. // m_log.DebugFormat(
  72. // "[AGENT ASSETS TRANSACTIONS]: Adding asset xfer uploader {0} since it didn't previously exist", transactionID);
  73. XferUploaders.Add(transactionID, uploader);
  74. }
  75. else
  76. {
  77. uploader = XferUploaders[transactionID];
  78. }
  79. }
  80. return uploader;
  81. }
  82. public void HandleXfer(ulong xferID, uint packetID, byte[] data)
  83. {
  84. AssetXferUploader foundUploader = null;
  85. lock (XferUploaders)
  86. {
  87. foreach (AssetXferUploader uploader in XferUploaders.Values)
  88. {
  89. // m_log.DebugFormat(
  90. // "[AGENT ASSETS TRANSACTIONS]: In HandleXfer, inspect xfer upload with xfer id {0}",
  91. // uploader.XferID);
  92. if (uploader.XferID == xferID)
  93. {
  94. foundUploader = uploader;
  95. break;
  96. }
  97. }
  98. }
  99. if (foundUploader != null)
  100. {
  101. // m_log.DebugFormat(
  102. // "[AGENT ASSETS TRANSACTIONS]: Found xfer uploader for xfer id {0}, packet id {1}, data length {2}",
  103. // xferID, packetID, data.Length);
  104. foundUploader.HandleXferPacket(xferID, packetID, data);
  105. }
  106. else
  107. {
  108. // Check if the xfer is a terrain xfer
  109. IEstateModule estateModule = m_Scene.RequestModuleInterface<IEstateModule>();
  110. if (estateModule != null)
  111. {
  112. if (estateModule.IsTerrainXfer(xferID))
  113. return;
  114. }
  115. m_log.ErrorFormat(
  116. "[AGENT ASSET TRANSACTIONS]: Could not find uploader for xfer id {0}, packet id {1}, data length {2}",
  117. xferID, packetID, data.Length);
  118. }
  119. }
  120. public bool RemoveXferUploader(UUID transactionID)
  121. {
  122. lock (XferUploaders)
  123. {
  124. bool removed = XferUploaders.Remove(transactionID);
  125. if (!removed)
  126. m_log.WarnFormat(
  127. "[AGENT ASSET TRANSACTIONS]: Received request to remove xfer uploader with transaction ID {0} but none found",
  128. transactionID);
  129. // else
  130. // m_log.DebugFormat(
  131. // "[AGENT ASSET TRANSACTIONS]: Removed xfer uploader with transaction ID {0}", transactionID);
  132. return removed;
  133. }
  134. }
  135. public bool RequestCreateInventoryItem(IClientAPI remoteClient,
  136. UUID transactionID, UUID folderID, uint callbackID,
  137. string description, string name, sbyte invType,
  138. sbyte type, byte wearableType, uint nextOwnerMask)
  139. {
  140. AssetXferUploader uploader = RequestXferUploader(transactionID);
  141. uploader.RequestCreateInventoryItem(
  142. remoteClient, folderID, callbackID,
  143. description, name, invType, type, wearableType, nextOwnerMask);
  144. return true;
  145. }
  146. public void RequestUpdateTaskInventoryItem(IClientAPI remoteClient,
  147. SceneObjectPart part, UUID transactionID,
  148. TaskInventoryItem item)
  149. {
  150. AssetXferUploader uploader = RequestXferUploader(transactionID);
  151. // Here we need to get the old asset to extract the
  152. // texture UUIDs if it's a wearable.
  153. if (item.Type == (int)AssetType.Bodypart ||
  154. item.Type == (int)AssetType.Clothing ||
  155. item.Type == (int)CustomAssetType.AnimationSet)
  156. {
  157. AssetBase oldAsset = m_Scene.AssetService.Get(item.AssetID.ToString());
  158. if (oldAsset != null)
  159. uploader.SetOldData(oldAsset.Data);
  160. }
  161. uploader.RequestUpdateTaskInventoryItem(remoteClient, item);
  162. }
  163. public void RequestUpdateInventoryItem(IClientAPI remoteClient,
  164. UUID transactionID, InventoryItemBase item)
  165. {
  166. AssetXferUploader uploader = RequestXferUploader(transactionID);
  167. // Here we need to get the old asset to extract the
  168. // texture UUIDs if it's a wearable.
  169. if (item.AssetType == (int)AssetType.Bodypart ||
  170. item.AssetType == (int)AssetType.Clothing ||
  171. item.AssetType == (int)CustomAssetType.AnimationSet)
  172. {
  173. AssetBase oldAsset = m_Scene.AssetService.Get(item.AssetID.ToString());
  174. if (oldAsset != null)
  175. uploader.SetOldData(oldAsset.Data);
  176. }
  177. uploader.RequestUpdateInventoryItem(remoteClient, item);
  178. }
  179. }
  180. }