HGInventoryAccessModule.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using OpenSim.Framework;
  31. using OpenSim.Region.Framework.Interfaces;
  32. using OpenSim.Region.Framework.Scenes;
  33. using OpenSim.Services.Connectors.Hypergrid;
  34. using OpenSim.Services.Interfaces;
  35. using OpenSim.Server.Base;
  36. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  37. using OpenMetaverse;
  38. using log4net;
  39. using Nini.Config;
  40. namespace OpenSim.Region.CoreModules.Framework.InventoryAccess
  41. {
  42. public class HGInventoryAccessModule : BasicInventoryAccessModule, INonSharedRegionModule, IInventoryAccessModule
  43. {
  44. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  45. private static HGAssetMapper m_assMapper;
  46. public static HGAssetMapper AssetMapper
  47. {
  48. get { return m_assMapper; }
  49. }
  50. // private bool m_Initialized = false;
  51. #region INonSharedRegionModule
  52. public override string Name
  53. {
  54. get { return "HGInventoryAccessModule"; }
  55. }
  56. public override void Initialise(IConfigSource source)
  57. {
  58. IConfig moduleConfig = source.Configs["Modules"];
  59. if (moduleConfig != null)
  60. {
  61. string name = moduleConfig.GetString("InventoryAccessModule", "");
  62. if (name == Name)
  63. {
  64. m_Enabled = true;
  65. m_log.InfoFormat("[HG INVENTORY ACCESS MODULE]: {0} enabled.", Name);
  66. }
  67. }
  68. }
  69. public override void AddRegion(Scene scene)
  70. {
  71. if (!m_Enabled)
  72. return;
  73. base.AddRegion(scene);
  74. m_assMapper = new HGAssetMapper(scene);
  75. scene.EventManager.OnNewInventoryItemUploadComplete += UploadInventoryItem;
  76. }
  77. #endregion
  78. #region Event handlers
  79. public void UploadInventoryItem(UUID avatarID, UUID assetID, string name, int userlevel)
  80. {
  81. string userAssetServer = string.Empty;
  82. if (IsForeignUser(avatarID, out userAssetServer))
  83. {
  84. m_assMapper.Post(assetID, avatarID, userAssetServer);
  85. }
  86. }
  87. #endregion
  88. #region Overrides of Basic Inventory Access methods
  89. ///
  90. /// CapsUpdateInventoryItemAsset
  91. ///
  92. public override UUID CapsUpdateInventoryItemAsset(IClientAPI remoteClient, UUID itemID, byte[] data)
  93. {
  94. UUID newAssetID = base.CapsUpdateInventoryItemAsset(remoteClient, itemID, data);
  95. UploadInventoryItem(remoteClient.AgentId, newAssetID, "", 0);
  96. return newAssetID;
  97. }
  98. ///
  99. /// DeleteToInventory
  100. ///
  101. public override UUID DeleteToInventory(DeRezAction action, UUID folderID, List<SceneObjectGroup> objectGroups, IClientAPI remoteClient)
  102. {
  103. UUID ret = UUID.Zero;
  104. // HACK: Only works for lists of length one.
  105. // Intermediate version, just to make things compile
  106. foreach (SceneObjectGroup g in objectGroups)
  107. ret = DeleteToInventory(action, folderID, g, remoteClient);
  108. return ret;
  109. }
  110. // DO NOT OVERRIDE THE BASE METHOD
  111. public new virtual UUID DeleteToInventory(DeRezAction action, UUID folderID,
  112. SceneObjectGroup objectGroup, IClientAPI remoteClient)
  113. {
  114. UUID assetID = base.DeleteToInventory(action, folderID, new List<SceneObjectGroup>() {objectGroup}, remoteClient);
  115. if (!assetID.Equals(UUID.Zero))
  116. {
  117. if (remoteClient != null)
  118. UploadInventoryItem(remoteClient.AgentId, assetID, "", 0);
  119. }
  120. else
  121. m_log.Debug("[HGScene]: Scene.Inventory did not create asset");
  122. return assetID;
  123. }
  124. ///
  125. /// RezObject
  126. ///
  127. public override SceneObjectGroup RezObject(IClientAPI remoteClient, UUID itemID, Vector3 RayEnd, Vector3 RayStart,
  128. UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
  129. bool RezSelected, bool RemoveItem, UUID fromTaskID, bool attachment)
  130. {
  131. m_log.DebugFormat("[HGScene] RezObject itemID={0} fromTaskID={1}", itemID, fromTaskID);
  132. //if (fromTaskID.Equals(UUID.Zero))
  133. //{
  134. InventoryItemBase item = new InventoryItemBase(itemID);
  135. item.Owner = remoteClient.AgentId;
  136. item = m_Scene.InventoryService.GetItem(item);
  137. //if (item == null)
  138. //{ // Fetch the item
  139. // item = new InventoryItemBase();
  140. // item.Owner = remoteClient.AgentId;
  141. // item.ID = itemID;
  142. // item = m_assMapper.Get(item, userInfo.RootFolder.ID, userInfo);
  143. //}
  144. string userAssetServer = string.Empty;
  145. if (item != null && IsForeignUser(remoteClient.AgentId, out userAssetServer))
  146. {
  147. m_assMapper.Get(item.AssetID, remoteClient.AgentId, userAssetServer);
  148. }
  149. //}
  150. // OK, we're done fetching. Pass it up to the default RezObject
  151. return base.RezObject(remoteClient, itemID, RayEnd, RayStart, RayTargetID, BypassRayCast, RayEndIsIntersection,
  152. RezSelected, RemoveItem, fromTaskID, attachment);
  153. }
  154. public override void TransferInventoryAssets(InventoryItemBase item, UUID sender, UUID receiver)
  155. {
  156. string userAssetServer = string.Empty;
  157. if (IsForeignUser(sender, out userAssetServer))
  158. m_assMapper.Get(item.AssetID, sender, userAssetServer);
  159. if (IsForeignUser(receiver, out userAssetServer))
  160. m_assMapper.Post(item.AssetID, receiver, userAssetServer);
  161. }
  162. public override bool IsForeignUser(UUID userID, out string assetServerURL)
  163. {
  164. assetServerURL = string.Empty;
  165. UserAccount account = null;
  166. if (m_Scene.UserAccountService != null)
  167. account = m_Scene.UserAccountService.GetUserAccount(m_Scene.RegionInfo.ScopeID, userID);
  168. if (account == null) // foreign
  169. {
  170. ScenePresence sp = null;
  171. if (m_Scene.TryGetScenePresence(userID, out sp))
  172. {
  173. AgentCircuitData aCircuit = m_Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode);
  174. if (aCircuit.ServiceURLs.ContainsKey("AssetServerURI"))
  175. {
  176. assetServerURL = aCircuit.ServiceURLs["AssetServerURI"].ToString();
  177. assetServerURL = assetServerURL.Trim(new char[] { '/' }); return true;
  178. }
  179. }
  180. }
  181. return false;
  182. }
  183. #endregion
  184. protected override InventoryItemBase GetItem(UUID agentID, UUID itemID)
  185. {
  186. InventoryItemBase item = base.GetItem(agentID, itemID);
  187. string userAssetServer = string.Empty;
  188. if (IsForeignUser(agentID, out userAssetServer))
  189. m_assMapper.Get(item.AssetID, agentID, userAssetServer);
  190. return item;
  191. }
  192. }
  193. }