HGInventoryService.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. protected new IXInventoryData m_Database;
  54. private string m_ProfileServiceURL;
  55. private IUserAccountService m_UserAccountService;
  56. private UserAccountCache m_Cache;
  57. public HGInventoryService(IConfigSource config)
  58. : base(config)
  59. {
  60. m_log.Debug("[HGInventory Service]: Starting");
  61. string dllName = String.Empty;
  62. string connString = String.Empty;
  63. //string realm = "Inventory"; // OSG version doesn't use this
  64. //
  65. // Try reading the [DatabaseService] section, if it exists
  66. //
  67. IConfig dbConfig = config.Configs["DatabaseService"];
  68. if (dbConfig != null)
  69. {
  70. if (dllName == String.Empty)
  71. dllName = dbConfig.GetString("StorageProvider", String.Empty);
  72. if (connString == String.Empty)
  73. connString = dbConfig.GetString("ConnectionString", String.Empty);
  74. }
  75. //
  76. // Try reading the [InventoryService] section, if it exists
  77. //
  78. IConfig invConfig = config.Configs["HGInventoryService"];
  79. if (invConfig != null)
  80. {
  81. dllName = invConfig.GetString("StorageProvider", dllName);
  82. connString = invConfig.GetString("ConnectionString", connString);
  83. // realm = authConfig.GetString("Realm", realm);
  84. string userAccountsDll = invConfig.GetString("UserAccountsService", string.Empty);
  85. if (userAccountsDll == string.Empty)
  86. throw new Exception("Please specify UserAccountsService in HGInventoryService configuration");
  87. Object[] args = new Object[] { config };
  88. m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userAccountsDll, args);
  89. if (m_UserAccountService == null)
  90. throw new Exception(String.Format("Unable to create UserAccountService from {0}", userAccountsDll));
  91. m_ProfileServiceURL = invConfig.GetString("ProfileServerURI", string.Empty);
  92. m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService);
  93. }
  94. //
  95. // We tried, but this doesn't exist. We can't proceed.
  96. //
  97. if (dllName == String.Empty)
  98. throw new Exception("No StorageProvider configured");
  99. m_Database = LoadPlugin<IXInventoryData>(dllName,
  100. new Object[] {connString, String.Empty});
  101. if (m_Database == null)
  102. throw new Exception("Could not find a storage interface in the given module");
  103. m_log.Debug("[HG INVENTORY SERVICE]: Starting...");
  104. }
  105. public override bool CreateUserInventory(UUID principalID)
  106. {
  107. // NOGO
  108. return false;
  109. }
  110. public override List<InventoryFolderBase> GetInventorySkeleton(UUID principalID)
  111. {
  112. // NOGO for this inventory service
  113. return new List<InventoryFolderBase>();
  114. }
  115. public override InventoryFolderBase GetRootFolder(UUID principalID)
  116. {
  117. // Warp! Root folder for travelers
  118. XInventoryFolder[] folders = m_Database.GetFolders(
  119. new string[] { "agentID", "folderName"},
  120. new string[] { principalID.ToString(), "My Suitcase" });
  121. if (folders.Length > 0)
  122. return ConvertToOpenSim(folders[0]);
  123. // make one
  124. XInventoryFolder suitcase = CreateFolder(principalID, UUID.Zero, (int)AssetType.Folder, "My Suitcase");
  125. return ConvertToOpenSim(suitcase);
  126. }
  127. //private bool CreateSystemFolders(UUID principalID, XInventoryFolder suitcase)
  128. //{
  129. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Animation, "Animations");
  130. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Bodypart, "Body Parts");
  131. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.CallingCard, "Calling Cards");
  132. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Clothing, "Clothing");
  133. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Gesture, "Gestures");
  134. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Landmark, "Landmarks");
  135. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.LostAndFoundFolder, "Lost And Found");
  136. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Notecard, "Notecards");
  137. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Object, "Objects");
  138. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.SnapshotFolder, "Photo Album");
  139. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.LSLText, "Scripts");
  140. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Sound, "Sounds");
  141. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Texture, "Textures");
  142. // CreateFolder(principalID, suitcase.folderID, (int)AssetType.TrashFolder, "Trash");
  143. // return true;
  144. //}
  145. public override InventoryFolderBase GetFolderForType(UUID principalID, AssetType type)
  146. {
  147. return GetRootFolder(principalID);
  148. }
  149. //
  150. // Use the inherited methods
  151. //
  152. //public InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
  153. //{
  154. //}
  155. //public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID)
  156. //{
  157. //}
  158. //public override bool AddFolder(InventoryFolderBase folder)
  159. //{
  160. // // Check if it's under the Suitcase folder
  161. // List<InventoryFolderBase> skel = base.GetInventorySkeleton(folder.Owner);
  162. // InventoryFolderBase suitcase = GetRootFolder(folder.Owner);
  163. // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
  164. // foreach (InventoryFolderBase f in suitDescendents)
  165. // if (folder.ParentID == f.ID)
  166. // {
  167. // XInventoryFolder xFolder = ConvertFromOpenSim(folder);
  168. // return m_Database.StoreFolder(xFolder);
  169. // }
  170. // return false;
  171. //}
  172. private List<InventoryFolderBase> GetDescendents(List<InventoryFolderBase> lst, UUID root)
  173. {
  174. List<InventoryFolderBase> direct = lst.FindAll(delegate(InventoryFolderBase f) { return f.ParentID == root; });
  175. if (direct == null)
  176. return new List<InventoryFolderBase>();
  177. List<InventoryFolderBase> indirect = new List<InventoryFolderBase>();
  178. foreach (InventoryFolderBase f in direct)
  179. indirect.AddRange(GetDescendents(lst, f.ID));
  180. direct.AddRange(indirect);
  181. return direct;
  182. }
  183. // Use inherited method
  184. //public bool UpdateFolder(InventoryFolderBase folder)
  185. //{
  186. //}
  187. //public override bool MoveFolder(InventoryFolderBase folder)
  188. //{
  189. // XInventoryFolder[] x = m_Database.GetFolders(
  190. // new string[] { "folderID" },
  191. // new string[] { folder.ID.ToString() });
  192. // if (x.Length == 0)
  193. // return false;
  194. // // Check if it's under the Suitcase folder
  195. // List<InventoryFolderBase> skel = base.GetInventorySkeleton(folder.Owner);
  196. // InventoryFolderBase suitcase = GetRootFolder(folder.Owner);
  197. // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
  198. // foreach (InventoryFolderBase f in suitDescendents)
  199. // if (folder.ParentID == f.ID)
  200. // {
  201. // x[0].parentFolderID = folder.ParentID;
  202. // return m_Database.StoreFolder(x[0]);
  203. // }
  204. // return false;
  205. //}
  206. public override bool DeleteFolders(UUID principalID, List<UUID> folderIDs)
  207. {
  208. // NOGO
  209. return false;
  210. }
  211. public override bool PurgeFolder(InventoryFolderBase folder)
  212. {
  213. // NOGO
  214. return false;
  215. }
  216. // Unfortunately we need to use the inherited method because of how DeRez works.
  217. // The viewer sends the folderID hard-wired in the derez message
  218. //public override bool AddItem(InventoryItemBase item)
  219. //{
  220. // // Check if it's under the Suitcase folder
  221. // List<InventoryFolderBase> skel = base.GetInventorySkeleton(item.Owner);
  222. // InventoryFolderBase suitcase = GetRootFolder(item.Owner);
  223. // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
  224. // foreach (InventoryFolderBase f in suitDescendents)
  225. // if (item.Folder == f.ID)
  226. // return m_Database.StoreItem(ConvertFromOpenSim(item));
  227. // return false;
  228. //}
  229. //public override bool UpdateItem(InventoryItemBase item)
  230. //{
  231. // // Check if it's under the Suitcase folder
  232. // List<InventoryFolderBase> skel = base.GetInventorySkeleton(item.Owner);
  233. // InventoryFolderBase suitcase = GetRootFolder(item.Owner);
  234. // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
  235. // foreach (InventoryFolderBase f in suitDescendents)
  236. // if (item.Folder == f.ID)
  237. // return m_Database.StoreItem(ConvertFromOpenSim(item));
  238. // return false;
  239. //}
  240. //public override bool MoveItems(UUID principalID, List<InventoryItemBase> items)
  241. //{
  242. // // Principal is b0rked. *sigh*
  243. // //
  244. // // Let's assume they all have the same principal
  245. // // Check if it's under the Suitcase folder
  246. // List<InventoryFolderBase> skel = base.GetInventorySkeleton(items[0].Owner);
  247. // InventoryFolderBase suitcase = GetRootFolder(items[0].Owner);
  248. // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
  249. // foreach (InventoryItemBase i in items)
  250. // {
  251. // foreach (InventoryFolderBase f in suitDescendents)
  252. // if (i.Folder == f.ID)
  253. // m_Database.MoveItem(i.ID.ToString(), i.Folder.ToString());
  254. // }
  255. // return true;
  256. //}
  257. // Let these pass. Use inherited methods.
  258. //public bool DeleteItems(UUID principalID, List<UUID> itemIDs)
  259. //{
  260. //}
  261. public override InventoryItemBase GetItem(InventoryItemBase item)
  262. {
  263. InventoryItemBase it = base.GetItem(item);
  264. UserAccount user = m_Cache.GetUser(it.CreatorId);
  265. // Adjust the creator data
  266. if (user != null && it != null && (it.CreatorData == null || it.CreatorData == string.Empty))
  267. it.CreatorData = m_ProfileServiceURL + "/" + it.CreatorId + ";" + user.FirstName + " " + user.LastName;
  268. return it;
  269. }
  270. //public InventoryFolderBase GetFolder(InventoryFolderBase folder)
  271. //{
  272. //}
  273. //public List<InventoryItemBase> GetActiveGestures(UUID principalID)
  274. //{
  275. //}
  276. //public int GetAssetPermissions(UUID principalID, UUID assetID)
  277. //{
  278. //}
  279. }
  280. }