From 1875d5e37ba1591ba9b75014a7618f38427f0d2f Mon Sep 17 00:00:00 2001
From: "Nyx (Neal Orman)" <nyx@lindenlab.com>
Date: Wed, 18 Nov 2009 14:48:05 -0500
Subject: [PATCH] EXT-2539 confirm we're not sending local texture IDs in
 appearance msg

created a throwaway function to temporarily set local texture IDs in the avatar
object to IMG_DEFAULT_AVATAR immediately before sending the TE message, and
restore the IDs when we're done. Will implement a more elegant solution for 2.1.
This is the least risky implementation, though it isn't elegant.

Code reviewed by Seraph
---
 indra/newview/llagent.cpp        |  2 +-
 indra/newview/llvoavatar.cpp     |  2 +-
 indra/newview/llvoavatar.h       |  2 +-
 indra/newview/llvoavatarself.cpp | 43 ++++++++++++++++++++++++++++++++
 indra/newview/llvoavatarself.h   |  1 +
 5 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp
index 7a540a45c4c..fb2ecb3bede 100644
--- a/indra/newview/llagent.cpp
+++ b/indra/newview/llagent.cpp
@@ -6326,7 +6326,7 @@ void LLAgent::sendAgentSetAppearance()
 			msg->addU8Fast(_PREHASH_TextureIndex, (U8)texture_index);
 		}
 		msg->nextBlockFast(_PREHASH_ObjectData);
-		mAvatarObject->packTEMessage( gMessageSystem );
+		mAvatarObject->sendAppearanceMessage( gMessageSystem );
 	}
 	else
 	{
diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index b6c1ee2f117..75e35e52214 100644
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -6267,7 +6267,7 @@ LLColor4 LLVOAvatar::getDummyColor()
 	return DUMMY_COLOR;
 }
 
-void LLVOAvatar::dumpAvatarTEs( const std::string& context )
+void LLVOAvatar::dumpAvatarTEs( const std::string& context ) const
 {	
 	/* const char* te_name[] = {
 			"TEX_HEAD_BODYPAINT   ",
diff --git a/indra/newview/llvoavatar.h b/indra/newview/llvoavatar.h
index 2fd1a506a90..4b3e850e7ac 100644
--- a/indra/newview/llvoavatar.h
+++ b/indra/newview/llvoavatar.h
@@ -889,7 +889,7 @@ class LLVOAvatar :
 	static void			dumpArchetypeXML(void*);
 	static void			dumpBakedStatus();
 	const std::string 	getBakedStatusForPrintout() const;
-	void				dumpAvatarTEs(const std::string& context);
+	void				dumpAvatarTEs(const std::string& context) const;
 
 	static F32 			sUnbakedTime; // Total seconds with >=1 unbaked avatars
 	static F32 			sUnbakedUpdateTime; // Last time stats were updated (to prevent multiple updates per frame) 
diff --git a/indra/newview/llvoavatarself.cpp b/indra/newview/llvoavatarself.cpp
index 711e9f90fcc..d9c5e932a26 100644
--- a/indra/newview/llvoavatarself.cpp
+++ b/indra/newview/llvoavatarself.cpp
@@ -2074,6 +2074,49 @@ void LLVOAvatarSelf::setInvisible(BOOL newvalue)
 	}
 }
 
+// HACK: this will null out the avatar's local texture IDs before the TE message is sent
+//       to ensure local texture IDs are not sent to other clients in the area.
+//       this is a short-term solution. The long term solution will be to not set the texture
+//       IDs in the avatar object, and keep them only in the wearable.
+//       This will involve further refactoring that is too risky for the initial release of 2.0.
+bool LLVOAvatarSelf::sendAppearanceMessage(LLMessageSystem *mesgsys) const
+{
+	LLUUID texture_id[TEX_NUM_INDICES];
+	// pack away current TEs to make sure we don't send them out
+	for (LLVOAvatarDictionary::Textures::const_iterator iter = LLVOAvatarDictionary::getInstance()->getTextures().begin();
+		 iter != LLVOAvatarDictionary::getInstance()->getTextures().end();
+		 ++iter)
+	{
+		const ETextureIndex index = iter->first;
+		const LLVOAvatarDictionary::TextureEntry *texture_dict = iter->second;
+		if (!texture_dict->mIsBakedTexture)
+		{
+			LLTextureEntry* entry = getTE((U8) index);
+			texture_id[index] = entry->getID();
+			entry->setID(IMG_DEFAULT_AVATAR);
+		}
+	}
+
+	bool success = packTEMessage(mesgsys);
+
+	// unpack TEs to make sure we don't re-trigger a bake
+	for (LLVOAvatarDictionary::Textures::const_iterator iter = LLVOAvatarDictionary::getInstance()->getTextures().begin();
+		 iter != LLVOAvatarDictionary::getInstance()->getTextures().end();
+		 ++iter)
+	{
+		const ETextureIndex index = iter->first;
+		const LLVOAvatarDictionary::TextureEntry *texture_dict = iter->second;
+		if (!texture_dict->mIsBakedTexture)
+		{
+			LLTextureEntry* entry = getTE((U8) index);
+			entry->setID(texture_id[index]);
+		}
+	}
+
+	return success;
+}
+
+
 //------------------------------------------------------------------------
 // needsRenderBeam()
 //------------------------------------------------------------------------
diff --git a/indra/newview/llvoavatarself.h b/indra/newview/llvoavatarself.h
index 6702f030feb..a1cad82effa 100644
--- a/indra/newview/llvoavatarself.h
+++ b/indra/newview/llvoavatarself.h
@@ -310,6 +310,7 @@ class LLVOAvatarSelf :
 public:
 	static void		onChangeSelfInvisible(BOOL newvalue);
 	void			setInvisible(BOOL newvalue);
+	bool			sendAppearanceMessage(LLMessageSystem *mesgsys) const;
 
 /**                    Appearance
  **                                                                            **
-- 
GitLab