GridInventoryService.cs 8.0 KB

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