llavatarproperties.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /**
  2. * @file llavatarproperties.h
  3. * @brief Class for requesting and storing avatar properties.
  4. *
  5. * $LicenseInfo:firstyear=2004&license=viewergpl$
  6. *
  7. * Copyright (c) 2004-2022, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLAVATARPROPERTIES_H
  33. #define LL_LLAVATARPROPERTIES_H
  34. #include <list>
  35. #include <map>
  36. #include <utility>
  37. #include "hbfastmap.h"
  38. #include "hbfastset.h"
  39. #include "lluuid.h"
  40. #include "llvector3d.h"
  41. class LLMessageSystem;
  42. struct LLGroupData;
  43. struct LLAvatarInfo
  44. {
  45. LLUUID mAvatarId;
  46. LLUUID mImageId;
  47. LLUUID mFLImageId;
  48. LLUUID mPartnerId;
  49. std::string mBirthDate;
  50. std::string mAbout;
  51. std::string mFLAbout;
  52. std::string mProfileUrl;
  53. std::string mCaptionText;
  54. U32 mFlags;
  55. U8 mCaptionIndex;
  56. bool mAllowPublish;
  57. bool mReceivedViaCap;
  58. };
  59. struct LLAvatarGroups
  60. {
  61. LLUUID mAvatarId;
  62. typedef std::list<LLGroupData> list_t;
  63. list_t mGroups;
  64. };
  65. struct LLAvatarInterests
  66. {
  67. LLUUID mAvatarId;
  68. std::string mLanguages;
  69. std::string mWantsText;
  70. std::string mSkillsText;
  71. U32 mWantsMask;
  72. U32 mSkillsMask;
  73. };
  74. struct LLAvatarPicks
  75. {
  76. LLUUID mAvatarId;
  77. // Picks UUID to name map.
  78. typedef fast_hmap<LLUUID, std::string> map_t;
  79. map_t mMap;
  80. bool mReceivedViaCap;
  81. };
  82. struct LLAvatarPickInfo
  83. {
  84. LLUUID mAvatarId;
  85. LLUUID mPickId;
  86. LLUUID mSnapshotId;
  87. LLUUID mParcelId;
  88. std::string mName;
  89. std::string mDesc;
  90. std::string mUserName;
  91. std::string mSimName;
  92. std::string mParcelName;
  93. LLVector3d mPosGlobal;
  94. S32 mSortOrder;
  95. bool mTopPick;
  96. bool mEnabled;
  97. };
  98. struct LLAvatarClassifieds
  99. {
  100. LLUUID mAvatarId;
  101. // Classifed UUID to name map.
  102. typedef fast_hmap<LLUUID, std::string> map_t;
  103. map_t mMap;
  104. };
  105. struct LLAvatarClassifiedInfo
  106. {
  107. LLUUID mAvatarId;
  108. LLUUID mClassifiedId;
  109. LLUUID mSnapshotId;
  110. LLUUID mParcelId;
  111. std::string mName;
  112. std::string mDesc;
  113. std::string mSimName;
  114. std::string mParcelName;
  115. LLVector3d mPosGlobal;
  116. U32 mParentEstate;
  117. S32 mListingPrice;
  118. U32 mCreationDate;
  119. U32 mExpirationDate;
  120. U32 mCategory;
  121. U8 mFlags;
  122. };
  123. struct LLAvatarNotes
  124. {
  125. LLUUID mAvatarId;
  126. std::string mNotes;
  127. bool mReceivedViaCap;
  128. };
  129. enum EAvatarPropertiesReplyFlags
  130. {
  131. // Whether profile is externally visible or not
  132. AVATAR_ALLOW_PUBLISH = 0x1 << 0,
  133. // Whether profile is "mature" (not used)
  134. AVATAR_MATURE_PUBLISH = 0x1 << 1,
  135. // Whether avatar has provided payment info
  136. AVATAR_IDENTIFIED = 0x1 << 2,
  137. // Whether avatar has actively used payment info
  138. AVATAR_TRANSACTED = 0x1 << 3,
  139. // The online status of this avatar, if known.
  140. AVATAR_ONLINE = 0x1 << 4,
  141. // Whether avatar has been age-verified: not currently reported by
  142. // servers for privacy considerations.
  143. AVATAR_AGEVERIFIED = 0x1 << 5,
  144. };
  145. enum EAvatarPropertiesUpdateType
  146. {
  147. APT_ALL = -1, // Use to observe all types.
  148. APT_NONE = 0, // Use to disable the observer without removing it.
  149. APT_AVATAR_INFO,
  150. APT_GROUPS, // } Types requested via send_generic_message():
  151. APT_PICKS, // } they must be kept in this order or the
  152. APT_CLASSIFIEDS, // } sendGenericRequest() method would need
  153. APT_NOTES, // } modifications. HB
  154. APT_INTERESTS,
  155. APT_PICK_INFO,
  156. APT_CLASSIFIED_INFO,
  157. };
  158. // Observer class to register to properties updates from server for a given
  159. // avatar (or all avatars, when passed a null UUID) and a given type (or all
  160. // types when omitted).
  161. class LLAvatarPropertiesObserver
  162. {
  163. public:
  164. LL_INLINE LLAvatarPropertiesObserver(const LLUUID& id, S32 type = APT_ALL)
  165. : mObservedAvatarId(id),
  166. mObservedUpdate(type)
  167. {
  168. }
  169. virtual ~LLAvatarPropertiesObserver() = default;
  170. virtual void processProperties(S32 type, void* data) = 0;
  171. LL_INLINE const LLUUID& getAvatarId() const
  172. {
  173. return mObservedAvatarId;
  174. }
  175. LL_INLINE S32 getUpdateType() const
  176. {
  177. return mObservedUpdate;
  178. }
  179. protected:
  180. LL_INLINE void setObservedAvatarId(const LLUUID& av_id)
  181. {
  182. mObservedAvatarId = av_id;
  183. }
  184. LL_INLINE void setObservedUpdateType(S32 type)
  185. {
  186. mObservedUpdate = type;
  187. }
  188. private:
  189. LLUUID mObservedAvatarId;
  190. S32 mObservedUpdate;
  191. };
  192. // Purely static class (a singleton in LL's code, because they like making it
  193. // pointlessly slow and complex). HB
  194. class LLAvatarProperties
  195. {
  196. protected:
  197. LOG_CLASS(LLAvatarProperties);
  198. public:
  199. LLAvatarProperties() = delete;
  200. ~LLAvatarProperties() = delete;
  201. LL_INLINE static void addObserver(LLAvatarPropertiesObserver* observerp)
  202. {
  203. if (observerp)
  204. {
  205. sObservers.insert(observerp);
  206. }
  207. }
  208. LL_INLINE static void removeObserver(LLAvatarPropertiesObserver* observerp)
  209. {
  210. sObservers.erase(observerp);
  211. }
  212. // The following two methods request various types of avatar data.
  213. // Duplicate requests are suppressed while waiting for a response from the
  214. // server.
  215. // The only allowed types for this method are APT_AVATAR_INFO, APT_GROUPS,
  216. // APT_PICKS, APT_CLASSIFIEDS and APT_NOTES: any other type would trigger a
  217. // llerrs !
  218. // For all but APT_CLASSIFIEDS requests, this method may use the new
  219. // "AgentProfile" capabilities, if available and the corresponding debug
  220. // setting ("UseAgentProfileCap") is set to TRUE. HB
  221. static void sendGenericRequest(const LLUUID& avatar_id, S32 type);
  222. // Method to request APT_AVATAR_INFO info via UDP messaging; which
  223. // imposes a limit on the SL/FL About text fields size, but also requests
  224. // the avatar interests data (which the capability does not provide). HB
  225. static void sendAvatarPropertiesRequest(const LLUUID& avatar_id);
  226. // Pick and classified detailed info requests (not tracked for duplicates).
  227. static void sendPickInfoRequest(const LLUUID& avatar_id,
  228. const LLUUID& pick_id);
  229. static void sendClassifiedInfoRequest(const LLUUID& classified_id);
  230. // These method send updates to our agent's data.
  231. static void sendAvatarPropertiesUpdate(const LLAvatarInfo& data);
  232. static void sendInterestsInfoUpdate(const LLAvatarInterests& data);
  233. static void sendPickInfoUpdate(const LLAvatarPickInfo& data);
  234. static void sendPickDelete(const LLUUID& avatar_id, const LLUUID& pick_id);
  235. static void sendClassifiedInfoUpdate(const LLAvatarClassifiedInfo& data);
  236. static void sendClassifiedDelete(const LLUUID& classified_id);
  237. static void sendAvatarNotesUpdate(const LLUUID& avatar_id,
  238. const std::string& notes);
  239. // These are callback methods for server replies, wired to the messaging
  240. // system in llstartup.cpp.
  241. static void processAvatarPropertiesReply(LLMessageSystem* msg, void**);
  242. static void processAvatarGroupsReply(LLMessageSystem* msg, void**);
  243. static void processAvatarInterestsReply(LLMessageSystem* msg, void**);
  244. static void processAvatarPicksReply(LLMessageSystem* msg, void**);
  245. static void processPickInfoReply(LLMessageSystem* msg, void**);
  246. static void processAvatarClassifiedReply(LLMessageSystem* msg, void**);
  247. static void processClassifiedInfoReply(LLMessageSystem* msg, void**);
  248. static void processAvatarNotesReply(LLMessageSystem* msg, void**);
  249. private:
  250. static void requestAvatarPropertiesCoro(LLUUID avatar_id,
  251. const std::string& cap_url);
  252. static void sendAvatarPropertiesUpdateCoro(LLSD data,
  253. const std::string& cap_url);
  254. static void notifyObservers(const LLUUID& id, S32 type, void* data);
  255. static void addPendingRequest(const LLUUID& id, S32 type);
  256. static void removePendingRequest(const LLUUID& id, S32 type);
  257. static bool isPendingRequest(const LLUUID& id, S32 type);
  258. private:
  259. typedef fast_hset<LLAvatarPropertiesObserver*> observers_set_t;
  260. static observers_set_t sObservers;
  261. // Keeps track of pending requests for data by avatar Id and type,
  262. // storing a timestamp for each request. Maps avatar_id+request_type to
  263. // an F32 timestamp in seconds.
  264. typedef std::map<std::pair<LLUUID, U32>, F32> pending_map_t;
  265. static pending_map_t sPendingRequests;
  266. };
  267. #endif // LL_LLAVATARPROPERTIES_H