HGScene.Inventory.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /**
  2. * Copyright (c) 2008, Contributors. All rights reserved.
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * * Neither the name of the Organizations nor the names of Individual
  14. * Contributors may be used to endorse or promote products derived from
  15. * this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  20. * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  22. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  23. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  25. * OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. */
  28. using System;
  29. using System.Collections;
  30. using System.Collections.Generic;
  31. using System.Reflection;
  32. using System.Threading;
  33. using log4net;
  34. using Nini.Config;
  35. using OpenMetaverse;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Communications;
  38. using OpenSim.Framework.Communications.Cache;
  39. using OpenSim.Framework.Servers;
  40. using OpenSim.Region.Environment;
  41. using OpenSim.Region.Environment.Scenes;
  42. namespace OpenSim.Region.Environment.Scenes.Hypergrid
  43. {
  44. public partial class HGScene : Scene
  45. {
  46. #region Fields
  47. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  48. private HGAssetMapper m_assMapper;
  49. #endregion
  50. #region Constructors
  51. public HGScene(RegionInfo regInfo, AgentCircuitManager authen,
  52. CommunicationsManager commsMan, SceneCommunicationService sceneGridService,
  53. AssetCache assetCach, StorageManager storeManager, BaseHttpServer httpServer,
  54. ModuleLoader moduleLoader, bool dumpAssetsToFile, bool physicalPrim,
  55. bool SeeIntoRegionFromNeighbor, IConfigSource config, string simulatorVersion)
  56. : base(regInfo, authen, commsMan, sceneGridService, assetCach, storeManager, httpServer, moduleLoader,
  57. dumpAssetsToFile, physicalPrim, SeeIntoRegionFromNeighbor, config, simulatorVersion)
  58. {
  59. m_log.Info("[HGScene]: Starting HGScene.");
  60. m_assMapper = new HGAssetMapper(this);
  61. EventManager.OnNewInventoryItemUploadComplete += UploadInventoryItem;
  62. }
  63. #endregion
  64. #region Event handlers
  65. public void UploadInventoryItem(UUID avatarID, UUID assetID, string name, int userlevel)
  66. {
  67. CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(avatarID);
  68. if (userInfo != null)
  69. {
  70. m_assMapper.Post(assetID, avatarID);
  71. }
  72. }
  73. #endregion
  74. #region Overrides of Scene.Inventory methods
  75. ///
  76. /// CapsUpdateInventoryItemAsset
  77. ///
  78. public override UUID CapsUpdateInventoryItemAsset(IClientAPI remoteClient, UUID itemID, byte[] data)
  79. {
  80. UUID newAssetID = base.CapsUpdateInventoryItemAsset(remoteClient, itemID, data);
  81. UploadInventoryItem(remoteClient.AgentId, newAssetID, "", 0);
  82. return newAssetID;
  83. }
  84. ///
  85. /// DeleteToInventory
  86. ///
  87. public override UUID DeleteToInventory(DeRezAction action, UUID folderID, SceneObjectGroup objectGroup, IClientAPI remoteClient)
  88. {
  89. UUID assetID = base.DeleteToInventory(action, folderID, objectGroup, remoteClient);
  90. if (!assetID.Equals(UUID.Zero))
  91. {
  92. UploadInventoryItem(remoteClient.AgentId, assetID, "", 0);
  93. }
  94. else
  95. m_log.Debug("[HGScene]: Scene.Inventory did not create asset");
  96. return assetID;
  97. }
  98. ///
  99. /// RezObject
  100. ///
  101. public override SceneObjectGroup RezObject(IClientAPI remoteClient, UUID itemID, Vector3 RayEnd, Vector3 RayStart,
  102. UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
  103. bool RezSelected, bool RemoveItem, UUID fromTaskID, bool attachment)
  104. {
  105. CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
  106. if (userInfo != null)
  107. {
  108. if (userInfo.RootFolder != null)
  109. {
  110. InventoryItemBase item = userInfo.RootFolder.FindItem(itemID);
  111. if (item != null)
  112. {
  113. m_assMapper.Get(item.AssetID, remoteClient.AgentId);
  114. }
  115. }
  116. }
  117. // OK, we're done fetching. Pass it up to the default RezObject
  118. return base.RezObject(remoteClient, itemID, RayEnd, RayStart, RayTargetID, BypassRayCast, RayEndIsIntersection,
  119. RezSelected, RemoveItem, fromTaskID, attachment);
  120. }
  121. #endregion
  122. }
  123. }