From e98d8d500f5c0dda6e9ef8b9a0e1bddec8510d1d Mon Sep 17 00:00:00 2001 From: Melanie Date: Sat, 30 Oct 2010 19:06:47 +0100 Subject: [PATCH] Fix logins and avatar appearance. Contains a Migration. May contain nuts. This will cause visual params to be persisted along with worn items. With this, alpha and tattoo laters will be saved. Multiple layers MAY work, but not tested because I don't use Viewer 2. --- .../Data/MySQL/Resources/Avatar.migrations | 8 ++ OpenSim/Framework/AvatarAppearance.cs | 40 +++++-- OpenSim/Framework/AvatarWearable.cs | 34 ++++-- .../ClientStack/LindenUDP/LLClientView.cs | 1 + .../AvatarFactory/AvatarFactoryModule.cs | 15 ++- OpenSim/Services/Interfaces/IAvatarService.cs | 103 +++++++++++++----- .../BodyPartsLibraryItems.xml | 28 ----- 7 files changed, 153 insertions(+), 76 deletions(-) diff --git a/OpenSim/Data/MySQL/Resources/Avatar.migrations b/OpenSim/Data/MySQL/Resources/Avatar.migrations index 8d0eee68a1..f7cf1766fc 100644 --- a/OpenSim/Data/MySQL/Resources/Avatar.migrations +++ b/OpenSim/Data/MySQL/Resources/Avatar.migrations @@ -10,3 +10,11 @@ CREATE TABLE Avatars ( KEY(PrincipalID)); COMMIT; + +:VERSION 2 + +BEGIN; + +alter table Avatars change column Value Value text; + +COMMIT; diff --git a/OpenSim/Framework/AvatarAppearance.cs b/OpenSim/Framework/AvatarAppearance.cs index f0d83359ec..d0a22b23b9 100644 --- a/OpenSim/Framework/AvatarAppearance.cs +++ b/OpenSim/Framework/AvatarAppearance.cs @@ -150,7 +150,11 @@ namespace OpenSim.Framework m_attachments = new Dictionary>(); } - public AvatarAppearance(AvatarAppearance appearance) + public AvatarAppearance(AvatarAppearance appearance) : this(appearance, true) + { + } + + public AvatarAppearance(AvatarAppearance appearance, bool copyWearables) { // m_log.WarnFormat("[AVATAR APPEARANCE] create from an existing appearance"); @@ -175,7 +179,7 @@ namespace OpenSim.Framework m_wearables = new AvatarWearable[AvatarWearable.MAX_WEARABLES]; for (int i = 0 ; i < AvatarWearable.MAX_WEARABLES ; i++ ) m_wearables[i] = new AvatarWearable(); - if (appearance.Wearables != null) + if (copyWearables && (appearance.Wearables != null)) { for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++) SetWearable(i,appearance.Wearables[i]); @@ -198,6 +202,28 @@ namespace OpenSim.Framework AppendAttachment(new AvatarAttachment(attachment)); } + public void GetAssetsFrom(AvatarAppearance app) + { + for (int i = 0 ; i < AvatarWearable.MAX_WEARABLES ; i++ ) + { + for (int j = 0 ; j < m_wearables[i].Count ; j++) + { + UUID itemID = m_wearables[i][j].ItemID; + UUID assetID = app.Wearables[i].GetAsset(itemID); + + if (assetID != UUID.Zero) + m_wearables[i].Add(itemID, assetID); + } + } + } + + public void ClearWearables() + { + m_wearables = new AvatarWearable[AvatarWearable.MAX_WEARABLES]; + for (int i = 0 ; i < AvatarWearable.MAX_WEARABLES ; i++ ) + m_wearables[i] = new AvatarWearable(); + } + protected virtual void SetDefaultWearables() { m_wearables = AvatarWearable.DefaultWearables; @@ -205,11 +231,11 @@ namespace OpenSim.Framework protected virtual void SetDefaultParams() { - m_visualparams = new byte[VISUALPARAM_COUNT]; - for (int i = 0; i < VISUALPARAM_COUNT; i++) - { - m_visualparams[i] = 150; - } + m_visualparams = new byte[] { 56,23,66,0,0,25,0,124,107,0,0,91,137,36,180,79,78,20,32,255,0,63,137,137,63,122,0,71,127,94,63,0,150,150,150,17,0,0,0,0,0,127,0,0,255,127,114,127,99,63,127,140,127,127,0,0,0,191,0,78,0,0,0,0,0,0,0,0,0,145,216,133,0,0,0,219,107,150,150,165,135,0,150,150,150,63,112,155,150,150,150,150,150,150,150,150,150,150,150,0,0,0,0,188,255,91,219,124,0,150,127,165,127,127,127,127,59,63,107,71,68,89,33,79,114,178,127,2,141,66,0,0,127,127,0,0,0,0,127,0,159,0,0,178,127,0,85,131,117,127,147,163,104,0,140,18,0,107,130,0,150,150,198,0,0,40,38,91,165,209,198,127,127,153,204,51,51,150,150,255,204,0,150,150,150,150,150,150,150,150,150,150,150,0,150,150,150,150,150,0,127,22,150,150,150,150,150,150,150,150,0,0,150,51,132,150,150,150 }; +// for (int i = 0; i < VISUALPARAM_COUNT; i++) +// { +// m_visualparams[i] = 150; +// } } protected virtual void SetDefaultTexture() diff --git a/OpenSim/Framework/AvatarWearable.cs b/OpenSim/Framework/AvatarWearable.cs index 0a02dcfc46..efec50b71f 100644 --- a/OpenSim/Framework/AvatarWearable.cs +++ b/OpenSim/Framework/AvatarWearable.cs @@ -82,12 +82,13 @@ namespace OpenSim.Framework public static readonly UUID DEFAULT_PANTS_ITEM = new UUID("77c41e39-38f9-f75a-0000-5859892f1111"); public static readonly UUID DEFAULT_PANTS_ASSET = new UUID("00000000-38f9-1111-024e-222222111120"); - public static readonly UUID DEFAULT_ALPHA_ITEM = new UUID("bfb9923c-4838-4d2d-bf07-608c5b1165c8"); - public static readonly UUID DEFAULT_ALPHA_ASSET = new UUID("1578a2b1-5179-4b53-b618-fe00ca5a5594"); +// public static readonly UUID DEFAULT_ALPHA_ITEM = new UUID("bfb9923c-4838-4d2d-bf07-608c5b1165c8"); +// public static readonly UUID DEFAULT_ALPHA_ASSET = new UUID("1578a2b1-5179-4b53-b618-fe00ca5a5594"); - public static readonly UUID DEFAULT_TATTOO_ITEM = new UUID("c47e22bd-3021-4ba4-82aa-2b5cb34d35e1"); - public static readonly UUID DEFAULT_TATTOO_ASSET = new UUID("00000000-0000-2222-3333-100000001007"); +// public static readonly UUID DEFAULT_TATTOO_ITEM = new UUID("c47e22bd-3021-4ba4-82aa-2b5cb34d35e1"); +// public static readonly UUID DEFAULT_TATTOO_ASSET = new UUID("00000000-0000-2222-3333-100000001007"); + private static AvatarWearable[] defaultWearables = null; protected Dictionary m_items = new Dictionary(); protected List m_ids = new List(); @@ -152,6 +153,11 @@ namespace OpenSim.Framework m_items[itemID] = assetID; } + public void Wear(WearableItem item) + { + Wear(item.ItemID, item.AssetID); + } + public void Wear(UUID itemID, UUID assetID) { Clear(); @@ -204,11 +210,21 @@ namespace OpenSim.Framework } } + public UUID GetAsset(UUID itemID) + { + if (!m_items.ContainsKey(itemID)) + return UUID.Zero; + return m_items[itemID]; + } + public static AvatarWearable[] DefaultWearables { get { - AvatarWearable[] defaultWearables = new AvatarWearable[MAX_WEARABLES]; //should be 15 of these + if (defaultWearables != null) + return defaultWearables; + + defaultWearables = new AvatarWearable[MAX_WEARABLES]; //should be 15 of these for (int i = 0; i < MAX_WEARABLES; i++) { defaultWearables[i] = new AvatarWearable(); @@ -229,11 +245,11 @@ namespace OpenSim.Framework // Pants defaultWearables[PANTS].Add(DEFAULT_PANTS_ITEM, DEFAULT_PANTS_ASSET); - // Alpha - defaultWearables[ALPHA].Add(DEFAULT_ALPHA_ITEM, DEFAULT_ALPHA_ASSET); +// // Alpha +// defaultWearables[ALPHA].Add(DEFAULT_ALPHA_ITEM, DEFAULT_ALPHA_ASSET); - // Tattoo - defaultWearables[TATTOO].Add(DEFAULT_TATTOO_ITEM, DEFAULT_TATTOO_ASSET); +// // Tattoo +// defaultWearables[TATTOO].Add(DEFAULT_TATTOO_ITEM, DEFAULT_TATTOO_ASSET); return defaultWearables; } diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index d7458b7bce..4aa19d1009 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -5734,6 +5734,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP AvatarWearingArgs wearingArgs = new AvatarWearingArgs(); for (int i = 0; i < nowWearing.WearableData.Length; i++) { + m_log.DebugFormat("[XXX]: Wearable type {0} item {1}", nowWearing.WearableData[i].WearableType, nowWearing.WearableData[i].ItemID); AvatarWearingArgs.Wearable wearable = new AvatarWearingArgs.Wearable(nowWearing.WearableData[i].ItemID, nowWearing.WearableData[i].WearableType); diff --git a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs index 6cbd8bdf58..7f482cb890 100644 --- a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs @@ -356,17 +356,16 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory // m_log.WarnFormat("[AVATAR FACTORY MODULE]: AvatarIsWearing called for {0}",client.AgentId); - AvatarAppearance avatAppearance = new AvatarAppearance(sp.Appearance); + AvatarAppearance avatAppearance = new AvatarAppearance(sp.Appearance, false); foreach (AvatarWearingArgs.Wearable wear in e.NowWearing) { if (wear.Type < AvatarWearable.MAX_WEARABLES) - { - AvatarWearable newWearable = new AvatarWearable(wear.ItemID,UUID.Zero); - avatAppearance.SetWearable(wear.Type, newWearable); - } + avatAppearance.Wearables[wear.Type].Add(wear.ItemID,UUID.Zero); } + avatAppearance.GetAssetsFrom(sp.Appearance); + // This could take awhile since it needs to pull inventory SetAppearanceAssets(sp.UUID, ref avatAppearance); @@ -384,6 +383,12 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory { for (int j = 0 ; j < appearance.Wearables[j].Count ; j ++ ) { + if (appearance.Wearables[i][j].ItemID == UUID.Zero) + continue; + + // Ignore ruth's assets + if (appearance.Wearables[i][j].ItemID == AvatarWearable.DefaultWearables[i][0].ItemID) + continue; InventoryItemBase baseItem = new InventoryItemBase(appearance.Wearables[i][j].ItemID, userID); baseItem = invService.GetItem(baseItem); diff --git a/OpenSim/Services/Interfaces/IAvatarService.cs b/OpenSim/Services/Interfaces/IAvatarService.cs index 186871a299..860a13b0c0 100644 --- a/OpenSim/Services/Interfaces/IAvatarService.cs +++ b/OpenSim/Services/Interfaces/IAvatarService.cs @@ -149,33 +149,28 @@ namespace OpenSim.Services.Interfaces Data["Serial"] = appearance.Serial.ToString(); // Wearables Data["AvatarHeight"] = appearance.AvatarHeight.ToString(); - Data["BodyItem"] = appearance.Wearables[AvatarWearable.BODY][0].ItemID.ToString(); - Data["EyesItem"] = appearance.Wearables[AvatarWearable.EYES][0].ItemID.ToString(); - Data["GlovesItem"] = appearance.Wearables[AvatarWearable.GLOVES][0].ItemID.ToString(); - Data["HairItem"] = appearance.Wearables[AvatarWearable.HAIR][0].ItemID.ToString(); - Data["JacketItem"] = appearance.Wearables[AvatarWearable.JACKET][0].ItemID.ToString(); - Data["PantsItem"] = appearance.Wearables[AvatarWearable.PANTS][0].ItemID.ToString(); - Data["ShirtItem"] = appearance.Wearables[AvatarWearable.SHIRT][0].ItemID.ToString(); - Data["ShoesItem"] = appearance.Wearables[AvatarWearable.SHOES][0].ItemID.ToString(); - Data["SkinItem"] = appearance.Wearables[AvatarWearable.SKIN][0].ItemID.ToString(); - Data["SkirtItem"] = appearance.Wearables[AvatarWearable.SKIRT][0].ItemID.ToString(); - Data["SocksItem"] = appearance.Wearables[AvatarWearable.SOCKS][0].ItemID.ToString(); - Data["UnderPantsItem"] = appearance.Wearables[AvatarWearable.UNDERPANTS][0].ItemID.ToString(); - Data["UnderShirtItem"] = appearance.Wearables[AvatarWearable.UNDERSHIRT][0].ItemID.ToString(); - Data["BodyAsset"] = appearance.Wearables[AvatarWearable.BODY][0].AssetID.ToString(); - Data["EyesAsset"] = appearance.Wearables[AvatarWearable.EYES][0].AssetID.ToString(); - Data["GlovesAsset"] = appearance.Wearables[AvatarWearable.GLOVES][0].AssetID.ToString(); - Data["HairAsset"] = appearance.Wearables[AvatarWearable.HAIR][0].AssetID.ToString(); - Data["JacketAsset"] = appearance.Wearables[AvatarWearable.JACKET][0].AssetID.ToString(); - Data["PantsAsset"] = appearance.Wearables[AvatarWearable.PANTS][0].AssetID.ToString(); - Data["ShirtAsset"] = appearance.Wearables[AvatarWearable.SHIRT][0].AssetID.ToString(); - Data["ShoesAsset"] = appearance.Wearables[AvatarWearable.SHOES][0].AssetID.ToString(); - Data["SkinAsset"] = appearance.Wearables[AvatarWearable.SKIN][0].AssetID.ToString(); - Data["SkirtAsset"] = appearance.Wearables[AvatarWearable.SKIRT][0].AssetID.ToString(); - Data["SocksAsset"] = appearance.Wearables[AvatarWearable.SOCKS][0].AssetID.ToString(); - Data["UnderPantsAsset"] = appearance.Wearables[AvatarWearable.UNDERPANTS][0].AssetID.ToString(); - Data["UnderShirtAsset"] = appearance.Wearables[AvatarWearable.UNDERSHIRT][0].AssetID.ToString(); + for (int i = 0 ; i < AvatarWearable.MAX_WEARABLES ; i++) + { + for (int j = 0 ; j < appearance.Wearables[i].Count ; j++) + { + string fieldName = String.Format("Wearable {0}:{1}", i, j); + Data[fieldName] = String.Format("{0}:{1}", + appearance.Wearables[i][j].ItemID.ToString(), + appearance.Wearables[i][j].AssetID.ToString()); + } + } + + // Visual Params + string[] vps = new string[AvatarAppearance.VISUALPARAM_COUNT]; + byte[] binary = appearance.VisualParams; + + for (int i = 0 ; i < AvatarAppearance.VISUALPARAM_COUNT ; i++) + { + vps[i] = binary[i].ToString(); + } + + Data["VisualParams"] = String.Join(",", vps); // Attachments List attachments = appearance.GetAttachments(); @@ -188,12 +183,17 @@ namespace OpenSim.Services.Interfaces public AvatarAppearance ToAvatarAppearance(UUID owner) { AvatarAppearance appearance = new AvatarAppearance(owner); + + if (Data.Count == 0) + return appearance; + + appearance.ClearWearables(); try { if (Data.ContainsKey("Serial")) appearance.Serial = Int32.Parse(Data["Serial"]); - // Wearables + // Legacy Wearables if (Data.ContainsKey("BodyItem")) appearance.Wearables[AvatarWearable.BODY].Wear( UUID.Parse(Data["BodyItem"]), @@ -260,6 +260,35 @@ namespace OpenSim.Services.Interfaces UUID.Parse(Data["SkirtAsset"])); + if (Data.ContainsKey("VisualParams")) + { + string[] vps = Data["VisualParams"].Split(new char[] {','}); + byte[] binary = new byte[AvatarAppearance.VISUALPARAM_COUNT]; + + for (int i = 0 ; i < vps.Length && i < binary.Length ; i++) + binary[i] = (byte)Convert.ToInt32(vps[i]); + + appearance.VisualParams = binary; + } + + // New style wearables + foreach (KeyValuePair _kvp in Data) + { + if (_kvp.Key.StartsWith("Wearable ")) + { + string wearIndex = _kvp.Key.Substring(9); + string[] wearIndices = wearIndex.Split(new char[] {':'}); + int index = Convert.ToInt32(wearIndices[0]); + + string[] ids = _kvp.Value.Split(new char[] {':'}); + UUID itemID = new UUID(ids[0]); + UUID assetID = new UUID(ids[1]); + + appearance.Wearables[index].Add(itemID, assetID); + } + } + + // Attachments Dictionary attchs = new Dictionary(); foreach (KeyValuePair _kvp in Data) @@ -278,6 +307,26 @@ namespace OpenSim.Services.Interfaces appearance.SetAttachment(point,uuid,UUID.Zero); } + + if (appearance.Wearables[AvatarWearable.BODY].Count == 0) + appearance.Wearables[AvatarWearable.BODY].Wear( + AvatarWearable.DefaultWearables[ + AvatarWearable.BODY][0]); + + if (appearance.Wearables[AvatarWearable.SKIN].Count == 0) + appearance.Wearables[AvatarWearable.SKIN].Wear( + AvatarWearable.DefaultWearables[ + AvatarWearable.SKIN][0]); + + if (appearance.Wearables[AvatarWearable.HAIR].Count == 0) + appearance.Wearables[AvatarWearable.HAIR].Wear( + AvatarWearable.DefaultWearables[ + AvatarWearable.HAIR][0]); + + if (appearance.Wearables[AvatarWearable.EYES].Count == 0) + appearance.Wearables[AvatarWearable.EYES].Wear( + AvatarWearable.DefaultWearables[ + AvatarWearable.EYES][0]); } catch { diff --git a/bin/inventory/BodyPartsLibrary/BodyPartsLibraryItems.xml b/bin/inventory/BodyPartsLibrary/BodyPartsLibraryItems.xml index 5cb71c0bbe..aa8d9d964b 100644 --- a/bin/inventory/BodyPartsLibrary/BodyPartsLibraryItems.xml +++ b/bin/inventory/BodyPartsLibrary/BodyPartsLibraryItems.xml @@ -16,34 +16,6 @@ -->