GridInventoryService.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 OpenSim 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. */
  28. using System;
  29. using System.Collections.Generic;
  30. using libsecondlife;
  31. using OpenSim.Framework;
  32. using OpenSim.Framework.Communications;
  33. using OpenSim.Framework.Console;
  34. namespace OpenSim.Grid.InventoryServer
  35. {
  36. public class GridInventoryService : InventoryServiceBase
  37. {
  38. private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  39. public override void RequestInventoryForUser(LLUUID userID, InventoryFolderInfo folderCallBack,
  40. InventoryItemInfo itemCallBack)
  41. {
  42. }
  43. private bool TryGetUsersInventory(LLUUID userID, out List<InventoryFolderBase> folderList,
  44. out List<InventoryItemBase> itemsList)
  45. {
  46. List<InventoryFolderBase> rootFolders = RequestFirstLevelFolders(userID);
  47. List<InventoryItemBase> allItems = new List<InventoryItemBase>();
  48. List<InventoryFolderBase> allFolders = new List<InventoryFolderBase>();
  49. if (rootFolders != null)
  50. {
  51. allFolders.InsertRange(0, rootFolders);
  52. foreach (InventoryFolderBase subfolder in rootFolders)
  53. {
  54. List<InventoryFolderBase> subFolders = GetAllFolders(subfolder.folderID);
  55. if (subFolders != null)
  56. {
  57. allFolders.InsertRange(0, subFolders);
  58. }
  59. }
  60. }
  61. foreach (InventoryFolderBase folder in allFolders)
  62. {
  63. List<InventoryItemBase> items = RequestFolderItems(folder.folderID);
  64. if (items != null)
  65. {
  66. allItems.InsertRange(0, items);
  67. }
  68. }
  69. folderList = allFolders;
  70. itemsList = allItems;
  71. if (folderList != null)
  72. {
  73. return true;
  74. }
  75. else
  76. {
  77. return false;
  78. }
  79. }
  80. private List<InventoryFolderBase> GetAllFolders(LLUUID folder)
  81. {
  82. List<InventoryFolderBase> allFolders = new List<InventoryFolderBase>();
  83. List<InventoryFolderBase> folders = RequestSubFolders(folder);
  84. if (folders != null)
  85. {
  86. allFolders.InsertRange(0, folders);
  87. foreach (InventoryFolderBase subfolder in folders)
  88. {
  89. List<InventoryFolderBase> subFolders = GetAllFolders(subfolder.folderID);
  90. if (subFolders != null)
  91. {
  92. allFolders.InsertRange(0, subFolders);
  93. }
  94. }
  95. }
  96. return allFolders;
  97. }
  98. public InventoryCollection GetUserInventory(Guid rawUserID)
  99. {
  100. LLUUID userID = new LLUUID(rawUserID);
  101. // We get enough verbose messages later on for diagnostics
  102. //m_log.Info("[INVENTORY]: Request for inventory for " + userID.ToString());
  103. InventoryCollection invCollection = new InventoryCollection();
  104. List<InventoryFolderBase> folders;
  105. List<InventoryItemBase> allItems;
  106. if (TryGetUsersInventory(userID, out folders, out allItems))
  107. {
  108. invCollection.AllItems = allItems;
  109. invCollection.Folders = folders;
  110. invCollection.UserID = userID;
  111. }
  112. return invCollection;
  113. }
  114. public bool CreateUsersInventory(Guid rawUserID)
  115. {
  116. LLUUID userID = new LLUUID(rawUserID);
  117. m_log.Info(
  118. "[INVENTORY]: Creating new set of inventory folders for " + userID.ToString());
  119. CreateNewUserInventory(userID);
  120. return true;
  121. }
  122. public override void AddNewInventoryFolder(LLUUID userID, InventoryFolderBase folder)
  123. {
  124. AddFolder(folder);
  125. }
  126. public override void MoveExistingInventoryFolder(InventoryFolderBase folder)
  127. {
  128. MoveFolder(folder);
  129. }
  130. public override void AddNewInventoryItem(LLUUID userID, InventoryItemBase item)
  131. {
  132. AddItem(item);
  133. }
  134. public bool AddInventoryFolder(InventoryFolderBase folder)
  135. {
  136. // Right now, this actions act more like an update/insert combination than a simple create.
  137. m_log.Info(
  138. "[INVENTORY]: " +
  139. "Updating in " + folder.parentID.ToString()
  140. + ", folder " + folder.name);
  141. AddNewInventoryFolder(folder.agentID, folder);
  142. return true;
  143. }
  144. public bool MoveInventoryFolder(InventoryFolderBase folder)
  145. {
  146. m_log.Info(
  147. "[INVENTORY]: " +
  148. "Moving folder " + folder.folderID
  149. + " to " + folder.parentID.ToString());
  150. MoveExistingInventoryFolder(folder);
  151. return true;
  152. }
  153. public bool AddInventoryItem(InventoryItemBase item)
  154. {
  155. // Right now, this actions act more like an update/insert combination than a simple create.
  156. m_log.Info(
  157. "[INVENTORY]: " +
  158. "Updating in " + item.parentFolderID.ToString()
  159. + ", item " + item.inventoryName);
  160. AddNewInventoryItem(item.avatarID, item);
  161. return true;
  162. }
  163. public override void DeleteInventoryItem(LLUUID userID, InventoryItemBase item)
  164. {
  165. // extra spaces to align with other inventory messages
  166. m_log.Info(
  167. "[INVENTORY]: " +
  168. "Deleting in " + item.parentFolderID.ToString()
  169. + ", item " + item.inventoryName);
  170. DeleteItem(item);
  171. }
  172. public bool DeleteInvItem(InventoryItemBase item)
  173. {
  174. DeleteInventoryItem(item.avatarID, item);
  175. return true;
  176. }
  177. }
  178. }