HGInventoryService.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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.Data;
  36. using OpenSim.Framework;
  37. namespace OpenSim.Services.InventoryService
  38. {
  39. public class HGInventoryService : XInventoryService, IInventoryService
  40. {
  41. private static readonly ILog m_log =
  42. LogManager.GetLogger(
  43. MethodBase.GetCurrentMethod().DeclaringType);
  44. protected IXInventoryData m_Database;
  45. public HGInventoryService(IConfigSource config)
  46. : base(config)
  47. {
  48. string dllName = String.Empty;
  49. string connString = String.Empty;
  50. //string realm = "Inventory"; // OSG version doesn't use this
  51. //
  52. // Try reading the [DatabaseService] section, if it exists
  53. //
  54. IConfig dbConfig = config.Configs["DatabaseService"];
  55. if (dbConfig != null)
  56. {
  57. if (dllName == String.Empty)
  58. dllName = dbConfig.GetString("StorageProvider", String.Empty);
  59. if (connString == String.Empty)
  60. connString = dbConfig.GetString("ConnectionString", String.Empty);
  61. }
  62. //
  63. // Try reading the [InventoryService] section, if it exists
  64. //
  65. IConfig authConfig = config.Configs["InventoryService"];
  66. if (authConfig != null)
  67. {
  68. dllName = authConfig.GetString("StorageProvider", dllName);
  69. connString = authConfig.GetString("ConnectionString", connString);
  70. // realm = authConfig.GetString("Realm", realm);
  71. }
  72. //
  73. // We tried, but this doesn't exist. We can't proceed.
  74. //
  75. if (dllName == String.Empty)
  76. throw new Exception("No StorageProvider configured");
  77. m_Database = LoadPlugin<IXInventoryData>(dllName,
  78. new Object[] {connString, String.Empty});
  79. if (m_Database == null)
  80. throw new Exception("Could not find a storage interface in the given module");
  81. m_log.Debug("[HG INVENTORY SERVICE]: Starting...");
  82. }
  83. public override bool CreateUserInventory(UUID principalID)
  84. {
  85. // NOGO
  86. return false;
  87. }
  88. public override List<InventoryFolderBase> GetInventorySkeleton(UUID principalID)
  89. {
  90. // NOGO for this inventory service
  91. return new List<InventoryFolderBase>();
  92. }
  93. public override InventoryFolderBase GetRootFolder(UUID principalID)
  94. {
  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)AssetType.Folder, "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, AssetType type)
  124. {
  125. return GetRootFolder(principalID);
  126. }
  127. //
  128. // Use the inherited methods
  129. //
  130. //public InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
  131. //{
  132. //}
  133. //public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID)
  134. //{
  135. //}
  136. //public override bool AddFolder(InventoryFolderBase folder)
  137. //{
  138. // // Check if it's under the Suitcase folder
  139. // List<InventoryFolderBase> skel = base.GetInventorySkeleton(folder.Owner);
  140. // InventoryFolderBase suitcase = GetRootFolder(folder.Owner);
  141. // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
  142. // foreach (InventoryFolderBase f in suitDescendents)
  143. // if (folder.ParentID == f.ID)
  144. // {
  145. // XInventoryFolder xFolder = ConvertFromOpenSim(folder);
  146. // return m_Database.StoreFolder(xFolder);
  147. // }
  148. // return false;
  149. //}
  150. private List<InventoryFolderBase> GetDescendents(List<InventoryFolderBase> lst, UUID root)
  151. {
  152. List<InventoryFolderBase> direct = lst.FindAll(delegate(InventoryFolderBase f) { return f.ParentID == root; });
  153. if (direct == null)
  154. return new List<InventoryFolderBase>();
  155. List<InventoryFolderBase> indirect = new List<InventoryFolderBase>();
  156. foreach (InventoryFolderBase f in direct)
  157. indirect.AddRange(GetDescendents(lst, f.ID));
  158. direct.AddRange(indirect);
  159. return direct;
  160. }
  161. // Use inherited method
  162. //public bool UpdateFolder(InventoryFolderBase folder)
  163. //{
  164. //}
  165. //public override bool MoveFolder(InventoryFolderBase folder)
  166. //{
  167. // XInventoryFolder[] x = m_Database.GetFolders(
  168. // new string[] { "folderID" },
  169. // new string[] { folder.ID.ToString() });
  170. // if (x.Length == 0)
  171. // return false;
  172. // // Check if it's under the Suitcase folder
  173. // List<InventoryFolderBase> skel = base.GetInventorySkeleton(folder.Owner);
  174. // InventoryFolderBase suitcase = GetRootFolder(folder.Owner);
  175. // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
  176. // foreach (InventoryFolderBase f in suitDescendents)
  177. // if (folder.ParentID == f.ID)
  178. // {
  179. // x[0].parentFolderID = folder.ParentID;
  180. // return m_Database.StoreFolder(x[0]);
  181. // }
  182. // return false;
  183. //}
  184. public override bool DeleteFolders(UUID principalID, List<UUID> folderIDs)
  185. {
  186. // NOGO
  187. return false;
  188. }
  189. public override bool PurgeFolder(InventoryFolderBase folder)
  190. {
  191. // NOGO
  192. return false;
  193. }
  194. // Unfortunately we need to use the inherited method because of how DeRez works.
  195. // The viewer sends the folderID hard-wired in the derez message
  196. //public override bool AddItem(InventoryItemBase item)
  197. //{
  198. // // Check if it's under the Suitcase folder
  199. // List<InventoryFolderBase> skel = base.GetInventorySkeleton(item.Owner);
  200. // InventoryFolderBase suitcase = GetRootFolder(item.Owner);
  201. // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
  202. // foreach (InventoryFolderBase f in suitDescendents)
  203. // if (item.Folder == f.ID)
  204. // return m_Database.StoreItem(ConvertFromOpenSim(item));
  205. // return false;
  206. //}
  207. //public override bool UpdateItem(InventoryItemBase item)
  208. //{
  209. // // Check if it's under the Suitcase folder
  210. // List<InventoryFolderBase> skel = base.GetInventorySkeleton(item.Owner);
  211. // InventoryFolderBase suitcase = GetRootFolder(item.Owner);
  212. // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
  213. // foreach (InventoryFolderBase f in suitDescendents)
  214. // if (item.Folder == f.ID)
  215. // return m_Database.StoreItem(ConvertFromOpenSim(item));
  216. // return false;
  217. //}
  218. //public override bool MoveItems(UUID principalID, List<InventoryItemBase> items)
  219. //{
  220. // // Principal is b0rked. *sigh*
  221. // //
  222. // // Let's assume they all have the same principal
  223. // // Check if it's under the Suitcase folder
  224. // List<InventoryFolderBase> skel = base.GetInventorySkeleton(items[0].Owner);
  225. // InventoryFolderBase suitcase = GetRootFolder(items[0].Owner);
  226. // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
  227. // foreach (InventoryItemBase i in items)
  228. // {
  229. // foreach (InventoryFolderBase f in suitDescendents)
  230. // if (i.Folder == f.ID)
  231. // m_Database.MoveItem(i.ID.ToString(), i.Folder.ToString());
  232. // }
  233. // return true;
  234. //}
  235. // Let these pass. Use inherited methods.
  236. //public bool DeleteItems(UUID principalID, List<UUID> itemIDs)
  237. //{
  238. //}
  239. //public InventoryItemBase GetItem(InventoryItemBase item)
  240. //{
  241. //}
  242. //public InventoryFolderBase GetFolder(InventoryFolderBase folder)
  243. //{
  244. //}
  245. //public List<InventoryItemBase> GetActiveGestures(UUID principalID)
  246. //{
  247. //}
  248. //public int GetAssetPermissions(UUID principalID, UUID assetID)
  249. //{
  250. //}
  251. }
  252. }