From 0d83b9edc3f965c3d9061265bb6962002eea1efd Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sat, 12 May 2018 19:16:23 +0100 Subject: create user with model: do not copy missing items; convert v1.0 to v2.0 wearables, fail if model has missing wearables --- .../UserAccountService/UserAccountService.cs | 48 ++++++++++++++-------- 1 file changed, 31 insertions(+), 17 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Services/UserAccountService/UserAccountService.cs b/OpenSim/Services/UserAccountService/UserAccountService.cs index 95c9e57..880517c 100644 --- a/OpenSim/Services/UserAccountService/UserAccountService.cs +++ b/OpenSim/Services/UserAccountService/UserAccountService.cs @@ -825,7 +825,6 @@ namespace OpenSim.Services.UserAccountService return; } - try { CopyWearablesAndAttachments(destinationAgent, modelAccount.PrincipalID, modelAppearance); @@ -849,19 +848,24 @@ namespace OpenSim.Services.UserAccountService /// private void CopyWearablesAndAttachments(UUID destination, UUID source, AvatarAppearance avatarAppearance) { + + AvatarWearable[] wearables = avatarAppearance.Wearables; + if(wearables.Length == 0) + throw new Exception("Model does not have wearables"); + // Get Clothing folder of receiver InventoryFolderBase destinationFolder = m_InventoryService.GetFolderForType(destination, FolderType.Clothing); - // Get Current Outfit folder - InventoryFolderBase currentOutfitFolder = m_InventoryService.GetFolderForType(destination, FolderType.CurrentOutfit); if (destinationFolder == null) - throw new Exception("Cannot locate folder(s)"); + throw new Exception("Cannot locate new clothing folder(s)"); - // Missing destination folder? This should *never* be the case + // Get Current Outfit folder + InventoryFolderBase currentOutfitFolder = m_InventoryService.GetFolderForType(destination, FolderType.CurrentOutfit); + + // wrong destination folder type? create new if (destinationFolder.Type != (short)FolderType.Clothing) { destinationFolder = new InventoryFolderBase(); - destinationFolder.ID = UUID.Random(); destinationFolder.Name = "Clothing"; destinationFolder.Owner = destination; @@ -869,21 +873,31 @@ namespace OpenSim.Services.UserAccountService destinationFolder.ParentID = m_InventoryService.GetRootFolder(destination).ID; destinationFolder.Version = 1; m_InventoryService.AddFolder(destinationFolder); // store base record - m_log.ErrorFormat("[USER ACCOUNT SERVICE]: Created folder for destination {0}", source); + m_log.ErrorFormat("[USER ACCOUNT SERVICE]: Created folder for destination {0} Clothing", source); } // Wearables - AvatarWearable[] wearables = avatarAppearance.Wearables; - AvatarWearable wearable; + AvatarWearable basewearable; + AvatarWearable newbasewearable; + WearableItem wearable; + // copy wearables creating new inventory entries + // converting from v1.0 wearables to v2.0 for (int i = 0; i < wearables.Length; i++) { - wearable = wearables[i]; - if (wearable[0].ItemID != UUID.Zero) + basewearable = wearables[i]; + if(basewearable == null || basewearable.Count == 0) + continue; + + newbasewearable = new AvatarWearable(); + int j = basewearable.Count - 1; + + wearable = basewearable[j]; + if (wearable.ItemID != UUID.Zero) { - m_log.DebugFormat("[XXX]: Getting item {0} from avie {1}", wearable[0].ItemID, source); + m_log.DebugFormat("[XXX]: Getting item {0} from avie {1}", wearable.ItemID, source); // Get inventory item and copy it - InventoryItemBase item = m_InventoryService.GetItem(source, wearable[0].ItemID); + InventoryItemBase item = m_InventoryService.GetItem(source, wearable.ItemID); if(item != null && item.AssetType == (int)AssetType.Link) { @@ -922,22 +936,22 @@ namespace OpenSim.Services.UserAccountService m_log.DebugFormat("[USER ACCOUNT SERVICE]: 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); + newbasewearable.Add(destinationItem.ID,wearable.AssetID); // Add to Current Outfit CreateCurrentOutfitLink((int)InventoryType.Wearable, item.Flags, item.Name, destinationItem.ID, destination, currentOutfitFolder.ID); } else { - m_log.WarnFormat("[USER ACCOUNT SERVICE]: Error transferring {0} to folder {1}", wearable[0].ItemID, destinationFolder.ID); + m_log.WarnFormat("[USER ACCOUNT SERVICE]: Error transferring {0} to folder {1}", wearable.ItemID, destinationFolder.ID); } } + avatarAppearance.SetWearable(i, newbasewearable); } // Attachments List attachments = avatarAppearance.GetAttachments(); + avatarAppearance.ClearAttachments(); foreach (AvatarAttachment attachment in attachments) { -- cgit v1.1