HGScene.Inventory.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. using Nini.Config;
  30. using OpenMetaverse;
  31. using OpenSim.Framework;
  32. using OpenSim.Framework.Communications;
  33. using OpenSim.Framework.Communications.Cache;
  34. using OpenSim.Region.Framework.Interfaces;
  35. namespace OpenSim.Region.Framework.Scenes.Hypergrid
  36. {
  37. public partial class HGScene : Scene
  38. {
  39. #region Fields
  40. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  41. private HGAssetMapper m_assMapper;
  42. public HGAssetMapper AssetMapper
  43. {
  44. get { return m_assMapper; }
  45. }
  46. private IHyperAssetService m_hyper;
  47. private IHyperAssetService HyperAssets
  48. {
  49. get
  50. {
  51. if (m_hyper == null)
  52. m_hyper = RequestModuleInterface<IHyperAssetService>();
  53. return m_hyper;
  54. }
  55. }
  56. #endregion
  57. #region Constructors
  58. public HGScene(RegionInfo regInfo, AgentCircuitManager authen,
  59. CommunicationsManager commsMan, SceneCommunicationService sceneGridService,
  60. StorageManager storeManager,
  61. ModuleLoader moduleLoader, bool dumpAssetsToFile, bool physicalPrim,
  62. bool SeeIntoRegionFromNeighbor, IConfigSource config, string simulatorVersion)
  63. : base(regInfo, authen, commsMan, sceneGridService, storeManager, moduleLoader,
  64. dumpAssetsToFile, physicalPrim, SeeIntoRegionFromNeighbor, config, simulatorVersion)
  65. {
  66. m_log.Info("[HGScene]: Starting HGScene.");
  67. m_assMapper = new HGAssetMapper(this);
  68. EventManager.OnNewInventoryItemUploadComplete += UploadInventoryItem;
  69. }
  70. #endregion
  71. #region Event handlers
  72. public void UploadInventoryItem(UUID avatarID, UUID assetID, string name, int userlevel)
  73. {
  74. CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(avatarID);
  75. if (userInfo != null)
  76. {
  77. m_assMapper.Post(assetID, avatarID);
  78. }
  79. }
  80. #endregion
  81. #region Overrides of Scene.Inventory methods
  82. ///
  83. /// CapsUpdateInventoryItemAsset
  84. ///
  85. public override UUID CapsUpdateInventoryItemAsset(IClientAPI remoteClient, UUID itemID, byte[] data)
  86. {
  87. UUID newAssetID = base.CapsUpdateInventoryItemAsset(remoteClient, itemID, data);
  88. UploadInventoryItem(remoteClient.AgentId, newAssetID, "", 0);
  89. return newAssetID;
  90. }
  91. ///
  92. /// DeleteToInventory
  93. ///
  94. public override UUID DeleteToInventory(DeRezAction action, UUID folderID, SceneObjectGroup objectGroup, IClientAPI remoteClient)
  95. {
  96. UUID assetID = base.DeleteToInventory(action, folderID, objectGroup, remoteClient);
  97. if (!assetID.Equals(UUID.Zero))
  98. {
  99. UploadInventoryItem(remoteClient.AgentId, assetID, "", 0);
  100. }
  101. else
  102. m_log.Debug("[HGScene]: Scene.Inventory did not create asset");
  103. return assetID;
  104. }
  105. ///
  106. /// RezObject
  107. ///
  108. public override SceneObjectGroup RezObject(IClientAPI remoteClient, UUID itemID, Vector3 RayEnd, Vector3 RayStart,
  109. UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
  110. bool RezSelected, bool RemoveItem, UUID fromTaskID, bool attachment)
  111. {
  112. m_log.DebugFormat("[HGScene] RezObject itemID={0} fromTaskID={1}", itemID, fromTaskID);
  113. //if (fromTaskID.Equals(UUID.Zero))
  114. //{
  115. InventoryItemBase item = new InventoryItemBase(itemID);
  116. item.Owner = remoteClient.AgentId;
  117. item = InventoryService.GetItem(item);
  118. //if (item == null)
  119. //{ // Fetch the item
  120. // item = new InventoryItemBase();
  121. // item.Owner = remoteClient.AgentId;
  122. // item.ID = itemID;
  123. // item = m_assMapper.Get(item, userInfo.RootFolder.ID, userInfo);
  124. //}
  125. if (item != null)
  126. {
  127. m_assMapper.Get(item.AssetID, remoteClient.AgentId);
  128. }
  129. //}
  130. // OK, we're done fetching. Pass it up to the default RezObject
  131. return base.RezObject(remoteClient, itemID, RayEnd, RayStart, RayTargetID, BypassRayCast, RayEndIsIntersection,
  132. RezSelected, RemoveItem, fromTaskID, attachment);
  133. }
  134. protected override void TransferInventoryAssets(InventoryItemBase item, UUID sender, UUID receiver)
  135. {
  136. string userAssetServer = HyperAssets.GetUserAssetServer(sender);
  137. if ((userAssetServer != string.Empty) && (userAssetServer != HyperAssets.GetSimAssetServer()))
  138. m_assMapper.Get(item.AssetID, sender);
  139. userAssetServer = HyperAssets.GetUserAssetServer(receiver);
  140. if ((userAssetServer != string.Empty) && (userAssetServer != HyperAssets.GetSimAssetServer()))
  141. m_assMapper.Post(item.AssetID, receiver);
  142. }
  143. #endregion
  144. }
  145. }