aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorDiva Canto2012-04-06 11:51:12 -0700
committerDiva Canto2012-04-06 11:51:12 -0700
commit25b3edc21c4d5deb7563410a4e0a5364153b1002 (patch)
tree8bc23006a534062db59946a4b0057ff496f7515e /OpenSim
parentA few minor tweaks here and there in XInventoryService. (diff)
downloadopensim-SC-25b3edc21c4d5deb7563410a4e0a5364153b1002.zip
opensim-SC-25b3edc21c4d5deb7563410a4e0a5364153b1002.tar.gz
opensim-SC-25b3edc21c4d5deb7563410a4e0a5364153b1002.tar.bz2
opensim-SC-25b3edc21c4d5deb7563410a4e0a5364153b1002.tar.xz
WARNING: LOTS OF COMMENTED AND UNUSED CODE IN THIS COMMIT. This is on purpose; it's an historical record of what works and what doesn't wrt manipulating inventory at the viewer. I'll remove the unused code in a subsequent commit, but wanted to place it in history. The uncommented code works.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs316
-rw-r--r--OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs748
2 files changed, 1007 insertions, 57 deletions
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/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}