GridInventoryService.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 System.Reflection;
  30. using System.Threading;
  31. using libsecondlife;
  32. using log4net;
  33. using OpenSim.Framework;
  34. using OpenSim.Framework.Communications;
  35. namespace OpenSim.Grid.InventoryServer
  36. {
  37. /// <summary>
  38. /// Used on a grid server to satisfy external inventory requests
  39. /// </summary>
  40. public class GridInventoryService : InventoryServiceBase
  41. {
  42. private static readonly ILog m_log
  43. = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  44. public override void RequestInventoryForUser(LLUUID userID, InventoryReceiptCallback callback)
  45. {
  46. }
  47. /// <summary>
  48. /// Return a user's entire inventory
  49. /// </summary>
  50. /// <param name="rawUserID"></param>
  51. /// <returns>The user's inventory. If an inventory cannot be found then an empty collection is returned.</returns>
  52. public InventoryCollection GetUserInventory(Guid rawUserID)
  53. {
  54. LLUUID userID = new LLUUID(rawUserID);
  55. m_log.InfoFormat("[GRID AGENT INVENTORY]: Processing request for inventory of {0}", userID);
  56. // Uncomment me to simulate a slow responding inventory server
  57. //Thread.Sleep(16000);
  58. InventoryCollection invCollection = new InventoryCollection();
  59. List<InventoryFolderBase> allFolders = GetInventorySkeleton(userID);
  60. if (null == allFolders)
  61. {
  62. m_log.WarnFormat("[GRID AGENT INVENTORY]: No inventory found for user {0}", rawUserID);
  63. return invCollection;
  64. }
  65. List<InventoryItemBase> allItems = new List<InventoryItemBase>();
  66. foreach (InventoryFolderBase folder in allFolders)
  67. {
  68. List<InventoryItemBase> items = RequestFolderItems(folder.ID);
  69. if (items != null)
  70. {
  71. allItems.InsertRange(0, items);
  72. }
  73. }
  74. invCollection.UserID = userID;
  75. invCollection.Folders = allFolders;
  76. invCollection.Items = allItems;
  77. // foreach (InventoryFolderBase folder in invCollection.Folders)
  78. // {
  79. // m_log.DebugFormat("[GRID AGENT INVENTORY]: Sending back folder {0} {1}", folder.Name, folder.ID);
  80. // }
  81. //
  82. // foreach (InventoryItemBase item in invCollection.Items)
  83. // {
  84. // m_log.DebugFormat("[GRID AGENT INVENTORY]: Sending back item {0} {1}, folder {2}", item.Name, item.ID, item.Folder);
  85. // }
  86. m_log.InfoFormat(
  87. "[GRID AGENT INVENTORY]: Sending back inventory response to user {0} containing {1} folders and {2} items",
  88. invCollection.UserID, invCollection.Folders.Count, invCollection.Items.Count);
  89. return invCollection;
  90. }
  91. /// <summary>
  92. /// Guid to UUID wrapper for same name IInventoryServices method
  93. /// </summary>
  94. /// <param name="rawUserID"></param>
  95. /// <returns></returns>
  96. public List<InventoryFolderBase> GetInventorySkeleton(Guid rawUserID)
  97. {
  98. LLUUID userID = new LLUUID(rawUserID);
  99. return GetInventorySkeleton(userID);
  100. }
  101. /// <summary>
  102. /// Create an inventory for the given user.
  103. /// </summary>
  104. /// <param name="rawUserID"></param>
  105. /// <returns></returns>
  106. public bool CreateUsersInventory(Guid rawUserID)
  107. {
  108. LLUUID userID = new LLUUID(rawUserID);
  109. m_log.InfoFormat("[GRID AGENT INVENTORY]: Creating new set of inventory folders for user {0}", userID);
  110. return CreateNewUserInventory(userID);
  111. }
  112. }
  113. }