Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
GuildFinderMgr.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#include "GuildFinderMgr.h"
7#include "GuildMgr.h"
8#include "ObjectMgr.h"
9#include "World.h"
10
14
18
24
26{
27 SF_LOG_INFO("server.loading", "Loading guild finder guild-related settings...");
28 // 0 1 2 3 4 5 6 7
29 QueryResult result = CharacterDatabase.Query("SELECT gfgs.guildId, gfgs.availability, gfgs.classRoles, gfgs.interests, gfgs.level, gfgs.listed, gfgs.comment, c.race "
30 "FROM guild_finder_guild_settings gfgs "
31 "LEFT JOIN guild_member gm ON gm.guildid=gfgs.guildId "
32 "LEFT JOIN characters c ON c.guid = gm.guid LIMIT 1");
33
34 if (!result)
35 {
36 SF_LOG_INFO("server.loading", ">> Loaded 0 guild finder guild-related settings. Table `guild_finder_guild_settings` is empty.");
37 return;
38 }
39
40 uint32 count = 0;
41 uint32 oldMSTime = getMSTime();
42 do
43 {
44 Field* fields = result->Fetch();
45 uint32 guildId = fields[0].GetUInt32();
46 uint8 availability = fields[1].GetUInt8();
47 uint8 classRoles = fields[2].GetUInt8();
48 uint8 interests = fields[3].GetUInt8();
49 uint8 level = fields[4].GetUInt8();
50 bool listed = (fields[5].GetUInt8() != 0);
51 std::string comment = fields[6].GetString();
52
53 TeamId guildTeam = TEAM_ALLIANCE;
54 if (ChrRacesEntry const* raceEntry = sChrRacesStore.LookupEntry(fields[7].GetUInt8()))
55 if (raceEntry->TeamID == 1)
56 guildTeam = TEAM_HORDE;
57
58 LFGuildSettings settings(listed, guildTeam, guildId, classRoles, availability, interests, level, comment);
59 _guildSettings[guildId] = settings;
60
61 ++count;
62 } while (result->NextRow());
63
64 SF_LOG_INFO("server.loading", ">> Loaded %u guild finder guild-related settings in %u ms.", count, GetMSTimeDiffToNow(oldMSTime));
65}
66
68{
69 SF_LOG_INFO("server.loading", "Loading guild finder membership requests...");
70 // 0 1 2 3 4 5 6
71 QueryResult result = CharacterDatabase.Query("SELECT guildId, playerGuid, availability, classRole, interests, comment, submitTime "
72 "FROM guild_finder_applicant");
73
74 if (!result)
75 {
76 SF_LOG_INFO("server.loading", ">> Loaded 0 guild finder membership requests. Table `guild_finder_applicant` is empty.");
77 return;
78 }
79
80 uint32 count = 0;
81 uint32 oldMSTime = getMSTime();
82 do
83 {
84 Field* fields = result->Fetch();
85 uint32 guildId = fields[0].GetUInt32();
86 uint32 playerId = fields[1].GetUInt32();
87 uint8 availability = fields[2].GetUInt8();
88 uint8 classRoles = fields[3].GetUInt8();
89 uint8 interests = fields[4].GetUInt8();
90 std::string comment = fields[5].GetString();
91 uint32 submitTime = fields[6].GetUInt32();
92
93 MembershipRequest request(playerId, guildId, availability, classRoles, interests, comment, time_t(submitTime));
94
95 _membershipRequests[guildId].push_back(request);
96
97 ++count;
98 } while (result->NextRow());
99
100 SF_LOG_INFO("server.loading", ">> Loaded %u guild finder membership requests in %u ms.", count, GetMSTimeDiffToNow(oldMSTime));
101}
102
104{
105 _membershipRequests[guildGuid].push_back(request);
106
107 SQLTransaction trans = CharacterDatabase.BeginTransaction();
109 stmt->setUInt32(0, request.GetGuildId());
110 stmt->setUInt32(1, request.GetPlayerGUID());
111 stmt->setUInt8(2, request.GetAvailability());
112 stmt->setUInt8(3, request.GetClassRoles());
113 stmt->setUInt8(4, request.GetInterests());
114 stmt->setString(5, request.GetComment());
115 stmt->setUInt32(6, request.GetSubmitTime());
116 trans->Append(stmt);
117 CharacterDatabase.CommitTransaction(trans);
118
119 // Notify the applicant his submittion has been added
122
123 // Notify the guild master and officers the list changed
124 if (Guild* guild = sGuildMgr->GetGuildById(guildGuid))
126}
127
129{
130 for (MembershipRequestStore::iterator itr = _membershipRequests.begin(); itr != _membershipRequests.end(); ++itr)
131 {
132 std::vector<MembershipRequest>::iterator itr2 = itr->second.begin();
133 for (; itr2 != itr->second.end(); ++itr2)
134 if (itr2->GetPlayerGUID() == playerId)
135 break;
136
137 if (itr2 == itr->second.end())
138 continue;
139
140 SQLTransaction trans = CharacterDatabase.BeginTransaction();
142 stmt->setUInt32(0, itr2->GetGuildId());
143 stmt->setUInt32(1, itr2->GetPlayerGUID());
144 trans->Append(stmt);
145
146 CharacterDatabase.CommitTransaction(trans);
147 itr->second.erase(itr2);
148
149 // Notify the guild master and officers the list changed
150 if (Guild* guild = sGuildMgr->GetGuildById(itr->first))
152 }
153}
154
156{
157 std::vector<MembershipRequest>::iterator itr = _membershipRequests[guildId].begin();
158 for (; itr != _membershipRequests[guildId].end(); ++itr)
159 if (itr->GetPlayerGUID() == playerId)
160 break;
161
162 if (itr == _membershipRequests[guildId].end())
163 return;
164
165 SQLTransaction trans = CharacterDatabase.BeginTransaction();
166
168 stmt->setUInt32(0, itr->GetGuildId());
169 stmt->setUInt32(1, itr->GetPlayerGUID());
170 trans->Append(stmt);
171
172 CharacterDatabase.CommitTransaction(trans);
173
174 _membershipRequests[guildId].erase(itr);
175
176 // Notify the applicant his submittion has been removed
179
180 // Notify the guild master and officers the list changed
181 if (Guild* guild = sGuildMgr->GetGuildById(guildId))
183}
184
185std::list<MembershipRequest> GuildFinderMgr::GetAllMembershipRequestsForPlayer(uint32 playerGuid)
186{
187 std::list<MembershipRequest> resultSet;
188 for (MembershipRequestStore::const_iterator itr = _membershipRequests.begin(); itr != _membershipRequests.end(); ++itr)
189 {
190 std::vector<MembershipRequest> const& guildReqs = itr->second;
191 for (std::vector<MembershipRequest>::const_iterator itr2 = guildReqs.begin(); itr2 != guildReqs.end(); ++itr2)
192 {
193 if (itr2->GetPlayerGUID() == playerGuid)
194 {
195 resultSet.push_back(*itr2);
196 break;
197 }
198 }
199 }
200 return resultSet;
201}
202
204{
205 uint8 result = 0;
206 for (MembershipRequestStore::const_iterator itr = _membershipRequests.begin(); itr != _membershipRequests.end(); ++itr)
207 {
208 for (std::vector<MembershipRequest>::const_iterator itr2 = itr->second.begin(); itr2 != itr->second.end(); ++itr2)
209 {
210 if (itr2->GetPlayerGUID() != playerId)
211 continue;
212 ++result;
213 break;
214 }
215 }
216 return result;
217}
218
220{
221 LFGuildStore resultSet;
222 for (LFGuildStore::const_iterator itr = _guildSettings.begin(); itr != _guildSettings.end(); ++itr)
223 {
224 LFGuildSettings const& guildSettings = itr->second;
225
226 if (guildSettings.GetTeam() != faction)
227 continue;
228
229 if (!(guildSettings.GetAvailability() & settings.GetAvailability()))
230 continue;
231
232 if (!(guildSettings.GetClassRoles() & settings.GetClassRoles()))
233 continue;
234
235 if (!(guildSettings.GetInterests() & settings.GetInterests()))
236 continue;
237
238 if (!(guildSettings.GetLevel() & settings.GetLevel()))
239 continue;
240
241 resultSet.insert(std::make_pair(itr->first, guildSettings));
242 }
243
244 return resultSet;
245}
246
248{
249 for (std::vector<MembershipRequest>::const_iterator itr = _membershipRequests[guildId].begin(); itr != _membershipRequests[guildId].end(); ++itr)
250 if (itr->GetPlayerGUID() == playerId)
251 return true;
252 return false;
253}
254
256{
257 _guildSettings[guildGuid] = settings;
258
259 SQLTransaction trans = CharacterDatabase.BeginTransaction();
260
262 stmt->setUInt32(0, settings.GetGUID());
263 stmt->setUInt8(1, settings.GetAvailability());
264 stmt->setUInt8(2, settings.GetClassRoles());
265 stmt->setUInt8(3, settings.GetInterests());
266 stmt->setUInt8(4, settings.GetLevel());
267 stmt->setUInt8(5, settings.IsListed());
268 stmt->setString(6, settings.GetComment());
269 trans->Append(stmt);
270
271 CharacterDatabase.CommitTransaction(trans);
272}
273
275{
276 std::vector<MembershipRequest>::iterator itr = _membershipRequests[guildId].begin();
277 while (itr != _membershipRequests[guildId].end())
278 {
279 SQLTransaction trans = CharacterDatabase.BeginTransaction();
280
281 uint32 applicant = itr->GetPlayerGUID();
282
284 stmt->setUInt32(0, itr->GetGuildId());
285 stmt->setUInt32(1, applicant);
286 trans->Append(stmt);
287
288 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GUILD_FINDER_GUILD_SETTINGS);
289 stmt->setUInt32(0, itr->GetGuildId());
290 trans->Append(stmt);
291
292 CharacterDatabase.CommitTransaction(trans);
293
294 // Notify the applicant his submition has been removed
297
298 ++itr;
299 }
300
301 _membershipRequests.erase(guildId);
302 _guildSettings.erase(guildId);
303
304 // Notify the guild master the list changed (even if he's not a GM any more, not sure if needed)
305 if (Guild* guild = sGuildMgr->GetGuildById(guildId))
307}
308
310{
312 if (Player* player = ObjectAccessor::FindPlayer(guild.GetLeaderGUID()))
313 player->SendDirectMessage(&data);
314 guild.BroadcastPacketToRank(&data, GR_OFFICER);
315}
316
@ CHAR_REP_GUILD_FINDER_APPLICANT
@ CHAR_DEL_GUILD_FINDER_APPLICANT
@ CHAR_DEL_GUILD_FINDER_GUILD_SETTINGS
@ CHAR_REP_GUILD_FINDER_GUILD_SETTINGS
DBCStorage< ChrRacesEntry > sChrRacesStore(ChrRacesEntryfmt)
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
@ GR_OFFICER
Definition Guild.h:45
std::map< uint32, LFGuildSettings > LFGuildStore
#define sGuildMgr
Definition GuildMgr.h:53
#define SF_LOG_INFO(filterType__,...)
Definition Log.h:137
@ HIGHGUID_PLAYER
uint64 MAKE_NEW_GUID(uint32 l, uint32 e, uint32 h)
Skyfire::AutoPtr< ResultSet, Skyfire::Mutex > QueryResult
Definition QueryResult.h:48
TeamId
@ TEAM_ALLIANCE
@ TEAM_HORDE
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition Timer.h:22
uint32 getMSTime()
Definition Timer.h:12
Skyfire::AutoPtr< Transaction, Skyfire::Mutex > SQLTransaction
Definition Transaction.h:42
Definition Field.h:16
uint8 GetUInt8() const
Definition Field.h:26
std::string GetString() const
Definition Field.h:228
uint32 GetUInt32() const
Definition Field.h:105
void SetGuildSettings(uint32 guildGuid, LFGuildSettings const &settings)
Stores guild settings and begins an asynchronous database insert.
void LoadMembershipRequests()
MembershipRequestStore _membershipRequests
void RemoveMembershipRequest(uint32 playerId, uint32 guildId)
Removes a membership request to a guild.
void AddMembershipRequest(uint32 guildGuid, MembershipRequest const &request)
Files a membership request to a guild.
bool HasRequest(uint32 playerId, uint32 guildId)
Provided a player DB guid and a guild DB guid, determines if a pending request is filed with these ke...
LFGuildStore GetGuildsMatchingSetting(LFGuildPlayer &settings, TeamId faction)
Returns a store of guilds matching the settings provided, using bitmask operators.
uint8 CountRequestsFromPlayer(uint32 playerId)
Counts the amount of pending membership requests, given the player's db guid.
void SendMembershipRequestListUpdate(Player &player)
std::list< MembershipRequest > GetAllMembershipRequestsForPlayer(uint32 playerGuid)
Returns a list of membership requests for a player.
void RemoveAllMembershipRequestsFromPlayer(uint32 playerId)
Removes all membership request from a player.
LFGuildStore _guildSettings
void SendApplicantListUpdate(Guild &guild)
void DeleteGuild(uint32 guildId)
Wipes everything related to a guild. Used when that guild is disbanded.
Definition Guild.h:324
uint64 GetLeaderGUID() const
Definition Guild.h:759
void BroadcastPacketToRank(WorldPacket *packet, uint8 rankId) const
Definition Guild.cpp:2758
static Player * FindPlayer(uint64)
void SendDirectMessage(WorldPacket *data)
Definition Player.cpp:6904
void setString(const uint8 index, const std::string &value)
void setUInt32(const uint8 index, const uint32 value)
void setUInt8(const uint8 index, const uint8 value)
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition Main.cpp:41
@ SMSG_LF_GUILD_APPLICANT_LIST_UPDATED
Definition Opcodes.h:751
@ SMSG_LF_GUILD_APPLICATIONS_LIST_CHANGED
Definition Opcodes.h:752
Holds all informations about a player's finder settings. NOT stored in database.
uint8 GetAvailability() const
std::string const & GetComment() const
uint8 GetClassRoles() const
uint32 GetGUID() const
uint8 GetLevel() const
uint8 GetInterests() const
Holds settings for a guild in the finder system. Saved to database.
bool IsListed() const
TeamId GetTeam() const
Holds all required informations about a membership request.
uint32 GetGuildId() const
uint8 GetClassRoles() const
time_t GetSubmitTime() const
uint8 GetInterests() const
uint32 GetPlayerGUID() const
std::string const & GetComment() const
uint8 GetAvailability() const