llmutelist.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /**
  2. * @file llmutelist.h
  3. * @brief Management of list of muted players
  4. *
  5. * $LicenseInfo:firstyear=2003&license=viewergpl$
  6. *
  7. * Copyright (c) 2003-2009, 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_MUTELIST_H
  33. #define LL_MUTELIST_H
  34. #include "boost/signals2.hpp"
  35. #include "llextendedstatus.h"
  36. #include "hbfastmap.h"
  37. #include "llstring.h"
  38. #include "lluuid.h"
  39. class LLMessageSystem;
  40. class LLMuteListObserver;
  41. class LLViewerObject;
  42. // An entry in the mute list.
  43. class LLMute
  44. {
  45. public:
  46. // Legacy mutes are BY_NAME and have null UUID.
  47. enum EType { BY_NAME = 0, AGENT = 1, OBJECT = 2, GROUP = 3, COUNT = 4 };
  48. // Bits in the mute flags. For backwards compatibility (since any mute list
  49. // entries that were created before the flags existed will have a flags
  50. // field of 0), the flags are "inverted" in the stored mute entry.
  51. // Note that it's possible, through flags, to completely disable an entry in
  52. // the mute list.
  53. // *TODO (?): consider adding partial mute flags for inventory offers,
  54. // script dialogs, Av rendering, TP offers, etc and then restore the
  55. // equivalence of flagAll = full mute ?
  56. enum
  57. {
  58. flagTextChat = 0x00000001, // If set do not mute text chat
  59. flagVoiceChat = 0x00000002, // If set do not mute voice chat
  60. flagParticles = 0x00000004, // If set do not mute particles
  61. flagObjectSounds = 0x00000008, // If set mute object sounds
  62. flagAll = 0x0000000F, // Mask of all defined flags
  63. flagPartialMute = 0x00000010 // Set when any of the above flags
  64. // is in use to differenciate
  65. // partial mutes from full mutes
  66. // and especially when an entry got
  67. // all partial mute flags set
  68. // (which is still not a full mute
  69. // but would appear as one in the
  70. // stored mask without
  71. // flagPartialMute).
  72. };
  73. static char CHAT_SUFFIX[];
  74. static char VOICE_SUFFIX[];
  75. static char PARTICLES_SUFFIX[];
  76. static char SOUNDS_SUFFIX[];
  77. static char BY_NAME_SUFFIX[];
  78. static char AGENT_SUFFIX[];
  79. static char OBJECT_SUFFIX[];
  80. static char GROUP_SUFFIX[];
  81. LLMute(const LLUUID& id, const std::string& name = std::string(),
  82. EType type = BY_NAME, U32 flags = 0);
  83. // Returns name + suffix based on type
  84. // For example: "James Tester (resident)"
  85. std::string getNameAndType() const;
  86. // Converts an entry name in the UI scroll list into just the agent or
  87. // object name. For example: "James Tester (resident)" sets the name to
  88. // "James Tester" and the type to AGENT.
  89. void setFromDisplayName(const std::string& entry_name);
  90. public:
  91. LLUUID mID; // agent or object id
  92. std::string mName; // agent or object name
  93. EType mType; // needed for UI display of existing mutes
  94. U32 mFlags; // flags pertaining to this mute entry
  95. };
  96. // Purely static class
  97. class LLMuteList
  98. {
  99. friend class LLDispatchEmptyMuteList;
  100. LLMuteList() = delete;
  101. ~LLMuteList() = delete;
  102. protected:
  103. LOG_CLASS(LLMuteList);
  104. public:
  105. // reasons for auto-unmuting a resident
  106. enum EAutoReason
  107. {
  108. AR_IM = 0, // agent IMed a muted resident
  109. AR_MONEY = 1, // agent paid L$ to a muted resident
  110. AR_INVENTORY = 2, // agent offered inventory to a muted resident
  111. AR_COUNT // enum count
  112. };
  113. static void initClass();
  114. static void shutDownClass();
  115. static void addObserver(LLMuteListObserver* observer);
  116. static void removeObserver(LLMuteListObserver* observer);
  117. // Add either a normal or a BY_NAME mute, for any or all properties.
  118. static bool add(const LLMute& mute, U32 flags = 0);
  119. // Remove both normal and legacy mutes, for any or all properties.
  120. static bool remove(const LLMute& mute, U32 flags = 0);
  121. static bool autoRemove(const LLUUID& agent_id,
  122. const EAutoReason reason,
  123. const std::string& first_name = LLStringUtil::null,
  124. const std::string& last_name = LLStringUtil::null);
  125. // Name is required to test against legacy text-only mutes.
  126. static bool isMuted(const LLUUID& id,
  127. const std::string& name = LLStringUtil::null,
  128. U32 flags = 0,
  129. LLMute::EType type = LLMute::COUNT);
  130. // Alternate (convenience) form for places we do not need to pass the name,
  131. // but do need flags
  132. LL_INLINE static bool isMuted(const LLUUID& id, U32 flags)
  133. {
  134. return isMuted(id, LLStringUtil::null, flags);
  135. }
  136. static S32 getMuteFlags(const LLUUID& id, std::string& description);
  137. static bool isLinden(const std::string& name);
  138. static LL_INLINE bool isLoaded() { return sIsLoaded; }
  139. static std::vector<LLMute> getMutes();
  140. // request the mute list
  141. static void requestFromServer();
  142. // call this method on logout to save everything.
  143. static void cache(bool force = false);
  144. static void setSavedResidentVolume(const LLUUID& id, F32 volume);
  145. static F32 getSavedResidentVolume(const LLUUID& id);
  146. private:
  147. static void loadUserVolumes();
  148. static void loadPerAccountMuteList();
  149. static void savePerAccountMuteList();
  150. static bool loadFromFile(const std::string& filename);
  151. static bool saveToFile(const std::string& filename);
  152. static void setLoaded();
  153. static void notifyObservers();
  154. static void onRegionBoundaryCrossed();
  155. static void getGodsNames();
  156. static void updateAdd(const LLMute& mute);
  157. static void updateRemove(const LLMute& mute);
  158. static std::string getCachedMuteFilename();
  159. static void processMuteListUpdate(LLMessageSystem* msg, void**);
  160. static void processUseCachedMuteList(LLMessageSystem* msg, void**);
  161. static void onFileMuteList(void** user_data, S32 code,
  162. LLExtStat ext_status);
  163. struct compare_by_name
  164. {
  165. LL_INLINE bool operator()(const LLMute& a, const LLMute& b) const
  166. {
  167. return a.mName < b.mName;
  168. }
  169. };
  170. struct compare_by_id
  171. {
  172. LL_INLINE bool operator()(const LLMute& a, const LLMute& b) const
  173. {
  174. return a.mID < b.mID;
  175. }
  176. };
  177. private:
  178. static bool sIsLoaded;
  179. static bool sUserVolumesLoaded;
  180. static boost::signals2::connection sRegionBoundaryCrossingSlot;
  181. static boost::signals2::connection sSimFeaturesReceivedSlot;
  182. typedef std::set<LLMute, compare_by_id> mute_set_t;
  183. static mute_set_t sMutes;
  184. typedef std::set<std::string> string_set_t;
  185. static string_set_t sLegacyMutes;
  186. typedef std::set<LLMuteListObserver*> observer_set_t;
  187. static observer_set_t sObservers;
  188. static std::set<std::string> sGodLastNames;
  189. static std::set<std::string> sGodFullNames;
  190. typedef fast_hmap<LLUUID, F32> user_volume_map_t;
  191. static user_volume_map_t sUserVolumeSettings;
  192. };
  193. class LLMuteListObserver
  194. {
  195. public:
  196. virtual ~LLMuteListObserver() = default;
  197. virtual void onChange() = 0;
  198. };
  199. #endif // LL_MUTELIST_H