HGScene.Inventory.cs 6.1 KB

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