llgroupmgr.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. /**
  2. * @file llgroupmgr.h
  3. * @brief Manager for aggregating all client knowledge for specific groups
  4. *
  5. * $LicenseInfo:firstyear=2004&license=viewergpl$
  6. *
  7. * Copyright (c) 2004-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_LLGROUPMGR_H
  33. #define LL_LLGROUPMGR_H
  34. #include <map>
  35. #include <string>
  36. #include "hbfastmap.h"
  37. #include "lluuid.h"
  38. #include "roles_constants.h"
  39. constexpr U32 GB_MAX_BANNED_AGENTS = 500;
  40. constexpr U32 MAX_GROUP_INVITES = 100;
  41. class LLDate;
  42. class LLGroupMgr;
  43. class LLGroupRoleData;
  44. class LLMessageSystem;
  45. enum LLGroupChange
  46. {
  47. GC_PROPERTIES,
  48. GC_MEMBER_DATA,
  49. GC_ROLE_DATA,
  50. GC_ROLE_MEMBER_DATA,
  51. GC_TITLES,
  52. GC_BANLIST,
  53. GC_ALL
  54. };
  55. class LLGroupMgrObserver
  56. {
  57. public:
  58. LLGroupMgrObserver(const LLUUID& id)
  59. : mID(id)
  60. {
  61. }
  62. virtual ~LLGroupMgrObserver()
  63. {
  64. }
  65. virtual void changed(LLGroupChange gc) = 0;
  66. LL_INLINE const LLUUID& getID() { return mID; }
  67. protected:
  68. LLUUID mID;
  69. };
  70. class LLGroupMemberData
  71. {
  72. friend class LLGroupMgrGroupData;
  73. public:
  74. LLGroupMemberData(const LLUUID& id, S32 contribution, U64 agent_powers,
  75. const std::string& title,
  76. const std::string& online_status, bool is_owner);
  77. LL_INLINE const LLUUID& getID() const { return mID; }
  78. LL_INLINE S32 getContribution() const { return mContribution; }
  79. LL_INLINE U64 getAgentPowers() const { return mAgentPowers; }
  80. LL_INLINE bool isOwner() const { return mIsOwner; }
  81. LL_INLINE const std::string& getTitle() const { return mTitle; }
  82. LL_INLINE const std::string& getOnlineStatus() const { return mOnlineStatus; }
  83. void addRole(const LLUUID& role, LLGroupRoleData* rd);
  84. bool removeRole(const LLUUID& role);
  85. typedef fast_hmap<LLUUID, LLGroupRoleData*> role_list_t;
  86. LL_INLINE void clearRoles() { mRolesList.clear(); };
  87. LL_INLINE role_list_t::iterator roleBegin() { return mRolesList.begin(); }
  88. LL_INLINE role_list_t::iterator roleEnd() { return mRolesList.end(); }
  89. LL_INLINE bool isInRole(const LLUUID& role_id) { return mRolesList.count(role_id) != 0; }
  90. private:
  91. std::string mTitle;
  92. std::string mOnlineStatus;
  93. role_list_t mRolesList;
  94. U64 mAgentPowers;
  95. LLUUID mID;
  96. S32 mContribution;
  97. bool mIsOwner;
  98. };
  99. struct LLRoleData
  100. {
  101. LLRoleData()
  102. : mRolePowers(0),
  103. mChangeType(RC_UPDATE_NONE)
  104. {
  105. }
  106. LLRoleData(const LLRoleData& rd)
  107. : mRoleName(rd.mRoleName),
  108. mRoleTitle(rd.mRoleTitle),
  109. mRoleDescription(rd.mRoleDescription),
  110. mRolePowers(rd.mRolePowers),
  111. mChangeType(rd.mChangeType)
  112. {
  113. }
  114. std::string mRoleName;
  115. std::string mRoleTitle;
  116. std::string mRoleDescription;
  117. U64 mRolePowers;
  118. LLRoleChangeType mChangeType;
  119. };
  120. class LLGroupRoleData
  121. {
  122. friend class LLGroupMgrGroupData;
  123. public:
  124. LLGroupRoleData(const LLUUID& role_id, const std::string& role_name,
  125. const std::string& title, const std::string& desc,
  126. U64 role_powers, S32 member_count);
  127. LLGroupRoleData(const LLUUID& role_id, LLRoleData role_data,
  128. S32 member_count);
  129. LL_INLINE const LLUUID& getID() const { return mRoleID; }
  130. LL_INLINE const uuid_vec_t& getRoleMembers() const { return mMemberIDs; }
  131. S32 getMembersInRole(uuid_vec_t members, bool needs_sort = true);
  132. LL_INLINE S32 getTotalMembersInRole()
  133. {
  134. // *FIXME: Returns 0 for Everyone role when Member list isn't yet
  135. // loaded, see MAINT-5225
  136. return mMemberCount ? mMemberCount : mMemberIDs.size();
  137. }
  138. LL_INLINE LLRoleData getRoleData() const { return mRoleData; }
  139. LL_INLINE void setRoleData(LLRoleData data) { mRoleData = data; }
  140. void addMember(const LLUUID& member);
  141. bool removeMember(const LLUUID& member);
  142. void clearMembers();
  143. LL_INLINE const uuid_vec_t::const_iterator getMembersBegin() const
  144. {
  145. return mMemberIDs.begin();
  146. }
  147. LL_INLINE const uuid_vec_t::const_iterator getMembersEnd() const
  148. {
  149. return mMemberIDs.end();
  150. }
  151. protected:
  152. LLGroupRoleData()
  153. : mMemberCount(0),
  154. mMembersNeedsSort(false)
  155. {
  156. }
  157. LLUUID mRoleID;
  158. LLRoleData mRoleData;
  159. uuid_vec_t mMemberIDs;
  160. S32 mMemberCount;
  161. private:
  162. bool mMembersNeedsSort;
  163. };
  164. struct LLRoleMemberChange
  165. {
  166. LLRoleMemberChange()
  167. : mChange(RMC_NONE)
  168. {
  169. }
  170. LLRoleMemberChange(const LLUUID& role, const LLUUID& member,
  171. LLRoleMemberChangeType change)
  172. : mRole(role),
  173. mMember(member),
  174. mChange(change)
  175. {
  176. }
  177. LLRoleMemberChange(const LLRoleMemberChange& rc)
  178. : mRole(rc.mRole),
  179. mMember(rc.mMember),
  180. mChange(rc.mChange)
  181. {
  182. }
  183. LLUUID mRole;
  184. LLUUID mMember;
  185. LLRoleMemberChangeType mChange;
  186. };
  187. typedef std::pair<LLUUID,LLUUID> lluuid_pair;
  188. struct lluuid_pair_less
  189. {
  190. bool operator()(const lluuid_pair& lhs, const lluuid_pair& rhs) const
  191. {
  192. if (lhs.first == rhs.first)
  193. {
  194. return lhs.second < rhs.second;
  195. }
  196. else
  197. {
  198. return lhs.first < rhs.first;
  199. }
  200. }
  201. };
  202. class LLGroupBanData
  203. {
  204. public:
  205. LLGroupBanData()
  206. : mBanDate()
  207. {
  208. }
  209. ~LLGroupBanData()
  210. {
  211. }
  212. LLDate mBanDate;
  213. // *TODO: std:string ban_reason;
  214. };
  215. struct LLGroupTitle
  216. {
  217. std::string mTitle;
  218. LLUUID mRoleID;
  219. bool mSelected;
  220. };
  221. class LLGroupMgrGroupData
  222. {
  223. friend class LLGroupMgr;
  224. public:
  225. LLGroupMgrGroupData(const LLUUID& id);
  226. ~LLGroupMgrGroupData();
  227. LL_INLINE const LLUUID& getID() { return mID; }
  228. bool getRoleData(const LLUUID& role_id, LLRoleData& role_data);
  229. void setRoleData(const LLUUID& role_id, LLRoleData role_data);
  230. void createRole(const LLUUID& role_id, LLRoleData role_data);
  231. void deleteRole(const LLUUID& role_id);
  232. LL_INLINE bool pendingRoleChanges() { return !mRoleChanges.empty(); }
  233. void addRolePower(const LLUUID& role_id, U64 power);
  234. void removeRolePower(const LLUUID& role_id, U64 power);
  235. U64 getRolePowers(const LLUUID& role_id);
  236. void removeData();
  237. void removeRoleData();
  238. void removeMemberData();
  239. void removeRoleMemberData();
  240. bool changeRoleMember(const LLUUID& role_id, const LLUUID& member_id,
  241. LLRoleMemberChangeType rmc);
  242. void recalcAllAgentPowers();
  243. void recalcAgentPowers(const LLUUID& agent_id);
  244. LL_INLINE bool isMemberDataComplete() { return mMemberDataComplete; }
  245. LL_INLINE bool isRoleDataComplete() { return mRoleDataComplete; }
  246. LL_INLINE bool isRoleMemberDataComplete() { return mRoleMemberDataComplete; }
  247. LL_INLINE bool isGroupPropertiesDataComplete() { return mGroupPropertiesDataComplete; }
  248. LL_INLINE bool hasGroupTitles() { return !mTitles.empty(); }
  249. LL_INLINE bool isMemberDataPending() { return mMemberRequestID.notNull(); }
  250. LL_INLINE bool isRoleDataPending() { return mRoleDataRequestID.notNull(); }
  251. LL_INLINE bool isRoleMemberDataPending() { return mPendingRoleMemberRequest ||
  252. mRoleMembersRequestID.notNull(); }
  253. LL_INLINE bool isGroupTitlePending() { return mTitlesRequestID.notNull() && mTitles.empty(); }
  254. LL_INLINE F32 getAccessTime() const { return mAccessTime; }
  255. void setAccessed();
  256. LL_INLINE void clearBanList() { mBanList.clear(); }
  257. void getBanList(const LLUUID& group_id, LLGroupBanData& ban_data);
  258. LL_INLINE const LLGroupBanData& getBanEntry(const LLUUID& ban_id)
  259. {
  260. return mBanList[ban_id];
  261. }
  262. void createBanEntry(const LLUUID& ban_id,
  263. const LLGroupBanData& ban_data = LLGroupBanData());
  264. void removeBanEntry(const LLUUID& ban_id);
  265. public:
  266. typedef fast_hmap<LLUUID, LLGroupMemberData*> member_list_t;
  267. typedef fast_hmap<LLUUID, LLGroupRoleData*> role_list_t;
  268. typedef std::map<lluuid_pair, LLRoleMemberChange, lluuid_pair_less> change_map_t;
  269. typedef fast_hmap<LLUUID, LLRoleData> role_data_map_t;
  270. typedef fast_hmap<LLUUID, LLGroupBanData> ban_list_t;
  271. member_list_t mMembers;
  272. role_list_t mRoles;
  273. change_map_t mRoleMemberChanges;
  274. role_data_map_t mRoleChanges;
  275. ban_list_t mBanList;
  276. std::vector<LLGroupTitle> mTitles;
  277. LLUUID mID;
  278. LLUUID mOwnerRole;
  279. LLUUID mInsigniaID;
  280. LLUUID mFounderID;
  281. S32 mMembershipFee;
  282. S32 mMemberCount;
  283. S32 mRoleCount;
  284. std::string mName;
  285. std::string mCharter;
  286. bool mShowInList;
  287. bool mOpenEnrollment;
  288. bool mAllowPublish;
  289. bool mListInProfile;
  290. bool mMaturePublish;
  291. bool mChanged;
  292. protected:
  293. void sendRoleChanges();
  294. void cancelRoleChanges();
  295. private:
  296. LLUUID mMemberRequestID;
  297. LLUUID mRoleDataRequestID;
  298. LLUUID mRoleMembersRequestID;
  299. LLUUID mTitlesRequestID;
  300. U32 mReceivedRoleMemberPairs;
  301. F32 mAccessTime;
  302. bool mMemberDataComplete;
  303. bool mRoleDataComplete;
  304. bool mRoleMemberDataComplete;
  305. bool mGroupPropertiesDataComplete;
  306. bool mPendingRoleMemberRequest;
  307. };
  308. struct LLRoleAction
  309. {
  310. std::string mName;
  311. std::string mDescription;
  312. std::string mLongDescription;
  313. U64 mPowerBit;
  314. };
  315. struct LLRoleActionSet
  316. {
  317. LLRoleActionSet();
  318. ~LLRoleActionSet();
  319. LLRoleAction* mActionSetData;
  320. std::vector<LLRoleAction*> mActions;
  321. };
  322. class LLGroupMgr
  323. {
  324. protected:
  325. LOG_CLASS(LLGroupMgr);
  326. public:
  327. enum EBanRequestType
  328. {
  329. REQUEST_GET = 0,
  330. REQUEST_POST,
  331. REQUEST_PUT,
  332. REQUEST_DEL
  333. };
  334. enum EBanRequestAction
  335. {
  336. BAN_NO_ACTION = 0,
  337. BAN_CREATE = 1,
  338. BAN_DELETE = 2,
  339. BAN_UPDATE = 4
  340. };
  341. LLGroupMgr();
  342. ~LLGroupMgr();
  343. void addObserver(LLGroupMgrObserver* observer);
  344. void removeObserver(LLGroupMgrObserver* observer);
  345. LLGroupMgrGroupData* getGroupData(const LLUUID& id);
  346. // Used to be a local function in llpanelgrouproles.cpp. Moved here so that
  347. // it can be used elsewhere in the viewer (currently also used in for Lua
  348. // in hbviewerautomation.cpp). HB
  349. bool agentCanAddToRole(const LLUUID& group_id, const LLUUID& role_id);
  350. // Sends group data requests for any missing data in an agent group.
  351. // Returns true whenever a fetch was actually performed or false when
  352. // not an agent group or all data is already available. Used for Lua. HB
  353. bool fetchGroupMissingData(const LLUUID& group_id);
  354. void sendGroupPropertiesRequest(const LLUUID& group_id);
  355. void sendGroupRoleDataRequest(const LLUUID& group_id);
  356. void sendGroupRoleMembersRequest(const LLUUID& group_id);
  357. void sendGroupMembersRequest(const LLUUID& group_id);
  358. void sendGroupTitlesRequest(const LLUUID& group_id);
  359. void sendGroupTitleUpdate(const LLUUID& group_id,
  360. const LLUUID& title_role_id);
  361. void sendUpdateGroupInfo(const LLUUID& group_id);
  362. void sendGroupRoleMemberChanges(const LLUUID& group_id);
  363. void sendGroupRoleChanges(const LLUUID& group_id);
  364. static void sendCreateGroupRequest(const std::string& name,
  365. const std::string& charter,
  366. U8 show_in_list,
  367. const LLUUID& insignia,
  368. S32 membership_fee,
  369. bool open_enrollment,
  370. bool allow_publish,
  371. bool mature_publish);
  372. static void sendGroupMemberJoin(const LLUUID& group_id);
  373. typedef fast_hmap<LLUUID, LLUUID> role_member_pairs_t;
  374. static void sendGroupMemberInvites(const LLUUID& group_id,
  375. role_member_pairs_t& role_member_pairs);
  376. static void sendGroupMemberEjects(const LLUUID& group_id,
  377. uuid_vec_t& member_ids);
  378. static void sendGroupBanRequest(EBanRequestType request_type,
  379. const LLUUID& group_id,
  380. U32 ban_action = BAN_NO_ACTION,
  381. const uuid_vec_t& ban_list = uuid_vec_t());
  382. static void processGroupBanRequest(const LLSD& content);
  383. void sendCapGroupMembersRequest(const LLUUID& group_id);
  384. void cancelGroupRoleChanges(const LLUUID& group_id);
  385. static void processGroupPropertiesReply(LLMessageSystem* msg, void** data);
  386. static void processGroupMembersReply(LLMessageSystem* msg, void** data);
  387. static void processGroupRoleDataReply(LLMessageSystem* msg, void** data);
  388. static void processGroupRoleMembersReply(LLMessageSystem* msg, void** data);
  389. static void processGroupTitlesReply(LLMessageSystem* msg, void** data);
  390. static void processCreateGroupReply(LLMessageSystem* msg, void** data);
  391. static void processJoinGroupReply(LLMessageSystem* msg, void ** data);
  392. static void processEjectGroupMemberReply(LLMessageSystem* msg, void ** data);
  393. static void processLeaveGroupReply(LLMessageSystem* msg, void ** data);
  394. static bool parseRoleActions(const std::string& xml_filename);
  395. static void debugClearAllGroups(void*);
  396. void clearGroups();
  397. void clearGroupData(const LLUUID& group_id);
  398. private:
  399. static void groupMembersRequestCoro(const std::string& url,
  400. const LLUUID& group_id);
  401. static void processCapGroupMembersRequest(const LLSD& content);
  402. static void getGroupBanRequestCoro(const std::string& url,
  403. const LLUUID& group_id);
  404. static void postGroupBanRequestCoro(std::string url, LLUUID group_id,
  405. U32 action, const uuid_vec_t& ban_list,
  406. bool update);
  407. void notifyObservers(LLGroupChange gc);
  408. void addGroup(LLGroupMgrGroupData* group_datap);
  409. LLGroupMgrGroupData* createGroupData(const LLUUID &id);
  410. public:
  411. std::vector<LLRoleActionSet*> mRoleActionSets;
  412. private:
  413. typedef std::multimap<LLUUID, LLGroupMgrObserver*> observer_multimap_t;
  414. observer_multimap_t mObservers;
  415. typedef fast_hmap<LLUUID, LLGroupMgrGroupData*> group_map_t;
  416. group_map_t mGroups;
  417. F32 mLastGroupMembersRequestTime;
  418. bool mMemberRequestInFlight;
  419. };
  420. extern LLGroupMgr gGroupMgr;
  421. #endif