OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
HGInventoryService.cs
Go to the documentation of this file.
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 
28 using System;
29 using System.Collections.Generic;
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 
41 namespace OpenSim.Services.HypergridService
42 {
51  {
52  private static readonly ILog m_log =
53  LogManager.GetLogger(
54  MethodBase.GetCurrentMethod().DeclaringType);
55 
56  private string m_HomeURL;
57  private IUserAccountService m_UserAccountService;
58 
59  private UserAccountCache m_Cache;
60 
61  public HGInventoryService(IConfigSource config, string configName)
62  : base(config, configName)
63  {
64  m_log.Debug("[HGInventory Service]: Starting");
65  if (configName != string.Empty)
66  m_ConfigName = configName;
67 
68  //
69  // Try reading the [InventoryService] section, if it exists
70  //
71  IConfig invConfig = config.Configs[m_ConfigName];
72  if (invConfig != null)
73  {
74  // realm = authConfig.GetString("Realm", realm);
75  string userAccountsDll = invConfig.GetString("UserAccountsService", string.Empty);
76  if (userAccountsDll == string.Empty)
77  throw new Exception("Please specify UserAccountsService in HGInventoryService configuration");
78 
79  Object[] args = new Object[] { config };
80  m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userAccountsDll, args);
81  if (m_UserAccountService == null)
82  throw new Exception(String.Format("Unable to create UserAccountService from {0}", userAccountsDll));
83 
84  m_HomeURL = Util.GetConfigVarFromSections<string>(config, "HomeURI",
85  new string[] { "Startup", "Hypergrid", m_ConfigName }, String.Empty);
86 
87  m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService);
88  }
89 
90  m_log.Debug("[HG INVENTORY SERVICE]: Starting...");
91  }
92 
93  public override bool CreateUserInventory(UUID principalID)
94  {
95  // NOGO
96  return false;
97  }
98 
99 
100  public override List<InventoryFolderBase> GetInventorySkeleton(UUID principalID)
101  {
102  // NOGO for this inventory service
103  return new List<InventoryFolderBase>();
104  }
105 
106  public override InventoryFolderBase GetRootFolder(UUID principalID)
107  {
108  //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetRootFolder for {0}", principalID);
109  // Warp! Root folder for travelers
110  XInventoryFolder[] folders = m_Database.GetFolders(
111  new string[] { "agentID", "folderName"},
112  new string[] { principalID.ToString(), "My Suitcase" });
113 
114  if (folders.Length > 0)
115  return ConvertToOpenSim(folders[0]);
116 
117  // make one
118  XInventoryFolder suitcase = CreateFolder(principalID, UUID.Zero, (int)FolderType.Suitcase, "My Suitcase");
119  return ConvertToOpenSim(suitcase);
120  }
121 
122  //private bool CreateSystemFolders(UUID principalID, XInventoryFolder suitcase)
123  //{
124 
125  // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Animation, "Animations");
126  // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Bodypart, "Body Parts");
127  // CreateFolder(principalID, suitcase.folderID, (int)AssetType.CallingCard, "Calling Cards");
128  // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Clothing, "Clothing");
129  // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Gesture, "Gestures");
130  // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Landmark, "Landmarks");
131  // CreateFolder(principalID, suitcase.folderID, (int)AssetType.LostAndFoundFolder, "Lost And Found");
132  // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Notecard, "Notecards");
133  // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Object, "Objects");
134  // CreateFolder(principalID, suitcase.folderID, (int)AssetType.SnapshotFolder, "Photo Album");
135  // CreateFolder(principalID, suitcase.folderID, (int)AssetType.LSLText, "Scripts");
136  // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Sound, "Sounds");
137  // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Texture, "Textures");
138  // CreateFolder(principalID, suitcase.folderID, (int)AssetType.TrashFolder, "Trash");
139 
140  // return true;
141  //}
142 
143 
144  public override InventoryFolderBase GetFolderForType(UUID principalID, FolderType type)
145  {
146  //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type);
147  return GetRootFolder(principalID);
148  }
149 
150  //
151  // Use the inherited methods
152  //
153  //public InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
154  //{
155  //}
156 
157  // NOGO
158  //
159  public override InventoryCollection[] GetMultipleFoldersContent(UUID principalID, UUID[] folderID)
160  {
161  return new InventoryCollection[0];
162  }
163 
164  //public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID)
165  //{
166  //}
167 
168  //public override bool AddFolder(InventoryFolderBase folder)
169  //{
170  // // Check if it's under the Suitcase folder
171  // List<InventoryFolderBase> skel = base.GetInventorySkeleton(folder.Owner);
172  // InventoryFolderBase suitcase = GetRootFolder(folder.Owner);
173  // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
174 
175  // foreach (InventoryFolderBase f in suitDescendents)
176  // if (folder.ParentID == f.ID)
177  // {
178  // XInventoryFolder xFolder = ConvertFromOpenSim(folder);
179  // return m_Database.StoreFolder(xFolder);
180  // }
181  // return false;
182  //}
183 
184  private List<InventoryFolderBase> GetDescendents(List<InventoryFolderBase> lst, UUID root)
185  {
186  List<InventoryFolderBase> direct = lst.FindAll(delegate(InventoryFolderBase f) { return f.ParentID == root; });
187  if (direct == null)
188  return new List<InventoryFolderBase>();
189 
190  List<InventoryFolderBase> indirect = new List<InventoryFolderBase>();
191  foreach (InventoryFolderBase f in direct)
192  indirect.AddRange(GetDescendents(lst, f.ID));
193 
194  direct.AddRange(indirect);
195  return direct;
196  }
197 
198  // Use inherited method
199  //public bool UpdateFolder(InventoryFolderBase folder)
200  //{
201  //}
202 
203  //public override bool MoveFolder(InventoryFolderBase folder)
204  //{
205  // XInventoryFolder[] x = m_Database.GetFolders(
206  // new string[] { "folderID" },
207  // new string[] { folder.ID.ToString() });
208 
209  // if (x.Length == 0)
210  // return false;
211 
212  // // Check if it's under the Suitcase folder
213  // List<InventoryFolderBase> skel = base.GetInventorySkeleton(folder.Owner);
214  // InventoryFolderBase suitcase = GetRootFolder(folder.Owner);
215  // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
216 
217  // foreach (InventoryFolderBase f in suitDescendents)
218  // if (folder.ParentID == f.ID)
219  // {
220  // x[0].parentFolderID = folder.ParentID;
221  // return m_Database.StoreFolder(x[0]);
222  // }
223 
224  // return false;
225  //}
226 
227  public override bool DeleteFolders(UUID principalID, List<UUID> folderIDs)
228  {
229  // NOGO
230  return false;
231  }
232 
233  public override bool PurgeFolder(InventoryFolderBase folder)
234  {
235  // NOGO
236  return false;
237  }
238 
239  // Unfortunately we need to use the inherited method because of how DeRez works.
240  // The viewer sends the folderID hard-wired in the derez message
241  //public override bool AddItem(InventoryItemBase item)
242  //{
243  // // Check if it's under the Suitcase folder
244  // List<InventoryFolderBase> skel = base.GetInventorySkeleton(item.Owner);
245  // InventoryFolderBase suitcase = GetRootFolder(item.Owner);
246  // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
247 
248  // foreach (InventoryFolderBase f in suitDescendents)
249  // if (item.Folder == f.ID)
250  // return m_Database.StoreItem(ConvertFromOpenSim(item));
251 
252  // return false;
253  //}
254 
255  //public override bool UpdateItem(InventoryItemBase item)
256  //{
257  // // Check if it's under the Suitcase folder
258  // List<InventoryFolderBase> skel = base.GetInventorySkeleton(item.Owner);
259  // InventoryFolderBase suitcase = GetRootFolder(item.Owner);
260  // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
261 
262  // foreach (InventoryFolderBase f in suitDescendents)
263  // if (item.Folder == f.ID)
264  // return m_Database.StoreItem(ConvertFromOpenSim(item));
265 
266  // return false;
267  //}
268 
269  //public override bool MoveItems(UUID principalID, List<InventoryItemBase> items)
270  //{
271  // // Principal is b0rked. *sigh*
272  // //
273  // // Let's assume they all have the same principal
274  // // Check if it's under the Suitcase folder
275  // List<InventoryFolderBase> skel = base.GetInventorySkeleton(items[0].Owner);
276  // InventoryFolderBase suitcase = GetRootFolder(items[0].Owner);
277  // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
278 
279  // foreach (InventoryItemBase i in items)
280  // {
281  // foreach (InventoryFolderBase f in suitDescendents)
282  // if (i.Folder == f.ID)
283  // m_Database.MoveItem(i.ID.ToString(), i.Folder.ToString());
284  // }
285 
286  // return true;
287  //}
288 
289  // Let these pass. Use inherited methods.
290  //public bool DeleteItems(UUID principalID, List<UUID> itemIDs)
291  //{
292  //}
293 
295  {
296  InventoryItemBase it = base.GetItem(item);
297  if (it != null)
298  {
299  UserAccount user = m_Cache.GetUser(it.CreatorId);
300 
301  // Adjust the creator data
302  if (user != null && it != null && string.IsNullOrEmpty(it.CreatorData))
303  it.CreatorData = m_HomeURL + ";" + user.FirstName + " " + user.LastName;
304  }
305  return it;
306  }
307 
308  //public InventoryFolderBase GetFolder(InventoryFolderBase folder)
309  //{
310  //}
311 
312  //public List<InventoryItemBase> GetActiveGestures(UUID principalID)
313  //{
314  //}
315 
316  //public int GetAssetPermissions(UUID principalID, UUID assetID)
317  //{
318  //}
319 
320  }
321 }
override bool DeleteFolders(UUID principalID, List< UUID > folderIDs)
Delete an item from the user's inventory
override InventoryItemBase GetItem(InventoryItemBase item)
Get an item, given by its UUID
override bool CreateUserInventory(UUID principalID)
Create the entire inventory for a given user
override InventoryFolderBase GetFolderForType(UUID principalID, FolderType type)
Gets the user folder for the given folder-type
HGInventoryService(IConfigSource config, string configName)
override InventoryFolderBase GetRootFolder(UUID principalID)
Retrieve the root inventory folder for the given user.
Inventory Item - contains all the properties associated with an individual inventory piece...
Hypergrid inventory service. It serves the IInventoryService interface, but implements it in ways tha...
string CreatorData
Extended creator information of the form <profile url>="">;<name>
UUID ID
A UUID containing the ID for the inventory node itself
override List< InventoryFolderBase > GetInventorySkeleton(UUID principalID)
Gets the skeleton of the inventory – folders only
override InventoryCollection[] GetMultipleFoldersContent(UUID principalID, UUID[] folderID)
Gets everything (folders and items) inside a folder
override bool PurgeFolder(InventoryFolderBase folder)
Purge an inventory folder of all its items and subfolders.
Used to serialize a whole inventory for transfer over the network.