TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
GuildFinderMgr.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __TRINITY_GUILDFINDER_H
19 #define __TRINITY_GUILDFINDER_H
20 
21 #include "Common.h"
22 #include "ObjectGuid.h"
23 #include "GuildMgr.h"
24 
26 {
30  INTEREST_PVP = 0x08,
33 };
34 
36 {
40 };
41 
43 {
48 };
49 
51 {
55 };
56 
59 {
60  public:
61  MembershipRequest(MembershipRequest const& settings) : _comment(settings.GetComment())
62  {
63  _availability = settings.GetAvailability();
64  _classRoles = settings.GetClassRoles();
65  _interests = settings.GetInterests();
66  _guildId = settings.GetGuildGuid();
67  _playerGUID = settings.GetPlayerGUID();
68  _time = settings.GetSubmitTime();
69  }
70 
71  MembershipRequest(ObjectGuid const& playerGUID, ObjectGuid const& guildId, uint32 availability, uint32 classRoles, uint32 interests, std::string& comment, time_t submitTime) :
72  _comment(comment), _guildId(guildId), _playerGUID(playerGUID), _availability(availability),
73  _classRoles(classRoles), _interests(interests), _time(submitTime) {}
74 
76  _interests(0), _time(time(NULL)) {}
77 
78  ObjectGuid const& GetGuildGuid() const { return _guildId; }
79  ObjectGuid const& GetPlayerGUID() const { return _playerGUID; }
80  uint8 GetAvailability() const { return _availability; }
81  uint8 GetClassRoles() const { return _classRoles; }
82  uint8 GetInterests() const { return _interests; }
83  time_t GetSubmitTime() const { return _time; }
84  time_t GetExpiryTime() const { return time_t(_time + 30 * 24 * 3600); } // Adding 30 days
85  std::string const& GetComment() const { return _comment; }
86 
87  private:
88  std::string _comment;
89 
92 
96 
97  time_t _time;
98 };
99 
102 {
103  public:
105  {
106  _roles = 0;
107  _availability = 0;
108  _interests = 0;
109  _level = 0;
110  }
111 
112  LFGuildPlayer(ObjectGuid const& guid, uint8 role, uint8 availability, uint8 interests, uint8 level)
113  {
114  _guid = guid;
115  _roles = role;
116  _availability = availability;
117  _interests = interests;
118  _level = level;
119  }
120 
121  LFGuildPlayer(ObjectGuid const& guid, uint8 role, uint8 availability, uint8 interests, uint8 level, std::string& comment) : _comment(comment)
122  {
123  _guid = guid;
124  _roles = role;
125  _availability = availability;
126  _interests = interests;
127  _level = level;
128  }
129 
130  LFGuildPlayer(LFGuildPlayer const& settings) : _comment(settings.GetComment())
131  {
132  _guid = settings.GetGUID();
133  _roles = settings.GetClassRoles();
134  _availability = settings.GetAvailability();
135  _interests = settings.GetInterests();
136  _level = settings.GetLevel();
137  }
138 
139  ObjectGuid const& GetGUID() const { return _guid; }
140  uint8 GetClassRoles() const { return _roles; }
141  uint8 GetAvailability() const { return _availability; }
142  uint8 GetInterests() const { return _interests; }
143  uint8 GetLevel() const { return _level; }
144  std::string const& GetComment() const { return _comment; }
145 
146  private:
147  std::string _comment;
153 };
154 
157 {
158  public:
160 
161  LFGuildSettings(bool listed, TeamId team) : LFGuildPlayer(), _listed(listed), _team(team) {}
162 
163  LFGuildSettings(bool listed, TeamId team, ObjectGuid const& guid, uint8 role, uint8 availability, uint8 interests, uint8 level) :
164  LFGuildPlayer(guid, role, availability, interests, level), _listed(listed), _team(team) {}
165 
166  LFGuildSettings(bool listed, TeamId team, ObjectGuid const& guid, uint8 role, uint8 availability, uint8 interests, uint8 level, std::string& comment) :
167  LFGuildPlayer(guid, role, availability, interests, level, comment), _listed(listed), _team(team) {}
168 
169  LFGuildSettings(LFGuildSettings const& settings) :
170  LFGuildPlayer(settings), _listed(settings.IsListed()), _team(settings.GetTeam()) {}
171 
172  bool IsListed() const { return _listed; }
173  void SetListed(bool state) { _listed = state; }
174 
175  TeamId GetTeam() const { return _team; }
176  private:
177  bool _listed;
179 };
180 
181 typedef std::unordered_map<ObjectGuid /* guildGuid */, LFGuildSettings> LFGuildStore;
182 
184 {
185  private:
186  GuildFinderMgr();
187  ~GuildFinderMgr();
188 
190 
191  std::unordered_map<ObjectGuid /*guildGUID*/, std::unordered_map<ObjectGuid /*playerGUID*/, MembershipRequest>> _membershipRequestsByGuild;
192  std::unordered_map<ObjectGuid /*playerGUID*/, std::unordered_map<ObjectGuid /*guildGUID*/, MembershipRequest>> _membershipRequestsByPlayer;
193 
194  void LoadGuildSettings();
195  void LoadMembershipRequests();
196 
197  public:
198  void LoadFromDB();
199 
205  void SetGuildSettings(ObjectGuid const& guildGuid, LFGuildSettings const& settings);
206 
211  LFGuildSettings const& GetGuildSettings(ObjectGuid const& guildGuid) { return _guildSettings[guildGuid]; }
212 
218  void AddMembershipRequest(ObjectGuid const& guildGuid, MembershipRequest const& request);
219 
224  void RemoveAllMembershipRequestsFromPlayer(ObjectGuid const& playerId);
225 
231  void RemoveMembershipRequest(ObjectGuid const& playerId, ObjectGuid const& guildId);
232 
234  void DeleteGuild(ObjectGuid const& guildId);
235 
240  std::unordered_map<ObjectGuid, MembershipRequest> const* GetAllMembershipRequestsForGuild(ObjectGuid const& guildGuid)
241  {
242  auto itr = _membershipRequestsByGuild.find(guildGuid);
243  return itr != _membershipRequestsByGuild.end() ? &itr->second : nullptr;
244  }
245 
250  std::vector<MembershipRequest const*> GetAllMembershipRequestsForPlayer(ObjectGuid const& playerGuid);
251 
257  std::vector<LFGuildSettings const*> GetGuildsMatchingSetting(LFGuildPlayer& settings, TeamId faction);
258 
260  bool HasRequest(ObjectGuid const& playerId, ObjectGuid const& guildId);
261 
263  uint8 CountRequestsFromPlayer(ObjectGuid const& playerId);
264 
265  static void SendApplicantListUpdate(Guild* guild);
266  static void SendMembershipRequestListUpdate(Player* player);
267 
268  static GuildFinderMgr* instance();
269 };
270 
271 #define sGuildFinderMgr GuildFinderMgr::instance()
272 
273 #endif // __TRINITY_GUILDFINDER_H
~GuildFinderMgr()
Definition: GuildFinderMgr.cpp:28
ObjectGuid const & GetPlayerGUID() const
Definition: GuildFinderMgr.h:79
void LoadMembershipRequests()
Definition: GuildFinderMgr.cpp:79
LFGuildPlayer(ObjectGuid const &guid, uint8 role, uint8 availability, uint8 interests, uint8 level)
Definition: GuildFinderMgr.h:112
std::vector< MembershipRequest const * > GetAllMembershipRequestsForPlayer(ObjectGuid const &playerGuid)
Returns a list of membership requests for a player.
Definition: GuildFinderMgr.cpp:210
Definition: GuildFinderMgr.h:44
void AddMembershipRequest(ObjectGuid const &guildGuid, MembershipRequest const &request)
Files a membership request to a guild.
Definition: GuildFinderMgr.cpp:116
uint8 GetClassRoles() const
Definition: GuildFinderMgr.h:81
void RemoveAllMembershipRequestsFromPlayer(ObjectGuid const &playerId)
Removes all membership request from a player.
Definition: GuildFinderMgr.cpp:142
uint8 _availability
Definition: GuildFinderMgr.h:93
LFGuildSettings(bool listed, TeamId team)
Definition: GuildFinderMgr.h:161
Definition: GuildFinderMgr.h:45
uint8 CountRequestsFromPlayer(ObjectGuid const &playerId)
Counts the amount of pending membership requests, given the player's db guid.
Definition: GuildFinderMgr.cpp:224
LFGuildStore _guildSettings
Definition: GuildFinderMgr.h:189
MembershipRequest(ObjectGuid const &playerGUID, ObjectGuid const &guildId, uint32 availability, uint32 classRoles, uint32 interests, std::string &comment, time_t submitTime)
Definition: GuildFinderMgr.h:71
LFGuildSettings const & GetGuildSettings(ObjectGuid const &guildGuid)
Returns settings for a guild.
Definition: GuildFinderMgr.h:211
uint8 GetClassRoles() const
Definition: GuildFinderMgr.h:140
std::unordered_map< ObjectGuid, LFGuildSettings > LFGuildStore
Definition: GuildFinderMgr.h:181
uint8 GetLevel() const
Definition: GuildFinderMgr.h:143
static GuildFinderMgr * instance()
Definition: GuildFinderMgr.cpp:343
Definition: GuildFinderMgr.h:29
std::vector< LFGuildSettings const * > GetGuildsMatchingSetting(LFGuildPlayer &settings, TeamId faction)
Returns a store of guilds matching the settings provided, using bitmask operators.
Definition: GuildFinderMgr.cpp:230
ObjectGuid const & GetGUID() const
Definition: GuildFinderMgr.h:139
LFGuildSettings()
Definition: GuildFinderMgr.h:159
time_t _time
Definition: GuildFinderMgr.h:97
bool IsListed() const
Definition: GuildFinderMgr.h:172
Definition: GuildFinderMgr.h:53
Holds settings for a guild in the finder system. Saved to database.
Definition: GuildFinderMgr.h:156
void LoadGuildSettings()
Definition: GuildFinderMgr.cpp:38
arena_t NULL
Definition: jemalloc_internal.h:624
#define false
Definition: CascPort.h:18
LFGuildSettings(LFGuildSettings const &settings)
Definition: GuildFinderMgr.h:169
void LoadFromDB()
Definition: GuildFinderMgr.cpp:32
LFGuildPlayer(ObjectGuid const &guid, uint8 role, uint8 availability, uint8 interests, uint8 level, std::string &comment)
Definition: GuildFinderMgr.h:121
void SetGuildSettings(ObjectGuid const &guildGuid, LFGuildSettings const &settings)
Stores guild settings and begins an asynchronous database insert.
Definition: GuildFinderMgr.cpp:270
MembershipRequest(MembershipRequest const &settings)
Definition: GuildFinderMgr.h:61
Definition: GuildFinderMgr.h:46
LFGuildSettings(bool listed, TeamId team, ObjectGuid const &guid, uint8 role, uint8 availability, uint8 interests, uint8 level)
Definition: GuildFinderMgr.h:163
Definition: GuildFinderMgr.h:183
Definition: GuildFinderMgr.h:47
Definition: GuildFinderMgr.h:30
uint8 _level
Definition: GuildFinderMgr.h:152
uint8 _interests
Definition: GuildFinderMgr.h:95
time_t GetExpiryTime() const
Definition: GuildFinderMgr.h:84
GuildFinderOptionsLevel
Definition: GuildFinderMgr.h:50
void SetListed(bool state)
Definition: GuildFinderMgr.h:173
Definition: GuildFinderMgr.h:37
uint8 _availability
Definition: GuildFinderMgr.h:150
LFGuildSettings(bool listed, TeamId team, ObjectGuid const &guid, uint8 role, uint8 availability, uint8 interests, uint8 level, std::string &comment)
Definition: GuildFinderMgr.h:166
uint8 _interests
Definition: GuildFinderMgr.h:151
ObjectGuid const & GetGuildGuid() const
Definition: GuildFinderMgr.h:78
GuildFinderOptionsInterest
Definition: GuildFinderMgr.h:25
void DeleteGuild(ObjectGuid const &guildId)
Wipes everything related to a guild. Used when that guild is disbanded.
Definition: GuildFinderMgr.cpp:289
Definition: GuildFinderMgr.h:28
uint8 GetAvailability() const
Definition: GuildFinderMgr.h:80
bool _listed
Definition: GuildFinderMgr.h:177
ObjectGuid _guid
Definition: GuildFinderMgr.h:148
time_t GetSubmitTime() const
Definition: GuildFinderMgr.h:83
std::string const & GetComment() const
Definition: GuildFinderMgr.h:144
Definition: GuildFinderMgr.h:54
uint32_t uint32
Definition: Define.h:150
Holds all required informations about a membership request.
Definition: GuildFinderMgr.h:58
void RemoveMembershipRequest(ObjectGuid const &playerId, ObjectGuid const &guildId)
Removes a membership request to a guild.
Definition: GuildFinderMgr.cpp:174
std::unordered_map< ObjectGuid, std::unordered_map< ObjectGuid, MembershipRequest > > _membershipRequestsByGuild
Definition: GuildFinderMgr.h:191
Definition: SharedDefines.h:992
std::string const & GetComment() const
Definition: GuildFinderMgr.h:85
uint8 GetInterests() const
Definition: GuildFinderMgr.h:82
uint8 GetAvailability() const
Definition: GuildFinderMgr.h:141
GuildFinderMgr()
Definition: GuildFinderMgr.cpp:24
ObjectGuid _playerGUID
Definition: GuildFinderMgr.h:91
std::string _comment
Definition: GuildFinderMgr.h:88
LFGuildPlayer(LFGuildPlayer const &settings)
Definition: GuildFinderMgr.h:130
TeamId GetTeam() const
Definition: GuildFinderMgr.h:175
TeamId
Definition: SharedDefines.h:990
std::string _comment
Definition: GuildFinderMgr.h:147
static void SendApplicantListUpdate(Guild *guild)
Definition: GuildFinderMgr.cpp:330
Definition: GuildFinderMgr.h:27
uint8 _roles
Definition: GuildFinderMgr.h:149
std::unordered_map< ObjectGuid, MembershipRequest > const * GetAllMembershipRequestsForGuild(ObjectGuid const &guildGuid)
Returns a set of membership requests for a guild.
Definition: GuildFinderMgr.h:240
GuildFinderOptionsRoles
Definition: GuildFinderMgr.h:42
GuildFinderOptionsAvailability
Definition: GuildFinderMgr.h:35
uint8_t uint8
Definition: Define.h:152
uint8 GetInterests() const
Definition: GuildFinderMgr.h:142
Definition: GuildFinderMgr.h:39
std::unordered_map< ObjectGuid, std::unordered_map< ObjectGuid, MembershipRequest > > _membershipRequestsByPlayer
Definition: GuildFinderMgr.h:192
Definition: ObjectGuid.h:189
Definition: GuildFinderMgr.h:38
Definition: GuildFinderMgr.h:52
MembershipRequest()
Definition: GuildFinderMgr.h:75
uint8 _classRoles
Definition: GuildFinderMgr.h:94
Definition: GuildFinderMgr.h:32
Definition: Guild.h:320
Holds all informations about a player's finder settings. NOT stored in database.
Definition: GuildFinderMgr.h:101
LFGuildPlayer()
Definition: GuildFinderMgr.h:104
ObjectGuid _guildId
Definition: GuildFinderMgr.h:90
static void SendMembershipRequestListUpdate(Player *player)
Definition: GuildFinderMgr.cpp:338
Definition: GuildFinderMgr.h:31
bool HasRequest(ObjectGuid const &playerId, ObjectGuid const &guildId)
Provided a player guid and a guild guid, determines if a pending request is filed with these keys...
Definition: GuildFinderMgr.cpp:261
TeamId _team
Definition: GuildFinderMgr.h:178