aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Capabilities/Handlers/WebFetchInventoryDescendents/WebFetchInvDescHandler.cs4
-rw-r--r--OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs4
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs3
-rw-r--r--OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs316
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs43
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs51
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteXInventoryServiceConnector.cs15
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.Inventory.cs83
-rw-r--r--OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs72
-rw-r--r--OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs47
-rw-r--r--OpenSim/Services/HypergridService/HGInventoryService.cs6
-rw-r--r--OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs748
-rw-r--r--OpenSim/Services/InventoryService/XInventoryService.cs62
13 files changed, 1325 insertions, 129 deletions
diff --git a/OpenSim/Capabilities/Handlers/WebFetchInventoryDescendents/WebFetchInvDescHandler.cs b/OpenSim/Capabilities/Handlers/WebFetchInventoryDescendents/WebFetchInvDescHandler.cs
index 8b44f72..d5c062b 100644
--- a/OpenSim/Capabilities/Handlers/WebFetchInventoryDescendents/WebFetchInvDescHandler.cs
+++ b/OpenSim/Capabilities/Handlers/WebFetchInventoryDescendents/WebFetchInvDescHandler.cs
@@ -162,7 +162,7 @@ namespace OpenSim.Capabilities.Handlers
162 invFetch.owner_id, invFetch.folder_id, invFetch.owner_id, 162 invFetch.owner_id, invFetch.folder_id, invFetch.owner_id,
163 invFetch.fetch_folders, invFetch.fetch_items, invFetch.sort_order, out version); 163 invFetch.fetch_folders, invFetch.fetch_items, invFetch.sort_order, out version);
164 164
165 if (inv.Folders != null) 165 if (inv != null && inv.Folders != null)
166 { 166 {
167 foreach (InventoryFolderBase invFolder in inv.Folders) 167 foreach (InventoryFolderBase invFolder in inv.Folders)
168 { 168 {
@@ -170,7 +170,7 @@ namespace OpenSim.Capabilities.Handlers
170 } 170 }
171 } 171 }
172 172
173 if (inv.Items != null) 173 if (inv != null && inv.Items != null)
174 { 174 {
175 foreach (InventoryItemBase invItem in inv.Items) 175 foreach (InventoryItemBase invItem in inv.Items)
176 { 176 {
diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
index a8ece79..9d8561b 100644
--- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
+++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs
@@ -662,11 +662,11 @@ namespace OpenSim.Framework.Servers.HttpServer
662 } 662 }
663 catch (IOException e) 663 catch (IOException e)
664 { 664 {
665 m_log.ErrorFormat("[BASE HTTP SERVER]: HandleRequest() threw ", e); 665 m_log.ErrorFormat("[BASE HTTP SERVER]: HandleRequest() threw {0}", e);
666 } 666 }
667 catch (Exception e) 667 catch (Exception e)
668 { 668 {
669 m_log.ErrorFormat("[BASE HTTP SERVER]: HandleRequest() threw " + e.ToString()); 669 m_log.ErrorFormat("[BASE HTTP SERVER]: HandleRequest() threw {0}", e.StackTrace);
670 SendHTML500(response); 670 SendHTML500(response);
671 } 671 }
672 finally 672 finally
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
index 3470fa9..9395233 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
@@ -1913,7 +1913,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
1913 1913
1914 folderBlock.FolderID = folder.ID; 1914 folderBlock.FolderID = folder.ID;
1915 folderBlock.ParentID = folder.ParentID; 1915 folderBlock.ParentID = folder.ParentID;
1916 folderBlock.Type = -1; 1916 //folderBlock.Type = -1;
1917 folderBlock.Type = (sbyte)folder.Type;
1917 folderBlock.Name = Util.StringToBytes256(folder.Name); 1918 folderBlock.Name = Util.StringToBytes256(folder.Name);
1918 1919
1919 return folderBlock; 1920 return folderBlock;
diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs
index ec260b4..d85a996 100644
--- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs
@@ -114,7 +114,17 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
114 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: ViaHGLogin"); 114 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: ViaHGLogin");
115 if (m_RestrictInventoryAccessAbroad) 115 if (m_RestrictInventoryAccessAbroad)
116 { 116 {
117 RestoreRootFolderContents(client); 117 IUserManagement uMan = m_Scenes[0].RequestModuleInterface<IUserManagement>();
118 if (uMan.IsLocalGridUser(client.AgentId))
119 {
120 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: User is local");
121 RestoreRootFolderContents(client);
122 }
123 else
124 {
125 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: User is foreign");
126 RestoreSuitcaseFolderContents(client);
127 }
118 } 128 }
119 } 129 }
120 } 130 }
@@ -210,7 +220,20 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
210 logout = success; // flag for later logout from this grid; this is an HG TP 220 logout = success; // flag for later logout from this grid; this is an HG TP
211 221
212 if (success && m_RestrictInventoryAccessAbroad) 222 if (success && m_RestrictInventoryAccessAbroad)
213 RemoveRootFolderContents(sp.ControllingClient); 223 {
224 IUserManagement uMan = m_aScene.RequestModuleInterface<IUserManagement>();
225 if (uMan != null && uMan.IsLocalGridUser(sp.UUID))
226 {
227 // local grid user
228 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: User is local");
229 RemoveRootFolderContents(sp.ControllingClient);
230 }
231 else
232 {
233 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: User is foreign");
234 RemoveSuitcaseFolderContents(sp.ControllingClient);
235 }
236 }
214 237
215 return success; 238 return success;
216 } 239 }
@@ -388,6 +411,36 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
388 411
389 #endregion 412 #endregion
390 413
414 // COMPLETE FAIL
415 //private void RemoveRootFolderContents(IClientAPI client)
416 //{
417 // InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(client.AgentId);
418 // m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Removing root inventory for user {0}, version {1}", client.AgentId, root.Version);
419 // InventoryCollection content = m_Scenes[0].InventoryService.GetFolderContent(client.AgentId, root.ID);
420
421 // List<InventoryFolderBase> keep = new List<InventoryFolderBase>();
422 // foreach (InventoryFolderBase f in content.Folders)
423 // {
424 // if (f.Type == (short)AssetType.TrashFolder || f.Type == (short)AssetType.Landmark ||
425 // f.Type == (short)AssetType.FavoriteFolder || f.Type == (short)AssetType.CurrentOutfitFolder)
426 // {
427 // // Don't remove these because the viewer refuses to exist without them
428 // // and immediately sends a request to create them again, which makes things
429 // // very confusing in the viewer.
430 // // Just change their names
431 // f.Name = "Home " + f.Name + " (Unavailable)";
432 // keep.Add(f);
433 // }
434 // else
435 // {
436 // m_log.DebugFormat("[RRR]: Name={0}, Version={1}, Type={2}, PfolderID={3}", f.Name, f.Version, f.Type, f.ParentID);
437 // }
438 // }
439
440
441 // client.SendInventoryFolderDetails(client.AgentId, root.ID, new List<InventoryItemBase>(), keep, root.Version + 1, true, true);
442 //}
443
391 private void RemoveRootFolderContents(IClientAPI client) 444 private void RemoveRootFolderContents(IClientAPI client)
392 { 445 {
393 // TODO tell the viewer to remove the root folder's content 446 // TODO tell the viewer to remove the root folder's content
@@ -401,25 +454,185 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
401 InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(client.AgentId); 454 InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(client.AgentId);
402 if (root != null) 455 if (root != null)
403 { 456 {
404 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Removing root inventory for user {0}", client.AgentId); 457 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Removing root inventory for user {0}", client.Name);
458 InventoryCollection content = m_Scenes[0].InventoryService.GetFolderContent(client.AgentId, root.ID);
459 List<UUID> fids = new List<UUID>();
460 List<UUID> iids = new List<UUID>();
461 List<InventoryFolderBase> keep = new List<InventoryFolderBase>();
462
463 foreach (InventoryFolderBase f in content.Folders)
464 {
465 if (f.Name != "My Suitcase")
466 {
467 f.Name = f.Name + " (Unavailable)";
468 keep.Add(f);
469 }
470 }
471
472 // items directly under the root folder
473 foreach (InventoryItemBase it in content.Items)
474 it.Name = it.Name + " (Unavailable)"; ;
475
476 // next, add the subfolders and items of the keep folders
477 //foreach (InventoryFolderBase f in keep)
478 //{
479 // InventoryCollection c = m_Scenes[0].InventoryService.GetFolderContent(client.AgentId, f.ID);
480 // foreach (InventoryFolderBase sf in c.Folders)
481 // {
482 // m_log.DebugFormat("[RRR]: Name={0}, Version={1}, Type={2}, PfolderID={3}", f.Name, f.Version, f.Type, f.ParentID);
483 // fids.Add(sf.ID);
484 // }
485 // foreach (InventoryItemBase it in c.Items)
486 // iids.Add(it.ID);
487 //}
488
489 //inv.SendRemoveInventoryFolders(fids.ToArray());
490
491 // Increase the version number
492 //root.Version += 1;
493 //m_Scenes[0].InventoryService.UpdateFolder(root);
494 //foreach (InventoryFolderBase f in keep)
495 //{
496 // f.Version += 1;
497 // m_Scenes[0].InventoryService.UpdateFolder(f);
498 //}
499
500 // Send the new names and versions
501 inv.SendBulkUpdateInventory(keep.ToArray(), content.Items.ToArray());
502
503 }
504 }
505 }
506 }
507
508 private void RemoveRootFolderContents2(IClientAPI client)
509 {
510 // TODO tell the viewer to remove the root folder's content
511 if (client is IClientCore)
512 {
513 IClientCore core = (IClientCore)client;
514 IClientInventory inv;
515
516 if (core.TryGet<IClientInventory>(out inv))
517 {
518 InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(client.AgentId);
519 if (root != null)
520 {
521 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Removing root inventory for user {0}", client.Name);
405 InventoryCollection content = m_Scenes[0].InventoryService.GetFolderContent(client.AgentId, root.ID); 522 InventoryCollection content = m_Scenes[0].InventoryService.GetFolderContent(client.AgentId, root.ID);
406 UUID[] ids = new UUID[content.Folders.Count]; 523 List<UUID> fids = new List<UUID>();
407 int i = 0; 524 List<UUID> iids = new List<UUID>();
525 List<InventoryFolderBase> keep = new List<InventoryFolderBase>();
526
408 foreach (InventoryFolderBase f in content.Folders) 527 foreach (InventoryFolderBase f in content.Folders)
409 ids[i++] = f.ID; 528 {
410 inv.SendRemoveInventoryFolders(ids); 529 if (f.Type == (short)AssetType.TrashFolder || f.Type == (short)AssetType.Landmark ||
411 ids = new UUID[content.Items.Count]; 530 f.Type == (short)AssetType.FavoriteFolder || f.Type == (short)AssetType.CurrentOutfitFolder)
412 i = 0; 531 {
532 // Don't remove these because the viewer refuses to exist without them
533 // and immediately sends a request to create them again, which makes things
534 // very confusing in the viewer.
535 // Just change their names
536 f.Name = "Home " + f.Name + " (Unavailable)";
537 keep.Add(f);
538 }
539 else
540 {
541 m_log.DebugFormat("[RRR]: Name={0}, Version={1}, Type={2}, PfolderID={3}", f.Name, f.Version, f.Type, f.ParentID);
542 fids.Add(f.ID);
543 }
544 }
545
413 foreach (InventoryItemBase it in content.Items) 546 foreach (InventoryItemBase it in content.Items)
414 ids[i++] = it.ID; 547 iids.Add(it.ID);
415 inv.SendRemoveInventoryItems(ids); 548
549 // next, add the subfolders and items of the keep folders
550 foreach (InventoryFolderBase f in keep)
551 {
552 InventoryCollection c = m_Scenes[0].InventoryService.GetFolderContent(client.AgentId, f.ID);
553 foreach (InventoryFolderBase sf in c.Folders)
554 {
555 m_log.DebugFormat("[RRR]: Name={0}, Version={1}, Type={2}, PfolderID={3}", f.Name, f.Version, f.Type, f.ParentID);
556 fids.Add(sf.ID);
557 }
558 foreach (InventoryItemBase it in c.Items)
559 iids.Add(it.ID);
560 }
561
562 inv.SendRemoveInventoryFolders(fids.ToArray());
563 inv.SendRemoveInventoryItems(iids.ToArray());
564
565 // Increase the version number
566 root.Version += 1;
567 m_Scenes[0].InventoryService.UpdateFolder(root);
568 //foreach (InventoryFolderBase f in keep)
569 //{
570 // f.Version += 1;
571 // m_Scenes[0].InventoryService.UpdateFolder(f);
572 //}
573
574 // Send the new names and versions
575 inv.SendBulkUpdateInventory(keep.ToArray(), new InventoryItemBase[0]);
576
416 } 577 }
417 } 578 }
418 } 579 }
419 } 580 }
420 581
582 private void RemoveSuitcaseFolderContents(IClientAPI client)
583 {
584 return;
585
586 //// TODO tell the viewer to remove the suitcase folder's content
587 //if (client is IClientCore)
588 //{
589 // IClientCore core = (IClientCore)client;
590 // IClientInventory inv;
591
592 // if (core.TryGet<IClientInventory>(out inv))
593 // {
594 // InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(client.AgentId);
595 // if (root != null)
596 // {
597 // m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Removing suitcase inventory for user {0}", client.Name);
598 // InventoryCollection content = m_Scenes[0].InventoryService.GetFolderContent(client.AgentId, root.ID);
599 // List<UUID> fids = new List<UUID>();
600 // List<UUID> iids = new List<UUID>();
601
602 // if (content.Folders.Count == 0)
603 // m_log.WarnFormat("[HG ENTITY TRANSFER MODULE]: no subfolders???");
604 // foreach (InventoryFolderBase f in content.Folders)
605 // {
606 // m_log.DebugFormat("[RRR]: Name={0}, Version={1}, Type={2}, PfolderID={3}", f.Name, f.Version, f.Type, f.ParentID);
607 // fids.Add(f.ID);
608 // }
609
610 // foreach (InventoryItemBase it in content.Items)
611 // iids.Add(it.ID);
612
613 // inv.SendRemoveInventoryFolders(fids.ToArray());
614 // inv.SendRemoveInventoryItems(iids.ToArray());
615
616 // // Increase the version number
617 // root.Version += 1;
618 // m_Scenes[0].InventoryService.UpdateFolder(root);
619 // }
620 // }
621 //}
622 }
623
421 private void RestoreRootFolderContents(IClientAPI client) 624 private void RestoreRootFolderContents(IClientAPI client)
422 { 625 {
626 // This works!
627 //InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(client.AgentId);
628 //client.SendBulkUpdateInventory(root);
629
630 // SORTA KINDA some items are missing...
631 //InventoryCollection userInventory = m_Scenes[0].InventoryService.GetUserInventory(client.AgentId);
632 //InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(client.AgentId);
633 //client.SendBulkUpdateInventory(root);
634
635 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Restoring root folder");
423 if (client is IClientCore) 636 if (client is IClientCore)
424 { 637 {
425 IClientCore core = (IClientCore)client; 638 IClientCore core = (IClientCore)client;
@@ -428,19 +641,80 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
428 if (core.TryGet<IClientInventory>(out inv)) 641 if (core.TryGet<IClientInventory>(out inv))
429 { 642 {
430 InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(client.AgentId); 643 InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(client.AgentId);
431 client.SendBulkUpdateInventory(root); 644 InventoryCollection content = m_Scenes[0].InventoryService.GetFolderContent(client.AgentId, root.ID);
432 //if (root != null)
433 //{
434 // m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Restoring root inventory for user {0}", client.AgentId);
435 // InventoryCollection content = m_Scenes[0].InventoryService.GetFolderContent(client.AgentId, root.ID);
436 // m_log.DebugFormat("[XXX]: Folder name {0}, id {1}, parent {2}", root.Name, root.ID, root.ParentID);
437 // foreach (InventoryItemBase i in content.Items)
438 // m_log.DebugFormat("[XXX]: Name={0}, folderID={1}", i.Name, i.Folder);
439 645
440 // inv.SendBulkUpdateInventory(content.Folders.ToArray(), content.Items.ToArray()); 646 inv.SendBulkUpdateInventory(content.Folders.ToArray(), content.Items.ToArray());
441 //}
442 } 647 }
443 } 648 }
649
650 // ATTEMPT # 3 -- STILL DOESN'T WORK!
651 //if (client is IClientCore)
652 //{
653 // IClientCore core = (IClientCore)client;
654 // IClientInventory inv;
655
656 // if (core.TryGet<IClientInventory>(out inv))
657 // {
658 // InventoryCollection userInventory = m_Scenes[0].InventoryService.GetUserInventory(client.AgentId);
659 // if (userInventory != null)
660 // {
661 // m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Restoring root inventory for user {0}", client.AgentId);
662 // foreach (InventoryFolderBase f in userInventory.Folders)
663 // m_log.DebugFormat("[AAA]: FOLDER {0} {1} {2} {3} {4}", f.Name, f.Type, f.Version, f.ID, f.ParentID);
664 // foreach (InventoryItemBase f in userInventory.Items)
665 // m_log.DebugFormat("[AAA]: ITEM {0} {1} {2}", f.Name, f.ID, f.Folder);
666 // inv.SendBulkUpdateInventory(userInventory.Folders.ToArray(), userInventory.Items.ToArray());
667 // }
668 // else
669 // m_log.WarnFormat("[HG ENTITY TRANSFER MODULE]: Unable to retrieve inventory for user {0}", client.AgentId);
670 // }
671 //}
672
673
674 // ATTEMPT #2 -- BETTER THAN 1, BUT STILL DOES NOT WORK WELL
675 //if (client is IClientCore)
676 //{
677 // IClientCore core = (IClientCore)client;
678 // IClientInventory inv;
679
680 // if (core.TryGet<IClientInventory>(out inv))
681 // {
682 // List<InventoryFolderBase> skel = m_Scenes[0].InventoryService.GetInventorySkeleton(client.AgentId);
683 // if (skel != null)
684 // {
685 // m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Restoring root inventory for user {0}", client.AgentId);
686 // foreach (InventoryFolderBase f in skel)
687 // m_log.DebugFormat("[AAA]: {0} {1} {2} {3} {4}", f.Name, f.Type, f.Version, f.ID, f.ParentID);
688 // inv.SendBulkUpdateInventory(skel.ToArray(), new InventoryItemBase[0]);
689 // }
690 // else
691 // m_log.WarnFormat("[HG ENTITY TRANSFER MODULE]: Unable to retrieve skeleton for user {0}", client.AgentId);
692
693 // ATTEMPT #1 -- DOES NOT WORK
694 //InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(client.AgentId);
695 //if (root != null)
696 //{
697 //InventoryCollection content = m_Scenes[0].InventoryService.GetFolderContent(client.AgentId, root.ID);
698 //InventoryFolderBase[] folders = new InventoryFolderBase[content.Folders.Count + 1];
699 //m_log.DebugFormat("[AAA]: Folder name {0}, id {1}, version {2}, parent {3}", root.Name, root.ID, root.Version, root.ParentID);
700 //folders[0] = root;
701 //for (int count = 1; count < content.Folders.Count + 1; count++)
702 //{
703 // folders[count] = content.Folders[count - 1];
704 // m_log.DebugFormat("[AAA]: Name={0}, Id={1}, Version={2}, type={3}, folderID={4}",
705 // folders[count].Name, folders[count].ID, folders[count].Version, folders[count].Type, folders[count].ParentID);
706 //}
707 //foreach (InventoryItemBase i in content.Items)
708 // m_log.DebugFormat("[AAA]: Name={0}, folderID={1}", i.Name, i.Folder);
709 //inv.SendBulkUpdateInventory(/*content.Folders.ToArray()*/ folders, content.Items.ToArray());
710 //}
711 //}
712 //}
713 }
714
715 private void RestoreSuitcaseFolderContents(IClientAPI client)
716 {
717
444 } 718 }
445 719
446 private GridRegion MakeRegion(AgentCircuitData aCircuit) 720 private GridRegion MakeRegion(AgentCircuitData aCircuit)
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs
index 4be3804..cf6d2f7 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs
@@ -297,14 +297,35 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
297 return m_LocalGridInventoryService.CreateUserInventory(userID); 297 return m_LocalGridInventoryService.CreateUserInventory(userID);
298 } 298 }
299 299
300 public List<InventoryFolderBase> GetInventorySkeleton(UUID userId) 300 public List<InventoryFolderBase> GetInventorySkeleton(UUID userID)
301 { 301 {
302 return m_LocalGridInventoryService.GetInventorySkeleton(userId); 302 string invURL = GetInventoryServiceURL(userID);
303
304 if (invURL == null) // not there, forward to local inventory connector to resolve
305 return m_LocalGridInventoryService.GetInventorySkeleton(userID);
306
307 IInventoryService connector = GetConnector(invURL);
308
309 return connector.GetInventorySkeleton(userID);
303 } 310 }
304 311
305 public InventoryCollection GetUserInventory(UUID userID) 312 public InventoryCollection GetUserInventory(UUID userID)
306 { 313 {
307 return null; 314 string invURL = GetInventoryServiceURL(userID);
315 m_log.DebugFormat("[HG INVENTORY CONNECTOR]: GetUserInventory for {0} {1}", userID, invURL);
316
317 if (invURL == null) // not there, forward to local inventory connector to resolve
318 return m_LocalGridInventoryService.GetUserInventory(userID);
319
320 InventoryCollection c = m_Cache.GetUserInventory(userID);
321 if (c != null)
322 return c;
323
324 IInventoryService connector = GetConnector(invURL);
325 c = connector.GetUserInventory(userID);
326
327 m_Cache.Cache(userID, c);
328 return c;
308 } 329 }
309 330
310 public void GetUserInventory(UUID userID, InventoryReceiptCallback callback) 331 public void GetUserInventory(UUID userID, InventoryReceiptCallback callback)
@@ -362,8 +383,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
362 if (invURL == null) // not there, forward to local inventory connector to resolve 383 if (invURL == null) // not there, forward to local inventory connector to resolve
363 return m_LocalGridInventoryService.GetFolderContent(userID, folderID); 384 return m_LocalGridInventoryService.GetFolderContent(userID, folderID);
364 385
365 IInventoryService connector = GetConnector(invURL); 386 InventoryCollection c = m_Cache.GetFolderContent(userID, folderID);
387 if (c != null)
388 {
389 m_log.Debug("[HG INVENTORY CONNECTOR]: GetFolderContent found content in cache " + folderID);
390 return c;
391 }
366 392
393 IInventoryService connector = GetConnector(invURL);
367 return connector.GetFolderContent(userID, folderID); 394 return connector.GetFolderContent(userID, folderID);
368 395
369 } 396 }
@@ -377,8 +404,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
377 if (invURL == null) // not there, forward to local inventory connector to resolve 404 if (invURL == null) // not there, forward to local inventory connector to resolve
378 return m_LocalGridInventoryService.GetFolderItems(userID, folderID); 405 return m_LocalGridInventoryService.GetFolderItems(userID, folderID);
379 406
380 IInventoryService connector = GetConnector(invURL); 407 List<InventoryItemBase> items = m_Cache.GetFolderItems(userID, folderID);
408 if (items != null)
409 {
410 m_log.Debug("[HG INVENTORY CONNECTOR]: GetFolderItems found items in cache " + folderID);
411 return items;
412 }
381 413
414 IInventoryService connector = GetConnector(invURL);
382 return connector.GetFolderItems(userID, folderID); 415 return connector.GetFolderItems(userID, folderID);
383 416
384 } 417 }
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs
index 0fe778d..1e434b9 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs
@@ -12,6 +12,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
12 12
13 private static ExpiringCache<UUID, InventoryFolderBase> m_RootFolders = new ExpiringCache<UUID, InventoryFolderBase>(); 13 private static ExpiringCache<UUID, InventoryFolderBase> m_RootFolders = new ExpiringCache<UUID, InventoryFolderBase>();
14 private static ExpiringCache<UUID, Dictionary<AssetType, InventoryFolderBase>> m_FolderTypes = new ExpiringCache<UUID, Dictionary<AssetType, InventoryFolderBase>>(); 14 private static ExpiringCache<UUID, Dictionary<AssetType, InventoryFolderBase>> m_FolderTypes = new ExpiringCache<UUID, Dictionary<AssetType, InventoryFolderBase>>();
15 private static ExpiringCache<UUID, InventoryCollection> m_Inventories = new ExpiringCache<UUID, InventoryCollection>();
15 16
16 public void Cache(UUID userID, InventoryFolderBase root) 17 public void Cache(UUID userID, InventoryFolderBase root)
17 { 18 {
@@ -55,5 +56,55 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
55 56
56 return null; 57 return null;
57 } 58 }
59
60 public void Cache(UUID userID, InventoryCollection inv)
61 {
62 lock (m_Inventories)
63 m_Inventories.AddOrUpdate(userID, inv, 120);
64 }
65
66 public InventoryCollection GetUserInventory(UUID userID)
67 {
68 InventoryCollection inv = null;
69 if (m_Inventories.TryGetValue(userID, out inv))
70 return inv;
71 return null;
72 }
73
74 public InventoryCollection GetFolderContent(UUID userID, UUID folderID)
75 {
76 InventoryCollection inv = null;
77 InventoryCollection c;
78 if (m_Inventories.TryGetValue(userID, out inv))
79 {
80 c = new InventoryCollection();
81 c.UserID = userID;
82
83 c.Folders = inv.Folders.FindAll(delegate(InventoryFolderBase f)
84 {
85 return f.ParentID == folderID;
86 });
87 c.Items = inv.Items.FindAll(delegate(InventoryItemBase i)
88 {
89 return i.Folder == folderID;
90 });
91 return c;
92 }
93 return null;
94 }
95
96 public List<InventoryItemBase> GetFolderItems(UUID userID, UUID folderID)
97 {
98 InventoryCollection inv = null;
99 if (m_Inventories.TryGetValue(userID, out inv))
100 {
101 List<InventoryItemBase> items = inv.Items.FindAll(delegate(InventoryItemBase i)
102 {
103 return i.Folder == folderID;
104 });
105 return items;
106 }
107 return null;
108 }
58 } 109 }
59} 110}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteXInventoryServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteXInventoryServiceConnector.cs
index 77573c3..990dffb 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteXInventoryServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteXInventoryServiceConnector.cs
@@ -172,7 +172,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
172 172
173 public InventoryCollection GetUserInventory(UUID userID) 173 public InventoryCollection GetUserInventory(UUID userID)
174 { 174 {
175 return null; 175 return m_RemoteConnector.GetUserInventory(userID);
176 } 176 }
177 177
178 public void GetUserInventory(UUID userID, InventoryReceiptCallback callback) 178 public void GetUserInventory(UUID userID, InventoryReceiptCallback callback)
@@ -193,16 +193,17 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
193 { 193 {
194 InventoryCollection invCol = m_RemoteConnector.GetFolderContent(userID, folderID); 194 InventoryCollection invCol = m_RemoteConnector.GetFolderContent(userID, folderID);
195 195
196 if (UserManager != null) 196 if (invCol != null && UserManager != null)
197 { 197 {
198 // Protect ourselves against the caller subsequently modifying the items list 198 // Protect ourselves against the caller subsequently modifying the items list
199 List<InventoryItemBase> items = new List<InventoryItemBase>(invCol.Items); 199 List<InventoryItemBase> items = new List<InventoryItemBase>(invCol.Items);
200 200
201 Util.FireAndForget(delegate 201 if (items != null && items.Count > 0)
202 { 202 Util.FireAndForget(delegate
203 foreach (InventoryItemBase item in items) 203 {
204 UserManager.AddUser(item.CreatorIdAsUuid, item.CreatorData); 204 foreach (InventoryItemBase item in items)
205 }); 205 UserManager.AddUser(item.CreatorIdAsUuid, item.CreatorData);
206 });
206 } 207 }
207 208
208 return invCol; 209 return invCol;
diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
index 5abd74f..10b25ed 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs
@@ -36,6 +36,7 @@ using OpenMetaverse.Packets;
36using log4net; 36using log4net;
37using OpenSim.Framework; 37using OpenSim.Framework;
38using OpenSim.Region.Framework; 38using OpenSim.Region.Framework;
39using OpenSim.Framework.Client;
39using OpenSim.Region.Framework.Interfaces; 40using OpenSim.Region.Framework.Interfaces;
40using OpenSim.Region.Framework.Scenes.Serialization; 41using OpenSim.Region.Framework.Scenes.Serialization;
41 42
@@ -117,31 +118,42 @@ namespace OpenSim.Region.Framework.Scenes
117 /// <param name="item"></param> 118 /// <param name="item"></param>
118 public bool AddInventoryItem(InventoryItemBase item) 119 public bool AddInventoryItem(InventoryItemBase item)
119 { 120 {
120 if (UUID.Zero == item.Folder) 121 if (item.Folder != UUID.Zero && InventoryService.AddItem(item))
121 { 122 {
122 InventoryFolderBase f = InventoryService.GetFolderForType(item.Owner, (AssetType)item.AssetType); 123 int userlevel = 0;
123 if (f != null) 124 if (Permissions.IsGod(item.Owner))
124 { 125 {
125// m_log.DebugFormat( 126 userlevel = 1;
126// "[LOCAL INVENTORY SERVICES CONNECTOR]: Found folder {0} type {1} for item {2}", 127 }
127// f.Name, (AssetType)f.Type, item.Name); 128 EventManager.TriggerOnNewInventoryItemUploadComplete(item.Owner, item.AssetID, item.Name, userlevel);
129
130 return true;
131 }
132
133 // OK so either the viewer didn't send a folderID or AddItem failed
134 UUID originalFolder = item.Folder;
135 InventoryFolderBase f = InventoryService.GetFolderForType(item.Owner, (AssetType)item.AssetType);
136 if (f != null)
137 {
138 m_log.DebugFormat(
139 "[AGENT INVENTORY]: Found folder {0} type {1} for item {2}",
140 f.Name, (AssetType)f.Type, item.Name);
128 141
142 item.Folder = f.ID;
143 }
144 else
145 {
146 f = InventoryService.GetRootFolder(item.Owner);
147 if (f != null)
148 {
129 item.Folder = f.ID; 149 item.Folder = f.ID;
130 } 150 }
131 else 151 else
132 { 152 {
133 f = InventoryService.GetRootFolder(item.Owner); 153 m_log.WarnFormat(
134 if (f != null) 154 "[AGENT INVENTORY]: Could not find root folder for {0} when trying to add item {1} with no parent folder specified",
135 { 155 item.Owner, item.Name);
136 item.Folder = f.ID; 156 return false;
137 }
138 else
139 {
140 m_log.WarnFormat(
141 "[AGENT INVENTORY]: Could not find root folder for {0} when trying to add item {1} with no parent folder specified",
142 item.Owner, item.Name);
143 return false;
144 }
145 } 157 }
146 } 158 }
147 159
@@ -153,7 +165,13 @@ namespace OpenSim.Region.Framework.Scenes
153 userlevel = 1; 165 userlevel = 1;
154 } 166 }
155 EventManager.TriggerOnNewInventoryItemUploadComplete(item.Owner, item.AssetID, item.Name, userlevel); 167 EventManager.TriggerOnNewInventoryItemUploadComplete(item.Owner, item.AssetID, item.Name, userlevel);
156 168
169 if (originalFolder != UUID.Zero)
170 {
171 // Tell the viewer that the item didn't go there
172 ChangePlacement(item, f);
173 }
174
157 return true; 175 return true;
158 } 176 }
159 else 177 else
@@ -165,7 +183,32 @@ namespace OpenSim.Region.Framework.Scenes
165 return false; 183 return false;
166 } 184 }
167 } 185 }
168 186
187 private void ChangePlacement(InventoryItemBase item, InventoryFolderBase f)
188 {
189 ScenePresence sp = GetScenePresence(item.Owner);
190 if (sp != null)
191 {
192 if (sp.ControllingClient is IClientCore)
193 {
194 IClientCore core = (IClientCore)sp.ControllingClient;
195 IClientInventory inv;
196
197 if (core.TryGet<IClientInventory>(out inv))
198 {
199 InventoryFolderBase parent = new InventoryFolderBase(f.ParentID, f.Owner);
200 parent = InventoryService.GetFolder(parent);
201 inv.SendRemoveInventoryItems(new UUID[] { item.ID });
202 inv.SendBulkUpdateInventory(new InventoryFolderBase[0], new InventoryItemBase[] { item });
203 string message = "The item was placed in folder " + f.Name;
204 if (parent != null)
205 message += " under " + parent.Name;
206 sp.ControllingClient.SendAgentAlertMessage(message, false);
207 }
208 }
209 }
210 }
211
169 /// <summary> 212 /// <summary>
170 /// Add the given inventory item to a user's inventory. 213 /// Add the given inventory item to a user's inventory.
171 /// </summary> 214 /// </summary>
diff --git a/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs b/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs
index 040c840..cb9b65d 100644
--- a/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs
+++ b/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs
@@ -114,6 +114,8 @@ namespace OpenSim.Server.Handlers.Asset
114 return HandleCreateUserInventory(request); 114 return HandleCreateUserInventory(request);
115 case "GETINVENTORYSKELETON": 115 case "GETINVENTORYSKELETON":
116 return HandleGetInventorySkeleton(request); 116 return HandleGetInventorySkeleton(request);
117 case "GETUSERINVENTORY":
118 return HandleGetUserInventory(request);
117 case "GETROOTFOLDER": 119 case "GETROOTFOLDER":
118 return HandleGetRootFolder(request); 120 return HandleGetRootFolder(request);
119 case "GETFOLDERFORTYPE": 121 case "GETFOLDERFORTYPE":
@@ -153,7 +155,7 @@ namespace OpenSim.Server.Handlers.Asset
153 } 155 }
154 catch (Exception e) 156 catch (Exception e)
155 { 157 {
156 m_log.DebugFormat("[XINVENTORY HANDLER]: Exception {0}", e); 158 m_log.DebugFormat("[XINVENTORY HANDLER]: Exception {0}", e.StackTrace);
157 } 159 }
158 160
159 return FailureResult(); 161 return FailureResult();
@@ -248,6 +250,45 @@ namespace OpenSim.Server.Handlers.Asset
248 return encoding.GetBytes(xmlString); 250 return encoding.GetBytes(xmlString);
249 } 251 }
250 252
253 byte[] HandleGetUserInventory(Dictionary<string, object> request)
254 {
255 Dictionary<string, object> result = new Dictionary<string, object>();
256 UUID principal = UUID.Zero;
257 UUID.TryParse(request["PRINCIPAL"].ToString(), out principal);
258
259 InventoryCollection icoll = m_InventoryService.GetUserInventory(principal);
260 if (icoll != null)
261 {
262 Dictionary<string, object> folders = new Dictionary<string, object>();
263 int i = 0;
264 if (icoll.Folders != null)
265 {
266 foreach (InventoryFolderBase f in icoll.Folders)
267 {
268 folders["folder_" + i.ToString()] = EncodeFolder(f);
269 i++;
270 }
271 result["FOLDERS"] = folders;
272 }
273 if (icoll.Items != null)
274 {
275 i = 0;
276 Dictionary<string, object> items = new Dictionary<string, object>();
277 foreach (InventoryItemBase it in icoll.Items)
278 {
279 items["item_" + i.ToString()] = EncodeItem(it);
280 i++;
281 }
282 result["ITEMS"] = items;
283 }
284 }
285
286 string xmlString = ServerUtils.BuildXmlResponse(result);
287 //m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
288 UTF8Encoding encoding = new UTF8Encoding();
289 return encoding.GetBytes(xmlString);
290 }
291
251 byte[] HandleGetRootFolder(Dictionary<string,object> request) 292 byte[] HandleGetRootFolder(Dictionary<string,object> request)
252 { 293 {
253 Dictionary<string,object> result = new Dictionary<string,object>(); 294 Dictionary<string,object> result = new Dictionary<string,object>();
@@ -293,22 +334,27 @@ namespace OpenSim.Server.Handlers.Asset
293 if (icoll != null) 334 if (icoll != null)
294 { 335 {
295 Dictionary<string, object> folders = new Dictionary<string, object>(); 336 Dictionary<string, object> folders = new Dictionary<string, object>();
296 int i = 0; 337 int i = 0;
297 foreach (InventoryFolderBase f in icoll.Folders) 338 if (icoll.Folders != null)
298 { 339 {
299 folders["folder_" + i.ToString()] = EncodeFolder(f); 340 foreach (InventoryFolderBase f in icoll.Folders)
300 i++; 341 {
342 folders["folder_" + i.ToString()] = EncodeFolder(f);
343 i++;
344 }
345 result["FOLDERS"] = folders;
301 } 346 }
302 result["FOLDERS"] = folders; 347 if (icoll.Items != null)
303
304 i = 0;
305 Dictionary<string, object> items = new Dictionary<string, object>();
306 foreach (InventoryItemBase it in icoll.Items)
307 { 348 {
308 items["item_" + i.ToString()] = EncodeItem(it); 349 i = 0;
309 i++; 350 Dictionary<string, object> items = new Dictionary<string, object>();
351 foreach (InventoryItemBase it in icoll.Items)
352 {
353 items["item_" + i.ToString()] = EncodeItem(it);
354 i++;
355 }
356 result["ITEMS"] = items;
310 } 357 }
311 result["ITEMS"] = items;
312 } 358 }
313 359
314 string xmlString = ServerUtils.BuildXmlResponse(result); 360 string xmlString = ServerUtils.BuildXmlResponse(result);
diff --git a/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs b/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs
index 39e983b..9d96703 100644
--- a/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs
+++ b/OpenSim/Services/Connectors/Inventory/XInventoryConnector.cs
@@ -111,19 +111,21 @@ namespace OpenSim.Services.Connectors
111 if (ret.Count == 0) 111 if (ret.Count == 0)
112 return null; 112 return null;
113 113
114 List<InventoryFolderBase> folders = new List<InventoryFolderBase>(); 114 Dictionary<string, object> folders = (Dictionary<string, object>)ret["FOLDERS"];
115
116 List<InventoryFolderBase> fldrs = new List<InventoryFolderBase>();
115 117
116 try 118 try
117 { 119 {
118 foreach (Object o in ret.Values) 120 foreach (Object o in folders.Values)
119 folders.Add(BuildFolder((Dictionary<string, object>)o)); 121 fldrs.Add(BuildFolder((Dictionary<string, object>)o));
120 } 122 }
121 catch (Exception e) 123 catch (Exception e)
122 { 124 {
123 m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception unwrapping folder list: {0}", e.Message); 125 m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception unwrapping folder list: {0}", e.Message);
124 } 126 }
125 127
126 return folders; 128 return fldrs;
127 } 129 }
128 130
129 public InventoryFolderBase GetRootFolder(UUID principalID) 131 public InventoryFolderBase GetRootFolder(UUID principalID)
@@ -492,12 +494,41 @@ namespace OpenSim.Services.Connectors
492 return int.Parse(ret["RESULT"].ToString()); 494 return int.Parse(ret["RESULT"].ToString());
493 } 495 }
494 496
495
496 // These are either obsolete or unused
497 //
498 public InventoryCollection GetUserInventory(UUID principalID) 497 public InventoryCollection GetUserInventory(UUID principalID)
499 { 498 {
500 return null; 499 InventoryCollection inventory = new InventoryCollection();
500 inventory.Folders = new List<InventoryFolderBase>();
501 inventory.Items = new List<InventoryItemBase>();
502 inventory.UserID = principalID;
503
504 try
505 {
506 Dictionary<string, object> ret = MakeRequest("GETUSERINVENTORY",
507 new Dictionary<string, object> {
508 { "PRINCIPAL", principalID.ToString() }
509 });
510
511 if (ret == null)
512 return null;
513 if (ret.Count == 0)
514 return null;
515
516 Dictionary<string, object> folders =
517 (Dictionary<string, object>)ret["FOLDERS"];
518 Dictionary<string, object> items =
519 (Dictionary<string, object>)ret["ITEMS"];
520
521 foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i
522 inventory.Folders.Add(BuildFolder((Dictionary<string, object>)o));
523 foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i
524 inventory.Items.Add(BuildItem((Dictionary<string, object>)o));
525 }
526 catch (Exception e)
527 {
528 m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception in GetUserInventory: {0}", e.Message);
529 }
530
531 return inventory;
501 } 532 }
502 533
503 public void GetUserInventory(UUID principalID, InventoryReceiptCallback callback) 534 public void GetUserInventory(UUID principalID, InventoryReceiptCallback callback)
diff --git a/OpenSim/Services/HypergridService/HGInventoryService.cs b/OpenSim/Services/HypergridService/HGInventoryService.cs
index b29d803..2e9bd40 100644
--- a/OpenSim/Services/HypergridService/HGInventoryService.cs
+++ b/OpenSim/Services/HypergridService/HGInventoryService.cs
@@ -105,6 +105,12 @@ namespace OpenSim.Services.HypergridService
105 return new List<InventoryFolderBase>(); 105 return new List<InventoryFolderBase>();
106 } 106 }
107 107
108 public override InventoryCollection GetUserInventory(UUID userID)
109 {
110 // NOGO for this inventory service
111 return null;
112 }
113
108 public override InventoryFolderBase GetRootFolder(UUID principalID) 114 public override InventoryFolderBase GetRootFolder(UUID principalID)
109 { 115 {
110 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetRootFolder for {0}", principalID); 116 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetRootFolder for {0}", principalID);
diff --git a/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs b/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs
index cb686e2..e65ad17 100644
--- a/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs
+++ b/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs
@@ -48,7 +48,7 @@ namespace OpenSim.Services.HypergridService
48 /// and it responds to GetRootFolder requests with the ID of the 48 /// and it responds to GetRootFolder requests with the ID of the
49 /// Suitcase folder, not the actual "My Inventory" folder. 49 /// Suitcase folder, not the actual "My Inventory" folder.
50 /// </summary> 50 /// </summary>
51 public class HGSuitcaseInventoryService : XInventoryService, IInventoryService 51 public class HGSuitcaseInventoryService1 : XInventoryService, IInventoryService
52 { 52 {
53 private static readonly ILog m_log = 53 private static readonly ILog m_log =
54 LogManager.GetLogger( 54 LogManager.GetLogger(
@@ -61,7 +61,7 @@ namespace OpenSim.Services.HypergridService
61 61
62 private ExpiringCache<UUID, List<XInventoryFolder>> m_SuitcaseTrees = new ExpiringCache<UUID,List<XInventoryFolder>>(); 62 private ExpiringCache<UUID, List<XInventoryFolder>> m_SuitcaseTrees = new ExpiringCache<UUID,List<XInventoryFolder>>();
63 63
64 public HGSuitcaseInventoryService(IConfigSource config, string configName) 64 public HGSuitcaseInventoryService1(IConfigSource config, string configName)
65 : base(config, configName) 65 : base(config, configName)
66 { 66 {
67 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Starting with config name {0}", configName); 67 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Starting with config name {0}", configName);
@@ -104,11 +104,79 @@ namespace OpenSim.Services.HypergridService
104 return false; 104 return false;
105 } 105 }
106 106
107
108 public override List<InventoryFolderBase> GetInventorySkeleton(UUID principalID) 107 public override List<InventoryFolderBase> GetInventorySkeleton(UUID principalID)
109 { 108 {
110 // NOGO for this inventory service 109 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
111 return new List<InventoryFolderBase>(); 110 XInventoryFolder root = GetRootXFolder(principalID);
111
112 List<XInventoryFolder> tree = GetFolderTree(suitcase.folderID);
113 if (tree == null || (tree != null && tree.Count == 0))
114 return null;
115
116 List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
117 foreach (XInventoryFolder x in tree)
118 {
119 if (x.parentFolderID == suitcase.folderID)
120 x.parentFolderID = root.folderID;
121
122 folders.Add(ConvertToOpenSim(x));
123 }
124
125 SetAsRootFolder(suitcase, root);
126 folders.Add(ConvertToOpenSim(suitcase));
127
128 return folders;
129 }
130
131 public override InventoryCollection GetUserInventory(UUID userID)
132 {
133 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Get Suitcase inventory for user {0}", userID);
134 InventoryCollection userInventory = new InventoryCollection();
135 userInventory.UserID = userID;
136 userInventory.Folders = new List<InventoryFolderBase>();
137 userInventory.Items = new List<InventoryItemBase>();
138
139 XInventoryFolder suitcase = GetSuitcaseXFolder(userID);
140 XInventoryFolder root = GetRootXFolder(userID);
141
142 List<XInventoryFolder> tree = GetFolderTree(suitcase.folderID);
143 if (tree == null || (tree != null && tree.Count == 0))
144 {
145 SetAsRootFolder(suitcase, root);
146 userInventory.Folders.Add(ConvertToOpenSim(suitcase));
147 return userInventory;
148 }
149
150 List<InventoryItemBase> items;
151 foreach (XInventoryFolder f in tree)
152 {
153 // Add the items of this subfolder
154 items = GetFolderItems(userID, f.folderID);
155 if (items != null && items.Count > 0)
156 {
157 userInventory.Items.AddRange(items);
158 }
159
160 // Add the folder itself
161 if (f.parentFolderID == suitcase.folderID)
162 f.parentFolderID = root.folderID;
163 userInventory.Folders.Add(ConvertToOpenSim(f));
164 }
165
166 items = GetFolderItems(userID, suitcase.folderID);
167 if (items != null && items.Count > 0)
168 {
169 foreach (InventoryItemBase i in items)
170 i.Folder = root.folderID;
171 userInventory.Items.AddRange(items);
172 }
173
174 SetAsRootFolder(suitcase, root);
175 userInventory.Folders.Add(ConvertToOpenSim(suitcase));
176
177 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetUserInventory for user {0} returning {1} folders and {2} items",
178 userID, userInventory.Folders.Count, userInventory.Items.Count);
179 return userInventory;
112 } 180 }
113 181
114 public override InventoryFolderBase GetRootFolder(UUID principalID) 182 public override InventoryFolderBase GetRootFolder(UUID principalID)
@@ -131,23 +199,87 @@ namespace OpenSim.Services.HypergridService
131 { 199 {
132 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: User {0} does not have a Suitcase folder. Creating it...", principalID); 200 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: User {0} does not have a Suitcase folder. Creating it...", principalID);
133 // make one, and let's add it to the user's inventory as a direct child of the root folder 201 // make one, and let's add it to the user's inventory as a direct child of the root folder
202 // In the DB we tag it as type 100, but we use -1 (Unknown) outside
134 suitcase = CreateFolder(principalID, root.folderID, 100, "My Suitcase"); 203 suitcase = CreateFolder(principalID, root.folderID, 100, "My Suitcase");
135 if (suitcase == null) 204 if (suitcase == null)
136 m_log.ErrorFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to create suitcase folder"); 205 m_log.ErrorFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to create suitcase folder");
206 suitcase.version = root.version;
207 m_Database.StoreFolder(suitcase);
137 208
209 // Create System folders
210 CreateSystemFolders(principalID, suitcase.folderID);
211 }
212 else if (suitcase.version < root.version)
213 {
214 suitcase.version = root.version;
138 m_Database.StoreFolder(suitcase); 215 m_Database.StoreFolder(suitcase);
139 } 216 }
140 217
141 // Now let's change the folder ID to match that of the real root folder 218 // Now let's change the folder ID to match that of the real root folder
142 SetAsRootFolder(suitcase, root.folderID); 219 SetAsRootFolder(suitcase, root);
143 220
144 return ConvertToOpenSim(suitcase); 221 return ConvertToOpenSim(suitcase);
145 } 222 }
146 223
224 protected void CreateSystemFolders(UUID principalID, UUID rootID)
225 {
226 m_log.Debug("[HG SUITCASE INVENTORY SERVICE]: Creating System folders under Suitcase...");
227 XInventoryFolder[] sysFolders = GetSystemFolders(principalID, rootID);
228
229 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Animation) return true; return false; }))
230 CreateFolder(principalID, rootID, (int)AssetType.Animation, "Animations");
231 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Bodypart) return true; return false; }))
232 CreateFolder(principalID, rootID, (int)AssetType.Bodypart, "Body Parts");
233 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.CallingCard) return true; return false; }))
234 CreateFolder(principalID, rootID, (int)AssetType.CallingCard, "Calling Cards");
235 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Clothing) return true; return false; }))
236 CreateFolder(principalID, rootID, (int)AssetType.Clothing, "Clothing");
237 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Gesture) return true; return false; }))
238 CreateFolder(principalID, rootID, (int)AssetType.Gesture, "Gestures");
239 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Landmark) return true; return false; }))
240 CreateFolder(principalID, rootID, (int)AssetType.Landmark, "Landmarks");
241 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.LostAndFoundFolder) return true; return false; }))
242 CreateFolder(principalID, rootID, (int)AssetType.LostAndFoundFolder, "Lost And Found");
243 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Notecard) return true; return false; }))
244 CreateFolder(principalID, rootID, (int)AssetType.Notecard, "Notecards");
245 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Object) return true; return false; }))
246 CreateFolder(principalID, rootID, (int)AssetType.Object, "Objects");
247 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.SnapshotFolder) return true; return false; }))
248 CreateFolder(principalID, rootID, (int)AssetType.SnapshotFolder, "Photo Album");
249 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.LSLText) return true; return false; }))
250 CreateFolder(principalID, rootID, (int)AssetType.LSLText, "Scripts");
251 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Sound) return true; return false; }))
252 CreateFolder(principalID, rootID, (int)AssetType.Sound, "Sounds");
253 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Texture) return true; return false; }))
254 CreateFolder(principalID, rootID, (int)AssetType.Texture, "Textures");
255 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.TrashFolder) return true; return false; }))
256 CreateFolder(principalID, rootID, (int)AssetType.TrashFolder, "Trash");
257 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.FavoriteFolder) return true; return false; }))
258 CreateFolder(principalID, rootID, (int)AssetType.FavoriteFolder, "Favorites");
259 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.CurrentOutfitFolder) return true; return false; }))
260 CreateFolder(principalID, rootID, (int)AssetType.CurrentOutfitFolder, "Current Outfit");
261
262 }
263
147 public override InventoryFolderBase GetFolderForType(UUID principalID, AssetType type) 264 public override InventoryFolderBase GetFolderForType(UUID principalID, AssetType type)
148 { 265 {
149 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type); 266 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type);
150 return GetRootFolder(principalID); 267 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
268 XInventoryFolder[] folders = m_Database.GetFolders(
269 new string[] { "agentID", "type", "parentFolderID"},
270 new string[] { principalID.ToString(), ((int)type).ToString(), suitcase.folderID.ToString() });
271
272 if (folders.Length == 0)
273 {
274 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Found no folder for type {0} for user {1}", type, principalID);
275 return null;
276 }
277
278 m_log.DebugFormat(
279 "[HG SUITCASE INVENTORY SERVICE]: Found folder {0} {1} for type {2} for user {3}",
280 folders[0].folderName, folders[0].folderID, type, principalID);
281
282 return ConvertToOpenSim(folders[0]);
151 } 283 }
152 284
153 public override InventoryCollection GetFolderContent(UUID principalID, UUID folderID) 285 public override InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
@@ -199,6 +331,7 @@ namespace OpenSim.Services.HypergridService
199 331
200 public override bool AddFolder(InventoryFolderBase folder) 332 public override bool AddFolder(InventoryFolderBase folder)
201 { 333 {
334 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: AddFolder {0} {1}", folder.Name, folder.ParentID);
202 // Let's do a bit of sanity checking, more than the base service does 335 // Let's do a bit of sanity checking, more than the base service does
203 // make sure the given folder's parent folder exists under the suitcase tree of this user 336 // make sure the given folder's parent folder exists under the suitcase tree of this user
204 XInventoryFolder root = GetRootXFolder(folder.Owner); 337 XInventoryFolder root = GetRootXFolder(folder.Owner);
@@ -219,14 +352,37 @@ namespace OpenSim.Services.HypergridService
219 return base.AddFolder(folder); 352 return base.AddFolder(folder);
220 } 353 }
221 354
222 public bool UpdateFolder(InventoryFolderBase folder) 355 public override bool UpdateFolder(InventoryFolderBase folder)
223 { 356 {
224 XInventoryFolder root = GetRootXFolder(folder.Owner); 357 XInventoryFolder root = GetRootXFolder(folder.Owner);
225 XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner); 358 XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner);
226 359
360 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Update folder {0}, version {1}", folder.ID, folder.Version);
227 if (!IsWithinSuitcaseTree(folder.ID, root, suitcase)) 361 if (!IsWithinSuitcaseTree(folder.ID, root, suitcase))
362 {
363 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: folder {0} not within Suitcase tree", folder.Name);
228 return false; 364 return false;
365 }
366
367 if (folder.ID == root.folderID)
368 {
369 if (folder.Version <= suitcase.version)
370 {
371 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: version {0} <= suitcase version {1}. Ignoring.", folder.Version, suitcase.version);
372 return false;
373 }
374 if (folder.Version <= root.version)
375 {
376 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: version {0} <= root version {1}. Ignoring.", folder.Version, suitcase.version);
377 return false;
378 }
379 suitcase.version = root.version = folder.Version;
380 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Storing {0} type {1} version {2}", suitcase.folderName, suitcase.type, suitcase.version);
381 m_Database.StoreFolder(suitcase);
382 m_Database.StoreFolder(root);
383 }
229 384
385 // For all others
230 return base.UpdateFolder(folder); 386 return base.UpdateFolder(folder);
231 } 387 }
232 388
@@ -301,9 +457,6 @@ namespace OpenSim.Services.HypergridService
301 XInventoryFolder root = GetRootXFolder(items[0].Owner); 457 XInventoryFolder root = GetRootXFolder(items[0].Owner);
302 XInventoryFolder suitcase = GetSuitcaseXFolder(items[0].Owner); 458 XInventoryFolder suitcase = GetSuitcaseXFolder(items[0].Owner);
303 459
304 if (!IsWithinSuitcaseTree(items[0].Folder, root, suitcase))
305 return false;
306
307 foreach (InventoryItemBase it in items) 460 foreach (InventoryItemBase it in items)
308 if (it.Folder == root.folderID) 461 if (it.Folder == root.folderID)
309 { 462 {
@@ -312,6 +465,9 @@ namespace OpenSim.Services.HypergridService
312 it.Folder = suitcase.folderID; 465 it.Folder = suitcase.folderID;
313 } 466 }
314 467
468 if (!IsWithinSuitcaseTree(items[0].Folder, root, suitcase))
469 return false;
470
315 return base.MoveItems(principalID, items); 471 return base.MoveItems(principalID, items);
316 472
317 } 473 }
@@ -322,44 +478,57 @@ namespace OpenSim.Services.HypergridService
322 return false; 478 return false;
323 } 479 }
324 480
325 public override InventoryItemBase GetItem(InventoryItemBase item) 481 public new InventoryItemBase GetItem(InventoryItemBase item)
326 { 482 {
327 InventoryItemBase it = base.GetItem(item); 483 InventoryItemBase it = base.GetItem(item);
484 if (it == null)
485 {
486 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to retrieve item {0} ({1}) in folder {2}",
487 item.Name, item.ID, item.Folder);
488 return null;
489 }
328 XInventoryFolder root = GetRootXFolder(it.Owner); 490 XInventoryFolder root = GetRootXFolder(it.Owner);
329 XInventoryFolder suitcase = GetSuitcaseXFolder(it.Owner); 491 XInventoryFolder suitcase = GetSuitcaseXFolder(it.Owner);
330 492 if (root == null || suitcase == null)
331 if (it != null)
332 { 493 {
333 if (!IsWithinSuitcaseTree(it.Folder, root, suitcase)) 494 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Root or Suitcase are null for user {0}",
334 return null; 495 it.Owner);
335 496 return null;
336 if (it.Folder == suitcase.folderID) 497 }
337 it.Folder = root.folderID;
338 498
339 // UserAccount user = m_Cache.GetUser(it.CreatorId); 499 if (it.Folder == suitcase.folderID)
500 it.Folder = root.folderID;
340 501
341 // // Adjust the creator data 502 if (!IsWithinSuitcaseTree(it.Folder, root, suitcase))
342 // if (user != null && it != null && (it.CreatorData == null || it.CreatorData == string.Empty)) 503 {
343 // it.CreatorData = m_HomeURL + ";" + user.FirstName + " " + user.LastName; 504 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Item {0} (folder {1}) is not within Suitcase",
344 //} 505 it.Name, it.Folder);
506 return null;
345 } 507 }
346 508
509 // UserAccount user = m_Cache.GetUser(it.CreatorId);
510
511 // // Adjust the creator data
512 // if (user != null && it != null && (it.CreatorData == null || it.CreatorData == string.Empty))
513 // it.CreatorData = m_HomeURL + ";" + user.FirstName + " " + user.LastName;
514 //}
515
347 return it; 516 return it;
348 } 517 }
349 518
350 public override InventoryFolderBase GetFolder(InventoryFolderBase folder) 519 public new InventoryFolderBase GetFolder(InventoryFolderBase folder)
351 { 520 {
352 InventoryFolderBase f = base.GetFolder(folder); 521 InventoryFolderBase f = base.GetFolder(folder);
353 XInventoryFolder root = GetRootXFolder(f.Owner);
354 XInventoryFolder suitcase = GetSuitcaseXFolder(f.Owner);
355 522
356 if (f != null) 523 if (f != null)
357 { 524 {
358 if (!IsWithinSuitcaseTree(f.ID, root, suitcase)) 525 XInventoryFolder root = GetRootXFolder(f.Owner);
359 return null; 526 XInventoryFolder suitcase = GetSuitcaseXFolder(f.Owner);
360
361 if (f.ParentID == suitcase.folderID) 527 if (f.ParentID == suitcase.folderID)
362 f.ParentID = root.folderID; 528 f.ParentID = root.folderID;
529
530 if (!IsWithinSuitcaseTree(f.ID, root, suitcase))
531 return null;
363 } 532 }
364 533
365 return f; 534 return f;
@@ -409,20 +578,22 @@ namespace OpenSim.Services.HypergridService
409 return null; 578 return null;
410 } 579 }
411 580
412 private void SetAsRootFolder(XInventoryFolder suitcase, UUID rootID) 581 private void SetAsRootFolder(XInventoryFolder suitcase, XInventoryFolder root)
413 { 582 {
414 suitcase.folderID = rootID; 583 suitcase.version = root.version;
584 suitcase.folderID = root.folderID;
415 suitcase.parentFolderID = UUID.Zero; 585 suitcase.parentFolderID = UUID.Zero;
586 suitcase.type = (short)AssetType.Folder;
416 } 587 }
417 588
418 private List<XInventoryFolder> GetFolderTree(UUID root) 589 private List<XInventoryFolder> GetFolderTree(UUID folder)
419 { 590 {
420 List<XInventoryFolder> t = null; 591 List<XInventoryFolder> t = null;
421 if (m_SuitcaseTrees.TryGetValue(root, out t)) 592 if (m_SuitcaseTrees.TryGetValue(folder, out t))
422 return t; 593 return t;
423 594
424 t = GetFolderTreeRecursive(root); 595 t = GetFolderTreeRecursive(folder);
425 m_SuitcaseTrees.AddOrUpdate(root, t, 120); 596 m_SuitcaseTrees.AddOrUpdate(folder, t, 120);
426 return t; 597 return t;
427 } 598 }
428 599
@@ -447,6 +618,13 @@ namespace OpenSim.Services.HypergridService
447 618
448 } 619 }
449 620
621 /// <summary>
622 /// Return true if the folderID is a subfolder of the Suitcase or the root folder ID itself
623 /// </summary>
624 /// <param name="folderID"></param>
625 /// <param name="root"></param>
626 /// <param name="suitcase"></param>
627 /// <returns></returns>
450 private bool IsWithinSuitcaseTree(UUID folderID, XInventoryFolder root, XInventoryFolder suitcase) 628 private bool IsWithinSuitcaseTree(UUID folderID, XInventoryFolder root, XInventoryFolder suitcase)
451 { 629 {
452 List<XInventoryFolder> tree = new List<XInventoryFolder>(); 630 List<XInventoryFolder> tree = new List<XInventoryFolder>();
@@ -463,4 +641,502 @@ namespace OpenSim.Services.HypergridService
463 } 641 }
464 #endregion 642 #endregion
465 } 643 }
644
645 public class HGSuitcaseInventoryService : XInventoryService, IInventoryService
646 {
647 private static readonly ILog m_log =
648 LogManager.GetLogger(
649 MethodBase.GetCurrentMethod().DeclaringType);
650
651 private string m_HomeURL;
652 private IUserAccountService m_UserAccountService;
653
654 private UserAccountCache m_Cache;
655
656 private ExpiringCache<UUID, List<XInventoryFolder>> m_SuitcaseTrees = new ExpiringCache<UUID, List<XInventoryFolder>>();
657
658 public HGSuitcaseInventoryService(IConfigSource config, string configName)
659 : base(config, configName)
660 {
661 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Starting with config name {0}", configName);
662 if (configName != string.Empty)
663 m_ConfigName = configName;
664
665 if (m_Database == null)
666 m_log.WarnFormat("[XXX]: m_Database is null!");
667
668 //
669 // Try reading the [InventoryService] section, if it exists
670 //
671 IConfig invConfig = config.Configs[m_ConfigName];
672 if (invConfig != null)
673 {
674 // realm = authConfig.GetString("Realm", realm);
675 string userAccountsDll = invConfig.GetString("UserAccountsService", string.Empty);
676 if (userAccountsDll == string.Empty)
677 throw new Exception("Please specify UserAccountsService in HGInventoryService configuration");
678
679 Object[] args = new Object[] { config };
680 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userAccountsDll, args);
681 if (m_UserAccountService == null)
682 throw new Exception(String.Format("Unable to create UserAccountService from {0}", userAccountsDll));
683
684 // legacy configuration [obsolete]
685 m_HomeURL = invConfig.GetString("ProfileServerURI", string.Empty);
686 // Preferred
687 m_HomeURL = invConfig.GetString("HomeURI", m_HomeURL);
688
689 m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService);
690 }
691
692 m_log.Debug("[HG SUITCASE INVENTORY SERVICE]: Starting...");
693 }
694
695 public override bool CreateUserInventory(UUID principalID)
696 {
697 // NOGO
698 return false;
699 }
700
701 public override List<InventoryFolderBase> GetInventorySkeleton(UUID principalID)
702 {
703 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
704 XInventoryFolder root = GetRootXFolder(principalID);
705
706 List<XInventoryFolder> tree = GetFolderTree(suitcase.folderID);
707 if (tree == null || (tree != null && tree.Count == 0))
708 return null;
709
710 List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
711 foreach (XInventoryFolder x in tree)
712 {
713 folders.Add(ConvertToOpenSim(x));
714 }
715
716 SetAsRootFolder(suitcase, root);
717 folders.Add(ConvertToOpenSim(suitcase));
718
719 return folders;
720 }
721
722 public override InventoryCollection GetUserInventory(UUID userID)
723 {
724 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Get Suitcase inventory for user {0}", userID);
725 InventoryCollection userInventory = new InventoryCollection();
726 userInventory.UserID = userID;
727 userInventory.Folders = new List<InventoryFolderBase>();
728 userInventory.Items = new List<InventoryItemBase>();
729
730 XInventoryFolder suitcase = GetSuitcaseXFolder(userID);
731 XInventoryFolder root = GetRootXFolder(userID);
732
733 List<XInventoryFolder> tree = GetFolderTree(suitcase.folderID);
734 if (tree == null || (tree != null && tree.Count == 0))
735 {
736 SetAsRootFolder(suitcase, root);
737 userInventory.Folders.Add(ConvertToOpenSim(suitcase));
738 return userInventory;
739 }
740
741 List<InventoryItemBase> items;
742 foreach (XInventoryFolder f in tree)
743 {
744 // Add the items of this subfolder
745 items = GetFolderItems(userID, f.folderID);
746 if (items != null && items.Count > 0)
747 {
748 userInventory.Items.AddRange(items);
749 }
750
751 // Add the folder itself
752 userInventory.Folders.Add(ConvertToOpenSim(f));
753 }
754
755 items = GetFolderItems(userID, suitcase.folderID);
756 if (items != null && items.Count > 0)
757 {
758 userInventory.Items.AddRange(items);
759 }
760
761 SetAsRootFolder(suitcase, root);
762 userInventory.Folders.Add(ConvertToOpenSim(suitcase));
763
764 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetUserInventory for user {0} returning {1} folders and {2} items",
765 userID, userInventory.Folders.Count, userInventory.Items.Count);
766 return userInventory;
767 }
768
769 public override InventoryFolderBase GetRootFolder(UUID principalID)
770 {
771 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetRootFolder for {0}", principalID);
772 if (m_Database == null)
773 m_log.ErrorFormat("[XXX]: m_Database is NULL!");
774
775 // Let's find out the local root folder
776 XInventoryFolder root = GetRootXFolder(principalID); ;
777 if (root == null)
778 {
779 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to retrieve local root folder for user {0}", principalID);
780 }
781
782 // Warp! Root folder for travelers is the suitcase folder
783 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
784
785 if (suitcase == null)
786 {
787 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: User {0} does not have a Suitcase folder. Creating it...", principalID);
788 // make one, and let's add it to the user's inventory as a direct child of the root folder
789 // In the DB we tag it as type 100, but we use -1 (Unknown) outside
790 suitcase = CreateFolder(principalID, root.folderID, 100, "My Suitcase");
791 if (suitcase == null)
792 m_log.ErrorFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to create suitcase folder");
793 m_Database.StoreFolder(suitcase);
794
795 // Create System folders
796 CreateSystemFolders(principalID, suitcase.folderID);
797 }
798
799 SetAsRootFolder(suitcase, root);
800
801 return ConvertToOpenSim(suitcase);
802 }
803
804 protected void CreateSystemFolders(UUID principalID, UUID rootID)
805 {
806 m_log.Debug("[HG SUITCASE INVENTORY SERVICE]: Creating System folders under Suitcase...");
807 XInventoryFolder[] sysFolders = GetSystemFolders(principalID, rootID);
808
809 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Animation) return true; return false; }))
810 CreateFolder(principalID, rootID, (int)AssetType.Animation, "Animations");
811 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Bodypart) return true; return false; }))
812 CreateFolder(principalID, rootID, (int)AssetType.Bodypart, "Body Parts");
813 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.CallingCard) return true; return false; }))
814 CreateFolder(principalID, rootID, (int)AssetType.CallingCard, "Calling Cards");
815 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Clothing) return true; return false; }))
816 CreateFolder(principalID, rootID, (int)AssetType.Clothing, "Clothing");
817 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Gesture) return true; return false; }))
818 CreateFolder(principalID, rootID, (int)AssetType.Gesture, "Gestures");
819 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Landmark) return true; return false; }))
820 CreateFolder(principalID, rootID, (int)AssetType.Landmark, "Landmarks");
821 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.LostAndFoundFolder) return true; return false; }))
822 CreateFolder(principalID, rootID, (int)AssetType.LostAndFoundFolder, "Lost And Found");
823 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Notecard) return true; return false; }))
824 CreateFolder(principalID, rootID, (int)AssetType.Notecard, "Notecards");
825 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Object) return true; return false; }))
826 CreateFolder(principalID, rootID, (int)AssetType.Object, "Objects");
827 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.SnapshotFolder) return true; return false; }))
828 CreateFolder(principalID, rootID, (int)AssetType.SnapshotFolder, "Photo Album");
829 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.LSLText) return true; return false; }))
830 CreateFolder(principalID, rootID, (int)AssetType.LSLText, "Scripts");
831 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Sound) return true; return false; }))
832 CreateFolder(principalID, rootID, (int)AssetType.Sound, "Sounds");
833 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Texture) return true; return false; }))
834 CreateFolder(principalID, rootID, (int)AssetType.Texture, "Textures");
835 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.TrashFolder) return true; return false; }))
836 CreateFolder(principalID, rootID, (int)AssetType.TrashFolder, "Trash");
837 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.FavoriteFolder) return true; return false; }))
838 CreateFolder(principalID, rootID, (int)AssetType.FavoriteFolder, "Favorites");
839 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.CurrentOutfitFolder) return true; return false; }))
840 CreateFolder(principalID, rootID, (int)AssetType.CurrentOutfitFolder, "Current Outfit");
841
842 }
843
844 public override InventoryFolderBase GetFolderForType(UUID principalID, AssetType type)
845 {
846 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type);
847 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
848 XInventoryFolder[] folders = m_Database.GetFolders(
849 new string[] { "agentID", "type", "parentFolderID" },
850 new string[] { principalID.ToString(), ((int)type).ToString(), suitcase.folderID.ToString() });
851
852 if (folders.Length == 0)
853 {
854 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Found no folder for type {0} for user {1}", type, principalID);
855 return null;
856 }
857
858 m_log.DebugFormat(
859 "[HG SUITCASE INVENTORY SERVICE]: Found folder {0} {1} for type {2} for user {3}",
860 folders[0].folderName, folders[0].folderID, type, principalID);
861
862 return ConvertToOpenSim(folders[0]);
863 }
864
865 public override InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
866 {
867 InventoryCollection coll = null;
868 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
869
870 if (!IsWithinSuitcaseTree(folderID, suitcase))
871 return new InventoryCollection();
872
873 coll = base.GetFolderContent(principalID, folderID);
874
875 if (coll == null)
876 {
877 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Something wrong with user {0}'s suitcase folder", principalID);
878 coll = new InventoryCollection();
879 }
880 return coll;
881 }
882
883 public override List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID)
884 {
885 // Let's do a bit of sanity checking, more than the base service does
886 // make sure the given folder exists under the suitcase tree of this user
887 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
888
889 if (!IsWithinSuitcaseTree(folderID, suitcase))
890 return new List<InventoryItemBase>();
891
892 return base.GetFolderItems(principalID, folderID);
893 }
894
895 public override bool AddFolder(InventoryFolderBase folder)
896 {
897 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: AddFolder {0} {1}", folder.Name, folder.ParentID);
898 // Let's do a bit of sanity checking, more than the base service does
899 // make sure the given folder's parent folder exists under the suitcase tree of this user
900 XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner);
901
902 if (!IsWithinSuitcaseTree(folder.ParentID, suitcase))
903 return false;
904
905 // OK, it's legit
906 return base.AddFolder(folder);
907 }
908
909 public override bool UpdateFolder(InventoryFolderBase folder)
910 {
911 XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner);
912
913 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Update folder {0}, version {1}", folder.ID, folder.Version);
914 if (!IsWithinSuitcaseTree(folder.ID, suitcase))
915 {
916 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: folder {0} not within Suitcase tree", folder.Name);
917 return false;
918 }
919
920 // For all others
921 return base.UpdateFolder(folder);
922 }
923
924 public override bool MoveFolder(InventoryFolderBase folder)
925 {
926 XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner);
927
928 if (!IsWithinSuitcaseTree(folder.ID, suitcase) || !IsWithinSuitcaseTree(folder.ParentID, suitcase))
929 return false;
930
931 return base.MoveFolder(folder);
932 }
933
934 public override bool DeleteFolders(UUID principalID, List<UUID> folderIDs)
935 {
936 // NOGO
937 return false;
938 }
939
940 public override bool PurgeFolder(InventoryFolderBase folder)
941 {
942 // NOGO
943 return false;
944 }
945
946 public override bool AddItem(InventoryItemBase item)
947 {
948 // Let's do a bit of sanity checking, more than the base service does
949 // make sure the given folder's parent folder exists under the suitcase tree of this user
950 XInventoryFolder suitcase = GetSuitcaseXFolder(item.Owner);
951
952 if (!IsWithinSuitcaseTree(item.Folder, suitcase))
953 return false;
954
955 // OK, it's legit
956 return base.AddItem(item);
957
958 }
959
960 public override bool UpdateItem(InventoryItemBase item)
961 {
962 XInventoryFolder suitcase = GetSuitcaseXFolder(item.Owner);
963
964 if (!IsWithinSuitcaseTree(item.Folder, suitcase))
965 return false;
966
967 return base.UpdateItem(item);
968 }
969
970 public override bool MoveItems(UUID principalID, List<InventoryItemBase> items)
971 {
972 // Principal is b0rked. *sigh*
973
974 XInventoryFolder suitcase = GetSuitcaseXFolder(items[0].Owner);
975
976 if (!IsWithinSuitcaseTree(items[0].Folder, suitcase))
977 return false;
978
979 return base.MoveItems(principalID, items);
980
981 }
982
983 public override bool DeleteItems(UUID principalID, List<UUID> itemIDs)
984 {
985 return false;
986 }
987
988 public new InventoryItemBase GetItem(InventoryItemBase item)
989 {
990 InventoryItemBase it = base.GetItem(item);
991 if (it == null)
992 {
993 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to retrieve item {0} ({1}) in folder {2}",
994 item.Name, item.ID, item.Folder);
995 return null;
996 }
997 XInventoryFolder suitcase = GetSuitcaseXFolder(it.Owner);
998 if (suitcase == null)
999 {
1000 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Root or Suitcase are null for user {0}",
1001 it.Owner);
1002 return null;
1003 }
1004
1005 if (!IsWithinSuitcaseTree(it.Folder, suitcase))
1006 {
1007 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Item {0} (folder {1}) is not within Suitcase",
1008 it.Name, it.Folder);
1009 return null;
1010 }
1011
1012 // UserAccount user = m_Cache.GetUser(it.CreatorId);
1013
1014 // // Adjust the creator data
1015 // if (user != null && it != null && (it.CreatorData == null || it.CreatorData == string.Empty))
1016 // it.CreatorData = m_HomeURL + ";" + user.FirstName + " " + user.LastName;
1017 //}
1018
1019 return it;
1020 }
1021
1022 public new InventoryFolderBase GetFolder(InventoryFolderBase folder)
1023 {
1024 InventoryFolderBase f = base.GetFolder(folder);
1025
1026 if (f != null)
1027 {
1028 XInventoryFolder suitcase = GetSuitcaseXFolder(f.Owner);
1029
1030 if (!IsWithinSuitcaseTree(f.ID, suitcase))
1031 return null;
1032 }
1033
1034 return f;
1035 }
1036
1037 //public List<InventoryItemBase> GetActiveGestures(UUID principalID)
1038 //{
1039 //}
1040
1041 //public int GetAssetPermissions(UUID principalID, UUID assetID)
1042 //{
1043 //}
1044
1045 #region Auxiliary functions
1046 private XInventoryFolder GetXFolder(UUID userID, UUID folderID)
1047 {
1048 XInventoryFolder[] folders = m_Database.GetFolders(
1049 new string[] { "agentID", "folderID" },
1050 new string[] { userID.ToString(), folderID.ToString() });
1051
1052 if (folders.Length == 0)
1053 return null;
1054
1055 return folders[0];
1056 }
1057
1058 private XInventoryFolder GetRootXFolder(UUID principalID)
1059 {
1060 XInventoryFolder[] folders = m_Database.GetFolders(
1061 new string[] { "agentID", "folderName", "type" },
1062 new string[] { principalID.ToString(), "My Inventory", ((int)AssetType.RootFolder).ToString() });
1063
1064 if (folders != null && folders.Length > 0)
1065 return folders[0];
1066 return null;
1067 }
1068
1069 private XInventoryFolder GetSuitcaseXFolder(UUID principalID)
1070 {
1071 // Warp! Root folder for travelers
1072 XInventoryFolder[] folders = m_Database.GetFolders(
1073 new string[] { "agentID", "type" },
1074 new string[] { principalID.ToString(), "100" }); // This is a special folder type...
1075
1076 if (folders != null && folders.Length > 0)
1077 return folders[0];
1078 return null;
1079 }
1080
1081 private void SetAsRootFolder(XInventoryFolder suitcase, XInventoryFolder root)
1082 {
1083 suitcase.type = (short)AssetType.Folder;
1084 }
1085
1086 private List<XInventoryFolder> GetFolderTree(UUID folder)
1087 {
1088 List<XInventoryFolder> t = null;
1089 if (m_SuitcaseTrees.TryGetValue(folder, out t))
1090 return t;
1091
1092 t = GetFolderTreeRecursive(folder);
1093 m_SuitcaseTrees.AddOrUpdate(folder, t, 120);
1094 return t;
1095 }
1096
1097 private List<XInventoryFolder> GetFolderTreeRecursive(UUID root)
1098 {
1099 List<XInventoryFolder> tree = new List<XInventoryFolder>();
1100 XInventoryFolder[] folders = m_Database.GetFolders(
1101 new string[] { "parentFolderID" },
1102 new string[] { root.ToString() });
1103
1104 if (folders == null || (folders != null && folders.Length == 0))
1105 return tree; // empty tree
1106 else
1107 {
1108 foreach (XInventoryFolder f in folders)
1109 {
1110 tree.Add(f);
1111 tree.AddRange(GetFolderTreeRecursive(f.folderID));
1112 }
1113 return tree;
1114 }
1115
1116 }
1117
1118 /// <summary>
1119 /// Return true if the folderID is a subfolder of the Suitcase or the suitcase folder itself
1120 /// </summary>
1121 /// <param name="folderID"></param>
1122 /// <param name="root"></param>
1123 /// <param name="suitcase"></param>
1124 /// <returns></returns>
1125 private bool IsWithinSuitcaseTree(UUID folderID, XInventoryFolder suitcase)
1126 {
1127 List<XInventoryFolder> tree = new List<XInventoryFolder>();
1128 tree.Add(suitcase); // Warp! the tree is the real root folder plus the children of the suitcase folder
1129 tree.AddRange(GetFolderTree(suitcase.folderID));
1130 XInventoryFolder f = tree.Find(delegate(XInventoryFolder fl)
1131 {
1132 if (fl.folderID == folderID) return true;
1133 else return false;
1134 });
1135
1136 if (f == null) return false;
1137 else return true;
1138 }
1139 #endregion
1140 }
1141
466} 1142}
diff --git a/OpenSim/Services/InventoryService/XInventoryService.cs b/OpenSim/Services/InventoryService/XInventoryService.cs
index 7b2c3a6..0e7a358 100644
--- a/OpenSim/Services/InventoryService/XInventoryService.cs
+++ b/OpenSim/Services/InventoryService/XInventoryService.cs
@@ -40,9 +40,9 @@ namespace OpenSim.Services.InventoryService
40{ 40{
41 public class XInventoryService : ServiceBase, IInventoryService 41 public class XInventoryService : ServiceBase, IInventoryService
42 { 42 {
43// private static readonly ILog m_log = 43 private static readonly ILog m_log =
44// LogManager.GetLogger( 44 LogManager.GetLogger(
45// MethodBase.GetCurrentMethod().DeclaringType); 45 MethodBase.GetCurrentMethod().DeclaringType);
46 46
47 protected IXInventoryData m_Database; 47 protected IXInventoryData m_Database;
48 protected bool m_AllowDelete = true; 48 protected bool m_AllowDelete = true;
@@ -113,7 +113,7 @@ namespace OpenSim.Services.InventoryService
113 result = true; 113 result = true;
114 } 114 }
115 115
116 XInventoryFolder[] sysFolders = GetSystemFolders(principalID); 116 XInventoryFolder[] sysFolders = GetSystemFolders(principalID, rootFolder.ID);
117 117
118 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Animation) return true; return false; })) 118 if (!Array.Exists(sysFolders, delegate (XInventoryFolder f) { if (f.type == (int)AssetType.Animation) return true; return false; }))
119 CreateFolder(principalID, rootFolder.ID, (int)AssetType.Animation, "Animations"); 119 CreateFolder(principalID, rootFolder.ID, (int)AssetType.Animation, "Animations");
@@ -163,13 +163,13 @@ namespace OpenSim.Services.InventoryService
163 return newFolder; 163 return newFolder;
164 } 164 }
165 165
166 protected virtual XInventoryFolder[] GetSystemFolders(UUID principalID) 166 protected virtual XInventoryFolder[] GetSystemFolders(UUID principalID, UUID rootID)
167 { 167 {
168// m_log.DebugFormat("[XINVENTORY SERVICE]: Getting system folders for {0}", principalID); 168// m_log.DebugFormat("[XINVENTORY SERVICE]: Getting system folders for {0}", principalID);
169 169
170 XInventoryFolder[] allFolders = m_Database.GetFolders( 170 XInventoryFolder[] allFolders = m_Database.GetFolders(
171 new string[] { "agentID" }, 171 new string[] { "agentID", "parentFolderID" },
172 new string[] { principalID.ToString() }); 172 new string[] { principalID.ToString(), rootID.ToString() });
173 173
174 XInventoryFolder[] sysFolders = Array.FindAll( 174 XInventoryFolder[] sysFolders = Array.FindAll(
175 allFolders, 175 allFolders,
@@ -301,16 +301,26 @@ namespace OpenSim.Services.InventoryService
301 301
302 public virtual bool AddFolder(InventoryFolderBase folder) 302 public virtual bool AddFolder(InventoryFolderBase folder)
303 { 303 {
304 //m_log.DebugFormat("[XINVENTORY]: Add folder {0} type {1} in parent {2}", folder.Name, folder.Type, folder.ParentID);
304 InventoryFolderBase check = GetFolder(folder); 305 InventoryFolderBase check = GetFolder(folder);
305 if (check != null) 306 if (check != null)
306 return false; 307 return false;
307 308
308 XInventoryFolder xFolder = ConvertFromOpenSim(folder); 309 if (folder.Type == (short)AssetType.Folder || folder.Type == (short)AssetType.Unknown ||
309 return m_Database.StoreFolder(xFolder); 310 GetFolderForType(folder.Owner, (AssetType)(folder.Type)) == null)
311 {
312 XInventoryFolder xFolder = ConvertFromOpenSim(folder);
313 return m_Database.StoreFolder(xFolder);
314 }
315 else
316 m_log.DebugFormat("[XINVENTORY]: Folder {0} of type {1} already exists", folder.Name, folder.Type);
317
318 return false;
310 } 319 }
311 320
312 public virtual bool UpdateFolder(InventoryFolderBase folder) 321 public virtual bool UpdateFolder(InventoryFolderBase folder)
313 { 322 {
323 //m_log.DebugFormat("[XINVENTORY]: Update folder {0} {1} ({2})", folder.Name, folder.Type, folder.ID);
314 XInventoryFolder xFolder = ConvertFromOpenSim(folder); 324 XInventoryFolder xFolder = ConvertFromOpenSim(folder);
315 InventoryFolderBase check = GetFolder(folder); 325 InventoryFolderBase check = GetFolder(folder);
316 if (check == null) 326 if (check == null)
@@ -319,9 +329,13 @@ namespace OpenSim.Services.InventoryService
319 if (check.Type != -1 || xFolder.type != -1) 329 if (check.Type != -1 || xFolder.type != -1)
320 { 330 {
321 if (xFolder.version < check.Version) 331 if (xFolder.version < check.Version)
332 {
333 //m_log.DebugFormat("[XINVENTORY]: {0} < {1} can't do", xFolder.version, check.Version);
322 return false; 334 return false;
335 }
323 check.Version = (ushort)xFolder.version; 336 check.Version = (ushort)xFolder.version;
324 xFolder = ConvertFromOpenSim(check); 337 xFolder = ConvertFromOpenSim(check);
338 //m_log.DebugFormat("[XINVENTORY]: Storing {0} {1} {2}", xFolder.folderName, xFolder.version, xFolder.type);
325 return m_Database.StoreFolder(xFolder); 339 return m_Database.StoreFolder(xFolder);
326 } 340 }
327 341
@@ -499,13 +513,30 @@ namespace OpenSim.Services.InventoryService
499 return m_Database.GetAssetPermissions(principalID, assetID); 513 return m_Database.GetAssetPermissions(principalID, assetID);
500 } 514 }
501 515
502 // CM never needed those. Left unimplemented. 516 public virtual InventoryCollection GetUserInventory(UUID userID)
503 // Obsolete in core
504 //
505 public InventoryCollection GetUserInventory(UUID userID)
506 { 517 {
507 return null; 518 InventoryCollection userInventory = new InventoryCollection();
519 userInventory.UserID = userID;
520 userInventory.Folders = new List<InventoryFolderBase>();
521 userInventory.Items = new List<InventoryItemBase>();
522
523 List<InventoryFolderBase> skel = GetInventorySkeleton(userID);
524 if (skel != null)
525 {
526 foreach (InventoryFolderBase f in skel)
527 {
528 InventoryCollection c = GetFolderContent(userID, f.ID);
529 if (c != null && c.Items != null && c.Items.Count > 0)
530 userInventory.Items.AddRange(c.Items);
531 if (c != null && c.Folders != null && c.Folders.Count > 0)
532 userInventory.Folders.AddRange(c.Folders);
533 }
534 }
535 m_log.DebugFormat("[XINVENTORY SERVICE]: GetUserInventory for user {0} returning {1} folders and {2} items",
536 userID, userInventory.Folders.Count, userInventory.Items.Count);
537 return userInventory;
508 } 538 }
539
509 public void GetUserInventory(UUID userID, InventoryReceiptCallback callback) 540 public void GetUserInventory(UUID userID, InventoryReceiptCallback callback)
510 { 541 {
511 } 542 }
@@ -525,6 +556,9 @@ namespace OpenSim.Services.InventoryService
525 556
526 newFolder.ParentID = folder.parentFolderID; 557 newFolder.ParentID = folder.parentFolderID;
527 newFolder.Type = (short)folder.type; 558 newFolder.Type = (short)folder.type;
559 // Viewer can't understand anything that's not in it's LLFolderType enum
560 if (newFolder.Type == 100)
561 newFolder.Type = -1;
528 newFolder.Version = (ushort)folder.version; 562 newFolder.Version = (ushort)folder.version;
529 newFolder.Name = folder.folderName; 563 newFolder.Name = folder.folderName;
530 newFolder.Owner = folder.agentID; 564 newFolder.Owner = folder.agentID;