From 6e58c3d563b50c5797d1cfffbaec3fe82f18c2ea Mon Sep 17 00:00:00 2001
From: Master ScienceSim
Date: Mon, 25 Oct 2010 14:11:47 -0700
Subject: Half of the compatibility is working. Login into a new region with
 old data works. Teleport out of a new region with old data works. Teleport
 into a new region with old data does not trigger the necessary rebake.

---
 OpenSim/Framework/AgentCircuitData.cs              | 13 ++++-----
 OpenSim/Framework/AvatarAppearance.cs              |  2 +-
 OpenSim/Framework/ChildAgentDataUpdate.cs          | 33 ++++++++++++++--------
 .../Avatar/AvatarFactory/AvatarFactoryModule.cs    |  2 +-
 4 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/OpenSim/Framework/AgentCircuitData.cs b/OpenSim/Framework/AgentCircuitData.cs
index 30a9548..098b33c 100644
--- a/OpenSim/Framework/AgentCircuitData.cs
+++ b/OpenSim/Framework/AgentCircuitData.cs
@@ -368,15 +368,12 @@ namespace OpenSim.Framework
                 }
             }
 
-            if (args["packed_appearance"] != null)
+            if (args.ContainsKey("packed_appearance") && (args["packed_appearance"].Type == OSDType.Map))
             {
-                if (args["packed_appearance"].Type == OSDType.Map)
-                {
-                    Appearance.Unpack((OSDMap)args["packed_appearance"]);
-                    m_log.WarnFormat("[AGENTCIRCUITDATA] unpacked appearance");
-                }
-                else
-                    m_log.WarnFormat("[AGENTCIRCUITDATA] packed_appearance is not a map:\n{0}",args["packed_appearance"].ToString());
+                Appearance.Unpack((OSDMap)args["packed_appearance"]);
+// DEBUG ON
+                m_log.WarnFormat("[AGENTCIRCUITDATA] unpacked appearance");
+// DEBUG OFF
             }
 // DEBUG ON
             else
diff --git a/OpenSim/Framework/AvatarAppearance.cs b/OpenSim/Framework/AvatarAppearance.cs
index ba0cad2..05330c7 100644
--- a/OpenSim/Framework/AvatarAppearance.cs
+++ b/OpenSim/Framework/AvatarAppearance.cs
@@ -389,7 +389,7 @@ namespace OpenSim.Framework
                 changed = true;
 // DEBUG ON
                 if (newface != null)
-                    m_log.WarnFormat("[SCENEPRESENCE] index {0}, new texture id {1}",i,newface.TextureID);
+                    m_log.WarnFormat("[AVATAR APPEARANCE] index {0}, new texture id {1}",i,newface.TextureID);
 // DEBUG OFF
             }
 
diff --git a/OpenSim/Framework/ChildAgentDataUpdate.cs b/OpenSim/Framework/ChildAgentDataUpdate.cs
index d7a7d1e..215682f 100644
--- a/OpenSim/Framework/ChildAgentDataUpdate.cs
+++ b/OpenSim/Framework/ChildAgentDataUpdate.cs
@@ -390,8 +390,11 @@ namespace OpenSim.Framework
             // The code to pack textures, visuals, wearables and attachments
             // should be removed; packed appearance contains the full appearance
             // This is retained for backward compatibility only
-            if ((Appearance.Texture != null) && (Appearance.Texture.Length > 0))
-                args["texture_entry"] = OSD.FromBinary(Appearance.Texture);
+            if (Appearance.Texture != null)
+            {
+                byte[] rawtextures = Appearance.Texture.GetBytes();
+                args["texture_entry"] = OSD.FromBinary(rawtextures);
+            }
 
             if ((Appearance.VisualParams != null) && (Appearance.VisualParams.Length > 0))
                 args["visual_params"] = OSD.FromBinary(Appearance.VisualParams);
@@ -408,10 +411,10 @@ namespace OpenSim.Framework
                 args["wearables"] = wears;
             }
 
-            List<AvatarAttachments> attachments = Appearance.GetAttachments();
-            if ((attachments != null) && (attachments.Length > 0))
+            List<AvatarAttachment> attachments = Appearance.GetAttachments();
+            if ((attachments != null) && (attachments.Count > 0))
             {
-                OSDArray attachs = new OSDArray(attachments.Length);
+                OSDArray attachs = new OSDArray(attachments.Count);
                 foreach (AvatarAttachment att in attachments)
                     attachs.Add(att.Pack());
                 args["attachments"] = attachs;
@@ -560,7 +563,11 @@ namespace OpenSim.Framework
             // should be removed; packed appearance contains the full appearance
             // This is retained for backward compatibility only
             if (args["texture_entry"] != null)
-                Appearance.SetTextureEntries(args["texture_entry"].AsBinary());
+            {
+                byte[] rawtextures = args["texture_entry"].AsBinary();
+                Primitive.TextureEntry textures = new Primitive.TextureEntry(rawtextures,0,rawtextures.Length);
+                Appearance.SetTextureEntries(textures);
+            }
 
             if (args["visual_params"] != null)
                 Appearance.SetVisualParams(args["visual_params"].AsBinary());
@@ -578,21 +585,25 @@ namespace OpenSim.Framework
             if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array)
             {
                 OSDArray attachs = (OSDArray)(args["attachments"]);
-                AvatarAttachment[] attachments = new AvatarAttachment[attachs.Count];
-                int i = 0;
                 foreach (OSD o in attachs)
                 {
                     if (o.Type == OSDType.Map)
                     {
-                        attachments[i++] = new AvatarAttachment((OSDMap)o);
+                        // We know all of these must end up as attachments so we
+                        // append rather than replace to ensure multiple attachments
+                        // per point continues to work
+                        Appearance.AppendAttachment(new AvatarAttachment((OSDMap)o));
                     }
                 }
-                Appearance.SetAttachments(attachments);
             }
             // end of code to remove
 
-            if (args["packed_appearance"] != null)
+            if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
                 Appearance = new AvatarAppearance(AgentID,(OSDMap)args["packed_appearance"]);
+// DEBUG ON
+            else
+                System.Console.WriteLine("No packed appearance in AgentUpdate");
+// DEBUG OFF
 
             if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
             {
diff --git a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs
index 9f7ff7f..b74cdc9 100644
--- a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs
@@ -136,7 +136,7 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
                     {
                         if (m_scene.AssetService.Get(face.TextureID.ToString()) == null)
                         {
-                            m_log.WarnFormat("[AVFACTORY]: Missing baked texture {0} ({1}) for avatar {2}",face.TextureID,j,this.Name);
+                            m_log.WarnFormat("[AVFACTORY]: Missing baked texture {0} ({1}) for avatar {2}",face.TextureID,j,client.Name);
                             client.SendRebakeAvatarTextures(face.TextureID);
                         }
                     }
-- 
cgit v1.1