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.
parent
953fe46811
commit
25b3edc21c
|
@ -114,8 +114,18 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
|
||||||
m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: ViaHGLogin");
|
m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: ViaHGLogin");
|
||||||
if (m_RestrictInventoryAccessAbroad)
|
if (m_RestrictInventoryAccessAbroad)
|
||||||
{
|
{
|
||||||
|
IUserManagement uMan = m_Scenes[0].RequestModuleInterface<IUserManagement>();
|
||||||
|
if (uMan.IsLocalGridUser(client.AgentId))
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: User is local");
|
||||||
RestoreRootFolderContents(client);
|
RestoreRootFolderContents(client);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: User is foreign");
|
||||||
|
RestoreSuitcaseFolderContents(client);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -210,7 +220,20 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
|
||||||
logout = success; // flag for later logout from this grid; this is an HG TP
|
logout = success; // flag for later logout from this grid; this is an HG TP
|
||||||
|
|
||||||
if (success && m_RestrictInventoryAccessAbroad)
|
if (success && m_RestrictInventoryAccessAbroad)
|
||||||
|
{
|
||||||
|
IUserManagement uMan = m_aScene.RequestModuleInterface<IUserManagement>();
|
||||||
|
if (uMan != null && uMan.IsLocalGridUser(sp.UUID))
|
||||||
|
{
|
||||||
|
// local grid user
|
||||||
|
m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: User is local");
|
||||||
RemoveRootFolderContents(sp.ControllingClient);
|
RemoveRootFolderContents(sp.ControllingClient);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: User is foreign");
|
||||||
|
RemoveSuitcaseFolderContents(sp.ControllingClient);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
@ -388,6 +411,36 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
// COMPLETE FAIL
|
||||||
|
//private void RemoveRootFolderContents(IClientAPI client)
|
||||||
|
//{
|
||||||
|
// InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(client.AgentId);
|
||||||
|
// m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Removing root inventory for user {0}, version {1}", client.AgentId, root.Version);
|
||||||
|
// InventoryCollection content = m_Scenes[0].InventoryService.GetFolderContent(client.AgentId, root.ID);
|
||||||
|
|
||||||
|
// List<InventoryFolderBase> keep = new List<InventoryFolderBase>();
|
||||||
|
// foreach (InventoryFolderBase f in content.Folders)
|
||||||
|
// {
|
||||||
|
// if (f.Type == (short)AssetType.TrashFolder || f.Type == (short)AssetType.Landmark ||
|
||||||
|
// f.Type == (short)AssetType.FavoriteFolder || f.Type == (short)AssetType.CurrentOutfitFolder)
|
||||||
|
// {
|
||||||
|
// // Don't remove these because the viewer refuses to exist without them
|
||||||
|
// // and immediately sends a request to create them again, which makes things
|
||||||
|
// // very confusing in the viewer.
|
||||||
|
// // Just change their names
|
||||||
|
// f.Name = "Home " + f.Name + " (Unavailable)";
|
||||||
|
// keep.Add(f);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// m_log.DebugFormat("[RRR]: Name={0}, Version={1}, Type={2}, PfolderID={3}", f.Name, f.Version, f.Type, f.ParentID);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// client.SendInventoryFolderDetails(client.AgentId, root.ID, new List<InventoryItemBase>(), keep, root.Version + 1, true, true);
|
||||||
|
//}
|
||||||
|
|
||||||
private void RemoveRootFolderContents(IClientAPI client)
|
private void RemoveRootFolderContents(IClientAPI client)
|
||||||
{
|
{
|
||||||
// TODO tell the viewer to remove the root folder's content
|
// TODO tell the viewer to remove the root folder's content
|
||||||
|
@ -401,25 +454,60 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
|
||||||
InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(client.AgentId);
|
InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(client.AgentId);
|
||||||
if (root != null)
|
if (root != null)
|
||||||
{
|
{
|
||||||
m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Removing root inventory for user {0}", client.AgentId);
|
m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Removing root inventory for user {0}", client.Name);
|
||||||
InventoryCollection content = m_Scenes[0].InventoryService.GetFolderContent(client.AgentId, root.ID);
|
InventoryCollection content = m_Scenes[0].InventoryService.GetFolderContent(client.AgentId, root.ID);
|
||||||
UUID[] ids = new UUID[content.Folders.Count];
|
List<UUID> fids = new List<UUID>();
|
||||||
int i = 0;
|
List<UUID> iids = new List<UUID>();
|
||||||
|
List<InventoryFolderBase> keep = new List<InventoryFolderBase>();
|
||||||
|
|
||||||
foreach (InventoryFolderBase f in content.Folders)
|
foreach (InventoryFolderBase f in content.Folders)
|
||||||
ids[i++] = f.ID;
|
{
|
||||||
inv.SendRemoveInventoryFolders(ids);
|
if (f.Name != "My Suitcase")
|
||||||
ids = new UUID[content.Items.Count];
|
{
|
||||||
i = 0;
|
f.Name = f.Name + " (Unavailable)";
|
||||||
|
keep.Add(f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// items directly under the root folder
|
||||||
foreach (InventoryItemBase it in content.Items)
|
foreach (InventoryItemBase it in content.Items)
|
||||||
ids[i++] = it.ID;
|
it.Name = it.Name + " (Unavailable)"; ;
|
||||||
inv.SendRemoveInventoryItems(ids);
|
|
||||||
|
// next, add the subfolders and items of the keep folders
|
||||||
|
//foreach (InventoryFolderBase f in keep)
|
||||||
|
//{
|
||||||
|
// InventoryCollection c = m_Scenes[0].InventoryService.GetFolderContent(client.AgentId, f.ID);
|
||||||
|
// foreach (InventoryFolderBase sf in c.Folders)
|
||||||
|
// {
|
||||||
|
// m_log.DebugFormat("[RRR]: Name={0}, Version={1}, Type={2}, PfolderID={3}", f.Name, f.Version, f.Type, f.ParentID);
|
||||||
|
// fids.Add(sf.ID);
|
||||||
|
// }
|
||||||
|
// foreach (InventoryItemBase it in c.Items)
|
||||||
|
// iids.Add(it.ID);
|
||||||
|
//}
|
||||||
|
|
||||||
|
//inv.SendRemoveInventoryFolders(fids.ToArray());
|
||||||
|
|
||||||
|
// Increase the version number
|
||||||
|
//root.Version += 1;
|
||||||
|
//m_Scenes[0].InventoryService.UpdateFolder(root);
|
||||||
|
//foreach (InventoryFolderBase f in keep)
|
||||||
|
//{
|
||||||
|
// f.Version += 1;
|
||||||
|
// m_Scenes[0].InventoryService.UpdateFolder(f);
|
||||||
|
//}
|
||||||
|
|
||||||
|
// Send the new names and versions
|
||||||
|
inv.SendBulkUpdateInventory(keep.ToArray(), content.Items.ToArray());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RestoreRootFolderContents(IClientAPI client)
|
private void RemoveRootFolderContents2(IClientAPI client)
|
||||||
{
|
{
|
||||||
|
// TODO tell the viewer to remove the root folder's content
|
||||||
if (client is IClientCore)
|
if (client is IClientCore)
|
||||||
{
|
{
|
||||||
IClientCore core = (IClientCore)client;
|
IClientCore core = (IClientCore)client;
|
||||||
|
@ -428,21 +516,207 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
|
||||||
if (core.TryGet<IClientInventory>(out inv))
|
if (core.TryGet<IClientInventory>(out inv))
|
||||||
{
|
{
|
||||||
InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(client.AgentId);
|
InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(client.AgentId);
|
||||||
client.SendBulkUpdateInventory(root);
|
if (root != null)
|
||||||
//if (root != null)
|
{
|
||||||
//{
|
m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Removing root inventory for user {0}", client.Name);
|
||||||
// m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Restoring root inventory for user {0}", client.AgentId);
|
InventoryCollection content = m_Scenes[0].InventoryService.GetFolderContent(client.AgentId, root.ID);
|
||||||
// InventoryCollection content = m_Scenes[0].InventoryService.GetFolderContent(client.AgentId, root.ID);
|
List<UUID> fids = new List<UUID>();
|
||||||
// m_log.DebugFormat("[XXX]: Folder name {0}, id {1}, parent {2}", root.Name, root.ID, root.ParentID);
|
List<UUID> iids = new List<UUID>();
|
||||||
// foreach (InventoryItemBase i in content.Items)
|
List<InventoryFolderBase> keep = new List<InventoryFolderBase>();
|
||||||
// m_log.DebugFormat("[XXX]: Name={0}, folderID={1}", i.Name, i.Folder);
|
|
||||||
|
|
||||||
// inv.SendBulkUpdateInventory(content.Folders.ToArray(), content.Items.ToArray());
|
foreach (InventoryFolderBase f in content.Folders)
|
||||||
|
{
|
||||||
|
if (f.Type == (short)AssetType.TrashFolder || f.Type == (short)AssetType.Landmark ||
|
||||||
|
f.Type == (short)AssetType.FavoriteFolder || f.Type == (short)AssetType.CurrentOutfitFolder)
|
||||||
|
{
|
||||||
|
// Don't remove these because the viewer refuses to exist without them
|
||||||
|
// and immediately sends a request to create them again, which makes things
|
||||||
|
// very confusing in the viewer.
|
||||||
|
// Just change their names
|
||||||
|
f.Name = "Home " + f.Name + " (Unavailable)";
|
||||||
|
keep.Add(f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[RRR]: Name={0}, Version={1}, Type={2}, PfolderID={3}", f.Name, f.Version, f.Type, f.ParentID);
|
||||||
|
fids.Add(f.ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (InventoryItemBase it in content.Items)
|
||||||
|
iids.Add(it.ID);
|
||||||
|
|
||||||
|
// next, add the subfolders and items of the keep folders
|
||||||
|
foreach (InventoryFolderBase f in keep)
|
||||||
|
{
|
||||||
|
InventoryCollection c = m_Scenes[0].InventoryService.GetFolderContent(client.AgentId, f.ID);
|
||||||
|
foreach (InventoryFolderBase sf in c.Folders)
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[RRR]: Name={0}, Version={1}, Type={2}, PfolderID={3}", f.Name, f.Version, f.Type, f.ParentID);
|
||||||
|
fids.Add(sf.ID);
|
||||||
|
}
|
||||||
|
foreach (InventoryItemBase it in c.Items)
|
||||||
|
iids.Add(it.ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
inv.SendRemoveInventoryFolders(fids.ToArray());
|
||||||
|
inv.SendRemoveInventoryItems(iids.ToArray());
|
||||||
|
|
||||||
|
// Increase the version number
|
||||||
|
root.Version += 1;
|
||||||
|
m_Scenes[0].InventoryService.UpdateFolder(root);
|
||||||
|
//foreach (InventoryFolderBase f in keep)
|
||||||
|
//{
|
||||||
|
// f.Version += 1;
|
||||||
|
// m_Scenes[0].InventoryService.UpdateFolder(f);
|
||||||
|
//}
|
||||||
|
|
||||||
|
// Send the new names and versions
|
||||||
|
inv.SendBulkUpdateInventory(keep.ToArray(), new InventoryItemBase[0]);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RemoveSuitcaseFolderContents(IClientAPI client)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
|
||||||
|
//// TODO tell the viewer to remove the suitcase folder's content
|
||||||
|
//if (client is IClientCore)
|
||||||
|
//{
|
||||||
|
// IClientCore core = (IClientCore)client;
|
||||||
|
// IClientInventory inv;
|
||||||
|
|
||||||
|
// if (core.TryGet<IClientInventory>(out inv))
|
||||||
|
// {
|
||||||
|
// InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(client.AgentId);
|
||||||
|
// if (root != null)
|
||||||
|
// {
|
||||||
|
// m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Removing suitcase inventory for user {0}", client.Name);
|
||||||
|
// InventoryCollection content = m_Scenes[0].InventoryService.GetFolderContent(client.AgentId, root.ID);
|
||||||
|
// List<UUID> fids = new List<UUID>();
|
||||||
|
// List<UUID> iids = new List<UUID>();
|
||||||
|
|
||||||
|
// if (content.Folders.Count == 0)
|
||||||
|
// m_log.WarnFormat("[HG ENTITY TRANSFER MODULE]: no subfolders???");
|
||||||
|
// foreach (InventoryFolderBase f in content.Folders)
|
||||||
|
// {
|
||||||
|
// m_log.DebugFormat("[RRR]: Name={0}, Version={1}, Type={2}, PfolderID={3}", f.Name, f.Version, f.Type, f.ParentID);
|
||||||
|
// fids.Add(f.ID);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// foreach (InventoryItemBase it in content.Items)
|
||||||
|
// iids.Add(it.ID);
|
||||||
|
|
||||||
|
// inv.SendRemoveInventoryFolders(fids.ToArray());
|
||||||
|
// inv.SendRemoveInventoryItems(iids.ToArray());
|
||||||
|
|
||||||
|
// // Increase the version number
|
||||||
|
// root.Version += 1;
|
||||||
|
// m_Scenes[0].InventoryService.UpdateFolder(root);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void RestoreRootFolderContents(IClientAPI client)
|
||||||
|
{
|
||||||
|
// This works!
|
||||||
|
//InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(client.AgentId);
|
||||||
|
//client.SendBulkUpdateInventory(root);
|
||||||
|
|
||||||
|
// SORTA KINDA some items are missing...
|
||||||
|
//InventoryCollection userInventory = m_Scenes[0].InventoryService.GetUserInventory(client.AgentId);
|
||||||
|
//InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(client.AgentId);
|
||||||
|
//client.SendBulkUpdateInventory(root);
|
||||||
|
|
||||||
|
m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Restoring root folder");
|
||||||
|
if (client is IClientCore)
|
||||||
|
{
|
||||||
|
IClientCore core = (IClientCore)client;
|
||||||
|
IClientInventory inv;
|
||||||
|
|
||||||
|
if (core.TryGet<IClientInventory>(out inv))
|
||||||
|
{
|
||||||
|
InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(client.AgentId);
|
||||||
|
InventoryCollection content = m_Scenes[0].InventoryService.GetFolderContent(client.AgentId, root.ID);
|
||||||
|
|
||||||
|
inv.SendBulkUpdateInventory(content.Folders.ToArray(), content.Items.ToArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ATTEMPT # 3 -- STILL DOESN'T WORK!
|
||||||
|
//if (client is IClientCore)
|
||||||
|
//{
|
||||||
|
// IClientCore core = (IClientCore)client;
|
||||||
|
// IClientInventory inv;
|
||||||
|
|
||||||
|
// if (core.TryGet<IClientInventory>(out inv))
|
||||||
|
// {
|
||||||
|
// InventoryCollection userInventory = m_Scenes[0].InventoryService.GetUserInventory(client.AgentId);
|
||||||
|
// if (userInventory != null)
|
||||||
|
// {
|
||||||
|
// m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Restoring root inventory for user {0}", client.AgentId);
|
||||||
|
// foreach (InventoryFolderBase f in userInventory.Folders)
|
||||||
|
// m_log.DebugFormat("[AAA]: FOLDER {0} {1} {2} {3} {4}", f.Name, f.Type, f.Version, f.ID, f.ParentID);
|
||||||
|
// foreach (InventoryItemBase f in userInventory.Items)
|
||||||
|
// m_log.DebugFormat("[AAA]: ITEM {0} {1} {2}", f.Name, f.ID, f.Folder);
|
||||||
|
// inv.SendBulkUpdateInventory(userInventory.Folders.ToArray(), userInventory.Items.ToArray());
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// m_log.WarnFormat("[HG ENTITY TRANSFER MODULE]: Unable to retrieve inventory for user {0}", client.AgentId);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
// ATTEMPT #2 -- BETTER THAN 1, BUT STILL DOES NOT WORK WELL
|
||||||
|
//if (client is IClientCore)
|
||||||
|
//{
|
||||||
|
// IClientCore core = (IClientCore)client;
|
||||||
|
// IClientInventory inv;
|
||||||
|
|
||||||
|
// if (core.TryGet<IClientInventory>(out inv))
|
||||||
|
// {
|
||||||
|
// List<InventoryFolderBase> skel = m_Scenes[0].InventoryService.GetInventorySkeleton(client.AgentId);
|
||||||
|
// if (skel != null)
|
||||||
|
// {
|
||||||
|
// m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Restoring root inventory for user {0}", client.AgentId);
|
||||||
|
// foreach (InventoryFolderBase f in skel)
|
||||||
|
// m_log.DebugFormat("[AAA]: {0} {1} {2} {3} {4}", f.Name, f.Type, f.Version, f.ID, f.ParentID);
|
||||||
|
// inv.SendBulkUpdateInventory(skel.ToArray(), new InventoryItemBase[0]);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// m_log.WarnFormat("[HG ENTITY TRANSFER MODULE]: Unable to retrieve skeleton for user {0}", client.AgentId);
|
||||||
|
|
||||||
|
// ATTEMPT #1 -- DOES NOT WORK
|
||||||
|
//InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(client.AgentId);
|
||||||
|
//if (root != null)
|
||||||
|
//{
|
||||||
|
//InventoryCollection content = m_Scenes[0].InventoryService.GetFolderContent(client.AgentId, root.ID);
|
||||||
|
//InventoryFolderBase[] folders = new InventoryFolderBase[content.Folders.Count + 1];
|
||||||
|
//m_log.DebugFormat("[AAA]: Folder name {0}, id {1}, version {2}, parent {3}", root.Name, root.ID, root.Version, root.ParentID);
|
||||||
|
//folders[0] = root;
|
||||||
|
//for (int count = 1; count < content.Folders.Count + 1; count++)
|
||||||
|
//{
|
||||||
|
// folders[count] = content.Folders[count - 1];
|
||||||
|
// m_log.DebugFormat("[AAA]: Name={0}, Id={1}, Version={2}, type={3}, folderID={4}",
|
||||||
|
// folders[count].Name, folders[count].ID, folders[count].Version, folders[count].Type, folders[count].ParentID);
|
||||||
|
//}
|
||||||
|
//foreach (InventoryItemBase i in content.Items)
|
||||||
|
// m_log.DebugFormat("[AAA]: Name={0}, folderID={1}", i.Name, i.Folder);
|
||||||
|
//inv.SendBulkUpdateInventory(/*content.Folders.ToArray()*/ folders, content.Items.ToArray());
|
||||||
|
//}
|
||||||
|
//}
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RestoreSuitcaseFolderContents(IClientAPI client)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private GridRegion MakeRegion(AgentCircuitData aCircuit)
|
private GridRegion MakeRegion(AgentCircuitData aCircuit)
|
||||||
{
|
{
|
||||||
GridRegion region = new GridRegion();
|
GridRegion region = new GridRegion();
|
||||||
|
|
|
@ -48,7 +48,7 @@ namespace OpenSim.Services.HypergridService
|
||||||
/// and it responds to GetRootFolder requests with the ID of the
|
/// and it responds to GetRootFolder requests with the ID of the
|
||||||
/// Suitcase folder, not the actual "My Inventory" folder.
|
/// Suitcase folder, not the actual "My Inventory" folder.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class HGSuitcaseInventoryService : XInventoryService, IInventoryService
|
public class HGSuitcaseInventoryService1 : XInventoryService, IInventoryService
|
||||||
{
|
{
|
||||||
private static readonly ILog m_log =
|
private static readonly ILog m_log =
|
||||||
LogManager.GetLogger(
|
LogManager.GetLogger(
|
||||||
|
@ -61,7 +61,7 @@ namespace OpenSim.Services.HypergridService
|
||||||
|
|
||||||
private ExpiringCache<UUID, List<XInventoryFolder>> m_SuitcaseTrees = new ExpiringCache<UUID,List<XInventoryFolder>>();
|
private ExpiringCache<UUID, List<XInventoryFolder>> m_SuitcaseTrees = new ExpiringCache<UUID,List<XInventoryFolder>>();
|
||||||
|
|
||||||
public HGSuitcaseInventoryService(IConfigSource config, string configName)
|
public HGSuitcaseInventoryService1(IConfigSource config, string configName)
|
||||||
: base(config, configName)
|
: base(config, configName)
|
||||||
{
|
{
|
||||||
m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Starting with config name {0}", configName);
|
m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Starting with config name {0}", configName);
|
||||||
|
@ -104,11 +104,79 @@ namespace OpenSim.Services.HypergridService
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override List<InventoryFolderBase> GetInventorySkeleton(UUID principalID)
|
public override List<InventoryFolderBase> GetInventorySkeleton(UUID principalID)
|
||||||
{
|
{
|
||||||
// NOGO for this inventory service
|
XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
|
||||||
return new List<InventoryFolderBase>();
|
XInventoryFolder root = GetRootXFolder(principalID);
|
||||||
|
|
||||||
|
List<XInventoryFolder> tree = GetFolderTree(suitcase.folderID);
|
||||||
|
if (tree == null || (tree != null && tree.Count == 0))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
|
||||||
|
foreach (XInventoryFolder x in tree)
|
||||||
|
{
|
||||||
|
if (x.parentFolderID == suitcase.folderID)
|
||||||
|
x.parentFolderID = root.folderID;
|
||||||
|
|
||||||
|
folders.Add(ConvertToOpenSim(x));
|
||||||
|
}
|
||||||
|
|
||||||
|
SetAsRootFolder(suitcase, root);
|
||||||
|
folders.Add(ConvertToOpenSim(suitcase));
|
||||||
|
|
||||||
|
return folders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override InventoryCollection GetUserInventory(UUID userID)
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Get Suitcase inventory for user {0}", userID);
|
||||||
|
InventoryCollection userInventory = new InventoryCollection();
|
||||||
|
userInventory.UserID = userID;
|
||||||
|
userInventory.Folders = new List<InventoryFolderBase>();
|
||||||
|
userInventory.Items = new List<InventoryItemBase>();
|
||||||
|
|
||||||
|
XInventoryFolder suitcase = GetSuitcaseXFolder(userID);
|
||||||
|
XInventoryFolder root = GetRootXFolder(userID);
|
||||||
|
|
||||||
|
List<XInventoryFolder> tree = GetFolderTree(suitcase.folderID);
|
||||||
|
if (tree == null || (tree != null && tree.Count == 0))
|
||||||
|
{
|
||||||
|
SetAsRootFolder(suitcase, root);
|
||||||
|
userInventory.Folders.Add(ConvertToOpenSim(suitcase));
|
||||||
|
return userInventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<InventoryItemBase> items;
|
||||||
|
foreach (XInventoryFolder f in tree)
|
||||||
|
{
|
||||||
|
// Add the items of this subfolder
|
||||||
|
items = GetFolderItems(userID, f.folderID);
|
||||||
|
if (items != null && items.Count > 0)
|
||||||
|
{
|
||||||
|
userInventory.Items.AddRange(items);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the folder itself
|
||||||
|
if (f.parentFolderID == suitcase.folderID)
|
||||||
|
f.parentFolderID = root.folderID;
|
||||||
|
userInventory.Folders.Add(ConvertToOpenSim(f));
|
||||||
|
}
|
||||||
|
|
||||||
|
items = GetFolderItems(userID, suitcase.folderID);
|
||||||
|
if (items != null && items.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (InventoryItemBase i in items)
|
||||||
|
i.Folder = root.folderID;
|
||||||
|
userInventory.Items.AddRange(items);
|
||||||
|
}
|
||||||
|
|
||||||
|
SetAsRootFolder(suitcase, root);
|
||||||
|
userInventory.Folders.Add(ConvertToOpenSim(suitcase));
|
||||||
|
|
||||||
|
m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetUserInventory for user {0} returning {1} folders and {2} items",
|
||||||
|
userID, userInventory.Folders.Count, userInventory.Items.Count);
|
||||||
|
return userInventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override InventoryFolderBase GetRootFolder(UUID principalID)
|
public override InventoryFolderBase GetRootFolder(UUID principalID)
|
||||||
|
@ -131,23 +199,87 @@ namespace OpenSim.Services.HypergridService
|
||||||
{
|
{
|
||||||
m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: User {0} does not have a Suitcase folder. Creating it...", principalID);
|
m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: User {0} does not have a Suitcase folder. Creating it...", principalID);
|
||||||
// make one, and let's add it to the user's inventory as a direct child of the root folder
|
// make one, and let's add it to the user's inventory as a direct child of the root folder
|
||||||
|
// In the DB we tag it as type 100, but we use -1 (Unknown) outside
|
||||||
suitcase = CreateFolder(principalID, root.folderID, 100, "My Suitcase");
|
suitcase = CreateFolder(principalID, root.folderID, 100, "My Suitcase");
|
||||||
if (suitcase == null)
|
if (suitcase == null)
|
||||||
m_log.ErrorFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to create suitcase folder");
|
m_log.ErrorFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to create suitcase folder");
|
||||||
|
suitcase.version = root.version;
|
||||||
|
m_Database.StoreFolder(suitcase);
|
||||||
|
|
||||||
|
// Create System folders
|
||||||
|
CreateSystemFolders(principalID, suitcase.folderID);
|
||||||
|
}
|
||||||
|
else if (suitcase.version < root.version)
|
||||||
|
{
|
||||||
|
suitcase.version = root.version;
|
||||||
m_Database.StoreFolder(suitcase);
|
m_Database.StoreFolder(suitcase);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now let's change the folder ID to match that of the real root folder
|
// Now let's change the folder ID to match that of the real root folder
|
||||||
SetAsRootFolder(suitcase, root.folderID);
|
SetAsRootFolder(suitcase, root);
|
||||||
|
|
||||||
return ConvertToOpenSim(suitcase);
|
return ConvertToOpenSim(suitcase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void CreateSystemFolders(UUID principalID, UUID rootID)
|
||||||
|
{
|
||||||
|
m_log.Debug("[HG SUITCASE INVENTORY SERVICE]: Creating System folders under Suitcase...");
|
||||||
|
XInventoryFolder[] sysFolders = GetSystemFolders(principalID, rootID);
|
||||||
|
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Animation) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.Animation, "Animations");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Bodypart) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.Bodypart, "Body Parts");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.CallingCard) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.CallingCard, "Calling Cards");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Clothing) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.Clothing, "Clothing");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Gesture) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.Gesture, "Gestures");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Landmark) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.Landmark, "Landmarks");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.LostAndFoundFolder) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.LostAndFoundFolder, "Lost And Found");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Notecard) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.Notecard, "Notecards");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Object) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.Object, "Objects");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.SnapshotFolder) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.SnapshotFolder, "Photo Album");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.LSLText) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.LSLText, "Scripts");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Sound) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.Sound, "Sounds");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Texture) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.Texture, "Textures");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.TrashFolder) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.TrashFolder, "Trash");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.FavoriteFolder) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.FavoriteFolder, "Favorites");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.CurrentOutfitFolder) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.CurrentOutfitFolder, "Current Outfit");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public override InventoryFolderBase GetFolderForType(UUID principalID, AssetType type)
|
public override InventoryFolderBase GetFolderForType(UUID principalID, AssetType type)
|
||||||
{
|
{
|
||||||
//m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type);
|
//m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type);
|
||||||
return GetRootFolder(principalID);
|
XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
|
||||||
|
XInventoryFolder[] folders = m_Database.GetFolders(
|
||||||
|
new string[] { "agentID", "type", "parentFolderID"},
|
||||||
|
new string[] { principalID.ToString(), ((int)type).ToString(), suitcase.folderID.ToString() });
|
||||||
|
|
||||||
|
if (folders.Length == 0)
|
||||||
|
{
|
||||||
|
m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Found no folder for type {0} for user {1}", type, principalID);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_log.DebugFormat(
|
||||||
|
"[HG SUITCASE INVENTORY SERVICE]: Found folder {0} {1} for type {2} for user {3}",
|
||||||
|
folders[0].folderName, folders[0].folderID, type, principalID);
|
||||||
|
|
||||||
|
return ConvertToOpenSim(folders[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
|
public override InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
|
||||||
|
@ -199,6 +331,7 @@ namespace OpenSim.Services.HypergridService
|
||||||
|
|
||||||
public override bool AddFolder(InventoryFolderBase folder)
|
public override bool AddFolder(InventoryFolderBase folder)
|
||||||
{
|
{
|
||||||
|
m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: AddFolder {0} {1}", folder.Name, folder.ParentID);
|
||||||
// Let's do a bit of sanity checking, more than the base service does
|
// Let's do a bit of sanity checking, more than the base service does
|
||||||
// make sure the given folder's parent folder exists under the suitcase tree of this user
|
// make sure the given folder's parent folder exists under the suitcase tree of this user
|
||||||
XInventoryFolder root = GetRootXFolder(folder.Owner);
|
XInventoryFolder root = GetRootXFolder(folder.Owner);
|
||||||
|
@ -219,14 +352,37 @@ namespace OpenSim.Services.HypergridService
|
||||||
return base.AddFolder(folder);
|
return base.AddFolder(folder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool UpdateFolder(InventoryFolderBase folder)
|
public override bool UpdateFolder(InventoryFolderBase folder)
|
||||||
{
|
{
|
||||||
XInventoryFolder root = GetRootXFolder(folder.Owner);
|
XInventoryFolder root = GetRootXFolder(folder.Owner);
|
||||||
XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner);
|
XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner);
|
||||||
|
|
||||||
|
m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Update folder {0}, version {1}", folder.ID, folder.Version);
|
||||||
if (!IsWithinSuitcaseTree(folder.ID, root, suitcase))
|
if (!IsWithinSuitcaseTree(folder.ID, root, suitcase))
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: folder {0} not within Suitcase tree", folder.Name);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (folder.ID == root.folderID)
|
||||||
|
{
|
||||||
|
if (folder.Version <= suitcase.version)
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: version {0} <= suitcase version {1}. Ignoring.", folder.Version, suitcase.version);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (folder.Version <= root.version)
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: version {0} <= root version {1}. Ignoring.", folder.Version, suitcase.version);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
suitcase.version = root.version = folder.Version;
|
||||||
|
m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Storing {0} type {1} version {2}", suitcase.folderName, suitcase.type, suitcase.version);
|
||||||
|
m_Database.StoreFolder(suitcase);
|
||||||
|
m_Database.StoreFolder(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
// For all others
|
||||||
return base.UpdateFolder(folder);
|
return base.UpdateFolder(folder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,9 +457,6 @@ namespace OpenSim.Services.HypergridService
|
||||||
XInventoryFolder root = GetRootXFolder(items[0].Owner);
|
XInventoryFolder root = GetRootXFolder(items[0].Owner);
|
||||||
XInventoryFolder suitcase = GetSuitcaseXFolder(items[0].Owner);
|
XInventoryFolder suitcase = GetSuitcaseXFolder(items[0].Owner);
|
||||||
|
|
||||||
if (!IsWithinSuitcaseTree(items[0].Folder, root, suitcase))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
foreach (InventoryItemBase it in items)
|
foreach (InventoryItemBase it in items)
|
||||||
if (it.Folder == root.folderID)
|
if (it.Folder == root.folderID)
|
||||||
{
|
{
|
||||||
|
@ -312,6 +465,9 @@ namespace OpenSim.Services.HypergridService
|
||||||
it.Folder = suitcase.folderID;
|
it.Folder = suitcase.folderID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!IsWithinSuitcaseTree(items[0].Folder, root, suitcase))
|
||||||
|
return false;
|
||||||
|
|
||||||
return base.MoveItems(principalID, items);
|
return base.MoveItems(principalID, items);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -322,44 +478,57 @@ namespace OpenSim.Services.HypergridService
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override InventoryItemBase GetItem(InventoryItemBase item)
|
public new InventoryItemBase GetItem(InventoryItemBase item)
|
||||||
{
|
{
|
||||||
InventoryItemBase it = base.GetItem(item);
|
InventoryItemBase it = base.GetItem(item);
|
||||||
|
if (it == null)
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to retrieve item {0} ({1}) in folder {2}",
|
||||||
|
item.Name, item.ID, item.Folder);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
XInventoryFolder root = GetRootXFolder(it.Owner);
|
XInventoryFolder root = GetRootXFolder(it.Owner);
|
||||||
XInventoryFolder suitcase = GetSuitcaseXFolder(it.Owner);
|
XInventoryFolder suitcase = GetSuitcaseXFolder(it.Owner);
|
||||||
|
if (root == null || suitcase == null)
|
||||||
if (it != null)
|
|
||||||
{
|
{
|
||||||
if (!IsWithinSuitcaseTree(it.Folder, root, suitcase))
|
m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Root or Suitcase are null for user {0}",
|
||||||
|
it.Owner);
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (it.Folder == suitcase.folderID)
|
if (it.Folder == suitcase.folderID)
|
||||||
it.Folder = root.folderID;
|
it.Folder = root.folderID;
|
||||||
|
|
||||||
|
if (!IsWithinSuitcaseTree(it.Folder, root, suitcase))
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Item {0} (folder {1}) is not within Suitcase",
|
||||||
|
it.Name, it.Folder);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// UserAccount user = m_Cache.GetUser(it.CreatorId);
|
// UserAccount user = m_Cache.GetUser(it.CreatorId);
|
||||||
|
|
||||||
// // Adjust the creator data
|
// // Adjust the creator data
|
||||||
// if (user != null && it != null && (it.CreatorData == null || it.CreatorData == string.Empty))
|
// if (user != null && it != null && (it.CreatorData == null || it.CreatorData == string.Empty))
|
||||||
// it.CreatorData = m_HomeURL + ";" + user.FirstName + " " + user.LastName;
|
// it.CreatorData = m_HomeURL + ";" + user.FirstName + " " + user.LastName;
|
||||||
//}
|
//}
|
||||||
}
|
|
||||||
|
|
||||||
return it;
|
return it;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override InventoryFolderBase GetFolder(InventoryFolderBase folder)
|
public new InventoryFolderBase GetFolder(InventoryFolderBase folder)
|
||||||
{
|
{
|
||||||
InventoryFolderBase f = base.GetFolder(folder);
|
InventoryFolderBase f = base.GetFolder(folder);
|
||||||
XInventoryFolder root = GetRootXFolder(f.Owner);
|
|
||||||
XInventoryFolder suitcase = GetSuitcaseXFolder(f.Owner);
|
|
||||||
|
|
||||||
if (f != null)
|
if (f != null)
|
||||||
{
|
{
|
||||||
if (!IsWithinSuitcaseTree(f.ID, root, suitcase))
|
XInventoryFolder root = GetRootXFolder(f.Owner);
|
||||||
return null;
|
XInventoryFolder suitcase = GetSuitcaseXFolder(f.Owner);
|
||||||
|
|
||||||
if (f.ParentID == suitcase.folderID)
|
if (f.ParentID == suitcase.folderID)
|
||||||
f.ParentID = root.folderID;
|
f.ParentID = root.folderID;
|
||||||
|
|
||||||
|
if (!IsWithinSuitcaseTree(f.ID, root, suitcase))
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return f;
|
return f;
|
||||||
|
@ -409,20 +578,22 @@ namespace OpenSim.Services.HypergridService
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetAsRootFolder(XInventoryFolder suitcase, UUID rootID)
|
private void SetAsRootFolder(XInventoryFolder suitcase, XInventoryFolder root)
|
||||||
{
|
{
|
||||||
suitcase.folderID = rootID;
|
suitcase.version = root.version;
|
||||||
|
suitcase.folderID = root.folderID;
|
||||||
suitcase.parentFolderID = UUID.Zero;
|
suitcase.parentFolderID = UUID.Zero;
|
||||||
|
suitcase.type = (short)AssetType.Folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<XInventoryFolder> GetFolderTree(UUID root)
|
private List<XInventoryFolder> GetFolderTree(UUID folder)
|
||||||
{
|
{
|
||||||
List<XInventoryFolder> t = null;
|
List<XInventoryFolder> t = null;
|
||||||
if (m_SuitcaseTrees.TryGetValue(root, out t))
|
if (m_SuitcaseTrees.TryGetValue(folder, out t))
|
||||||
return t;
|
return t;
|
||||||
|
|
||||||
t = GetFolderTreeRecursive(root);
|
t = GetFolderTreeRecursive(folder);
|
||||||
m_SuitcaseTrees.AddOrUpdate(root, t, 120);
|
m_SuitcaseTrees.AddOrUpdate(folder, t, 120);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,6 +618,13 @@ namespace OpenSim.Services.HypergridService
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return true if the folderID is a subfolder of the Suitcase or the root folder ID itself
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderID"></param>
|
||||||
|
/// <param name="root"></param>
|
||||||
|
/// <param name="suitcase"></param>
|
||||||
|
/// <returns></returns>
|
||||||
private bool IsWithinSuitcaseTree(UUID folderID, XInventoryFolder root, XInventoryFolder suitcase)
|
private bool IsWithinSuitcaseTree(UUID folderID, XInventoryFolder root, XInventoryFolder suitcase)
|
||||||
{
|
{
|
||||||
List<XInventoryFolder> tree = new List<XInventoryFolder>();
|
List<XInventoryFolder> tree = new List<XInventoryFolder>();
|
||||||
|
@ -463,4 +641,502 @@ namespace OpenSim.Services.HypergridService
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class HGSuitcaseInventoryService : XInventoryService, IInventoryService
|
||||||
|
{
|
||||||
|
private static readonly ILog m_log =
|
||||||
|
LogManager.GetLogger(
|
||||||
|
MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
|
private string m_HomeURL;
|
||||||
|
private IUserAccountService m_UserAccountService;
|
||||||
|
|
||||||
|
private UserAccountCache m_Cache;
|
||||||
|
|
||||||
|
private ExpiringCache<UUID, List<XInventoryFolder>> m_SuitcaseTrees = new ExpiringCache<UUID, List<XInventoryFolder>>();
|
||||||
|
|
||||||
|
public HGSuitcaseInventoryService(IConfigSource config, string configName)
|
||||||
|
: base(config, configName)
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Starting with config name {0}", configName);
|
||||||
|
if (configName != string.Empty)
|
||||||
|
m_ConfigName = configName;
|
||||||
|
|
||||||
|
if (m_Database == null)
|
||||||
|
m_log.WarnFormat("[XXX]: m_Database is null!");
|
||||||
|
|
||||||
|
//
|
||||||
|
// Try reading the [InventoryService] section, if it exists
|
||||||
|
//
|
||||||
|
IConfig invConfig = config.Configs[m_ConfigName];
|
||||||
|
if (invConfig != null)
|
||||||
|
{
|
||||||
|
// realm = authConfig.GetString("Realm", realm);
|
||||||
|
string userAccountsDll = invConfig.GetString("UserAccountsService", string.Empty);
|
||||||
|
if (userAccountsDll == string.Empty)
|
||||||
|
throw new Exception("Please specify UserAccountsService in HGInventoryService configuration");
|
||||||
|
|
||||||
|
Object[] args = new Object[] { config };
|
||||||
|
m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userAccountsDll, args);
|
||||||
|
if (m_UserAccountService == null)
|
||||||
|
throw new Exception(String.Format("Unable to create UserAccountService from {0}", userAccountsDll));
|
||||||
|
|
||||||
|
// legacy configuration [obsolete]
|
||||||
|
m_HomeURL = invConfig.GetString("ProfileServerURI", string.Empty);
|
||||||
|
// Preferred
|
||||||
|
m_HomeURL = invConfig.GetString("HomeURI", m_HomeURL);
|
||||||
|
|
||||||
|
m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_log.Debug("[HG SUITCASE INVENTORY SERVICE]: Starting...");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CreateUserInventory(UUID principalID)
|
||||||
|
{
|
||||||
|
// NOGO
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override List<InventoryFolderBase> GetInventorySkeleton(UUID principalID)
|
||||||
|
{
|
||||||
|
XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
|
||||||
|
XInventoryFolder root = GetRootXFolder(principalID);
|
||||||
|
|
||||||
|
List<XInventoryFolder> tree = GetFolderTree(suitcase.folderID);
|
||||||
|
if (tree == null || (tree != null && tree.Count == 0))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
|
||||||
|
foreach (XInventoryFolder x in tree)
|
||||||
|
{
|
||||||
|
folders.Add(ConvertToOpenSim(x));
|
||||||
|
}
|
||||||
|
|
||||||
|
SetAsRootFolder(suitcase, root);
|
||||||
|
folders.Add(ConvertToOpenSim(suitcase));
|
||||||
|
|
||||||
|
return folders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override InventoryCollection GetUserInventory(UUID userID)
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Get Suitcase inventory for user {0}", userID);
|
||||||
|
InventoryCollection userInventory = new InventoryCollection();
|
||||||
|
userInventory.UserID = userID;
|
||||||
|
userInventory.Folders = new List<InventoryFolderBase>();
|
||||||
|
userInventory.Items = new List<InventoryItemBase>();
|
||||||
|
|
||||||
|
XInventoryFolder suitcase = GetSuitcaseXFolder(userID);
|
||||||
|
XInventoryFolder root = GetRootXFolder(userID);
|
||||||
|
|
||||||
|
List<XInventoryFolder> tree = GetFolderTree(suitcase.folderID);
|
||||||
|
if (tree == null || (tree != null && tree.Count == 0))
|
||||||
|
{
|
||||||
|
SetAsRootFolder(suitcase, root);
|
||||||
|
userInventory.Folders.Add(ConvertToOpenSim(suitcase));
|
||||||
|
return userInventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<InventoryItemBase> items;
|
||||||
|
foreach (XInventoryFolder f in tree)
|
||||||
|
{
|
||||||
|
// Add the items of this subfolder
|
||||||
|
items = GetFolderItems(userID, f.folderID);
|
||||||
|
if (items != null && items.Count > 0)
|
||||||
|
{
|
||||||
|
userInventory.Items.AddRange(items);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the folder itself
|
||||||
|
userInventory.Folders.Add(ConvertToOpenSim(f));
|
||||||
|
}
|
||||||
|
|
||||||
|
items = GetFolderItems(userID, suitcase.folderID);
|
||||||
|
if (items != null && items.Count > 0)
|
||||||
|
{
|
||||||
|
userInventory.Items.AddRange(items);
|
||||||
|
}
|
||||||
|
|
||||||
|
SetAsRootFolder(suitcase, root);
|
||||||
|
userInventory.Folders.Add(ConvertToOpenSim(suitcase));
|
||||||
|
|
||||||
|
m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetUserInventory for user {0} returning {1} folders and {2} items",
|
||||||
|
userID, userInventory.Folders.Count, userInventory.Items.Count);
|
||||||
|
return userInventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override InventoryFolderBase GetRootFolder(UUID principalID)
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetRootFolder for {0}", principalID);
|
||||||
|
if (m_Database == null)
|
||||||
|
m_log.ErrorFormat("[XXX]: m_Database is NULL!");
|
||||||
|
|
||||||
|
// Let's find out the local root folder
|
||||||
|
XInventoryFolder root = GetRootXFolder(principalID); ;
|
||||||
|
if (root == null)
|
||||||
|
{
|
||||||
|
m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to retrieve local root folder for user {0}", principalID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Warp! Root folder for travelers is the suitcase folder
|
||||||
|
XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
|
||||||
|
|
||||||
|
if (suitcase == null)
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: User {0} does not have a Suitcase folder. Creating it...", principalID);
|
||||||
|
// make one, and let's add it to the user's inventory as a direct child of the root folder
|
||||||
|
// In the DB we tag it as type 100, but we use -1 (Unknown) outside
|
||||||
|
suitcase = CreateFolder(principalID, root.folderID, 100, "My Suitcase");
|
||||||
|
if (suitcase == null)
|
||||||
|
m_log.ErrorFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to create suitcase folder");
|
||||||
|
m_Database.StoreFolder(suitcase);
|
||||||
|
|
||||||
|
// Create System folders
|
||||||
|
CreateSystemFolders(principalID, suitcase.folderID);
|
||||||
|
}
|
||||||
|
|
||||||
|
SetAsRootFolder(suitcase, root);
|
||||||
|
|
||||||
|
return ConvertToOpenSim(suitcase);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void CreateSystemFolders(UUID principalID, UUID rootID)
|
||||||
|
{
|
||||||
|
m_log.Debug("[HG SUITCASE INVENTORY SERVICE]: Creating System folders under Suitcase...");
|
||||||
|
XInventoryFolder[] sysFolders = GetSystemFolders(principalID, rootID);
|
||||||
|
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Animation) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.Animation, "Animations");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Bodypart) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.Bodypart, "Body Parts");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.CallingCard) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.CallingCard, "Calling Cards");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Clothing) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.Clothing, "Clothing");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Gesture) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.Gesture, "Gestures");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Landmark) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.Landmark, "Landmarks");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.LostAndFoundFolder) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.LostAndFoundFolder, "Lost And Found");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Notecard) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.Notecard, "Notecards");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Object) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.Object, "Objects");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.SnapshotFolder) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.SnapshotFolder, "Photo Album");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.LSLText) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.LSLText, "Scripts");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Sound) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.Sound, "Sounds");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Texture) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.Texture, "Textures");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.TrashFolder) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.TrashFolder, "Trash");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.FavoriteFolder) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.FavoriteFolder, "Favorites");
|
||||||
|
if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.CurrentOutfitFolder) return true; return false; }))
|
||||||
|
CreateFolder(principalID, rootID, (int)AssetType.CurrentOutfitFolder, "Current Outfit");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override InventoryFolderBase GetFolderForType(UUID principalID, AssetType type)
|
||||||
|
{
|
||||||
|
//m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type);
|
||||||
|
XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
|
||||||
|
XInventoryFolder[] folders = m_Database.GetFolders(
|
||||||
|
new string[] { "agentID", "type", "parentFolderID" },
|
||||||
|
new string[] { principalID.ToString(), ((int)type).ToString(), suitcase.folderID.ToString() });
|
||||||
|
|
||||||
|
if (folders.Length == 0)
|
||||||
|
{
|
||||||
|
m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Found no folder for type {0} for user {1}", type, principalID);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_log.DebugFormat(
|
||||||
|
"[HG SUITCASE INVENTORY SERVICE]: Found folder {0} {1} for type {2} for user {3}",
|
||||||
|
folders[0].folderName, folders[0].folderID, type, principalID);
|
||||||
|
|
||||||
|
return ConvertToOpenSim(folders[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
|
||||||
|
{
|
||||||
|
InventoryCollection coll = null;
|
||||||
|
XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
|
||||||
|
|
||||||
|
if (!IsWithinSuitcaseTree(folderID, suitcase))
|
||||||
|
return new InventoryCollection();
|
||||||
|
|
||||||
|
coll = base.GetFolderContent(principalID, folderID);
|
||||||
|
|
||||||
|
if (coll == null)
|
||||||
|
{
|
||||||
|
m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Something wrong with user {0}'s suitcase folder", principalID);
|
||||||
|
coll = new InventoryCollection();
|
||||||
|
}
|
||||||
|
return coll;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID)
|
||||||
|
{
|
||||||
|
// Let's do a bit of sanity checking, more than the base service does
|
||||||
|
// make sure the given folder exists under the suitcase tree of this user
|
||||||
|
XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
|
||||||
|
|
||||||
|
if (!IsWithinSuitcaseTree(folderID, suitcase))
|
||||||
|
return new List<InventoryItemBase>();
|
||||||
|
|
||||||
|
return base.GetFolderItems(principalID, folderID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool AddFolder(InventoryFolderBase folder)
|
||||||
|
{
|
||||||
|
m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: AddFolder {0} {1}", folder.Name, folder.ParentID);
|
||||||
|
// Let's do a bit of sanity checking, more than the base service does
|
||||||
|
// make sure the given folder's parent folder exists under the suitcase tree of this user
|
||||||
|
XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner);
|
||||||
|
|
||||||
|
if (!IsWithinSuitcaseTree(folder.ParentID, suitcase))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// OK, it's legit
|
||||||
|
return base.AddFolder(folder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool UpdateFolder(InventoryFolderBase folder)
|
||||||
|
{
|
||||||
|
XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner);
|
||||||
|
|
||||||
|
m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Update folder {0}, version {1}", folder.ID, folder.Version);
|
||||||
|
if (!IsWithinSuitcaseTree(folder.ID, suitcase))
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: folder {0} not within Suitcase tree", folder.Name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For all others
|
||||||
|
return base.UpdateFolder(folder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool MoveFolder(InventoryFolderBase folder)
|
||||||
|
{
|
||||||
|
XInventoryFolder suitcase = GetSuitcaseXFolder(folder.Owner);
|
||||||
|
|
||||||
|
if (!IsWithinSuitcaseTree(folder.ID, suitcase) || !IsWithinSuitcaseTree(folder.ParentID, suitcase))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return base.MoveFolder(folder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool DeleteFolders(UUID principalID, List<UUID> folderIDs)
|
||||||
|
{
|
||||||
|
// NOGO
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool PurgeFolder(InventoryFolderBase folder)
|
||||||
|
{
|
||||||
|
// NOGO
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool AddItem(InventoryItemBase item)
|
||||||
|
{
|
||||||
|
// Let's do a bit of sanity checking, more than the base service does
|
||||||
|
// make sure the given folder's parent folder exists under the suitcase tree of this user
|
||||||
|
XInventoryFolder suitcase = GetSuitcaseXFolder(item.Owner);
|
||||||
|
|
||||||
|
if (!IsWithinSuitcaseTree(item.Folder, suitcase))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// OK, it's legit
|
||||||
|
return base.AddItem(item);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool UpdateItem(InventoryItemBase item)
|
||||||
|
{
|
||||||
|
XInventoryFolder suitcase = GetSuitcaseXFolder(item.Owner);
|
||||||
|
|
||||||
|
if (!IsWithinSuitcaseTree(item.Folder, suitcase))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return base.UpdateItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool MoveItems(UUID principalID, List<InventoryItemBase> items)
|
||||||
|
{
|
||||||
|
// Principal is b0rked. *sigh*
|
||||||
|
|
||||||
|
XInventoryFolder suitcase = GetSuitcaseXFolder(items[0].Owner);
|
||||||
|
|
||||||
|
if (!IsWithinSuitcaseTree(items[0].Folder, suitcase))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return base.MoveItems(principalID, items);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool DeleteItems(UUID principalID, List<UUID> itemIDs)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public new InventoryItemBase GetItem(InventoryItemBase item)
|
||||||
|
{
|
||||||
|
InventoryItemBase it = base.GetItem(item);
|
||||||
|
if (it == null)
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to retrieve item {0} ({1}) in folder {2}",
|
||||||
|
item.Name, item.ID, item.Folder);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
XInventoryFolder suitcase = GetSuitcaseXFolder(it.Owner);
|
||||||
|
if (suitcase == null)
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Root or Suitcase are null for user {0}",
|
||||||
|
it.Owner);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!IsWithinSuitcaseTree(it.Folder, suitcase))
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Item {0} (folder {1}) is not within Suitcase",
|
||||||
|
it.Name, it.Folder);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserAccount user = m_Cache.GetUser(it.CreatorId);
|
||||||
|
|
||||||
|
// // Adjust the creator data
|
||||||
|
// if (user != null && it != null && (it.CreatorData == null || it.CreatorData == string.Empty))
|
||||||
|
// it.CreatorData = m_HomeURL + ";" + user.FirstName + " " + user.LastName;
|
||||||
|
//}
|
||||||
|
|
||||||
|
return it;
|
||||||
|
}
|
||||||
|
|
||||||
|
public new InventoryFolderBase GetFolder(InventoryFolderBase folder)
|
||||||
|
{
|
||||||
|
InventoryFolderBase f = base.GetFolder(folder);
|
||||||
|
|
||||||
|
if (f != null)
|
||||||
|
{
|
||||||
|
XInventoryFolder suitcase = GetSuitcaseXFolder(f.Owner);
|
||||||
|
|
||||||
|
if (!IsWithinSuitcaseTree(f.ID, suitcase))
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
//public List<InventoryItemBase> GetActiveGestures(UUID principalID)
|
||||||
|
//{
|
||||||
|
//}
|
||||||
|
|
||||||
|
//public int GetAssetPermissions(UUID principalID, UUID assetID)
|
||||||
|
//{
|
||||||
|
//}
|
||||||
|
|
||||||
|
#region Auxiliary functions
|
||||||
|
private XInventoryFolder GetXFolder(UUID userID, UUID folderID)
|
||||||
|
{
|
||||||
|
XInventoryFolder[] folders = m_Database.GetFolders(
|
||||||
|
new string[] { "agentID", "folderID" },
|
||||||
|
new string[] { userID.ToString(), folderID.ToString() });
|
||||||
|
|
||||||
|
if (folders.Length == 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return folders[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
private XInventoryFolder GetRootXFolder(UUID principalID)
|
||||||
|
{
|
||||||
|
XInventoryFolder[] folders = m_Database.GetFolders(
|
||||||
|
new string[] { "agentID", "folderName", "type" },
|
||||||
|
new string[] { principalID.ToString(), "My Inventory", ((int)AssetType.RootFolder).ToString() });
|
||||||
|
|
||||||
|
if (folders != null && folders.Length > 0)
|
||||||
|
return folders[0];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private XInventoryFolder GetSuitcaseXFolder(UUID principalID)
|
||||||
|
{
|
||||||
|
// Warp! Root folder for travelers
|
||||||
|
XInventoryFolder[] folders = m_Database.GetFolders(
|
||||||
|
new string[] { "agentID", "type" },
|
||||||
|
new string[] { principalID.ToString(), "100" }); // This is a special folder type...
|
||||||
|
|
||||||
|
if (folders != null && folders.Length > 0)
|
||||||
|
return folders[0];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetAsRootFolder(XInventoryFolder suitcase, XInventoryFolder root)
|
||||||
|
{
|
||||||
|
suitcase.type = (short)AssetType.Folder;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<XInventoryFolder> GetFolderTree(UUID folder)
|
||||||
|
{
|
||||||
|
List<XInventoryFolder> t = null;
|
||||||
|
if (m_SuitcaseTrees.TryGetValue(folder, out t))
|
||||||
|
return t;
|
||||||
|
|
||||||
|
t = GetFolderTreeRecursive(folder);
|
||||||
|
m_SuitcaseTrees.AddOrUpdate(folder, t, 120);
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<XInventoryFolder> GetFolderTreeRecursive(UUID root)
|
||||||
|
{
|
||||||
|
List<XInventoryFolder> tree = new List<XInventoryFolder>();
|
||||||
|
XInventoryFolder[] folders = m_Database.GetFolders(
|
||||||
|
new string[] { "parentFolderID" },
|
||||||
|
new string[] { root.ToString() });
|
||||||
|
|
||||||
|
if (folders == null || (folders != null && folders.Length == 0))
|
||||||
|
return tree; // empty tree
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (XInventoryFolder f in folders)
|
||||||
|
{
|
||||||
|
tree.Add(f);
|
||||||
|
tree.AddRange(GetFolderTreeRecursive(f.folderID));
|
||||||
|
}
|
||||||
|
return tree;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return true if the folderID is a subfolder of the Suitcase or the suitcase folder itself
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="folderID"></param>
|
||||||
|
/// <param name="root"></param>
|
||||||
|
/// <param name="suitcase"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private bool IsWithinSuitcaseTree(UUID folderID, XInventoryFolder suitcase)
|
||||||
|
{
|
||||||
|
List<XInventoryFolder> tree = new List<XInventoryFolder>();
|
||||||
|
tree.Add(suitcase); // Warp! the tree is the real root folder plus the children of the suitcase folder
|
||||||
|
tree.AddRange(GetFolderTree(suitcase.folderID));
|
||||||
|
XInventoryFolder f = tree.Find(delegate(XInventoryFolder fl)
|
||||||
|
{
|
||||||
|
if (fl.folderID == folderID) return true;
|
||||||
|
else return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (f == null) return false;
|
||||||
|
else return true;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue