1
0

HGInventoryService.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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 OpenMetaverse;
  30. using log4net;
  31. using Nini.Config;
  32. using System.Reflection;
  33. using OpenSim.Services.Base;
  34. using OpenSim.Services.Interfaces;
  35. using OpenSim.Services.InventoryService;
  36. using OpenSim.Data;
  37. using OpenSim.Framework;
  38. using OpenSim.Server.Base;
  39. namespace OpenSim.Services.HypergridService
  40. {
  41. /// <summary>
  42. /// Hypergrid inventory service. It serves the IInventoryService interface,
  43. /// but implements it in ways that are appropriate for inter-grid
  44. /// inventory exchanges. Specifically, it does not performs deletions
  45. /// and it responds to GetRootFolder requests with the ID of the
  46. /// Suitcase folder, not the actual "My Inventory" folder.
  47. /// </summary>
  48. public class HGInventoryService : XInventoryService, IInventoryService
  49. {
  50. private static readonly ILog m_log =
  51. LogManager.GetLogger(
  52. MethodBase.GetCurrentMethod().DeclaringType);
  53. private string m_HomeURL;
  54. private IUserAccountService m_UserAccountService;
  55. private UserAccountCache m_Cache;
  56. public HGInventoryService(IConfigSource config, string configName)
  57. : base(config, configName)
  58. {
  59. m_log.Debug("[HGInventory Service]: Starting");
  60. if (configName != string.Empty)
  61. m_ConfigName = configName;
  62. //
  63. // Try reading the [InventoryService] section, if it exists
  64. //
  65. IConfig invConfig = config.Configs[m_ConfigName];
  66. if (invConfig != null)
  67. {
  68. // realm = authConfig.GetString("Realm", realm);
  69. string userAccountsDll = invConfig.GetString("UserAccountsService", string.Empty);
  70. if (userAccountsDll == string.Empty)
  71. throw new Exception("Please specify UserAccountsService in HGInventoryService configuration");
  72. Object[] args = new Object[] { config };
  73. m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userAccountsDll, args);
  74. if (m_UserAccountService == null)
  75. throw new Exception(String.Format("Unable to create UserAccountService from {0}", userAccountsDll));
  76. m_HomeURL = Util.GetConfigVarFromSections<string>(config, "HomeURI",
  77. new string[] { "Startup", "Hypergrid", m_ConfigName }, String.Empty);
  78. m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService);
  79. }
  80. m_log.Debug("[HG INVENTORY SERVICE]: Starting...");
  81. }
  82. public override bool CreateUserInventory(UUID principalID)
  83. {
  84. // NOGO
  85. return false;
  86. }
  87. public override List<InventoryFolderBase> GetInventorySkeleton(UUID principalID)
  88. {
  89. // NOGO for this inventory service
  90. return new List<InventoryFolderBase>();
  91. }
  92. public override InventoryFolderBase GetRootFolder(UUID principalID)
  93. {
  94. //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetRootFolder for {0}", principalID);
  95. // Warp! Root folder for travelers
  96. XInventoryFolder[] folders = m_Database.GetFolders(
  97. new string[] { "agentID", "folderName"},
  98. new string[] { principalID.ToString(), "My Suitcase" });
  99. if (folders.Length > 0)
  100. return ConvertToOpenSim(folders[0]);
  101. // make one
  102. XInventoryFolder suitcase = CreateFolder(principalID, UUID.Zero, (int)FolderType.Suitcase, "My Suitcase");
  103. return ConvertToOpenSim(suitcase);
  104. }
  105. //private bool CreateSystemFolders(UUID principalID, XInventoryFolder suitcase)
  106. //{
  107. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Animation, "Animations");
  108. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Bodypart, "Body Parts");
  109. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.CallingCard, "Calling Cards");
  110. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Clothing, "Clothing");
  111. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Gesture, "Gestures");
  112. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Landmark, "Landmarks");
  113. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.LostAndFoundFolder, "Lost And Found");
  114. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Notecard, "Notecards");
  115. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Object, "Objects");
  116. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.SnapshotFolder, "Photo Album");
  117. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.LSLText, "Scripts");
  118. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Sound, "Sounds");
  119. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Texture, "Textures");
  120. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.TrashFolder, "Trash");
  121. // return true;
  122. //}
  123. public override InventoryFolderBase GetFolderForType(UUID principalID, FolderType type)
  124. {
  125. //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type);
  126. return GetRootFolder(principalID);
  127. }
  128. //
  129. // Use the inherited methods
  130. //
  131. //public InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
  132. //{
  133. //}
  134. // NOGO
  135. //
  136. public override InventoryCollection[] GetMultipleFoldersContent(UUID principalID, UUID[] folderID)
  137. {
  138. return new InventoryCollection[0];
  139. }
  140. //public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID)
  141. //{
  142. //}
  143. //public override bool AddFolder(InventoryFolderBase folder)
  144. //{
  145. // // Check if it's under the Suitcase folder
  146. // List<InventoryFolderBase> skel = base.GetInventorySkeleton(folder.Owner);
  147. // InventoryFolderBase suitcase = GetRootFolder(folder.Owner);
  148. // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
  149. // foreach (InventoryFolderBase f in suitDescendents)
  150. // if (folder.ParentID == f.ID)
  151. // {
  152. // XInventoryFolder xFolder = ConvertFromOpenSim(folder);
  153. // return m_Database.StoreFolder(xFolder);
  154. // }
  155. // return false;
  156. //}
  157. private List<InventoryFolderBase> GetDescendents(List<InventoryFolderBase> lst, UUID root)
  158. {
  159. List<InventoryFolderBase> direct = lst.FindAll(delegate(InventoryFolderBase f) { return f.ParentID == root; });
  160. if (direct == null)
  161. return new List<InventoryFolderBase>();
  162. List<InventoryFolderBase> indirect = new List<InventoryFolderBase>();
  163. foreach (InventoryFolderBase f in direct)
  164. indirect.AddRange(GetDescendents(lst, f.ID));
  165. direct.AddRange(indirect);
  166. return direct;
  167. }
  168. // Use inherited method
  169. //public bool UpdateFolder(InventoryFolderBase folder)
  170. //{
  171. //}
  172. //public override bool MoveFolder(InventoryFolderBase folder)
  173. //{
  174. // XInventoryFolder[] x = m_Database.GetFolders(
  175. // new string[] { "folderID" },
  176. // new string[] { folder.ID.ToString() });
  177. // if (x.Length == 0)
  178. // return false;
  179. // // Check if it's under the Suitcase folder
  180. // List<InventoryFolderBase> skel = base.GetInventorySkeleton(folder.Owner);
  181. // InventoryFolderBase suitcase = GetRootFolder(folder.Owner);
  182. // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
  183. // foreach (InventoryFolderBase f in suitDescendents)
  184. // if (folder.ParentID == f.ID)
  185. // {
  186. // x[0].parentFolderID = folder.ParentID;
  187. // return m_Database.StoreFolder(x[0]);
  188. // }
  189. // return false;
  190. //}
  191. public override bool DeleteFolders(UUID principalID, List<UUID> folderIDs)
  192. {
  193. // NOGO
  194. return false;
  195. }
  196. public override bool PurgeFolder(InventoryFolderBase folder)
  197. {
  198. // NOGO
  199. return false;
  200. }
  201. // Unfortunately we need to use the inherited method because of how DeRez works.
  202. // The viewer sends the folderID hard-wired in the derez message
  203. //public override bool AddItem(InventoryItemBase item)
  204. //{
  205. // // Check if it's under the Suitcase folder
  206. // List<InventoryFolderBase> skel = base.GetInventorySkeleton(item.Owner);
  207. // InventoryFolderBase suitcase = GetRootFolder(item.Owner);
  208. // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
  209. // foreach (InventoryFolderBase f in suitDescendents)
  210. // if (item.Folder == f.ID)
  211. // return m_Database.StoreItem(ConvertFromOpenSim(item));
  212. // return false;
  213. //}
  214. //public override bool UpdateItem(InventoryItemBase item)
  215. //{
  216. // // Check if it's under the Suitcase folder
  217. // List<InventoryFolderBase> skel = base.GetInventorySkeleton(item.Owner);
  218. // InventoryFolderBase suitcase = GetRootFolder(item.Owner);
  219. // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
  220. // foreach (InventoryFolderBase f in suitDescendents)
  221. // if (item.Folder == f.ID)
  222. // return m_Database.StoreItem(ConvertFromOpenSim(item));
  223. // return false;
  224. //}
  225. //public override bool MoveItems(UUID principalID, List<InventoryItemBase> items)
  226. //{
  227. // // Principal is b0rked. *sigh*
  228. // //
  229. // // Let's assume they all have the same principal
  230. // // Check if it's under the Suitcase folder
  231. // List<InventoryFolderBase> skel = base.GetInventorySkeleton(items[0].Owner);
  232. // InventoryFolderBase suitcase = GetRootFolder(items[0].Owner);
  233. // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
  234. // foreach (InventoryItemBase i in items)
  235. // {
  236. // foreach (InventoryFolderBase f in suitDescendents)
  237. // if (i.Folder == f.ID)
  238. // m_Database.MoveItem(i.ID.ToString(), i.Folder.ToString());
  239. // }
  240. // return true;
  241. //}
  242. // Let these pass. Use inherited methods.
  243. //public bool DeleteItems(UUID principalID, List<UUID> itemIDs)
  244. //{
  245. //}
  246. public override InventoryItemBase GetItem(UUID principalID, UUID itemID)
  247. {
  248. InventoryItemBase it = base.GetItem(principalID, itemID);
  249. if (it != null)
  250. {
  251. UserAccount user = m_Cache.GetUser(it.CreatorId);
  252. // Adjust the creator data
  253. if (user != null && it != null && string.IsNullOrEmpty(it.CreatorData))
  254. it.CreatorData = m_HomeURL + ";" + user.FirstName + " " + user.LastName;
  255. }
  256. return it;
  257. }
  258. //public InventoryFolderBase GetFolder(InventoryFolderBase folder)
  259. //{
  260. //}
  261. //public List<InventoryItemBase> GetActiveGestures(UUID principalID)
  262. //{
  263. //}
  264. //public int GetAssetPermissions(UUID principalID, UUID assetID)
  265. //{
  266. //}
  267. }
  268. }