AgentAssetsTransactions.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
  35. {
  36. /// <summary>
  37. /// Manage asset transactions for a single agent.
  38. /// </summary>
  39. public class AgentAssetTransactions
  40. {
  41. // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  42. // Fields
  43. private bool m_dumpAssetsToFile;
  44. private Scene m_Scene;
  45. public UUID UserID;
  46. public Dictionary<UUID, AssetXferUploader> XferUploaders =
  47. new Dictionary<UUID, AssetXferUploader>();
  48. // Methods
  49. public AgentAssetTransactions(UUID agentID, Scene scene,
  50. bool dumpAssetsToFile)
  51. {
  52. m_Scene = scene;
  53. UserID = agentID;
  54. m_dumpAssetsToFile = dumpAssetsToFile;
  55. }
  56. public AssetXferUploader RequestXferUploader(UUID transactionID)
  57. {
  58. if (!XferUploaders.ContainsKey(transactionID))
  59. {
  60. AssetXferUploader uploader = new AssetXferUploader(m_Scene,
  61. m_dumpAssetsToFile);
  62. lock (XferUploaders)
  63. {
  64. XferUploaders.Add(transactionID, uploader);
  65. }
  66. return uploader;
  67. }
  68. return null;
  69. }
  70. public void HandleXfer(ulong xferID, uint packetID, byte[] data)
  71. {
  72. lock (XferUploaders)
  73. {
  74. foreach (AssetXferUploader uploader in XferUploaders.Values)
  75. {
  76. if (uploader.XferID == xferID)
  77. {
  78. uploader.HandleXferPacket(xferID, packetID, data);
  79. break;
  80. }
  81. }
  82. }
  83. }
  84. public void RequestCreateInventoryItem(IClientAPI remoteClient,
  85. UUID transactionID, UUID folderID, uint callbackID,
  86. string description, string name, sbyte invType,
  87. sbyte type, byte wearableType, uint nextOwnerMask)
  88. {
  89. if (XferUploaders.ContainsKey(transactionID))
  90. {
  91. XferUploaders[transactionID].RequestCreateInventoryItem(
  92. remoteClient, transactionID, folderID,
  93. callbackID, description, name, invType, type,
  94. wearableType, nextOwnerMask);
  95. }
  96. }
  97. /// <summary>
  98. /// Get an uploaded asset. If the data is successfully retrieved,
  99. /// the transaction will be removed.
  100. /// </summary>
  101. /// <param name="transactionID"></param>
  102. /// <returns>The asset if the upload has completed, null if it has not.</returns>
  103. public AssetBase GetTransactionAsset(UUID transactionID)
  104. {
  105. if (XferUploaders.ContainsKey(transactionID))
  106. {
  107. AssetXferUploader uploader = XferUploaders[transactionID];
  108. AssetBase asset = uploader.GetAssetData();
  109. lock (XferUploaders)
  110. {
  111. XferUploaders.Remove(transactionID);
  112. }
  113. return asset;
  114. }
  115. return null;
  116. }
  117. public void RequestUpdateTaskInventoryItem(IClientAPI remoteClient,
  118. SceneObjectPart part, UUID transactionID,
  119. TaskInventoryItem item)
  120. {
  121. if (XferUploaders.ContainsKey(transactionID))
  122. {
  123. AssetBase asset = GetTransactionAsset(transactionID);
  124. // Only legacy viewers use this, and they prefer CAPS, which
  125. // we have, so this really never runs.
  126. // Allow it, but only for "safe" types.
  127. if ((InventoryType)item.InvType != InventoryType.Notecard &&
  128. (InventoryType)item.InvType != InventoryType.LSL)
  129. return;
  130. if (asset != null)
  131. {
  132. // m_log.DebugFormat(
  133. // "[AGENT ASSETS TRANSACTIONS]: Updating item {0} in {1} for transaction {2}",
  134. // item.Name, part.Name, transactionID);
  135. asset.FullID = UUID.Random();
  136. asset.Name = item.Name;
  137. asset.Description = item.Description;
  138. asset.Type = (sbyte)item.Type;
  139. item.AssetID = asset.FullID;
  140. m_Scene.AssetService.Store(asset);
  141. }
  142. }
  143. }
  144. public void RequestUpdateInventoryItem(IClientAPI remoteClient,
  145. UUID transactionID, InventoryItemBase item)
  146. {
  147. if (XferUploaders.ContainsKey(transactionID))
  148. {
  149. AssetBase asset = GetTransactionAsset(transactionID);
  150. if (asset != null)
  151. {
  152. asset.FullID = UUID.Random();
  153. asset.Name = item.Name;
  154. asset.Description = item.Description;
  155. asset.Type = (sbyte)item.AssetType;
  156. item.AssetID = asset.FullID;
  157. m_Scene.AssetService.Store(asset);
  158. IInventoryService invService = m_Scene.InventoryService;
  159. invService.UpdateItem(item);
  160. }
  161. }
  162. }
  163. }
  164. }