1
0

HGSuitcaseInventoryService.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  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.Linq;
  30. using OpenMetaverse;
  31. using log4net;
  32. using Nini.Config;
  33. using System.Reflection;
  34. using OpenSim.Services.Base;
  35. using OpenSim.Services.Interfaces;
  36. using OpenSim.Services.InventoryService;
  37. using OpenSim.Data;
  38. using OpenSim.Framework;
  39. using OpenSim.Server.Base;
  40. namespace OpenSim.Services.HypergridService
  41. {
  42. /// <summary>
  43. /// Hypergrid inventory service. It serves the IInventoryService interface,
  44. /// but implements it in ways that are appropriate for inter-grid
  45. /// inventory exchanges. Specifically, it does not performs deletions
  46. /// and it responds to GetRootFolder requests with the ID of the
  47. /// Suitcase folder, not the actual "My Inventory" folder.
  48. /// </summary>
  49. public class HGSuitcaseInventoryService : XInventoryService, IInventoryService
  50. {
  51. private static readonly ILog m_log =
  52. LogManager.GetLogger(
  53. MethodBase.GetCurrentMethod().DeclaringType);
  54. // private string m_HomeURL;
  55. private IUserAccountService m_UserAccountService;
  56. private IAvatarService m_AvatarService;
  57. // private UserAccountCache m_Cache;
  58. private ExpiringCache<UUID, List<XInventoryFolder>> m_SuitcaseTrees = new ExpiringCache<UUID, List<XInventoryFolder>>();
  59. private ExpiringCache<UUID, AvatarAppearance> m_Appearances = new ExpiringCache<UUID, AvatarAppearance>();
  60. public HGSuitcaseInventoryService(IConfigSource config, string configName)
  61. : base(config, configName)
  62. {
  63. m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Starting with config name {0}", configName);
  64. if (configName != string.Empty)
  65. m_ConfigName = configName;
  66. if (m_Database == null)
  67. m_log.ErrorFormat("[HG SUITCASE INVENTORY SERVICE]: m_Database is null!");
  68. //
  69. // Try reading the [InventoryService] section, if it exists
  70. //
  71. IConfig invConfig = config.Configs[m_ConfigName];
  72. if (invConfig != null)
  73. {
  74. string userAccountsDll = invConfig.GetString("UserAccountsService", string.Empty);
  75. if (userAccountsDll == string.Empty)
  76. throw new Exception("Please specify UserAccountsService in HGInventoryService configuration");
  77. Object[] args = new Object[] { config };
  78. m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userAccountsDll, args);
  79. if (m_UserAccountService == null)
  80. throw new Exception(String.Format("Unable to create UserAccountService from {0}", userAccountsDll));
  81. string avatarDll = invConfig.GetString("AvatarService", string.Empty);
  82. if (avatarDll == string.Empty)
  83. throw new Exception("Please specify AvatarService in HGInventoryService configuration");
  84. m_AvatarService = ServerUtils.LoadPlugin<IAvatarService>(avatarDll, args);
  85. if (m_AvatarService == null)
  86. throw new Exception(String.Format("Unable to create m_AvatarService from {0}", avatarDll));
  87. // m_HomeURL = Util.GetConfigVarFromSections<string>(config, "HomeURI",
  88. // new string[] { "Startup", "Hypergrid", m_ConfigName }, String.Empty);
  89. // m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService);
  90. }
  91. m_log.Debug("[HG SUITCASE INVENTORY SERVICE]: Starting...");
  92. }
  93. public override bool CreateUserInventory(UUID principalID)
  94. {
  95. // NOGO
  96. return false;
  97. }
  98. public override List<InventoryFolderBase> GetInventorySkeleton(UUID principalID)
  99. {
  100. XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
  101. if (suitcase == null)
  102. {
  103. m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Found no suitcase folder for user {0} when looking for inventory skeleton", principalID);
  104. return null;
  105. }
  106. List<XInventoryFolder> tree = GetFolderTree(principalID, suitcase.folderID);
  107. if (tree == null || (tree != null && tree.Count == 0))
  108. return null;
  109. List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
  110. foreach (XInventoryFolder x in tree)
  111. {
  112. folders.Add(ConvertToOpenSim(x));
  113. }
  114. SetAsNormalFolder(suitcase);
  115. folders.Add(ConvertToOpenSim(suitcase));
  116. return folders;
  117. }
  118. public override InventoryCollection GetUserInventory(UUID userID)
  119. {
  120. m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Get Suitcase inventory for user {0}", userID);
  121. InventoryCollection userInventory = new InventoryCollection();
  122. userInventory.UserID = userID;
  123. userInventory.Folders = new List<InventoryFolderBase>();
  124. userInventory.Items = new List<InventoryItemBase>();
  125. XInventoryFolder suitcase = GetSuitcaseXFolder(userID);
  126. if (suitcase == null)
  127. {
  128. m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Found no suitcase folder for user {0} when looking for user inventory", userID);
  129. return null;
  130. }
  131. List<XInventoryFolder> tree = GetFolderTree(userID, suitcase.folderID);
  132. if (tree == null || (tree != null && tree.Count == 0))
  133. {
  134. SetAsNormalFolder(suitcase);
  135. userInventory.Folders.Add(ConvertToOpenSim(suitcase));
  136. return userInventory;
  137. }
  138. List<InventoryItemBase> items;
  139. foreach (XInventoryFolder f in tree)
  140. {
  141. // Add the items of this subfolder
  142. items = GetFolderItems(userID, f.folderID);
  143. if (items != null && items.Count > 0)
  144. {
  145. userInventory.Items.AddRange(items);
  146. }
  147. // Add the folder itself
  148. userInventory.Folders.Add(ConvertToOpenSim(f));
  149. }
  150. items = GetFolderItems(userID, suitcase.folderID);
  151. if (items != null && items.Count > 0)
  152. {
  153. userInventory.Items.AddRange(items);
  154. }
  155. SetAsNormalFolder(suitcase);
  156. userInventory.Folders.Add(ConvertToOpenSim(suitcase));
  157. m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetUserInventory for user {0} returning {1} folders and {2} items",
  158. userID, userInventory.Folders.Count, userInventory.Items.Count);
  159. return userInventory;
  160. }
  161. public override InventoryFolderBase GetRootFolder(UUID principalID)
  162. {
  163. m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetRootFolder for {0}", principalID);
  164. // Let's find out the local root folder
  165. XInventoryFolder root = GetRootXFolder(principalID);
  166. if (root == null)
  167. {
  168. m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to retrieve local root folder for user {0}", principalID);
  169. return null;
  170. }
  171. // Warp! Root folder for travelers is the suitcase folder
  172. XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
  173. if (suitcase == null)
  174. {
  175. m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: User {0} does not have a Suitcase folder. Creating it...", principalID);
  176. // make one, and let's add it to the user's inventory as a direct child of the root folder
  177. // In the DB we tag it as type 100, but we use -1 (Unknown) outside
  178. suitcase = CreateFolder(principalID, root.folderID, 100, "My Suitcase");
  179. if (suitcase == null)
  180. m_log.ErrorFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to create suitcase folder");
  181. m_Database.StoreFolder(suitcase);
  182. // Create System folders
  183. CreateSystemFolders(principalID, suitcase.folderID);
  184. }
  185. SetAsNormalFolder(suitcase);
  186. return ConvertToOpenSim(suitcase);
  187. }
  188. protected void CreateSystemFolders(UUID principalID, UUID rootID)
  189. {
  190. m_log.Debug("[HG SUITCASE INVENTORY SERVICE]: Creating System folders under Suitcase...");
  191. XInventoryFolder[] sysFolders = GetSystemFolders(principalID, rootID);
  192. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Animation) return true; return false; }))
  193. CreateFolder(principalID, rootID, (int)AssetType.Animation, "Animations");
  194. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Bodypart) return true; return false; }))
  195. CreateFolder(principalID, rootID, (int)AssetType.Bodypart, "Body Parts");
  196. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.CallingCard) return true; return false; }))
  197. CreateFolder(principalID, rootID, (int)AssetType.CallingCard, "Calling Cards");
  198. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Clothing) return true; return false; }))
  199. CreateFolder(principalID, rootID, (int)AssetType.Clothing, "Clothing");
  200. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Gesture) return true; return false; }))
  201. CreateFolder(principalID, rootID, (int)AssetType.Gesture, "Gestures");
  202. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Landmark) return true; return false; }))
  203. CreateFolder(principalID, rootID, (int)AssetType.Landmark, "Landmarks");
  204. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.LostAndFoundFolder) return true; return false; }))
  205. CreateFolder(principalID, rootID, (int)AssetType.LostAndFoundFolder, "Lost And Found");
  206. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Notecard) return true; return false; }))
  207. CreateFolder(principalID, rootID, (int)AssetType.Notecard, "Notecards");
  208. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Object) return true; return false; }))
  209. CreateFolder(principalID, rootID, (int)AssetType.Object, "Objects");
  210. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.SnapshotFolder) return true; return false; }))
  211. CreateFolder(principalID, rootID, (int)AssetType.SnapshotFolder, "Photo Album");
  212. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.LSLText) return true; return false; }))
  213. CreateFolder(principalID, rootID, (int)AssetType.LSLText, "Scripts");
  214. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Sound) return true; return false; }))
  215. CreateFolder(principalID, rootID, (int)AssetType.Sound, "Sounds");
  216. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Texture) return true; return false; }))
  217. CreateFolder(principalID, rootID, (int)AssetType.Texture, "Textures");
  218. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.TrashFolder) return true; return false; }))
  219. CreateFolder(principalID, rootID, (int)AssetType.TrashFolder, "Trash");
  220. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.FavoriteFolder) return true; return false; }))
  221. CreateFolder(principalID, rootID, (int)AssetType.FavoriteFolder, "Favorites");
  222. if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.CurrentOutfitFolder) return true; return false; }))
  223. CreateFolder(principalID, rootID, (int)AssetType.CurrentOutfitFolder, "Current Outfit");
  224. }
  225. public override InventoryFolderBase GetFolderForType(UUID principalID, AssetType type)
  226. {
  227. //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type);
  228. XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
  229. if (suitcase == null)
  230. {
  231. m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Found no suitcase folder for user {0} when looking for child type folder {1}", principalID, type);
  232. return null;
  233. }
  234. XInventoryFolder[] folders = m_Database.GetFolders(
  235. new string[] { "agentID", "type", "parentFolderID" },
  236. new string[] { principalID.ToString(), ((int)type).ToString(), suitcase.folderID.ToString() });
  237. if (folders.Length == 0)
  238. {
  239. m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Found no folder for type {0} for user {1}", type, principalID);
  240. return null;
  241. }
  242. m_log.DebugFormat(
  243. "[HG SUITCASE INVENTORY SERVICE]: Found folder {0} {1} for type {2} for user {3}",
  244. folders[0].folderName, folders[0].folderID, type, principalID);
  245. return ConvertToOpenSim(folders[0]);
  246. }
  247. public override InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
  248. {
  249. InventoryCollection coll = null;
  250. if (!IsWithinSuitcaseTree(principalID, folderID))
  251. return new InventoryCollection();
  252. coll = base.GetFolderContent(principalID, folderID);
  253. if (coll == null)
  254. {
  255. m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Something wrong with user {0}'s suitcase folder", principalID);
  256. coll = new InventoryCollection();
  257. }
  258. return coll;
  259. }
  260. public override List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID)
  261. {
  262. // Let's do a bit of sanity checking, more than the base service does
  263. // make sure the given folder exists under the suitcase tree of this user
  264. if (!IsWithinSuitcaseTree(principalID, folderID))
  265. return new List<InventoryItemBase>();
  266. return base.GetFolderItems(principalID, folderID);
  267. }
  268. public override bool AddFolder(InventoryFolderBase folder)
  269. {
  270. //m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: AddFolder {0} {1}", folder.Name, folder.ParentID);
  271. // Let's do a bit of sanity checking, more than the base service does
  272. // make sure the given folder's parent folder exists under the suitcase tree of this user
  273. if (!IsWithinSuitcaseTree(folder.Owner, folder.ParentID))
  274. return false;
  275. // OK, it's legit
  276. if (base.AddFolder(folder))
  277. {
  278. List<XInventoryFolder> tree;
  279. if (m_SuitcaseTrees.TryGetValue(folder.Owner, out tree))
  280. tree.Add(ConvertFromOpenSim(folder));
  281. return true;
  282. }
  283. return false;
  284. }
  285. public override bool UpdateFolder(InventoryFolderBase folder)
  286. {
  287. //m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Update folder {0}, version {1}", folder.ID, folder.Version);
  288. if (!IsWithinSuitcaseTree(folder.Owner, folder.ID))
  289. {
  290. m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: folder {0} not within Suitcase tree", folder.Name);
  291. return false;
  292. }
  293. // For all others
  294. return base.UpdateFolder(folder);
  295. }
  296. public override bool MoveFolder(InventoryFolderBase folder)
  297. {
  298. if (!IsWithinSuitcaseTree(folder.Owner, folder.ID) ||
  299. !IsWithinSuitcaseTree(folder.Owner, folder.ParentID))
  300. return false;
  301. return base.MoveFolder(folder);
  302. }
  303. public override bool DeleteFolders(UUID principalID, List<UUID> folderIDs)
  304. {
  305. // NOGO
  306. return false;
  307. }
  308. public override bool PurgeFolder(InventoryFolderBase folder)
  309. {
  310. // NOGO
  311. return false;
  312. }
  313. public override bool AddItem(InventoryItemBase item)
  314. {
  315. // Let's do a bit of sanity checking, more than the base service does
  316. // make sure the given folder's parent folder exists under the suitcase tree of this user
  317. if (!IsWithinSuitcaseTree(item.Owner, item.Folder))
  318. return false;
  319. // OK, it's legit
  320. return base.AddItem(item);
  321. }
  322. public override bool UpdateItem(InventoryItemBase item)
  323. {
  324. if (!IsWithinSuitcaseTree(item.Owner, item.Folder))
  325. return false;
  326. return base.UpdateItem(item);
  327. }
  328. public override bool MoveItems(UUID principalID, List<InventoryItemBase> items)
  329. {
  330. // Principal is b0rked. *sigh*
  331. if (!IsWithinSuitcaseTree(items[0].Owner, items[0].Folder))
  332. return false;
  333. return base.MoveItems(principalID, items);
  334. }
  335. public override bool DeleteItems(UUID principalID, List<UUID> itemIDs)
  336. {
  337. return false;
  338. }
  339. public new InventoryItemBase GetItem(InventoryItemBase item)
  340. {
  341. InventoryItemBase it = base.GetItem(item);
  342. if (it == null)
  343. {
  344. m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to retrieve item {0} ({1}) in folder {2}",
  345. item.Name, item.ID, item.Folder);
  346. return null;
  347. }
  348. if (!IsWithinSuitcaseTree(it.Owner, it.Folder) && !IsPartOfAppearance(it.Owner, it.ID))
  349. {
  350. m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Item {0} (folder {1}) is not within Suitcase",
  351. it.Name, it.Folder);
  352. return null;
  353. }
  354. // UserAccount user = m_Cache.GetUser(it.CreatorId);
  355. // // Adjust the creator data
  356. // if (user != null && it != null && (it.CreatorData == null || it.CreatorData == string.Empty))
  357. // it.CreatorData = m_HomeURL + ";" + user.FirstName + " " + user.LastName;
  358. //}
  359. return it;
  360. }
  361. public new InventoryFolderBase GetFolder(InventoryFolderBase folder)
  362. {
  363. InventoryFolderBase f = base.GetFolder(folder);
  364. if (f != null)
  365. {
  366. if (!IsWithinSuitcaseTree(f.Owner, f.ID))
  367. return null;
  368. }
  369. return f;
  370. }
  371. //public List<InventoryItemBase> GetActiveGestures(UUID principalID)
  372. //{
  373. //}
  374. //public int GetAssetPermissions(UUID principalID, UUID assetID)
  375. //{
  376. //}
  377. #region Auxiliary functions
  378. private XInventoryFolder GetXFolder(UUID userID, UUID folderID)
  379. {
  380. XInventoryFolder[] folders = m_Database.GetFolders(
  381. new string[] { "agentID", "folderID" },
  382. new string[] { userID.ToString(), folderID.ToString() });
  383. if (folders.Length == 0)
  384. return null;
  385. return folders[0];
  386. }
  387. private XInventoryFolder GetRootXFolder(UUID principalID)
  388. {
  389. XInventoryFolder[] folders = m_Database.GetFolders(
  390. new string[] { "agentID", "folderName", "type" },
  391. new string[] { principalID.ToString(), "My Inventory", ((int)AssetType.RootFolder).ToString() });
  392. if (folders != null && folders.Length > 0)
  393. return folders[0];
  394. // OK, so the RootFolder type didn't work. Let's look for any type with parent UUID.Zero.
  395. folders = m_Database.GetFolders(
  396. new string[] { "agentID", "folderName", "parentFolderID" },
  397. new string[] { principalID.ToString(), "My Inventory", UUID.Zero.ToString() });
  398. if (folders != null && folders.Length > 0)
  399. return folders[0];
  400. return null;
  401. }
  402. private XInventoryFolder GetCurrentOutfitXFolder(UUID userID)
  403. {
  404. XInventoryFolder root = GetRootXFolder(userID);
  405. if (root == null)
  406. return null;
  407. XInventoryFolder[] folders = m_Database.GetFolders(
  408. new string[] { "agentID", "type", "parentFolderID" },
  409. new string[] { userID.ToString(), ((int)AssetType.CurrentOutfitFolder).ToString(), root.folderID.ToString() });
  410. if (folders.Length == 0)
  411. return null;
  412. return folders[0];
  413. }
  414. private XInventoryFolder GetSuitcaseXFolder(UUID principalID)
  415. {
  416. // Warp! Root folder for travelers
  417. XInventoryFolder[] folders = m_Database.GetFolders(
  418. new string[] { "agentID", "type" },
  419. new string[] { principalID.ToString(), "100" }); // This is a special folder type...
  420. if (folders != null && folders.Length > 0)
  421. return folders[0];
  422. // check to see if we have the old Suitcase folder
  423. folders = m_Database.GetFolders(
  424. new string[] { "agentID", "folderName", "parentFolderID" },
  425. new string[] { principalID.ToString(), "My Suitcase", UUID.Zero.ToString() });
  426. if (folders != null && folders.Length > 0)
  427. {
  428. // Move it to under the root folder
  429. XInventoryFolder root = GetRootXFolder(principalID);
  430. folders[0].parentFolderID = root.folderID;
  431. folders[0].type = 100;
  432. m_Database.StoreFolder(folders[0]);
  433. return folders[0];
  434. }
  435. return null;
  436. }
  437. private void SetAsNormalFolder(XInventoryFolder suitcase)
  438. {
  439. suitcase.type = (short)AssetType.Folder;
  440. }
  441. private List<XInventoryFolder> GetFolderTree(UUID principalID, UUID folder)
  442. {
  443. List<XInventoryFolder> t = null;
  444. if (m_SuitcaseTrees.TryGetValue(principalID, out t))
  445. return t;
  446. // Get the tree of the suitcase folder
  447. t = GetFolderTreeRecursive(folder);
  448. m_SuitcaseTrees.AddOrUpdate(principalID, t, 5*60); // 5minutes
  449. return t;
  450. }
  451. private List<XInventoryFolder> GetFolderTreeRecursive(UUID root)
  452. {
  453. List<XInventoryFolder> tree = new List<XInventoryFolder>();
  454. XInventoryFolder[] folders = m_Database.GetFolders(
  455. new string[] { "parentFolderID" },
  456. new string[] { root.ToString() });
  457. if (folders == null || (folders != null && folders.Length == 0))
  458. return tree; // empty tree
  459. else
  460. {
  461. foreach (XInventoryFolder f in folders)
  462. {
  463. tree.Add(f);
  464. tree.AddRange(GetFolderTreeRecursive(f.folderID));
  465. }
  466. return tree;
  467. }
  468. }
  469. /// <summary>
  470. /// Return true if the folderID is a subfolder of the Suitcase or the suitcase folder itself
  471. /// </summary>
  472. /// <param name="folderID"></param>
  473. /// <param name="root"></param>
  474. /// <param name="suitcase"></param>
  475. /// <returns></returns>
  476. private bool IsWithinSuitcaseTree(UUID principalID, UUID folderID)
  477. {
  478. XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
  479. if (suitcase == null)
  480. {
  481. m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: User {0} does not have a Suitcase folder", principalID);
  482. return false;
  483. }
  484. List<XInventoryFolder> tree = new List<XInventoryFolder>();
  485. tree.Add(suitcase); // Warp! the tree is the real root folder plus the children of the suitcase folder
  486. tree.AddRange(GetFolderTree(principalID, suitcase.folderID));
  487. // Also add the Current Outfit folder to the list of available folders
  488. tree.Add(GetCurrentOutfitXFolder(principalID));
  489. XInventoryFolder f = tree.Find(delegate(XInventoryFolder fl)
  490. {
  491. if (fl.folderID == folderID) return true;
  492. else return false;
  493. });
  494. if (f == null) return false;
  495. else return true;
  496. }
  497. #endregion
  498. #region Avatar Appearance
  499. private AvatarAppearance GetAppearance(UUID principalID)
  500. {
  501. AvatarAppearance a = null;
  502. if (m_Appearances.TryGetValue(principalID, out a))
  503. return a;
  504. a = m_AvatarService.GetAppearance(principalID);
  505. m_Appearances.AddOrUpdate(principalID, a, 5 * 60); // 5minutes
  506. return a;
  507. }
  508. private bool IsPartOfAppearance(UUID principalID, UUID itemID)
  509. {
  510. AvatarAppearance a = GetAppearance(principalID);
  511. if (a == null)
  512. return false;
  513. // Check wearables (body parts and clothes)
  514. for (int i = 0; i < a.Wearables.Length; i++)
  515. {
  516. for (int j = 0; j < a.Wearables[i].Count; j++)
  517. {
  518. if (a.Wearables[i][j].ItemID == itemID)
  519. {
  520. //m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: item {0} is a wearable", itemID);
  521. return true;
  522. }
  523. }
  524. }
  525. // Check attachments
  526. if (a.GetAttachmentForItem(itemID) != null)
  527. {
  528. //m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: item {0} is an attachment", itemID);
  529. return true;
  530. }
  531. return false;
  532. }
  533. #endregion
  534. }
  535. }