/// <summary> /// This method is called by updateAvatarAppearance once any specified model has been /// ratified, or an appropriate default value has been adopted. The intended prototype /// is known to exist, as is the target avatar. /// </summary> private void EstablishAppearance(UUID destination, UUID source) { m_log.DebugFormat("[RADMIN]: Initializing inventory for {0} from {1}", destination, source); Scene scene = m_application.SceneManager.CurrentOrFirstScene; // If the model has no associated appearance we're done. AvatarAppearance avatarAppearance = scene.AvatarService.GetAppearance(source); if (avatarAppearance == null) return; // Simple appearance copy or copy Clothing and Bodyparts folders? bool copyFolders = m_config.GetBoolean("copy_folders", false); if (!copyFolders) { // Simple copy of wearables and appearance update try { CopyWearablesAndAttachments(destination, source, avatarAppearance); scene.AvatarService.SetAppearance(destination, avatarAppearance); } catch (Exception e) { m_log.WarnFormat("[RADMIN]: Error transferring appearance for {0} : {1}", destination, e.Message); } return; } // Copy Clothing and Bodypart folders and appearance update try { Dictionary<UUID,UUID> inventoryMap = new Dictionary<UUID,UUID>(); CopyInventoryFolders(destination, source, AssetType.Clothing, inventoryMap, avatarAppearance); CopyInventoryFolders(destination, source, AssetType.Bodypart, inventoryMap, avatarAppearance); AvatarWearable[] wearables = avatarAppearance.Wearables; for (int i=0; i<wearables.Length; i++) { if (inventoryMap.ContainsKey(wearables[i][0].ItemID)) { AvatarWearable wearable = new AvatarWearable(); wearable.Wear(inventoryMap[wearables[i][0].ItemID], wearables[i][0].AssetID); avatarAppearance.SetWearable(i, wearable); } } scene.AvatarService.SetAppearance(destination, avatarAppearance); } catch (Exception e) { m_log.WarnFormat("[RADMIN]: Error transferring appearance for {0} : {1}", destination, e.Message); } return; }
/// <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> /// 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 = manager.CurrentOrFirstScene.InventoryService; // Get Clothing folder of receiver InventoryFolderBase destinationFolder = inventoryService.GetFolderForType (destination, InventoryType.Wearable, 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 { ID = UUID.Random(), Name = "Clothing", Owner = destination, Type = (short) AssetType.Clothing, ParentID = inventoryService.GetRootFolder(destination).ID, Version = 1 }; inventoryService.AddFolder(destinationFolder); // store base record MainConsole.Instance.ErrorFormat("[RADMIN] Created folder for destination {0}", source); } // Wearables AvatarWearable[] wearables = avatarAppearance.Wearables; for (int i = 0; i < wearables.Length; i++) { AvatarWearable 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) { Name = item.Name, Description = item.Description, InvType = item.InvType, CreatorId = item.CreatorId, CreatorData = item.CreatorData, CreatorIdAsUuid = item.CreatorIdAsUuid, NextPermissions = item.NextPermissions, CurrentPermissions = item.CurrentPermissions, BasePermissions = item.BasePermissions, EveryOnePermissions = item.EveryOnePermissions, GroupPermissions = item.GroupPermissions, AssetType = item.AssetType, AssetID = item.AssetID, GroupID = item.GroupID, GroupOwned = item.GroupOwned, SalePrice = item.SalePrice, SaleType = item.SaleType, Flags = item.Flags, CreationDate = item.CreationDate, Folder = destinationFolder.ID }; ILLClientInventory inventoryModule = manager.CurrentOrFirstScene.RequestModuleInterface<ILLClientInventory>(); if (inventoryModule != null) inventoryModule.AddInventoryItem(destinationItem); MainConsole.Instance.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 { MainConsole.Instance.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) { Name = item.Name, Description = item.Description, InvType = item.InvType, CreatorId = item.CreatorId, CreatorData = item.CreatorData, CreatorIdAsUuid = item.CreatorIdAsUuid, NextPermissions = item.NextPermissions, CurrentPermissions = item.CurrentPermissions, BasePermissions = item.BasePermissions, EveryOnePermissions = item.EveryOnePermissions, GroupPermissions = item.GroupPermissions, AssetType = item.AssetType, AssetID = item.AssetID, GroupID = item.GroupID, GroupOwned = item.GroupOwned, SalePrice = item.SalePrice, SaleType = item.SaleType, Flags = item.Flags, CreationDate = item.CreationDate, Folder = destinationFolder.ID }; ILLClientInventory inventoryModule = manager.CurrentOrFirstScene.RequestModuleInterface<ILLClientInventory>(); if (inventoryModule != null) inventoryModule.AddInventoryItem(destinationItem); MainConsole.Instance.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID); // Attach item avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID); MainConsole.Instance.DebugFormat("[RADMIN]: Attached {0}", destinationItem.ID); } else { MainConsole.Instance.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}", itemID, destinationFolder.ID); } } } }