GridInventoryService.cs 7.6 KB

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