aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services
diff options
context:
space:
mode:
authorMelanie2010-01-04 18:47:47 +0000
committerMelanie2010-01-04 20:53:26 +0000
commite76333555d2016412b17f43039962d32ad8c0609 (patch)
tree554d6f09b25bde1364ac83c3f2329020e45e86bd /OpenSim/Services
parentWhen rezzing a no-copy object on a no-rez parcel, the object vanishes from (diff)
downloadopensim-SC_OLD-e76333555d2016412b17f43039962d32ad8c0609.zip
opensim-SC_OLD-e76333555d2016412b17f43039962d32ad8c0609.tar.gz
opensim-SC_OLD-e76333555d2016412b17f43039962d32ad8c0609.tar.bz2
opensim-SC_OLD-e76333555d2016412b17f43039962d32ad8c0609.tar.xz
First stage port of the XInventoryService
Diffstat (limited to 'OpenSim/Services')
-rw-r--r--OpenSim/Services/InventoryService/XInventoryService.cs474
1 files changed, 474 insertions, 0 deletions
diff --git a/OpenSim/Services/InventoryService/XInventoryService.cs b/OpenSim/Services/InventoryService/XInventoryService.cs
new file mode 100644
index 0000000..1e7f206
--- /dev/null
+++ b/OpenSim/Services/InventoryService/XInventoryService.cs
@@ -0,0 +1,474 @@
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
28using System;
29using System.Collections.Generic;
30using OpenMetaverse;
31using log4net;
32using Nini.Config;
33using System.Reflection;
34using OpenSim.Services.Base;
35using OpenSim.Services.Interfaces;
36using OpenSim.Data;
37using OpenSim.Framework;
38
39namespace OpenSim.Services.InventoryService
40{
41 public class XInventoryService : ServiceBase, IInventoryService
42 {
43 private static readonly ILog m_log =
44 LogManager.GetLogger(
45 MethodBase.GetCurrentMethod().DeclaringType);
46
47 protected IXInventoryData m_Database;
48
49 public XInventoryService(IConfigSource config) : base(config)
50 {
51 string dllName = String.Empty;
52 string connString = String.Empty;
53 //string realm = "Inventory"; // OSG version doesn't use this
54
55 //
56 // Try reading the [InventoryService] section first, if it exists
57 //
58 IConfig authConfig = config.Configs["InventoryService"];
59 if (authConfig != null)
60 {
61 dllName = authConfig.GetString("StorageProvider", dllName);
62 connString = authConfig.GetString("ConnectionString", connString);
63 // realm = authConfig.GetString("Realm", realm);
64 }
65
66 //
67 // Try reading the [DatabaseService] section, if it exists
68 //
69 IConfig dbConfig = config.Configs["DatabaseService"];
70 if (dbConfig != null)
71 {
72 if (dllName == String.Empty)
73 dllName = dbConfig.GetString("StorageProvider", String.Empty);
74 if (connString == String.Empty)
75 connString = dbConfig.GetString("ConnectionString", String.Empty);
76 }
77
78 //
79 // We tried, but this doesn't exist. We can't proceed.
80 //
81 if (dllName == String.Empty)
82 throw new Exception("No StorageProvider configured");
83
84 m_Database = LoadPlugin<IXInventoryData>(dllName,
85 new Object[] {connString, String.Empty});
86 if (m_Database == null)
87 throw new Exception("Could not find a storage interface in the given module");
88 }
89
90 public bool CreateUserInventory(UUID principalID)
91 {
92 // This is braindeaad. We can't ever communicate that we fixed
93 // an existing inventory. Well, just return root folder status,
94 // but check sanity anyway.
95 //
96 bool result = false;
97
98 InventoryFolderBase rootFolder = GetRootFolder(principalID);
99
100 if (rootFolder == null)
101 {
102 rootFolder = ConvertToOpenSim(CreateFolder(principalID, UUID.Zero, (int)AssetType.Folder, "My Inventory"));
103 result = true;
104 }
105
106 XInventoryFolder[] sysFolders = GetSystemFolders(principalID);
107
108 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Animation) return true; return false; }))
109 CreateFolder(principalID, rootFolder.ID, (int)AssetType.Animation, "Animations");
110 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Bodypart) return true; return false; }))
111 CreateFolder(principalID, rootFolder.ID, (int)AssetType.Bodypart, "Body Parts");
112 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.CallingCard) return true; return false; }))
113 CreateFolder(principalID, rootFolder.ID, (int)AssetType.CallingCard, "Calling Cards");
114 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Clothing) return true; return false; }))
115 CreateFolder(principalID, rootFolder.ID, (int)AssetType.Clothing, "Clothing");
116 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Gesture) return true; return false; }))
117 CreateFolder(principalID, rootFolder.ID, (int)AssetType.Gesture, "Gestures");
118 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Landmark) return true; return false; }))
119 CreateFolder(principalID, rootFolder.ID, (int)AssetType.Landmark, "Landmarks");
120 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.LostAndFoundFolder) return true; return false; }))
121 CreateFolder(principalID, rootFolder.ID, (int)AssetType.LostAndFoundFolder, "Lost And Found");
122 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Notecard) return true; return false; }))
123 CreateFolder(principalID, rootFolder.ID, (int)AssetType.Notecard, "Notecards");
124 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Object) return true; return false; }))
125 CreateFolder(principalID, rootFolder.ID, (int)AssetType.Object, "Objects");
126 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.SnapshotFolder) return true; return false; }))
127 CreateFolder(principalID, rootFolder.ID, (int)AssetType.SnapshotFolder, "Photo Album");
128 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.LSLText) return true; return false; }))
129 CreateFolder(principalID, rootFolder.ID, (int)AssetType.LSLText, "Scripts");
130 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Sound) return true; return false; }))
131 CreateFolder(principalID, rootFolder.ID, (int)AssetType.Sound, "Sounds");
132 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Texture) return true; return false; }))
133 CreateFolder(principalID, rootFolder.ID, (int)AssetType.Texture, "Textures");
134 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.TrashFolder) return true; return false; }))
135 CreateFolder(principalID, rootFolder.ID, (int)AssetType.TrashFolder, "Trash");
136
137 return result;
138 }
139
140 private XInventoryFolder CreateFolder(UUID principalID, UUID parentID, int type, string name)
141 {
142 XInventoryFolder newFolder = new XInventoryFolder();
143
144 newFolder.folderName = name;
145 newFolder.type = type;
146 newFolder.version = 1;
147 newFolder.folderID = UUID.Random();
148 newFolder.agentID = principalID;
149 newFolder.parentFolderID = parentID;
150
151 m_Database.StoreFolder(newFolder);
152
153 return newFolder;
154 }
155
156 private XInventoryFolder[] GetSystemFolders(UUID principalID)
157 {
158 XInventoryFolder[] allFolders = m_Database.GetFolders(
159 new string[] { "agentID" },
160 new string[] { principalID.ToString() });
161
162 XInventoryFolder[] sysFolders = Array.FindAll(
163 allFolders,
164 delegate (XInventoryFolder f)
165 {
166 if (f.type > 0)
167 return true;
168 return false;
169 });
170
171 return sysFolders;
172 }
173
174 public List<InventoryFolderBase> GetInventorySkeleton(UUID principalID)
175 {
176 XInventoryFolder[] allFolders = m_Database.GetFolders(
177 new string[] { "agentID" },
178 new string[] { principalID.ToString() });
179
180 if (allFolders.Length == 0)
181 return null;
182
183 List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
184
185 foreach (XInventoryFolder x in allFolders)
186 folders.Add(ConvertToOpenSim(x));
187
188 return folders;
189 }
190
191 public InventoryFolderBase GetRootFolder(UUID principalID)
192 {
193 XInventoryFolder[] folders = m_Database.GetFolders(
194 new string[] { "agentID", "parentFolderID"},
195 new string[] { principalID.ToString(), UUID.Zero.ToString() });
196
197 if (folders.Length == 0)
198 return null;
199
200 return ConvertToOpenSim(folders[0]);
201 }
202
203 public InventoryFolderBase GetFolderForType(UUID principalID, AssetType type)
204 {
205 XInventoryFolder[] folders = m_Database.GetFolders(
206 new string[] { "agentID", "type"},
207 new string[] { principalID.ToString(), ((int)type).ToString() });
208
209 if (folders.Length == 0)
210 return null;
211
212 return ConvertToOpenSim(folders[0]);
213 }
214
215 public InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
216 {
217 InventoryCollection inventory = new InventoryCollection();
218 inventory.UserID = principalID;
219 inventory.Folders = new List<InventoryFolderBase>();
220 inventory.Items = new List<InventoryItemBase>();
221
222 XInventoryFolder[] folders = m_Database.GetFolders(
223 new string[] { "agentID", "parentFolderID"},
224 new string[] { principalID.ToString(), UUID.Zero.ToString() });
225
226 foreach (XInventoryFolder x in folders)
227 inventory.Folders.Add(ConvertToOpenSim(x));
228
229 XInventoryItem[] items = m_Database.GetItems(
230 new string[] { "avatarID", "parentFolderID"},
231 new string[] { principalID.ToString(), UUID.Zero.ToString() });
232
233 foreach (XInventoryItem i in items)
234 inventory.Items.Add(ConvertToOpenSim(i));
235
236 return inventory;
237 }
238
239 public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID)
240 {
241 List<InventoryItemBase> invItems = new List<InventoryItemBase>();
242
243 XInventoryItem[] items = m_Database.GetItems(
244 new string[] { "avatarID", "parentFolderID"},
245 new string[] { principalID.ToString(), UUID.Zero.ToString() });
246
247 foreach (XInventoryItem i in items)
248 invItems.Add(ConvertToOpenSim(i));
249
250 return invItems;
251 }
252
253 public bool AddFolder(InventoryFolderBase folder)
254 {
255 XInventoryFolder xFolder = ConvertFromOpenSim(folder);
256 return m_Database.StoreFolder(xFolder);
257 }
258
259 public bool UpdateFolder(InventoryFolderBase folder)
260 {
261 return AddFolder(folder);
262 }
263
264 public bool MoveFolder(InventoryFolderBase folder)
265 {
266 XInventoryFolder[] x = m_Database.GetFolders(
267 new string[] { "folderID" },
268 new string[] { folder.ID.ToString() });
269
270 if (x.Length == 0)
271 return false;
272
273 x[0].parentFolderID = folder.ParentID;
274
275 return m_Database.StoreFolder(x[0]);
276 }
277
278 // We don't check the principal's ID here
279 //
280 public bool DeleteFolders(UUID principalID, List<UUID> folderIDs)
281 {
282 foreach (UUID id in folderIDs)
283 {
284 InventoryFolderBase f = new InventoryFolderBase();
285 f.ID = id;
286 PurgeFolder(f);
287 m_Database.DeleteFolders("folderID", id.ToString());
288 }
289
290 return true;
291 }
292
293 public bool PurgeFolder(InventoryFolderBase folder)
294 {
295 XInventoryFolder[] subFolders = m_Database.GetFolders(
296 new string[] { "parentFolderID" },
297 new string[] { folder.ID.ToString() });
298
299 foreach (XInventoryFolder x in subFolders)
300 PurgeFolder(ConvertToOpenSim(x));
301
302 m_Database.DeleteItems("parentFolderID", folder.ID.ToString());
303
304 return true;
305 }
306
307 public bool AddItem(InventoryItemBase item)
308 {
309 return m_Database.StoreItem(ConvertFromOpenSim(item));
310 }
311
312 public bool UpdateItem(InventoryItemBase item)
313 {
314 return m_Database.StoreItem(ConvertFromOpenSim(item));
315 }
316
317 public bool MoveItems(UUID principalID, List<InventoryItemBase> items)
318 {
319 foreach (InventoryItemBase i in items)
320 {
321 m_Database.MoveItem(principalID.ToString(), i.ID.ToString(),
322 i.Folder.ToString());
323 }
324
325 return true;
326 }
327
328 public bool DeleteItems(UUID principalID, List<UUID> itemIDs)
329 {
330 foreach (UUID id in itemIDs)
331 m_Database.DeleteItems("inventoryID", id.ToString());
332
333 return true;
334 }
335
336 public InventoryItemBase GetItem(InventoryItemBase item)
337 {
338 XInventoryItem[] items = m_Database.GetItems(
339 new string[] { "inventoryID" },
340 new string[] { item.ID.ToString() });
341
342 if (items.Length == 0)
343 return null;
344
345 return ConvertToOpenSim(items[0]);
346 }
347
348 public InventoryFolderBase GetFolder(InventoryFolderBase folder)
349 {
350 XInventoryFolder[] folders = m_Database.GetFolders(
351 new string[] { "folderID"},
352 new string[] { folder.ID.ToString() });
353
354 if (folders.Length == 0)
355 return null;
356
357 return ConvertToOpenSim(folders[0]);
358 }
359
360 public List<InventoryItemBase> GetActiveGestures(UUID userId)
361 {
362 return null;
363 }
364
365 public int GetAssetPermissions(UUID userID, UUID assetID)
366 {
367 return 0;
368 }
369
370 // CM never needed those. Left unimplemented.
371 // Obsolete in core
372 //
373 public InventoryCollection GetUserInventory(UUID userID)
374 {
375 return null;
376 }
377 public void GetUserInventory(UUID userID, InventoryReceiptCallback callback)
378 {
379 }
380
381 // Unused.
382 //
383 public bool HasInventoryForUser(UUID userID)
384 {
385 return false;
386 }
387
388 // CM Helpers
389 //
390 private InventoryFolderBase ConvertToOpenSim(XInventoryFolder folder)
391 {
392 InventoryFolderBase newFolder = new InventoryFolderBase();
393
394 newFolder.ParentID = folder.parentFolderID;
395 newFolder.Type = (short)folder.type;
396 newFolder.Version = (ushort)folder.version;
397 newFolder.Name = folder.folderName;
398 newFolder.Owner = folder.agentID;
399 newFolder.ID = folder.folderID;
400
401 return newFolder;
402 }
403
404 private XInventoryFolder ConvertFromOpenSim(InventoryFolderBase folder)
405 {
406 XInventoryFolder newFolder = new XInventoryFolder();
407
408 newFolder.parentFolderID = folder.ParentID;
409 newFolder.type = (int)folder.Type;
410 newFolder.version = (int)folder.Version;
411 newFolder.folderName = folder.Name;
412 newFolder.agentID = folder.Owner;
413 newFolder.folderID = folder.ID;
414
415 return newFolder;
416 }
417
418 private InventoryItemBase ConvertToOpenSim(XInventoryItem item)
419 {
420 InventoryItemBase newItem = new InventoryItemBase();
421
422 newItem.AssetID = item.assetID;
423 newItem.AssetType = item.assetType;
424 newItem.Name = item.inventoryName;
425 newItem.Owner = item.avatarID;
426 newItem.ID = item.inventoryID;
427 newItem.InvType = item.invType;
428 newItem.Folder = item.parentFolderID;
429 newItem.CreatorId = item.creatorID.ToString();
430 newItem.Description = item.inventoryDescription;
431 newItem.NextPermissions = (uint)item.inventoryNextPermissions;
432 newItem.CurrentPermissions = (uint)item.inventoryCurrentPermissions;
433 newItem.BasePermissions = (uint)item.inventoryBasePermissions;
434 newItem.EveryOnePermissions = (uint)item.inventoryEveryOnePermissions;
435 newItem.GroupPermissions = (uint)item.inventoryGroupPermissions;
436 newItem.GroupID = item.groupID;
437 newItem.GroupOwned = item.groupOwned;
438 newItem.SalePrice = item.salePrice;
439 newItem.SaleType = (byte)item.saleType;
440 newItem.Flags = (uint)item.flags;
441 newItem.CreationDate = item.creationDate;
442
443 return newItem;
444 }
445
446 private XInventoryItem ConvertFromOpenSim(InventoryItemBase item)
447 {
448 XInventoryItem newItem = new XInventoryItem();
449
450 newItem.assetID = item.AssetID;
451 newItem.assetType = item.AssetType;
452 newItem.inventoryName = item.Name;
453 newItem.avatarID = item.Owner;
454 newItem.inventoryID = item.ID;
455 newItem.invType = item.InvType;
456 newItem.parentFolderID = item.Folder;
457 newItem.creatorID = item.CreatorIdAsUuid;
458 newItem.inventoryDescription = item.Description;
459 newItem.inventoryNextPermissions = (int)item.NextPermissions;
460 newItem.inventoryCurrentPermissions = (int)item.CurrentPermissions;
461 newItem.inventoryBasePermissions = (int)item.BasePermissions;
462 newItem.inventoryEveryOnePermissions = (int)item.EveryOnePermissions;
463 newItem.inventoryGroupPermissions = (int)item.GroupPermissions;
464 newItem.groupID = item.GroupID;
465 newItem.groupOwned = item.GroupOwned;
466 newItem.salePrice = item.SalePrice;
467 newItem.saleType = (int)item.SaleType;
468 newItem.flags = (int)item.Flags;
469 newItem.creationDate = item.CreationDate;
470
471 return newItem;
472 }
473 }
474}