Some changes to the AvatarCreationModule to reduce the number of database reads/writes. Still requires more work in this area.

0.6.6-post-fixes
MW 2009-06-01 11:16:07 +00:00
parent 840de6c036
commit a71d9c95cf
1 changed files with 86 additions and 69 deletions

View File

@ -1,4 +1,4 @@
/* /*
* Copyright (c) Contributors, http://opensimulator.org/ * Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders. * See CONTRIBUTORS.TXT for a full list of copyright holders.
* *
@ -69,7 +69,7 @@ namespace OpenSim.Grid.UserServer.Modules
{ {
console.Commands.AddCommand("userserver", false, "clone avatar", console.Commands.AddCommand("userserver", false, "clone avatar",
"clone avatar <TemplateAvatarFirstName> <TemplateAvatarLastName> <TargetAvatarFirstName> <TargetAvatarLastName>", "clone avatar <TemplateAvatarFirstName> <TemplateAvatarLastName> <TargetAvatarFirstName> <TargetAvatarLastName>",
"Clone the template avatar inventory into a target avatar", RunCommand); "Clone the template avatar's inventory into a target avatar", RunCommand);
} }
} }
@ -145,7 +145,7 @@ namespace OpenSim.Grid.UserServer.Modules
if (removeTargetsClothes) if (removeTargetsClothes)
{ {
//remove clothes and attachments from target avatar so that the end result isn't a merge of its existing clothes //remove clothes and attachments from target avatar so that the end result isn't a merger of its existing clothes
// and the clothes from the template avatar. // and the clothes from the template avatar.
RemoveClothesAndAttachments(avID); RemoveClothesAndAttachments(avID);
} }
@ -204,6 +204,9 @@ namespace OpenSim.Grid.UserServer.Modules
"POST", m_inventoryServerUrl + "GetItems/", templateFolderId.Guid); "POST", m_inventoryServerUrl + "GetItems/", templateFolderId.Guid);
if ((templateItems != null) && (templateItems.Count > 0)) if ((templateItems != null) && (templateItems.Count > 0))
{ {
List<ClothesAttachment> wornClothes = new List<ClothesAttachment>();
List<ClothesAttachment> attachedItems = new List<ClothesAttachment>();
foreach (InventoryItemBase item in templateItems) foreach (InventoryItemBase item in templateItems)
{ {
@ -213,7 +216,8 @@ namespace OpenSim.Grid.UserServer.Modules
int appearanceType = ItemIsPartOfAppearance(item, appearance); int appearanceType = ItemIsPartOfAppearance(item, appearance);
if (appearanceType >= 0) if (appearanceType >= 0)
{ {
UpdateAvatarAppearance(avID, appearanceType, clonedItemId, item.AssetID); // UpdateAvatarAppearance(avID, appearanceType, clonedItemId, item.AssetID);
wornClothes.Add(new ClothesAttachment(appearanceType, clonedItemId, item.AssetID));
} }
if (appearance != null) if (appearance != null)
@ -221,12 +225,36 @@ namespace OpenSim.Grid.UserServer.Modules
int attachment = appearance.GetAttachpoint(item.ID); int attachment = appearance.GetAttachpoint(item.ID);
if (attachment > 0) if (attachment > 0)
{ {
UpdateAvatarAttachment(avID, attachment, clonedItemId, item.AssetID); //UpdateAvatarAttachment(avID, attachment, clonedItemId, item.AssetID);
attachedItems.Add(new ClothesAttachment(attachment, clonedItemId, item.AssetID));
} }
} }
success = true; success = true;
} }
} }
if ((wornClothes.Count > 0) || (attachedItems.Count > 0))
{
//Update the worn clothes and attachments
AvatarAppearance targetAppearance = GetAppearance(avID);
if (targetAppearance != null)
{
foreach (ClothesAttachment wornItem in wornClothes)
{
targetAppearance.Wearables[wornItem.Type].AssetID = wornItem.AssetID;
targetAppearance.Wearables[wornItem.Type].ItemID = wornItem.ItemID;
}
foreach (ClothesAttachment wornItem in attachedItems)
{
targetAppearance.SetAttachment(wornItem.Type, wornItem.ItemID, wornItem.AssetID);
}
m_userDataBaseService.UpdateUserAppearance(avID, targetAppearance);
wornClothes.Clear();
attachedItems.Clear();
}
}
} }
List<InventoryFolderBase> subFolders = FindSubFolders(templateFolder.ID.Guid, templateFolders); List<InventoryFolderBase> subFolders = FindSubFolders(templateFolder.ID.Guid, templateFolders);
@ -288,40 +316,27 @@ namespace OpenSim.Grid.UserServer.Modules
private void UpdateAvatarAppearance(UUID avatarID, int wearableType, UUID itemID, UUID assetID) private void UpdateAvatarAppearance(UUID avatarID, int wearableType, UUID itemID, UUID assetID)
{ {
AvatarAppearance appearance = m_userDataBaseService.GetUserAppearance(avatarID); AvatarAppearance appearance = GetAppearance(avatarID);
if (appearance == null)
{
appearance = CreateDefaultAppearance(avatarID);
}
appearance.Wearables[wearableType].AssetID = assetID; appearance.Wearables[wearableType].AssetID = assetID;
appearance.Wearables[wearableType].ItemID = itemID; appearance.Wearables[wearableType].ItemID = itemID;
m_userDataBaseService.UpdateUserAppearance(avatarID, appearance); m_userDataBaseService.UpdateUserAppearance(avatarID, appearance);
} }
private void UpdateAvatarAttachment(UUID avatarID, int attachmentPoint, UUID itemID, UUID assetID) private void UpdateAvatarAttachment(UUID avatarID, int attachmentPoint, UUID itemID, UUID assetID)
{ {
AvatarAppearance appearance = m_userDataBaseService.GetUserAppearance(avatarID); AvatarAppearance appearance = GetAppearance(avatarID);
if (appearance == null)
{
appearance = CreateDefaultAppearance(avatarID);
}
appearance.SetAttachment(attachmentPoint, itemID, assetID); appearance.SetAttachment(attachmentPoint, itemID, assetID);
m_userDataBaseService.UpdateUserAppearance(avatarID, appearance); m_userDataBaseService.UpdateUserAppearance(avatarID, appearance);
} }
private void RemoveClothesAndAttachments(UUID avatarID) private void RemoveClothesAndAttachments(UUID avatarID)
{ {
AvatarAppearance appearance = m_userDataBaseService.GetUserAppearance(avatarID); AvatarAppearance appearance = GetAppearance(avatarID);
if (appearance == null)
{
appearance = CreateDefaultAppearance(avatarID);
}
appearance.ClearWearables(); appearance.ClearWearables();
appearance.ClearAttachments(); appearance.ClearAttachments();
@ -329,6 +344,16 @@ namespace OpenSim.Grid.UserServer.Modules
} }
private AvatarAppearance GetAppearance(UUID avatarID)
{
AvatarAppearance appearance = m_userDataBaseService.GetUserAppearance(avatarID);
if (appearance == null)
{
appearance = CreateDefaultAppearance(avatarID);
}
return appearance;
}
private UUID FindFolderID(string name, List<InventoryFolderBase> folders) private UUID FindFolderID(string name, List<InventoryFolderBase> folders)
{ {
foreach (InventoryFolderBase folder in folders) foreach (InventoryFolderBase folder in folders)
@ -398,27 +423,6 @@ namespace OpenSim.Grid.UserServer.Modules
item.EveryOnePermissions = item.EveryOnePermissions & item.NextPermissions; item.EveryOnePermissions = item.EveryOnePermissions & item.NextPermissions;
item.GroupPermissions = item.GroupPermissions & item.NextPermissions; item.GroupPermissions = item.GroupPermissions & item.NextPermissions;
//set all items to +mod/+copy/- transfer
//if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0)
// item.CurrentPermissions |= (uint)PermissionMask.Modify;
//if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
// item.CurrentPermissions |= (uint)PermissionMask.Copy;
//if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) != 0)
// item.CurrentPermissions &= ~(uint)PermissionMask.Transfer;
//if ((item.NextPermissions & (uint)PermissionMask.Modify) == 0)
// item.NextPermissions |= (uint)PermissionMask.Modify;
//if ((item.NextPermissions & (uint)PermissionMask.Copy) == 0)
// item.NextPermissions |= (uint)PermissionMask.Copy;
//if ((item.NextPermissions & (uint)PermissionMask.Transfer) != 0)
// item.NextPermissions &= ~(uint)PermissionMask.Transfer;
//if ((item.EveryOnePermissions & (uint)PermissionMask.Transfer) != 0)
// item.EveryOnePermissions &= ~(uint)PermissionMask.Transfer;
} }
private AvatarAppearance CreateDefaultAppearance(UUID avatarId) private AvatarAppearance CreateDefaultAppearance(UUID avatarId)
@ -496,8 +500,6 @@ namespace OpenSim.Grid.UserServer.Modules
} }
#endregion #endregion
}
public enum PermissionMask public enum PermissionMask
{ {
None = 0, None = 0,
@ -525,4 +527,19 @@ namespace OpenSim.Grid.UserServer.Modules
Underpants = 11, Underpants = 11,
Skirt = 12, Skirt = 12,
} }
public class ClothesAttachment
{
public int Type;
public UUID ItemID;
public UUID AssetID;
public ClothesAttachment(int type, UUID itemID, UUID assetID)
{
Type = type;
ItemID = itemID;
AssetID = assetID;
}
}
}
} }