public void TestBasicCreateFolder() { UUID userId = UUID.Random(); InventoryFolderBase folder = new InventoryFolderBase(); folder.ID = UUID.Random(); folder.Name = "Test Root 1"; folder.Level = InventoryFolderBase.FolderLevel.Root; folder.Owner = userId; folder.ParentID = UUID.Zero; folder.Type = 1; _storage.CreateFolder(folder); List<InventoryFolderBase> skel = _storage.GetInventorySkeleton(userId); Assert.IsTrue(skel.Count == 1); Assert.AreEqual(skel[0].ID, folder.ID); InventoryFolderBase folderCopy = _storage.GetFolderAttributes(folder.ID); AssertFolderEqual(folder, folderCopy, true); Assert.AreEqual(1, folderCopy.Version); _storage.SaveFolder(folderCopy); InventoryFolderBase folderCopy2 = _storage.GetFolderAttributes(folder.ID); AssertFolderEqual(folder, folderCopy2, true); Assert.AreEqual(2, folderCopy2.Version); }
public virtual bool CreateUserRootFolder(UUID principalID) { bool result = false; InventoryFolderBase rootFolder = GetRootFolder(principalID); if (rootFolder == null) { List<InventoryFolderBase> rootFolders = GetInventorySkeleton(principalID); if (rootFolders.Count == 0) rootFolder = CreateFolder(principalID, UUID.Zero, (int) AssetType.RootFolder, "My Inventory"); else { rootFolder = new InventoryFolderBase { Name = "My Inventory", Type = (short) AssetType.RootFolder, Version = 1, ID = rootFolders[0].ParentID, Owner = principalID, ParentID = UUID.Zero }; m_Database.StoreFolder(rootFolder); } result = true; } return result; }
public void CreateFolder(UUID userId, InventoryFolderBase folder) { if (folder.Owner != userId) { throw new InventorySecurityException(String.Format("Not creating folder {0} for user {1}. User does not own the folder", folder.ID, userId)); } _storage.CreateFolder(folder); }
/// <summary> /// <see cref="OpenSim.Framework.Communications.IInterServiceInventoryServices"/> /// </summary> /// <param name="userId"></param> /// <returns></returns> public List<InventoryFolderBase> GetInventorySkeleton(UUID userId) { List<InventoryFolderBase> folders = new List<InventoryFolderBase>(); InventoryFolderBase folder = new InventoryFolderBase(); folder.ID = UUID.Random(); folder.Owner = userId; folders.Add(folder); return folders; }
// Constructors public InventoryFolderImpl(InventoryFolderBase folderbase) { Owner = folderbase.Owner; ID = folderbase.ID; Name = folderbase.Name; ParentID = folderbase.ParentID; Type = folderbase.Type; Version = folderbase.Version; }
public void Cache(UUID userID, AssetType type, InventoryFolderBase folder) { lock (m_FolderTypes) { Dictionary<AssetType, InventoryFolderBase> ff = null; if (!m_FolderTypes.TryGetValue(userID, out ff)) { ff = new Dictionary<AssetType, InventoryFolderBase>(); m_FolderTypes.Add(userID, ff, CACHE_EXPIRATION_SECONDS); } if (!ff.ContainsKey(type)) ff.Add(type, folder); } }
public bool AddFolder(InventoryFolderBase folder) { Dictionary<string,object> ret = MakeRequest("ADDFOLDER", new Dictionary<string,object> { { "ParentID", folder.ParentID.ToString() }, { "Type", folder.Type.ToString() }, { "Version", folder.Version.ToString() }, { "Name", folder.Name.ToString() }, { "Owner", folder.Owner.ToString() }, { "ID", folder.ID.ToString() } }); return CheckReturn(ret); }
/// <summary> /// Create inventory folders starting from a given parent folder /// </summary> /// /// Ignores any existing folders with the same name /// /// <param name="inventoryService"></param> /// <param name="parentFolder"></param> /// <param name="path"> /// The folders to create. Multiple folders can be specified on a path delimited by the PATH_DELIMITER /// </param> /// <returns> /// The folder created. If the path contains multiple folders then the last one created is returned. /// </returns> public static InventoryFolderBase CreateInventoryFolder( IInventoryService inventoryService, InventoryFolderBase parentFolder, string path) { string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None); InventoryFolderBase newFolder = new InventoryFolderBase(UUID.Random(), components[0], parentFolder.Owner, parentFolder.ID); inventoryService.AddFolder(newFolder); if (components.Length > 1) return CreateInventoryFolder(inventoryService, newFolder, components[1]); else return newFolder; }
public void Cache(UUID userID, AssetType type, InventoryFolderBase folder) { ThreadedClasses.RwLockedDictionary<AssetType, InventoryFolderBase> ff = null; ff = m_FolderTypes.GetOrAdd(userID, delegate() { return new ThreadedClasses.RwLockedDictionary<AssetType, InventoryFolderBase>(); }, CACHE_EXPIRATION_SECONDS); try { ff.Add(type, folder); } catch { } }
public void Cache(UUID userID, AssetType type, InventoryFolderBase folder) { Dictionary<AssetType, InventoryFolderBase> ff = null; if (!m_FolderTypes.TryGetValue(userID, out ff)) { ff = new Dictionary<AssetType, InventoryFolderBase>(); m_FolderTypes.Add(userID, ff, CACHE_EXPIRATION_SECONDS); } // We need to lock here since two threads could potentially retrieve the same dictionary // and try to add a folder for that type simultaneously. Dictionary<>.Add() is not described as thread-safe in the SDK // even if the folders are identical. lock (ff) { if (!ff.ContainsKey(type)) ff.Add(type, folder); } }
public virtual bool PurgeFolder(InventoryFolderBase folder) { if (!m_AllowDelete) return false; if (!ParentIsTrash(folder.ID)) return false; XInventoryFolder[] subFolders = m_Database.GetFolders( new string[] { "parentFolderID" }, new string[] { folder.ID.ToString() }); foreach (XInventoryFolder x in subFolders) { PurgeFolder(ConvertToOpenSim(x)); m_Database.DeleteFolders("folderID", x.folderID.ToString()); } m_Database.DeleteItems("parentFolderID", folder.ID.ToString()); return true; }
// We don't check the principal's ID here // public virtual bool DeleteFolders(UUID principalID, List<UUID> folderIDs) { if (!m_AllowDelete) return false; // Ignore principal ID, it's bogus at connector level // foreach (UUID id in folderIDs) { if (!ParentIsTrash(id)) continue; InventoryFolderBase f = new InventoryFolderBase(); f.ID = id; PurgeFolder(f); m_Database.DeleteFolders("folderID", id.ToString()); } return true; }
public virtual bool MoveFolder(InventoryFolderBase folder) { XInventoryFolder[] x = m_Database.GetFolders( new string[] { "folderID" }, new string[] { folder.ID.ToString() }); if (x.Length == 0) return false; x[0].parentFolderID = folder.ParentID; return m_Database.StoreFolder(x[0]); }
public virtual bool UpdateFolder(InventoryFolderBase folder) { XInventoryFolder xFolder = ConvertFromOpenSim(folder); InventoryFolderBase check = GetFolder(folder); if (check == null) return AddFolder(folder); if (check.Type != -1 || xFolder.type != -1) { if (xFolder.version > check.Version) return false; check.Version = (ushort)xFolder.version; xFolder = ConvertFromOpenSim(check); return m_Database.StoreFolder(xFolder); } if (xFolder.version < check.Version) xFolder.version = check.Version; xFolder.folderID = check.ID; return m_Database.StoreFolder(xFolder); }
public virtual bool AddFolder(InventoryFolderBase folder) { InventoryFolderBase check = GetFolder(folder); if (check != null) return false; XInventoryFolder xFolder = ConvertFromOpenSim(folder); return m_Database.StoreFolder(xFolder); }
/// <summary> /// This method is called by establishAppearance to copy inventory folders to make /// copies of Clothing and Bodyparts inventory folders and attaches worn attachments /// </summary> private void CopyInventoryFolders(UUID destination, UUID source, AssetType assetType, Dictionary<UUID,UUID> inventoryMap, AvatarAppearance avatarAppearance) { IInventoryService inventoryService = m_application.SceneManager.CurrentOrFirstScene.InventoryService; InventoryFolderBase sourceFolder = inventoryService.GetFolderForType(source, assetType); InventoryFolderBase destinationFolder = inventoryService.GetFolderForType(destination, assetType); if (sourceFolder == null || destinationFolder == null) throw new Exception("Cannot locate folder(s)"); // Missing source folder? This should *never* be the case if (sourceFolder.Type != (short)assetType) { sourceFolder = new InventoryFolderBase(); sourceFolder.ID = UUID.Random(); if (assetType == AssetType.Clothing) { sourceFolder.Name = "Clothing"; } else { sourceFolder.Name = "Body Parts"; } sourceFolder.Owner = source; sourceFolder.Type = (short)assetType; sourceFolder.ParentID = inventoryService.GetRootFolder(source).ID; sourceFolder.Version = 1; inventoryService.AddFolder(sourceFolder); // store base record m_log.ErrorFormat("[RADMIN] Created folder for source {0}", source); } // Missing destination folder? This should *never* be the case if (destinationFolder.Type != (short)assetType) { destinationFolder = new InventoryFolderBase(); destinationFolder.ID = UUID.Random(); if (assetType == AssetType.Clothing) { destinationFolder.Name = "Clothing"; } else { destinationFolder.Name = "Body Parts"; } destinationFolder.Owner = destination; destinationFolder.Type = (short)assetType; destinationFolder.ParentID = inventoryService.GetRootFolder(destination).ID; destinationFolder.Version = 1; inventoryService.AddFolder(destinationFolder); // store base record m_log.ErrorFormat("[RADMIN]: Created folder for destination {0}", source); } InventoryFolderBase extraFolder; List<InventoryFolderBase> folders = inventoryService.GetFolderContent(source, sourceFolder.ID).Folders; foreach (InventoryFolderBase folder in folders) { extraFolder = new InventoryFolderBase(); extraFolder.ID = UUID.Random(); extraFolder.Name = folder.Name; extraFolder.Owner = destination; extraFolder.Type = folder.Type; extraFolder.Version = folder.Version; extraFolder.ParentID = destinationFolder.ID; inventoryService.AddFolder(extraFolder); m_log.DebugFormat("[RADMIN]: Added folder {0} to folder {1}", extraFolder.ID, sourceFolder.ID); List<InventoryItemBase> items = inventoryService.GetFolderContent(source, folder.ID).Items; foreach (InventoryItemBase item in items) { InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination); destinationItem.Name = item.Name; destinationItem.Owner = destination; destinationItem.Description = item.Description; destinationItem.InvType = item.InvType; destinationItem.CreatorId = item.CreatorId; destinationItem.CreatorIdAsUuid = item.CreatorIdAsUuid; destinationItem.CreatorData = item.CreatorData; destinationItem.NextPermissions = item.NextPermissions; destinationItem.CurrentPermissions = item.CurrentPermissions; destinationItem.BasePermissions = item.BasePermissions; destinationItem.EveryOnePermissions = item.EveryOnePermissions; destinationItem.GroupPermissions = item.GroupPermissions; destinationItem.AssetType = item.AssetType; destinationItem.AssetID = item.AssetID; destinationItem.GroupID = item.GroupID; destinationItem.GroupOwned = item.GroupOwned; destinationItem.SalePrice = item.SalePrice; destinationItem.SaleType = item.SaleType; destinationItem.Flags = item.Flags; destinationItem.CreationDate = item.CreationDate; destinationItem.Folder = extraFolder.ID; ApplyNextOwnerPermissions(destinationItem); m_application.SceneManager.CurrentOrFirstScene.AddInventoryItem(destinationItem); inventoryMap.Add(item.ID, destinationItem.ID); m_log.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, extraFolder.ID); // Attach item, if original is attached int attachpoint = avatarAppearance.GetAttachpoint(item.ID); if (attachpoint != 0) { avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID); m_log.DebugFormat("[RADMIN]: Attached {0}", destinationItem.ID); } } } }
public bool AddFolder(InventoryFolderBase folder) { return false; }
public InventoryFolderBase RequestRootFolder(UUID userID) { InventoryFolderBase root = new InventoryFolderBase(); root.ID = UUID.Random(); root.Owner = userID; root.ParentID = UUID.Zero; return root; }
protected XInventoryFolder ConvertFromOpenSim(InventoryFolderBase folder) { XInventoryFolder newFolder = new XInventoryFolder(); newFolder.parentFolderID = folder.ParentID; newFolder.type = (int)folder.Type; newFolder.version = (int)folder.Version; newFolder.folderName = folder.Name; newFolder.agentID = folder.Owner; newFolder.folderID = folder.ID; return newFolder; }
public InventoryFolderBase GetFolder(InventoryFolderBase folder) { return null; }
public bool PurgeFolder(InventoryFolderBase folder) { return false; }
public bool UpdateFolder(InventoryFolderBase folder) { return false; }
public virtual InventoryFolderBase GetFolder(InventoryFolderBase folder) { XInventoryFolder[] folders = m_Database.GetFolders( new string[] { "folderID"}, new string[] { folder.ID.ToString() }); if (folders.Length == 0) return null; return ConvertToOpenSim(folders[0]); }
/// <summary> /// Purge an inventory folder of all its items and subfolders. /// </summary> /// <param name="folder"></param> /// <returns>true if the folder was successfully purged</returns> public bool PurgeFolder(InventoryFolderBase folder) { NameValueCollection requestArgs = new NameValueCollection { { "RequestMethod", "PurgeInventoryFolder" }, { "OwnerID", folder.Owner.ToString() }, { "FolderID", folder.ID.ToString() } }; OSDMap response = WebUtils.PostToService(m_serverUrl, requestArgs); bool success = response["Success"].AsBoolean(); if (!success) { m_log.Warn("[SIMIAN INVENTORY CONNECTOR]: Error purging folder " + folder.ID + " for " + folder.Owner + ": " + response["Message"].AsString()); } return success; }
// CM Helpers // protected InventoryFolderBase ConvertToOpenSim(XInventoryFolder folder) { InventoryFolderBase newFolder = new InventoryFolderBase(); newFolder.ParentID = folder.parentFolderID; newFolder.Type = (short)folder.type; newFolder.Version = (ushort)folder.version; newFolder.Name = folder.folderName; newFolder.Owner = folder.agentID; newFolder.ID = folder.folderID; return newFolder; }
/// <summary> /// Update an item in the user's inventory /// </summary> /// <param name="item"></param> /// <returns>true if the item was successfully updated</returns> public bool UpdateItem(InventoryItemBase item) { if (item.AssetID != UUID.Zero) { return AddItem(item); } else { // This is actually a folder update InventoryFolderBase folder = new InventoryFolderBase(item.ID, item.Name, item.Owner, (short)item.AssetType, item.Folder, 0); return UpdateFolder(folder); } }
/// <summary> /// This method is called by establishAppearance to do a copy all inventory items /// worn or attached to the Clothing inventory folder of the receiving avatar. /// In parallel the avatar wearables and attachments are updated. /// </summary> private void CopyWearablesAndAttachments(UUID destination, UUID source, AvatarAppearance avatarAppearance) { IInventoryService inventoryService = m_application.SceneManager.CurrentOrFirstScene.InventoryService; // Get Clothing folder of receiver InventoryFolderBase destinationFolder = inventoryService.GetFolderForType(destination, AssetType.Clothing); if (destinationFolder == null) throw new Exception("Cannot locate folder(s)"); // Missing destination folder? This should *never* be the case if (destinationFolder.Type != (short)AssetType.Clothing) { destinationFolder = new InventoryFolderBase(); destinationFolder.ID = UUID.Random(); destinationFolder.Name = "Clothing"; destinationFolder.Owner = destination; destinationFolder.Type = (short)AssetType.Clothing; destinationFolder.ParentID = inventoryService.GetRootFolder(destination).ID; destinationFolder.Version = 1; inventoryService.AddFolder(destinationFolder); // store base record m_log.ErrorFormat("[RADMIN]: Created folder for destination {0}", source); } // Wearables AvatarWearable[] wearables = avatarAppearance.Wearables; AvatarWearable wearable; for (int i=0; i<wearables.Length; i++) { wearable = wearables[i]; if (wearable[0].ItemID != UUID.Zero) { // Get inventory item and copy it InventoryItemBase item = new InventoryItemBase(wearable[0].ItemID, source); item = inventoryService.GetItem(item); if (item != null) { InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination); destinationItem.Name = item.Name; destinationItem.Owner = destination; destinationItem.Description = item.Description; destinationItem.InvType = item.InvType; destinationItem.CreatorId = item.CreatorId; destinationItem.CreatorIdAsUuid = item.CreatorIdAsUuid; destinationItem.CreatorData = item.CreatorData; destinationItem.NextPermissions = item.NextPermissions; destinationItem.CurrentPermissions = item.CurrentPermissions; destinationItem.BasePermissions = item.BasePermissions; destinationItem.EveryOnePermissions = item.EveryOnePermissions; destinationItem.GroupPermissions = item.GroupPermissions; destinationItem.AssetType = item.AssetType; destinationItem.AssetID = item.AssetID; destinationItem.GroupID = item.GroupID; destinationItem.GroupOwned = item.GroupOwned; destinationItem.SalePrice = item.SalePrice; destinationItem.SaleType = item.SaleType; destinationItem.Flags = item.Flags; destinationItem.CreationDate = item.CreationDate; destinationItem.Folder = destinationFolder.ID; ApplyNextOwnerPermissions(destinationItem); m_application.SceneManager.CurrentOrFirstScene.AddInventoryItem(destinationItem); m_log.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID); // Wear item AvatarWearable newWearable = new AvatarWearable(); newWearable.Wear(destinationItem.ID, wearable[0].AssetID); avatarAppearance.SetWearable(i, newWearable); } else { m_log.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}", wearable[0].ItemID, destinationFolder.ID); } } } // Attachments List<AvatarAttachment> attachments = avatarAppearance.GetAttachments(); foreach (AvatarAttachment attachment in attachments) { int attachpoint = attachment.AttachPoint; UUID itemID = attachment.ItemID; if (itemID != UUID.Zero) { // Get inventory item and copy it InventoryItemBase item = new InventoryItemBase(itemID, source); item = inventoryService.GetItem(item); if (item != null) { InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination); destinationItem.Name = item.Name; destinationItem.Owner = destination; destinationItem.Description = item.Description; destinationItem.InvType = item.InvType; destinationItem.CreatorId = item.CreatorId; destinationItem.CreatorIdAsUuid = item.CreatorIdAsUuid; destinationItem.CreatorData = item.CreatorData; destinationItem.NextPermissions = item.NextPermissions; destinationItem.CurrentPermissions = item.CurrentPermissions; destinationItem.BasePermissions = item.BasePermissions; destinationItem.EveryOnePermissions = item.EveryOnePermissions; destinationItem.GroupPermissions = item.GroupPermissions; destinationItem.AssetType = item.AssetType; destinationItem.AssetID = item.AssetID; destinationItem.GroupID = item.GroupID; destinationItem.GroupOwned = item.GroupOwned; destinationItem.SalePrice = item.SalePrice; destinationItem.SaleType = item.SaleType; destinationItem.Flags = item.Flags; destinationItem.CreationDate = item.CreationDate; destinationItem.Folder = destinationFolder.ID; ApplyNextOwnerPermissions(destinationItem); m_application.SceneManager.CurrentOrFirstScene.AddInventoryItem(destinationItem); m_log.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID); // Attach item avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID); m_log.DebugFormat("[RADMIN]: Attached {0}", destinationItem.ID); } else { m_log.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}", itemID, destinationFolder.ID); } } } }
/// <summary> /// Save an inventory folder /// </summary> /// <param name="inventoryFolder">The inventory folder to save</param> /// <param name="path">The path to which the folder should be saved</param> /// <param name="saveThisFolderItself">If true, save this folder itself. If false, only saves contents</param> protected void SaveInvFolder(InventoryFolderBase inventoryFolder, string path, bool saveThisFolderItself) { if (saveThisFolderItself) { path += CreateArchiveFolderName(inventoryFolder); // We need to make sure that we record empty folders m_archiveWriter.WriteDir(path); } InventoryCollection contents = m_scene.InventoryService.GetFolderContent(inventoryFolder.Owner, inventoryFolder.ID); //List<InventoryFolderImpl> childFolders = inventoryFolder.RequestListOfFolderImpls(); //List<InventoryItemBase> items = inventoryFolder.RequestListOfItems(); /* Dictionary identicalFolderNames = new Dictionary<string, int>(); foreach (InventoryFolderImpl folder in inventories) { if (!identicalFolderNames.ContainsKey(folder.Name)) identicalFolderNames[folder.Name] = 0; else identicalFolderNames[folder.Name] = identicalFolderNames[folder.Name]++; int folderNameNumber = identicalFolderName[folder.Name]; SaveInvDir( folder, string.Format( "{0}{1}{2}/", path, ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR, folderNameNumber)); } */ foreach (InventoryFolderBase childFolder in contents.Folders) { SaveInvFolder(childFolder, path, true); } foreach (InventoryItemBase item in contents.Items) { SaveInvItem(item, path); } }
/// <summary> /// This method is called if a given model avatar name can not be found. If the external /// file has already been loaded once, then control returns immediately. If not, then it /// looks for a default appearance file. This file contains XML definitions of zero or more named /// avatars, each avatar can specify zero or more "outfits". Each outfit is a collection /// of items that together, define a particular ensemble for the avatar. Each avatar should /// indicate which outfit is the default, and this outfit will be automatically worn. The /// other outfits are provided to allow "real" avatars a way to easily change their outfits. /// </summary> private bool CreateDefaultAvatars() { // Only load once if (m_defaultAvatarsLoaded) { return false; } m_log.DebugFormat("[RADMIN]: Creating default avatar entries"); m_defaultAvatarsLoaded = true; // Load processing starts here... try { string defaultAppearanceFileName = null; //m_config may be null if RemoteAdmin configuration secition is missing or disabled in OpenSim.ini if (m_config != null) { defaultAppearanceFileName = m_config.GetString("default_appearance", "default_appearance.xml"); } if (File.Exists(defaultAppearanceFileName)) { XmlDocument doc = new XmlDocument(); string name = "*unknown*"; string email = "anon@anon"; uint regionXLocation = 1000; uint regionYLocation = 1000; string password = UUID.Random().ToString(); // No requirement to sign-in. UUID ID = UUID.Zero; AvatarAppearance avatarAppearance; XmlNodeList avatars; XmlNodeList assets; XmlNode perms = null; bool include = false; bool select = false; Scene scene = m_application.SceneManager.CurrentOrFirstScene; IInventoryService inventoryService = scene.InventoryService; IAssetService assetService = scene.AssetService; doc.LoadXml(File.ReadAllText(defaultAppearanceFileName)); // Load up any included assets. Duplicates will be ignored assets = doc.GetElementsByTagName("RequiredAsset"); foreach (XmlNode assetNode in assets) { AssetBase asset = new AssetBase(UUID.Random(), GetStringAttribute(assetNode, "name", ""), SByte.Parse(GetStringAttribute(assetNode, "type", "")), UUID.Zero.ToString()); asset.Description = GetStringAttribute(assetNode,"desc",""); asset.Local = Boolean.Parse(GetStringAttribute(assetNode,"local","")); asset.Temporary = Boolean.Parse(GetStringAttribute(assetNode,"temporary","")); asset.Data = Convert.FromBase64String(assetNode.InnerText); assetService.Store(asset); } avatars = doc.GetElementsByTagName("Avatar"); // The document may contain multiple avatars foreach (XmlElement avatar in avatars) { m_log.DebugFormat("[RADMIN]: Loading appearance for {0}, gender = {1}", GetStringAttribute(avatar,"name","?"), GetStringAttribute(avatar,"gender","?")); // Create the user identified by the avatar entry try { // Only the name value is mandatory name = GetStringAttribute(avatar,"name",name); email = GetStringAttribute(avatar,"email",email); regionXLocation = GetUnsignedAttribute(avatar,"regx",regionXLocation); regionYLocation = GetUnsignedAttribute(avatar,"regy",regionYLocation); password = GetStringAttribute(avatar,"password",password); string[] names = name.Split(); UUID scopeID = scene.RegionInfo.ScopeID; UserAccount account = scene.UserAccountService.GetUserAccount(scopeID, names[0], names[1]); if (null == account) { account = CreateUser(scopeID, names[0], names[1], password, email); if (null == account) { m_log.ErrorFormat("[RADMIN]: Avatar {0} {1} was not created", names[0], names[1]); return false; } } // Set home position GridRegion home = scene.GridService.GetRegionByPosition(scopeID, (int)(regionXLocation * Constants.RegionSize), (int)(regionYLocation * Constants.RegionSize)); if (null == home) { m_log.WarnFormat("[RADMIN]: Unable to set home region for newly created user account {0} {1}", names[0], names[1]); } else { scene.GridUserService.SetHome(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0)); m_log.DebugFormat("[RADMIN]: Set home region {0} for updated user account {1} {2}", home.RegionID, names[0], names[1]); } ID = account.PrincipalID; m_log.DebugFormat("[RADMIN]: User {0}[{1}] created or retrieved", name, ID); include = true; } catch (Exception e) { m_log.DebugFormat("[RADMIN]: Error creating user {0} : {1}", name, e.Message); include = false; } // OK, User has been created OK, now we can install the inventory. // First retrieve the current inventory (the user may already exist) // Note that althought he inventory is retrieved, the hierarchy has // not been interpreted at all. if (include) { // Setup for appearance processing avatarAppearance = scene.AvatarService.GetAppearance(ID); if (avatarAppearance == null) avatarAppearance = new AvatarAppearance(); AvatarWearable[] wearables = avatarAppearance.Wearables; for (int i=0; i<wearables.Length; i++) { wearables[i] = new AvatarWearable(); } try { // m_log.DebugFormat("[RADMIN] {0} folders, {1} items in inventory", // uic.folders.Count, uic.items.Count); InventoryFolderBase clothingFolder = inventoryService.GetFolderForType(ID, AssetType.Clothing); // This should *never* be the case if (clothingFolder == null || clothingFolder.Type != (short)AssetType.Clothing) { clothingFolder = new InventoryFolderBase(); clothingFolder.ID = UUID.Random(); clothingFolder.Name = "Clothing"; clothingFolder.Owner = ID; clothingFolder.Type = (short)AssetType.Clothing; clothingFolder.ParentID = inventoryService.GetRootFolder(ID).ID; clothingFolder.Version = 1; inventoryService.AddFolder(clothingFolder); // store base record m_log.ErrorFormat("[RADMIN]: Created clothing folder for {0}/{1}", name, ID); } // OK, now we have an inventory for the user, read in the outfits from the // default appearance XMl file. XmlNodeList outfits = avatar.GetElementsByTagName("Ensemble"); InventoryFolderBase extraFolder; string outfitName; UUID assetid; foreach (XmlElement outfit in outfits) { m_log.DebugFormat("[RADMIN]: Loading outfit {0} for {1}", GetStringAttribute(outfit,"name","?"), GetStringAttribute(avatar,"name","?")); outfitName = GetStringAttribute(outfit,"name",""); select = (GetStringAttribute(outfit,"default","no") == "yes"); // If the folder already exists, re-use it. The defaults may // change over time. Augment only. List<InventoryFolderBase> folders = inventoryService.GetFolderContent(ID, clothingFolder.ID).Folders; extraFolder = null; foreach (InventoryFolderBase folder in folders) { if (folder.Name == outfitName) { extraFolder = folder; break; } } // Otherwise, we must create the folder. if (extraFolder == null) { m_log.DebugFormat("[RADMIN]: Creating outfit folder {0} for {1}", outfitName, name); extraFolder = new InventoryFolderBase(); extraFolder.ID = UUID.Random(); extraFolder.Name = outfitName; extraFolder.Owner = ID; extraFolder.Type = (short)AssetType.Clothing; extraFolder.Version = 1; extraFolder.ParentID = clothingFolder.ID; inventoryService.AddFolder(extraFolder); m_log.DebugFormat("[RADMIN]: Adding outfile folder {0} to folder {1}", extraFolder.ID, clothingFolder.ID); } // Now get the pieces that make up the outfit XmlNodeList items = outfit.GetElementsByTagName("Item"); foreach (XmlElement item in items) { assetid = UUID.Zero; XmlNodeList children = item.ChildNodes; foreach (XmlNode child in children) { switch (child.Name) { case "Permissions" : m_log.DebugFormat("[RADMIN]: Permissions specified"); perms = child; break; case "Asset" : assetid = new UUID(child.InnerText); break; } } InventoryItemBase inventoryItem = null; // Check if asset is in inventory already inventoryItem = null; List<InventoryItemBase> inventoryItems = inventoryService.GetFolderContent(ID, extraFolder.ID).Items; foreach (InventoryItemBase listItem in inventoryItems) { if (listItem.AssetID == assetid) { inventoryItem = listItem; break; } } // Create inventory item if (inventoryItem == null) { inventoryItem = new InventoryItemBase(UUID.Random(), ID); inventoryItem.Name = GetStringAttribute(item,"name",""); inventoryItem.Description = GetStringAttribute(item,"desc",""); inventoryItem.InvType = GetIntegerAttribute(item,"invtype",-1); inventoryItem.CreatorId = GetStringAttribute(item,"creatorid",""); inventoryItem.CreatorIdAsUuid = (UUID)GetStringAttribute(item,"creatoruuid",""); inventoryItem.CreatorData = GetStringAttribute(item, "creatordata", ""); inventoryItem.NextPermissions = GetUnsignedAttribute(perms, "next", 0x7fffffff); inventoryItem.CurrentPermissions = GetUnsignedAttribute(perms,"current",0x7fffffff); inventoryItem.BasePermissions = GetUnsignedAttribute(perms,"base",0x7fffffff); inventoryItem.EveryOnePermissions = GetUnsignedAttribute(perms,"everyone",0x7fffffff); inventoryItem.GroupPermissions = GetUnsignedAttribute(perms,"group",0x7fffffff); inventoryItem.AssetType = GetIntegerAttribute(item,"assettype",-1); inventoryItem.AssetID = assetid; // associated asset inventoryItem.GroupID = (UUID)GetStringAttribute(item,"groupid",""); inventoryItem.GroupOwned = (GetStringAttribute(item,"groupowned","false") == "true"); inventoryItem.SalePrice = GetIntegerAttribute(item,"saleprice",0); inventoryItem.SaleType = (byte)GetIntegerAttribute(item,"saletype",0); inventoryItem.Flags = GetUnsignedAttribute(item,"flags",0); inventoryItem.CreationDate = GetIntegerAttribute(item,"creationdate",Util.UnixTimeSinceEpoch()); inventoryItem.Folder = extraFolder.ID; // Parent folder m_application.SceneManager.CurrentOrFirstScene.AddInventoryItem(inventoryItem); m_log.DebugFormat("[RADMIN]: Added item {0} to folder {1}", inventoryItem.ID, extraFolder.ID); } // Attach item, if attachpoint is specified int attachpoint = GetIntegerAttribute(item,"attachpoint",0); if (attachpoint != 0) { avatarAppearance.SetAttachment(attachpoint, inventoryItem.ID, inventoryItem.AssetID); m_log.DebugFormat("[RADMIN]: Attached {0}", inventoryItem.ID); } // Record whether or not the item is to be initially worn try { if (select && (GetStringAttribute(item, "wear", "false") == "true")) { avatarAppearance.Wearables[inventoryItem.Flags].Wear(inventoryItem.ID, inventoryItem.AssetID); } } catch (Exception e) { m_log.WarnFormat("[RADMIN]: Error wearing item {0} : {1}", inventoryItem.ID, e.Message); } } // foreach item in outfit m_log.DebugFormat("[RADMIN]: Outfit {0} load completed", outfitName); } // foreach outfit m_log.DebugFormat("[RADMIN]: Inventory update complete for {0}", name); scene.AvatarService.SetAppearance(ID, avatarAppearance); } catch (Exception e) { m_log.WarnFormat("[RADMIN]: Inventory processing incomplete for user {0} : {1}", name, e.Message); } } // End of include } m_log.DebugFormat("[RADMIN]: Default avatar loading complete"); } else { m_log.DebugFormat("[RADMIN]: No default avatar information available"); return false; } } catch (Exception e) { m_log.WarnFormat("[RADMIN]: Exception whilst loading default avatars ; {0}", e.Message); return false; } return true; }
/// <summary> /// Create the archive name for a particular folder. /// </summary> /// /// These names are prepended with an inventory folder's UUID so that more than one folder can have the /// same name /// /// <param name="folder"></param> /// <returns></returns> public static string CreateArchiveFolderName(InventoryFolderBase folder) { return CreateArchiveFolderName(folder.Name, folder.ID); }