AgentAssetsTransactions.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. private Dictionary<UUID, AssetXferUploader> XferUploaders = new Dictionary<UUID, AssetXferUploader>();
  46. // Methods
  47. public AgentAssetTransactions(UUID agentID, Scene scene,
  48. bool dumpAssetsToFile)
  49. {
  50. m_Scene = scene;
  51. m_dumpAssetsToFile = dumpAssetsToFile;
  52. }
  53. /// <summary>
  54. /// Return the xfer uploader for the given transaction.
  55. /// </summary>
  56. /// <remarks>
  57. /// If an uploader does not already exist for this transaction then it is created, otherwise the existing
  58. /// uploader is returned.
  59. /// </remarks>
  60. /// <param name="transactionID"></param>
  61. /// <returns>The asset xfer uploader</returns>
  62. public AssetXferUploader RequestXferUploader(UUID transactionID)
  63. {
  64. AssetXferUploader uploader;
  65. lock (XferUploaders)
  66. {
  67. if (!XferUploaders.ContainsKey(transactionID))
  68. {
  69. uploader = new AssetXferUploader(this, m_Scene, transactionID, m_dumpAssetsToFile);
  70. // m_log.DebugFormat(
  71. // "[AGENT ASSETS TRANSACTIONS]: Adding asset xfer uploader {0} since it didn't previously exist", transactionID);
  72. XferUploaders.Add(transactionID, uploader);
  73. }
  74. else
  75. {
  76. uploader = XferUploaders[transactionID];
  77. }
  78. }
  79. return uploader;
  80. }
  81. public void HandleXfer(ulong xferID, uint packetID, byte[] data)
  82. {
  83. AssetXferUploader foundUploader = null;
  84. lock (XferUploaders)
  85. {
  86. foreach (AssetXferUploader uploader in XferUploaders.Values)
  87. {
  88. // m_log.DebugFormat(
  89. // "[AGENT ASSETS TRANSACTIONS]: In HandleXfer, inspect xfer upload with xfer id {0}",
  90. // uploader.XferID);
  91. if (uploader.XferID == xferID)
  92. {
  93. foundUploader = uploader;
  94. break;
  95. }
  96. }
  97. }
  98. if (foundUploader != null)
  99. {
  100. // m_log.DebugFormat(
  101. // "[AGENT ASSETS TRANSACTIONS]: Found xfer uploader for xfer id {0}, packet id {1}, data length {2}",
  102. // xferID, packetID, data.Length);
  103. foundUploader.HandleXferPacket(xferID, packetID, data);
  104. }
  105. else
  106. {
  107. m_log.ErrorFormat(
  108. "[AGENT ASSET TRANSACTIONS]: Could not find uploader for xfer id {0}, packet id {1}, data length {2}",
  109. xferID, packetID, data.Length);
  110. }
  111. }
  112. public bool RemoveXferUploader(UUID transactionID)
  113. {
  114. lock (XferUploaders)
  115. {
  116. bool removed = XferUploaders.Remove(transactionID);
  117. if (!removed)
  118. m_log.WarnFormat(
  119. "[AGENT ASSET TRANSACTIONS]: Received request to remove xfer uploader with transaction ID {0} but none found",
  120. transactionID);
  121. // else
  122. // m_log.DebugFormat(
  123. // "[AGENT ASSET TRANSACTIONS]: Removed xfer uploader with transaction ID {0}", transactionID);
  124. return removed;
  125. }
  126. }
  127. public void RequestCreateInventoryItem(IClientAPI remoteClient,
  128. UUID transactionID, UUID folderID, uint callbackID,
  129. string description, string name, sbyte invType,
  130. sbyte type, byte wearableType, uint nextOwnerMask)
  131. {
  132. AssetXferUploader uploader = RequestXferUploader(transactionID);
  133. uploader.RequestCreateInventoryItem(
  134. remoteClient, folderID, callbackID,
  135. description, name, invType, type, wearableType, nextOwnerMask);
  136. }
  137. public void RequestUpdateTaskInventoryItem(IClientAPI remoteClient,
  138. SceneObjectPart part, UUID transactionID,
  139. TaskInventoryItem item)
  140. {
  141. AssetXferUploader uploader = RequestXferUploader(transactionID);
  142. uploader.RequestUpdateTaskInventoryItem(remoteClient, item);
  143. }
  144. public void RequestUpdateInventoryItem(IClientAPI remoteClient,
  145. UUID transactionID, InventoryItemBase item)
  146. {
  147. AssetXferUploader uploader = RequestXferUploader(transactionID);
  148. uploader.RequestUpdateInventoryItem(remoteClient, item);
  149. }
  150. }
  151. }