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,33 +500,46 @@ namespace OpenSim.Grid.UserServer.Modules
} }
#endregion #endregion
public enum PermissionMask
{
None = 0,
Transfer = 8192,
Modify = 16384,
Copy = 32768,
Move = 524288,
Damage = 1048576,
All = 2147483647,
}
} public enum WearableType
public enum PermissionMask {
{ Shape = 0,
None = 0, Skin = 1,
Transfer = 8192, Hair = 2,
Modify = 16384, Eyes = 3,
Copy = 32768, Shirt = 4,
Move = 524288, Pants = 5,
Damage = 1048576, Shoes = 6,
All = 2147483647, Socks = 7,
} Jacket = 8,
Gloves = 9,
Undershirt = 10,
Underpants = 11,
Skirt = 12,
}
public enum WearableType public class ClothesAttachment
{ {
Shape = 0, public int Type;
Skin = 1, public UUID ItemID;
Hair = 2, public UUID AssetID;
Eyes = 3,
Shirt = 4, public ClothesAttachment(int type, UUID itemID, UUID assetID)
Pants = 5, {
Shoes = 6, Type = type;
Socks = 7, ItemID = itemID;
Jacket = 8, AssetID = assetID;
Gloves = 9, }
Undershirt = 10, }
Underpants = 11,
Skirt = 12,
} }
} }