aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDiva Canto2012-04-06 12:28:15 -0700
committerDiva Canto2012-04-06 12:28:15 -0700
commit6a9f36788df8c07b76d779236b66e48cab6ae316 (patch)
tree51516067b8c1a2a31c1b6f0d2d414a0739d7c280
parentMerge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff)
downloadopensim-SC_OLD-6a9f36788df8c07b76d779236b66e48cab6ae316.zip
opensim-SC_OLD-6a9f36788df8c07b76d779236b66e48cab6ae316.tar.gz
opensim-SC_OLD-6a9f36788df8c07b76d779236b66e48cab6ae316.tar.bz2
opensim-SC_OLD-6a9f36788df8c07b76d779236b66e48cab6ae316.tar.xz
Deleted the unused and commented code from 2 commits ago.
-rw-r--r--OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs242
-rw-r--r--OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs594
2 files changed, 1 insertions, 835 deletions
diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs
index d85a996..0f422ae 100644
--- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs
+++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/HGEntityTransferModule.cs
@@ -411,36 +411,6 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
411 411
412 #endregion 412 #endregion
413 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
444 private void RemoveRootFolderContents(IClientAPI client) 414 private void RemoveRootFolderContents(IClientAPI client)
445 { 415 {
446 // TODO tell the viewer to remove the root folder's content 416 // TODO tell the viewer to remove the root folder's content
@@ -473,31 +443,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
473 foreach (InventoryItemBase it in content.Items) 443 foreach (InventoryItemBase it in content.Items)
474 it.Name = it.Name + " (Unavailable)"; ; 444 it.Name = it.Name + " (Unavailable)"; ;
475 445
476 // next, add the subfolders and items of the keep folders 446 // Send the new names
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()); 447 inv.SendBulkUpdateInventory(keep.ToArray(), content.Items.ToArray());
502 448
503 } 449 }
@@ -505,133 +451,12 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
505 } 451 }
506 } 452 }
507 453
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);
522 InventoryCollection content = m_Scenes[0].InventoryService.GetFolderContent(client.AgentId, root.ID);
523 List<UUID> fids = new List<UUID>();
524 List<UUID> iids = new List<UUID>();
525 List<InventoryFolderBase> keep = new List<InventoryFolderBase>();
526
527 foreach (InventoryFolderBase f in content.Folders)
528 {
529 if (f.Type == (short)AssetType.TrashFolder || f.Type == (short)AssetType.Landmark ||
530 f.Type == (short)AssetType.FavoriteFolder || f.Type == (short)AssetType.CurrentOutfitFolder)
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
546 foreach (InventoryItemBase it in content.Items)
547 iids.Add(it.ID);
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
577 }
578 }
579 }
580 }
581
582 private void RemoveSuitcaseFolderContents(IClientAPI client) 454 private void RemoveSuitcaseFolderContents(IClientAPI client)
583 { 455 {
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 } 456 }
623 457
624 private void RestoreRootFolderContents(IClientAPI client) 458 private void RestoreRootFolderContents(IClientAPI client)
625 { 459 {
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"); 460 m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Restoring root folder");
636 if (client is IClientCore) 461 if (client is IClientCore)
637 { 462 {
@@ -646,75 +471,10 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
646 inv.SendBulkUpdateInventory(content.Folders.ToArray(), content.Items.ToArray()); 471 inv.SendBulkUpdateInventory(content.Folders.ToArray(), content.Items.ToArray());
647 } 472 }
648 } 473 }
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 } 474 }
714 475
715 private void RestoreSuitcaseFolderContents(IClientAPI client) 476 private void RestoreSuitcaseFolderContents(IClientAPI client)
716 { 477 {
717
718 } 478 }
719 479
720 private GridRegion MakeRegion(AgentCircuitData aCircuit) 480 private GridRegion MakeRegion(AgentCircuitData aCircuit)
diff --git a/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs b/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs
index e65ad17..b6ec558 100644
--- a/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs
+++ b/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs
@@ -48,600 +48,6 @@ 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 HGSuitcaseInventoryService1 : XInventoryService, IInventoryService
52 {
53 private static readonly ILog m_log =
54 LogManager.GetLogger(
55 MethodBase.GetCurrentMethod().DeclaringType);
56
57 private string m_HomeURL;
58 private IUserAccountService m_UserAccountService;
59
60 private UserAccountCache m_Cache;
61
62 private ExpiringCache<UUID, List<XInventoryFolder>> m_SuitcaseTrees = new ExpiringCache<UUID,List<XInventoryFolder>>();
63
64 public HGSuitcaseInventoryService1(IConfigSource config, string configName)
65 : base(config, configName)
66 {
67 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Starting with config name {0}", configName);
68 if (configName != string.Empty)
69 m_ConfigName = configName;
70
71 if (m_Database == null)
72 m_log.WarnFormat("[XXX]: m_Database is null!");
73
74 //
75 // Try reading the [InventoryService] section, if it exists
76 //
77 IConfig invConfig = config.Configs[m_ConfigName];
78 if (invConfig != null)
79 {
80 // realm = authConfig.GetString("Realm", realm);
81 string userAccountsDll = invConfig.GetString("UserAccountsService", string.Empty);
82 if (userAccountsDll == string.Empty)
83 throw new Exception("Please specify UserAccountsService in HGInventoryService configuration");
84
85 Object[] args = new Object[] { config };
86 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userAccountsDll, args);
87 if (m_UserAccountService == null)
88 throw new Exception(String.Format("Unable to create UserAccountService from {0}", userAccountsDll));
89
90 // legacy configuration [obsolete]
91 m_HomeURL = invConfig.GetString("ProfileServerURI", string.Empty);
92 // Preferred
93 m_HomeURL = invConfig.GetString("HomeURI", m_HomeURL);
94
95 m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService);
96 }
97
98 m_log.Debug("[HG SUITCASE INVENTORY SERVICE]: Starting...");
99 }
100
101 public override bool CreateUserInventory(UUID principalID)
102 {
103 // NOGO
104 return false;
105 }
106
107 public override List<InventoryFolderBase> GetInventorySkeleton(UUID principalID)
108 {
109 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
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;
180 }
181
182 public override InventoryFolderBase GetRootFolder(UUID principalID)
183 {
184 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetRootFolder for {0}", principalID);
185 if (m_Database == null)
186 m_log.ErrorFormat("[XXX]: m_Database is NULL!");
187
188 // Let's find out the local root folder
189 XInventoryFolder root = GetRootXFolder(principalID); ;
190 if (root == null)
191 {
192 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to retrieve local root folder for user {0}", principalID);
193 }
194
195 // Warp! Root folder for travelers is the suitcase folder
196 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
197
198 if (suitcase == null)
199 {
200 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: User {0} does not have a Suitcase folder. Creating it...", principalID);
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
203 suitcase = CreateFolder(principalID, root.folderID, 100, "My Suitcase");
204 if (suitcase == null)
205 m_log.ErrorFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to create suitcase folder");
206 suitcase.version = root.version;
207 m_Database.StoreFolder(suitcase);
208
209 // Create System folders
210 CreateSystemFolders(principalID, suitcase.folderID);
211 }
212 else if (suitcase.version < root.version)
213 {
214 suitcase.version = root.version;
215 m_Database.StoreFolder(suitcase);
216 }
217
218 // Now let's change the folder ID to match that of the real root folder
219 SetAsRootFolder(suitcase, root);
220
221 return ConvertToOpenSim(suitcase);
222 }
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
264 public override InventoryFolderBase GetFolderForType(UUID principalID, AssetType type)
265 {
266 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type);
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]);
283 }
284
285 public override InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
286 {
287 InventoryCollection coll = null;
288 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
289 XInventoryFolder root = GetRootXFolder(principalID);
290
291 if (!IsWithinSuitcaseTree(folderID, root, suitcase))
292 return new InventoryCollection();
293
294 if (folderID == root.folderID) // someone's asking for the root folder, we'll give them the suitcase
295 {
296 if (suitcase != null)
297 {
298 coll = base.GetFolderContent(principalID, suitcase.folderID);
299 foreach (InventoryFolderBase f in coll.Folders)
300 f.ParentID = root.folderID;
301 foreach (InventoryItemBase i in coll.Items)
302 i.Folder = root.folderID;
303 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetFolderContent for root folder returned content for suitcase folder");
304 }
305 }
306 else
307 {
308 coll = base.GetFolderContent(principalID, folderID);
309 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetFolderContent for non-root folder {0}", folderID);
310 }
311 if (coll == null)
312 {
313 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Something wrong with user {0}'s suitcase folder", principalID);
314 coll = new InventoryCollection();
315 }
316 return coll;
317 }
318
319 public override List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID)
320 {
321 // Let's do a bit of sanity checking, more than the base service does
322 // make sure the given folder exists under the suitcase tree of this user
323 XInventoryFolder root = GetRootXFolder(principalID);
324 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
325
326 if (!IsWithinSuitcaseTree(folderID, root, suitcase))
327 return new List<InventoryItemBase>();
328
329 return base.GetFolderItems(principalID, folderID);
330 }
331
332 public override bool AddFolder(InventoryFolderBase folder)
333 {
334 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: AddFolder {0} {1}", folder.Name, folder.ParentID);
335 // Let's do a bit of sanity checking, more than the base service does
336 // make sure the given folder's parent folder exists under the suitcase tree of this user
337 XInventoryFolder root = GetRootXFolder(folder.Owner);
338 XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner);
339
340 if (!IsWithinSuitcaseTree(folder.ParentID, root, suitcase))
341 return false;
342
343 // OK, it's legit
344 // Check if it's under the Root folder directly
345 if (folder.ParentID == root.folderID)
346 {
347 // someone's trying to add a subfolder of the root folder, we'll add it to the suitcase instead
348 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: AddFolder for root folder for user {0}. Adding in suitcase instead", folder.Owner);
349 folder.ParentID = suitcase.folderID;
350 }
351
352 return base.AddFolder(folder);
353 }
354
355 public override bool UpdateFolder(InventoryFolderBase folder)
356 {
357 XInventoryFolder root = GetRootXFolder(folder.Owner);
358 XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner);
359
360 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Update folder {0}, version {1}", folder.ID, folder.Version);
361 if (!IsWithinSuitcaseTree(folder.ID, root, suitcase))
362 {
363 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: folder {0} not within Suitcase tree", folder.Name);
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 }
384
385 // For all others
386 return base.UpdateFolder(folder);
387 }
388
389 public override bool MoveFolder(InventoryFolderBase folder)
390 {
391 XInventoryFolder root = GetRootXFolder(folder.Owner);
392 XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner);
393
394 if (!IsWithinSuitcaseTree(folder.ID, root, suitcase) || !IsWithinSuitcaseTree(folder.ParentID, root, suitcase))
395 return false;
396
397 if (folder.ParentID == root.folderID)
398 {
399 // someone's trying to add a subfolder of the root folder, we'll add it to the suitcase instead
400 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: MoveFolder to root folder for user {0}. Moving it to suitcase instead", folder.Owner);
401 folder.ParentID = suitcase.folderID;
402 }
403
404 return base.MoveFolder(folder);
405 }
406
407 public override bool DeleteFolders(UUID principalID, List<UUID> folderIDs)
408 {
409 // NOGO
410 return false;
411 }
412
413 public override bool PurgeFolder(InventoryFolderBase folder)
414 {
415 // NOGO
416 return false;
417 }
418
419 public override bool AddItem(InventoryItemBase item)
420 {
421 // Let's do a bit of sanity checking, more than the base service does
422 // make sure the given folder's parent folder exists under the suitcase tree of this user
423 XInventoryFolder root = GetRootXFolder(item.Owner);
424 XInventoryFolder suitcase = GetSuitcaseXFolder(item.Owner);
425
426 if (!IsWithinSuitcaseTree(item.Folder, root, suitcase))
427 return false;
428
429 // OK, it's legit
430 // Check if it's under the Root folder directly
431 if (item.Folder == root.folderID)
432 {
433 // someone's trying to add a subfolder of the root folder, we'll add it to the suitcase instead
434 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: AddItem for root folder for user {0}. Adding in suitcase instead", item.Owner);
435 item.Folder = suitcase.folderID;
436 }
437
438 return base.AddItem(item);
439
440 }
441
442 public override bool UpdateItem(InventoryItemBase item)
443 {
444 XInventoryFolder root = GetRootXFolder(item.Owner);
445 XInventoryFolder suitcase = GetSuitcaseXFolder(item.Owner);
446
447 if (!IsWithinSuitcaseTree(item.Folder, root, suitcase))
448 return false;
449
450 return base.UpdateItem(item);
451 }
452
453 public override bool MoveItems(UUID principalID, List<InventoryItemBase> items)
454 {
455 // Principal is b0rked. *sigh*
456
457 XInventoryFolder root = GetRootXFolder(items[0].Owner);
458 XInventoryFolder suitcase = GetSuitcaseXFolder(items[0].Owner);
459
460 foreach (InventoryItemBase it in items)
461 if (it.Folder == root.folderID)
462 {
463 // someone's trying to add a subfolder of the root folder, we'll add it to the suitcase instead
464 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: MoveItem to root folder for user {0}. Moving it to suitcase instead", it.Owner);
465 it.Folder = suitcase.folderID;
466 }
467
468 if (!IsWithinSuitcaseTree(items[0].Folder, root, suitcase))
469 return false;
470
471 return base.MoveItems(principalID, items);
472
473 }
474
475 // Let these pass. Use inherited methods.
476 public override bool DeleteItems(UUID principalID, List<UUID> itemIDs)
477 {
478 return false;
479 }
480
481 public new InventoryItemBase GetItem(InventoryItemBase item)
482 {
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 }
490 XInventoryFolder root = GetRootXFolder(it.Owner);
491 XInventoryFolder suitcase = GetSuitcaseXFolder(it.Owner);
492 if (root == null || suitcase == null)
493 {
494 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Root or Suitcase are null for user {0}",
495 it.Owner);
496 return null;
497 }
498
499 if (it.Folder == suitcase.folderID)
500 it.Folder = root.folderID;
501
502 if (!IsWithinSuitcaseTree(it.Folder, root, suitcase))
503 {
504 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Item {0} (folder {1}) is not within Suitcase",
505 it.Name, it.Folder);
506 return null;
507 }
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
516 return it;
517 }
518
519 public new InventoryFolderBase GetFolder(InventoryFolderBase folder)
520 {
521 InventoryFolderBase f = base.GetFolder(folder);
522
523 if (f != null)
524 {
525 XInventoryFolder root = GetRootXFolder(f.Owner);
526 XInventoryFolder suitcase = GetSuitcaseXFolder(f.Owner);
527 if (f.ParentID == suitcase.folderID)
528 f.ParentID = root.folderID;
529
530 if (!IsWithinSuitcaseTree(f.ID, root, suitcase))
531 return null;
532 }
533
534 return f;
535 }
536
537 //public List<InventoryItemBase> GetActiveGestures(UUID principalID)
538 //{
539 //}
540
541 //public int GetAssetPermissions(UUID principalID, UUID assetID)
542 //{
543 //}
544
545 #region Auxiliary functions
546 private XInventoryFolder GetXFolder(UUID userID, UUID folderID)
547 {
548 XInventoryFolder[] folders = m_Database.GetFolders(
549 new string[] { "agentID", "folderID" },
550 new string[] { userID.ToString(), folderID.ToString() });
551
552 if (folders.Length == 0)
553 return null;
554
555 return folders[0];
556 }
557
558 private XInventoryFolder GetRootXFolder(UUID principalID)
559 {
560 XInventoryFolder[] folders = m_Database.GetFolders(
561 new string[] { "agentID", "folderName", "type" },
562 new string[] { principalID.ToString(), "My Inventory", ((int)AssetType.RootFolder).ToString() });
563
564 if (folders != null && folders.Length > 0)
565 return folders[0];
566 return null;
567 }
568
569 private XInventoryFolder GetSuitcaseXFolder(UUID principalID)
570 {
571 // Warp! Root folder for travelers
572 XInventoryFolder[] folders = m_Database.GetFolders(
573 new string[] { "agentID", "type" },
574 new string[] { principalID.ToString(), "100" }); // This is a special folder type...
575
576 if (folders != null && folders.Length > 0)
577 return folders[0];
578 return null;
579 }
580
581 private void SetAsRootFolder(XInventoryFolder suitcase, XInventoryFolder root)
582 {
583 suitcase.version = root.version;
584 suitcase.folderID = root.folderID;
585 suitcase.parentFolderID = UUID.Zero;
586 suitcase.type = (short)AssetType.Folder;
587 }
588
589 private List<XInventoryFolder> GetFolderTree(UUID folder)
590 {
591 List<XInventoryFolder> t = null;
592 if (m_SuitcaseTrees.TryGetValue(folder, out t))
593 return t;
594
595 t = GetFolderTreeRecursive(folder);
596 m_SuitcaseTrees.AddOrUpdate(folder, t, 120);
597 return t;
598 }
599
600 private List<XInventoryFolder> GetFolderTreeRecursive(UUID root)
601 {
602 List<XInventoryFolder> tree = new List<XInventoryFolder>();
603 XInventoryFolder[] folders = m_Database.GetFolders(
604 new string[] { "parentFolderID" },
605 new string[] { root.ToString() });
606
607 if (folders == null || (folders != null && folders.Length == 0))
608 return tree; // empty tree
609 else
610 {
611 foreach (XInventoryFolder f in folders)
612 {
613 tree.Add(f);
614 tree.AddRange(GetFolderTreeRecursive(f.folderID));
615 }
616 return tree;
617 }
618
619 }
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>
628 private bool IsWithinSuitcaseTree(UUID folderID, XInventoryFolder root, XInventoryFolder suitcase)
629 {
630 List<XInventoryFolder> tree = new List<XInventoryFolder>();
631 tree.Add(root); // Warp! the tree is the real root folder plus the children of the suitcase folder
632 tree.AddRange(GetFolderTree(suitcase.folderID));
633 XInventoryFolder f = tree.Find(delegate(XInventoryFolder fl)
634 {
635 if (fl.folderID == folderID) return true;
636 else return false;
637 });
638
639 if (f == null) return false;
640 else return true;
641 }
642 #endregion
643 }
644
645 public class HGSuitcaseInventoryService : XInventoryService, IInventoryService 51 public class HGSuitcaseInventoryService : XInventoryService, IInventoryService
646 { 52 {
647 private static readonly ILog m_log = 53 private static readonly ILog m_log =