diff --git a/SecondBotEvents/Commands/Inventory.cs b/SecondBotEvents/Commands/Inventory.cs index 939f014..87f7b54 100644 --- a/SecondBotEvents/Commands/Inventory.cs +++ b/SecondBotEvents/Commands/Inventory.cs @@ -392,6 +392,28 @@ namespace SecondBotEvents.Commands GetClient().Inventory.GiveItem(itm.UUID, itm.Name, itm.AssetType, avataruuid, false); return BasicReply("ok", new [] { item, avatar }); } + [About("Sends a folder to an avatar")] + [ReturnHints("ok")] + [ReturnHints("Invaild avatar uuid")] + [ReturnHints("Unable to find folder")] + [ArgHints("path", "path to the folder from root")] + [ArgHints("avatar", "a UUID or Firstname Lastname")] + public object SendFolderByPath(string path, string avatar) + { + ProcessAvatar(avatar); + if (avataruuid == UUID.Zero) + { + return Failure("Invaild avatar uuid", new[] { path, avatar }); + } + InventoryFolder FindFolderHelper = HelperInventory.FindFolderByPath(GetClient(), path); + if (FindFolderHelper == null) + { + return Failure("Unable to find folder", new[] { path, avatar }); + } + GetClient().Inventory.GiveFolder(FindFolderHelper.UUID, FindFolderHelper.Name, avataruuid, false); + return BasicReply("ok", new[] { path, avatar }); + } + [About("Sends a folder to an avatar")] [ReturnHints("ok")] diff --git a/SecondBotEvents/Static/Inventory.cs b/SecondBotEvents/Static/Inventory.cs index b5f8c1d..d452dca 100644 --- a/SecondBotEvents/Static/Inventory.cs +++ b/SecondBotEvents/Static/Inventory.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using OpenMetaverse; +using OpenMetaverse.ImportExport.Collada14; using System; using System.Collections.Generic; using System.Text; @@ -34,6 +35,61 @@ namespace BetterSecondBot.Static } return UUID.Zero; } + + public static InventoryFolder FindFolderByPath(GridClient bot, string path) + { + return DigFolderForPath(bot, path, 0, bot.Inventory.Store.RootFolder.UUID); + } + + private static InventoryFolder DigFolderForPath(GridClient bot, string path, int level, UUID folder) + { + string[] bits = path.Split('/'); + List T = bot.Inventory.Store.GetContents(folder); + InventoryFolder foundFolder = null; + bool found = false; + foreach (InventoryBase t in T) + { + if (t.GetType() == typeof(InventoryFolder)) + { + if (t.Name == bits[level]) + { + folder = t.UUID; + if (bits.Length > (level+1)) + { + // need to go deeper + foundFolder = DigFolderForPath(bot, path, level + 1, folder); + if (foundFolder != null) + { + found = true; + } + } + else + { + // we are here + foundFolder = (InventoryFolder)t; + found = true; + break; + } + } + else + { + continue; + } + } + else + { + continue; + } + } + if(found == true) + { + return foundFolder; + } + else + { + return null; + } + } public static InventoryBase FindFolder(GridClient bot, InventoryFolder current,UUID target) { List T = bot.Inventory.Store.GetContents(current);