mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 22:37:03 +00:00
[8560] Optimized guild and arena team loading at startup.
Signed-off-by: Triply <triply@getmangos.com>
This commit is contained in:
parent
e412e10de1
commit
0356924cf9
6 changed files with 239 additions and 197 deletions
|
|
@ -161,90 +161,87 @@ bool ArenaTeam::AddMember(const uint64& PlayerGuid)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ArenaTeam::LoadArenaTeamFromDB(uint32 ArenaTeamId)
|
||||
bool ArenaTeam::LoadArenaTeamFromDB(QueryResult *arenaTeamDataResult)
|
||||
{
|
||||
QueryResult *result = CharacterDatabase.PQuery("SELECT arenateamid,name,captainguid,type,BackgroundColor,EmblemStyle,EmblemColor,BorderStyle,BorderColor FROM arena_team WHERE arenateamid = '%u'", ArenaTeamId);
|
||||
|
||||
if(!result)
|
||||
if(!arenaTeamDataResult)
|
||||
return false;
|
||||
|
||||
Field *fields = result->Fetch();
|
||||
Field *fields = arenaTeamDataResult->Fetch();
|
||||
|
||||
m_TeamId = fields[0].GetUInt32();
|
||||
m_Name = fields[1].GetCppString();
|
||||
m_CaptainGuid = MAKE_NEW_GUID(fields[2].GetUInt32(), 0, HIGHGUID_PLAYER);
|
||||
m_Type = fields[3].GetUInt32();
|
||||
m_BackgroundColor = fields[4].GetUInt32();
|
||||
m_EmblemStyle = fields[5].GetUInt32();
|
||||
m_EmblemColor = fields[6].GetUInt32();
|
||||
m_BorderStyle = fields[7].GetUInt32();
|
||||
m_BorderColor = fields[8].GetUInt32();
|
||||
|
||||
delete result;
|
||||
|
||||
// only load here, so additional checks can be made
|
||||
LoadStatsFromDB(ArenaTeamId);
|
||||
LoadMembersFromDB(ArenaTeamId);
|
||||
|
||||
if(Empty())
|
||||
{
|
||||
// arena team is empty, delete from db
|
||||
CharacterDatabase.BeginTransaction();
|
||||
CharacterDatabase.PExecute("DELETE FROM arena_team WHERE arenateamid = '%u'", ArenaTeamId);
|
||||
CharacterDatabase.PExecute("DELETE FROM arena_team_member WHERE arenateamid = '%u'", ArenaTeamId);
|
||||
CharacterDatabase.PExecute("DELETE FROM arena_team_stats WHERE arenateamid = '%u'", ArenaTeamId);
|
||||
CharacterDatabase.CommitTransaction();
|
||||
return false;
|
||||
}
|
||||
m_TeamId = fields[0].GetUInt32();
|
||||
m_Name = fields[1].GetCppString();
|
||||
m_CaptainGuid = MAKE_NEW_GUID(fields[2].GetUInt32(), 0, HIGHGUID_PLAYER);
|
||||
m_Type = fields[3].GetUInt32();
|
||||
m_BackgroundColor = fields[4].GetUInt32();
|
||||
m_EmblemStyle = fields[5].GetUInt32();
|
||||
m_EmblemColor = fields[6].GetUInt32();
|
||||
m_BorderStyle = fields[7].GetUInt32();
|
||||
m_BorderColor = fields[8].GetUInt32();
|
||||
//load team stats
|
||||
m_stats.rating = fields[9].GetUInt32();
|
||||
m_stats.games_week = fields[10].GetUInt32();
|
||||
m_stats.wins_week = fields[11].GetUInt32();
|
||||
m_stats.games_season = fields[12].GetUInt32();
|
||||
m_stats.wins_season = fields[13].GetUInt32();
|
||||
m_stats.rank = fields[14].GetUInt32();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ArenaTeam::LoadStatsFromDB(uint32 ArenaTeamId)
|
||||
bool ArenaTeam::LoadMembersFromDB(QueryResult *arenaTeamMembersResult)
|
||||
{
|
||||
// 0 1 2 3 4 5
|
||||
QueryResult *result = CharacterDatabase.PQuery("SELECT rating,games,wins,played,wins2,rank FROM arena_team_stats WHERE arenateamid = '%u'", ArenaTeamId);
|
||||
if(!arenaTeamMembersResult)
|
||||
return false;
|
||||
|
||||
if(!result)
|
||||
return;
|
||||
|
||||
Field *fields = result->Fetch();
|
||||
|
||||
m_stats.rating = fields[0].GetUInt32();
|
||||
m_stats.games_week = fields[1].GetUInt32();
|
||||
m_stats.wins_week = fields[2].GetUInt32();
|
||||
m_stats.games_season = fields[3].GetUInt32();
|
||||
m_stats.wins_season = fields[4].GetUInt32();
|
||||
m_stats.rank = fields[5].GetUInt32();
|
||||
|
||||
delete result;
|
||||
}
|
||||
|
||||
void ArenaTeam::LoadMembersFromDB(uint32 ArenaTeamId)
|
||||
{
|
||||
// 0 1 2 3 4 5 6 7
|
||||
QueryResult *result = CharacterDatabase.PQuery("SELECT member.guid,played_week,wons_week,played_season,wons_season,personal_rating,name,class "
|
||||
"FROM arena_team_member member "
|
||||
"INNER JOIN characters chars on member.guid = chars.guid "
|
||||
"WHERE member.arenateamid = '%u'", ArenaTeamId);
|
||||
if(!result)
|
||||
return;
|
||||
bool captainPresentInTeam = false;
|
||||
|
||||
do
|
||||
{
|
||||
Field *fields = result->Fetch();
|
||||
Field *fields = arenaTeamMembersResult->Fetch();
|
||||
uint32 arenaTeamId = fields[0].GetUInt32();
|
||||
if (arenaTeamId < m_TeamId)
|
||||
{
|
||||
//there is in table arena_team_member record which doesn't have arenateamid in arena_team table, report error
|
||||
sLog.outErrorDb("ArenaTeam %u does not exist but it has record in arena_team_member table, deleting it!", arenaTeamId);
|
||||
CharacterDatabase.PExecute("DELETE FROM arena_team_member WHERE arenateamid = '%u'", arenaTeamId);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (arenaTeamId > m_TeamId)
|
||||
//we loaded all members for this arena_team already, break cycle
|
||||
break;
|
||||
|
||||
ArenaTeamMember newmember;
|
||||
newmember.guid = MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER);
|
||||
newmember.games_week = fields[1].GetUInt32();
|
||||
newmember.wins_week = fields[2].GetUInt32();
|
||||
newmember.games_season = fields[3].GetUInt32();
|
||||
newmember.wins_season = fields[4].GetUInt32();
|
||||
newmember.personal_rating = fields[5].GetUInt32();
|
||||
newmember.name = fields[6].GetCppString();
|
||||
newmember.Class = fields[7].GetUInt8();
|
||||
newmember.guid = MAKE_NEW_GUID(fields[1].GetUInt32(), 0, HIGHGUID_PLAYER);
|
||||
newmember.games_week = fields[2].GetUInt32();
|
||||
newmember.wins_week = fields[3].GetUInt32();
|
||||
newmember.games_season = fields[4].GetUInt32();
|
||||
newmember.wins_season = fields[5].GetUInt32();
|
||||
newmember.personal_rating = fields[6].GetUInt32();
|
||||
newmember.name = fields[7].GetCppString();
|
||||
newmember.Class = fields[8].GetUInt8();
|
||||
|
||||
//check if member exists in characters table
|
||||
if (newmember.name.empty())
|
||||
{
|
||||
sLog.outErrorDb("ArenaTeam %u has member with empty name - probably player %u doesn't exist, deleting him from memberlist!", arenaTeamId, GUID_LOPART(newmember.guid));
|
||||
this->DelMember(newmember.guid);
|
||||
continue;
|
||||
}
|
||||
if (newmember.guid == GetCaptain())
|
||||
captainPresentInTeam = true;
|
||||
|
||||
m_members.push_back(newmember);
|
||||
}while( result->NextRow() );
|
||||
delete result;
|
||||
}while (arenaTeamMembersResult->NextRow());
|
||||
|
||||
if(Empty() || !captainPresentInTeam)
|
||||
{
|
||||
// arena team is empty or captain is not in team, delete from db
|
||||
sLog.outErrorDb("ArenaTeam %u does not have any members or its captain is not in team, disbanding it...", m_TeamId);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ArenaTeam::SetCaptain(const uint64& guid)
|
||||
|
|
@ -296,9 +293,12 @@ void ArenaTeam::DelMember(uint64 guid)
|
|||
void ArenaTeam::Disband(WorldSession *session)
|
||||
{
|
||||
// event
|
||||
WorldPacket data;
|
||||
session->BuildArenaTeamEventPacket(&data, ERR_ARENA_TEAM_DISBANDED_S, 2, session->GetPlayerName(), GetName(), "");
|
||||
BroadcastPacket(&data);
|
||||
if (session)
|
||||
{
|
||||
WorldPacket data;
|
||||
session->BuildArenaTeamEventPacket(&data, ERR_ARENA_TEAM_DISBANDED_S, 2, session->GetPlayerName(), GetName(), "");
|
||||
BroadcastPacket(&data);
|
||||
}
|
||||
|
||||
while (!m_members.empty())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -179,8 +179,8 @@ class ArenaTeam
|
|||
|
||||
bool IsFighting() const;
|
||||
|
||||
bool LoadArenaTeamFromDB(uint32 ArenaTeamId);
|
||||
void LoadMembersFromDB(uint32 ArenaTeamId);
|
||||
bool LoadArenaTeamFromDB(QueryResult *arenaTeamDataResult);
|
||||
bool LoadMembersFromDB(QueryResult *arenaTeamMembersResult);
|
||||
void LoadStatsFromDB(uint32 ArenaTeamId);
|
||||
|
||||
void SaveToDB();
|
||||
|
|
|
|||
|
|
@ -208,62 +208,43 @@ void Guild::SetGINFO(std::string ginfo)
|
|||
CharacterDatabase.PExecute("UPDATE guild SET info='%s' WHERE guildid='%u'", ginfo.c_str(), m_Id);
|
||||
}
|
||||
|
||||
bool Guild::LoadGuildFromDB(uint32 GuildId)
|
||||
bool Guild::LoadGuildFromDB(QueryResult *guildDataResult)
|
||||
{
|
||||
//set m_Id in case guild data are broken in DB and Guild will be Disbanded (deleted from DB)
|
||||
m_Id = GuildId;
|
||||
|
||||
QueryResult *result = CharacterDatabase.PQuery("SELECT COUNT(TabId) FROM guild_bank_tab WHERE guildid='%u'", GuildId);
|
||||
if (result)
|
||||
{
|
||||
Field *fields = result->Fetch();
|
||||
m_PurchasedTabs = fields[0].GetUInt32();
|
||||
if (m_PurchasedTabs > GUILD_BANK_MAX_TABS)
|
||||
m_PurchasedTabs = GUILD_BANK_MAX_TABS;
|
||||
delete result;
|
||||
}
|
||||
|
||||
if (!LoadRanksFromDB(GuildId))
|
||||
if (!guildDataResult)
|
||||
return false;
|
||||
|
||||
if (!LoadMembersFromDB(GuildId))
|
||||
return false;
|
||||
Field *fields = guildDataResult->Fetch();
|
||||
|
||||
LoadBankRightsFromDB(GuildId); // Must be after LoadRanksFromDB because it populates rank struct
|
||||
m_Id = fields[0].GetUInt32();
|
||||
m_Name = fields[1].GetCppString();
|
||||
m_LeaderGuid = MAKE_NEW_GUID(fields[2].GetUInt32(), 0, HIGHGUID_PLAYER);
|
||||
m_EmblemStyle = fields[3].GetUInt32();
|
||||
m_EmblemColor = fields[4].GetUInt32();
|
||||
m_BorderStyle = fields[5].GetUInt32();
|
||||
m_BorderColor = fields[6].GetUInt32();
|
||||
m_BackgroundColor = fields[7].GetUInt32();
|
||||
GINFO = fields[8].GetCppString();
|
||||
MOTD = fields[9].GetCppString();
|
||||
time_t time = fields[10].GetUInt64();
|
||||
m_GuildBankMoney = fields[11].GetUInt64();
|
||||
m_PurchasedTabs = fields[12].GetUInt32();
|
||||
|
||||
// 0 1 2 3 4 5
|
||||
result = CharacterDatabase.PQuery("SELECT name, leaderguid, EmblemStyle, EmblemColor, BorderStyle, BorderColor,"
|
||||
// 6 7 8 9 10
|
||||
"BackgroundColor, info, motd, createdate, BankMoney FROM guild WHERE guildid = '%u'", GuildId);
|
||||
|
||||
if (!result)
|
||||
return false;
|
||||
|
||||
Field *fields = result->Fetch();
|
||||
|
||||
m_Name = fields[0].GetCppString();
|
||||
m_LeaderGuid = MAKE_NEW_GUID(fields[1].GetUInt32(), 0, HIGHGUID_PLAYER);
|
||||
|
||||
m_EmblemStyle = fields[2].GetUInt32();
|
||||
m_EmblemColor = fields[3].GetUInt32();
|
||||
m_BorderStyle = fields[4].GetUInt32();
|
||||
m_BorderColor = fields[5].GetUInt32();
|
||||
m_BackgroundColor = fields[6].GetUInt32();
|
||||
GINFO = fields[7].GetCppString();
|
||||
MOTD = fields[8].GetCppString();
|
||||
time_t time = fields[9].GetUInt64();
|
||||
m_GuildBankMoney = fields[10].GetUInt64();
|
||||
|
||||
delete result;
|
||||
if (m_PurchasedTabs > GUILD_BANK_MAX_TABS)
|
||||
m_PurchasedTabs = GUILD_BANK_MAX_TABS;
|
||||
|
||||
if (time > 0)
|
||||
{
|
||||
tm local = *(localtime(&time)); // dereference and assign
|
||||
tm local = *(localtime(&time)); // dereference and assign
|
||||
m_CreatedDay = local.tm_mday;
|
||||
m_CreatedMonth = local.tm_mon + 1;
|
||||
m_CreatedYear = local.tm_year + 1900;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Guild::CheckGuildStructure()
|
||||
{
|
||||
// Repair the structure of guild
|
||||
// If the guildmaster doesn't exist or isn't the member of guild
|
||||
// attempt to promote another member
|
||||
|
|
@ -286,24 +267,19 @@ bool Guild::LoadGuildFromDB(uint32 GuildId)
|
|||
ChangeRank(itr->first, GR_OFFICER);
|
||||
}
|
||||
|
||||
sLog.outDebug("Guild %u Creation time Loaded day: %u, month: %u, year: %u", GuildId, m_CreatedDay, m_CreatedMonth, m_CreatedYear);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Guild::LoadRanksFromDB(uint32 GuildId)
|
||||
bool Guild::LoadRanksFromDB(QueryResult *guildRanksResult)
|
||||
{
|
||||
Field *fields;
|
||||
// 0 1 2 3
|
||||
QueryResult *result = CharacterDatabase.PQuery("SELECT rid,rname,rights,BankMoneyPerDay FROM guild_rank WHERE guildid = '%u' ORDER BY rid ASC", GuildId);
|
||||
|
||||
if (!result)
|
||||
if (!guildRanksResult)
|
||||
{
|
||||
sLog.outError("Guild %u has broken `guild_rank` data, creating new...",GuildId);
|
||||
sLog.outError("Guild %u has broken `guild_rank` data, creating new...",m_Id);
|
||||
CreateDefaultGuildRanks(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
Field *fields;
|
||||
bool broken_ranks = false;
|
||||
|
||||
//GUILD RANKS are sequence starting from 0 = GUILD_MASTER (ALL PRIVILEGES) to max 9 (lowest privileges)
|
||||
|
|
@ -313,12 +289,24 @@ bool Guild::LoadRanksFromDB(uint32 GuildId)
|
|||
|
||||
do
|
||||
{
|
||||
fields = result->Fetch();
|
||||
fields = guildRanksResult->Fetch();
|
||||
|
||||
uint32 rankID = fields[0].GetUInt32();
|
||||
std::string rankName = fields[1].GetCppString();
|
||||
uint32 rankRights = fields[2].GetUInt32();
|
||||
uint32 rankMoney = fields[3].GetUInt32();
|
||||
uint32 guildId = fields[0].GetUInt32();
|
||||
if (guildId < m_Id)
|
||||
{
|
||||
//there is in table guild_rank record which doesn't have guildid in guild table, report error
|
||||
sLog.outErrorDb("Guild %u does not exist but it has a record in guild_rank table, deleting it!", guildId);
|
||||
CharacterDatabase.PExecute("DELETE FROM guild_rank WHERE guildid = '%u'", guildId);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (guildId > m_Id)
|
||||
//we loaded all ranks for this guild already, break cycle
|
||||
break;
|
||||
uint32 rankID = fields[1].GetUInt32();
|
||||
std::string rankName = fields[2].GetCppString();
|
||||
uint32 rankRights = fields[3].GetUInt32();
|
||||
uint32 rankMoney = fields[4].GetUInt32();
|
||||
|
||||
if (rankID != m_Ranks.size()) // guild_rank.ids are sequence 0,1,2,3..
|
||||
broken_ranks = true;
|
||||
|
|
@ -328,28 +316,27 @@ bool Guild::LoadRanksFromDB(uint32 GuildId)
|
|||
rankRights |= GR_RIGHT_ALL;
|
||||
|
||||
AddRank(rankName,rankRights,rankMoney);
|
||||
}while( result->NextRow() );
|
||||
delete result;
|
||||
}while( guildRanksResult->NextRow() );
|
||||
|
||||
if (m_Ranks.size() < GUILD_RANKS_MIN_COUNT) // if too few ranks, renew them
|
||||
{
|
||||
m_Ranks.clear();
|
||||
sLog.outError("Guild %u has broken `guild_rank` data, creating new...",GuildId);
|
||||
sLog.outError("Guild %u has broken `guild_rank` data, creating new...", m_Id);
|
||||
CreateDefaultGuildRanks(0); // 0 is default locale_idx
|
||||
broken_ranks = false;
|
||||
}
|
||||
// guild_rank have wrong numbered ranks, repair
|
||||
if (broken_ranks)
|
||||
{
|
||||
sLog.outError("Guild %u has broken `guild_rank` data, repairing...",GuildId);
|
||||
sLog.outError("Guild %u has broken `guild_rank` data, repairing...", m_Id);
|
||||
CharacterDatabase.BeginTransaction();
|
||||
CharacterDatabase.PExecute("DELETE FROM guild_rank WHERE guildid='%u'", GuildId);
|
||||
CharacterDatabase.PExecute("DELETE FROM guild_rank WHERE guildid='%u'", m_Id);
|
||||
for(size_t i = 0; i < m_Ranks.size(); ++i)
|
||||
{
|
||||
std::string name = m_Ranks[i].Name;
|
||||
uint32 rights = m_Ranks[i].Rights;
|
||||
CharacterDatabase.escape_string(name);
|
||||
CharacterDatabase.PExecute( "INSERT INTO guild_rank (guildid,rid,rname,rights) VALUES ('%u', '%u', '%s', '%u')", GuildId, uint32(i), name.c_str(), rights);
|
||||
CharacterDatabase.PExecute( "INSERT INTO guild_rank (guildid,rid,rname,rights) VALUES ('%u', '%u', '%s', '%u')", m_Id, uint32(i), name.c_str(), rights);
|
||||
}
|
||||
CharacterDatabase.CommitTransaction();
|
||||
}
|
||||
|
|
@ -357,46 +344,49 @@ bool Guild::LoadRanksFromDB(uint32 GuildId)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Guild::LoadMembersFromDB(uint32 GuildId)
|
||||
bool Guild::LoadMembersFromDB(QueryResult *guildMembersResult)
|
||||
{
|
||||
// 0 1 2 3 4 5
|
||||
QueryResult *result = CharacterDatabase.PQuery("SELECT guild_member.guid,rank, pnote, offnote, BankResetTimeMoney,BankRemMoney,"
|
||||
// 6 7 8 9 10 11
|
||||
"BankResetTimeTab0, BankRemSlotsTab0, BankResetTimeTab1, BankRemSlotsTab1, BankResetTimeTab2, BankRemSlotsTab2,"
|
||||
// 12 13 14 15 16 17
|
||||
"BankResetTimeTab3, BankRemSlotsTab3, BankResetTimeTab4, BankRemSlotsTab4, BankResetTimeTab5, BankRemSlotsTab5,"
|
||||
// 18 19 20 21 22
|
||||
"characters.name, characters.level, characters.class, characters.zone, characters.logout_time "
|
||||
"FROM guild_member LEFT JOIN characters ON characters.guid = guild_member.guid WHERE guildid = '%u'", GuildId);
|
||||
|
||||
if (!result)
|
||||
if (!guildMembersResult)
|
||||
return false;
|
||||
|
||||
do
|
||||
{
|
||||
Field *fields = result->Fetch();
|
||||
Field *fields = guildMembersResult->Fetch();
|
||||
uint32 guildId = fields[0].GetUInt32();
|
||||
if (guildId < m_Id)
|
||||
{
|
||||
//there is in table guild_member record which doesn't have guildid in guild table, report error
|
||||
sLog.outErrorDb("Guild %u does not exist but it has a record in guild_member table, deleting it!", guildId);
|
||||
CharacterDatabase.PExecute("DELETE FROM guild_member WHERE guildid = '%u'", guildId);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (guildId > m_Id)
|
||||
//we loaded all members for this guild already, break cycle
|
||||
break;
|
||||
|
||||
MemberSlot newmember;
|
||||
uint64 guid = MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER);
|
||||
newmember.RankId = fields[1].GetUInt32();
|
||||
uint64 guid = MAKE_NEW_GUID(fields[1].GetUInt32(), 0, HIGHGUID_PLAYER);
|
||||
newmember.RankId = fields[2].GetUInt32();
|
||||
//don't allow member to have not existing rank!
|
||||
if (newmember.RankId >= m_Ranks.size())
|
||||
newmember.RankId = GetLowestRank();
|
||||
|
||||
newmember.Pnote = fields[2].GetCppString();
|
||||
newmember.OFFnote = fields[3].GetCppString();
|
||||
newmember.BankResetTimeMoney = fields[4].GetUInt32();
|
||||
newmember.BankRemMoney = fields[5].GetUInt32();
|
||||
newmember.Pnote = fields[3].GetCppString();
|
||||
newmember.OFFnote = fields[4].GetCppString();
|
||||
newmember.BankResetTimeMoney = fields[5].GetUInt32();
|
||||
newmember.BankRemMoney = fields[6].GetUInt32();
|
||||
for (int i = 0; i < GUILD_BANK_MAX_TABS; ++i)
|
||||
{
|
||||
newmember.BankResetTimeTab[i] = fields[6+(2*i)].GetUInt32();
|
||||
newmember.BankRemSlotsTab[i] = fields[7+(2*i)].GetUInt32();
|
||||
newmember.BankResetTimeTab[i] = fields[7+(2*i)].GetUInt32();
|
||||
newmember.BankRemSlotsTab[i] = fields[8+(2*i)].GetUInt32();
|
||||
}
|
||||
|
||||
newmember.Name = fields[18].GetCppString();
|
||||
newmember.Level = fields[19].GetUInt8();
|
||||
newmember.Class = fields[20].GetUInt8();
|
||||
newmember.ZoneId = fields[21].GetUInt32();
|
||||
newmember.LogoutTime = fields[22].GetUInt64();
|
||||
newmember.Name = fields[19].GetCppString();
|
||||
newmember.Level = fields[20].GetUInt8();
|
||||
newmember.Class = fields[21].GetUInt8();
|
||||
newmember.ZoneId = fields[22].GetUInt32();
|
||||
newmember.LogoutTime = fields[23].GetUInt64();
|
||||
|
||||
//this code will remove unexisting character guids from guild
|
||||
if (newmember.Level < 1 || newmember.Level > STRONG_MAX_LEVEL) // can be at broken `data` field
|
||||
|
|
@ -421,8 +411,7 @@ bool Guild::LoadMembersFromDB(uint32 GuildId)
|
|||
|
||||
members[GUID_LOPART(guid)] = newmember;
|
||||
|
||||
}while( result->NextRow() );
|
||||
delete result;
|
||||
}while (guildMembersResult->NextRow());
|
||||
|
||||
if (members.empty())
|
||||
return false;
|
||||
|
|
@ -1464,28 +1453,36 @@ uint32 Guild::GetBankSlotPerDay(uint32 rankId, uint8 TabId)
|
|||
// *************************************************
|
||||
// Rights per day related
|
||||
|
||||
void Guild::LoadBankRightsFromDB(uint32 GuildId)
|
||||
bool Guild::LoadBankRightsFromDB(QueryResult *guildBankTabRightsResult)
|
||||
{
|
||||
// 0 1 2 3
|
||||
QueryResult *result = CharacterDatabase.PQuery("SELECT TabId, rid, gbright, SlotPerDay FROM guild_bank_right WHERE guildid = '%u' ORDER BY TabId", GuildId);
|
||||
|
||||
if (!result)
|
||||
return;
|
||||
if (!guildBankTabRightsResult)
|
||||
return true;
|
||||
|
||||
do
|
||||
{
|
||||
Field *fields = result->Fetch();
|
||||
uint8 TabId = fields[0].GetUInt8();
|
||||
uint32 rankId = fields[1].GetUInt32();
|
||||
uint16 right = fields[2].GetUInt16();
|
||||
uint16 SlotPerDay = fields[3].GetUInt16();
|
||||
Field *fields = guildBankTabRightsResult->Fetch();
|
||||
uint32 guildId = fields[0].GetUInt32();
|
||||
if (guildId < m_Id)
|
||||
{
|
||||
//there is in table guild_bank_right record which doesn't have guildid in guild table, report error
|
||||
sLog.outErrorDb("Guild %u does not exist but it has a record in guild_bank_right table, deleting it!", guildId);
|
||||
CharacterDatabase.PExecute("DELETE FROM guild_bank_right WHERE guildid = '%u'", guildId);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (guildId > m_Id)
|
||||
//we loaded all ranks for this guild bank already, break cycle
|
||||
break;
|
||||
uint8 TabId = fields[1].GetUInt8();
|
||||
uint32 rankId = fields[2].GetUInt32();
|
||||
uint16 right = fields[3].GetUInt16();
|
||||
uint16 SlotPerDay = fields[4].GetUInt16();
|
||||
|
||||
SetBankRightsAndSlots(rankId, TabId, right, SlotPerDay, false);
|
||||
|
||||
} while (result->NextRow());
|
||||
delete result;
|
||||
} while (guildBankTabRightsResult->NextRow());
|
||||
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
// *************************************************
|
||||
|
|
|
|||
|
|
@ -324,9 +324,10 @@ class Guild
|
|||
|
||||
uint32 GetMemberSize() const { return members.size(); }
|
||||
|
||||
bool LoadGuildFromDB(uint32 GuildId);
|
||||
bool LoadRanksFromDB(uint32 GuildId);
|
||||
bool LoadMembersFromDB(uint32 GuildId);
|
||||
bool LoadGuildFromDB(QueryResult *guildDataResult);
|
||||
bool CheckGuildStructure();
|
||||
bool LoadRanksFromDB(QueryResult *guildRanksResult);
|
||||
bool LoadMembersFromDB(QueryResult *guildMembersResult);
|
||||
|
||||
void SetMemberStats(uint64 guid);
|
||||
|
||||
|
|
@ -422,7 +423,7 @@ class Guild
|
|||
uint32 GetBankMoneyPerDay(uint32 rankId);
|
||||
uint32 GetBankSlotPerDay(uint32 rankId, uint8 TabId);
|
||||
// rights per day
|
||||
void LoadBankRightsFromDB(uint32 GuildId);
|
||||
bool LoadBankRightsFromDB(QueryResult *guildBankTabRightsResult);
|
||||
// Guild Bank Event Logs
|
||||
void LoadGuildBankEventLogFromDB();
|
||||
void UnloadGuildBankEventLog();
|
||||
|
|
|
|||
|
|
@ -2855,10 +2855,14 @@ void ObjectMgr::BuildPlayerLevelInfo(uint8 race, uint8 _class, uint8 level, Play
|
|||
|
||||
void ObjectMgr::LoadGuilds()
|
||||
{
|
||||
Guild *newguild;
|
||||
Guild *newGuild;
|
||||
uint32 count = 0;
|
||||
|
||||
QueryResult *result = CharacterDatabase.Query( "SELECT guildid FROM guild" );
|
||||
// 0 1 2 3 4 5 6
|
||||
QueryResult *result = CharacterDatabase.Query("SELECT guild.guildid,guild.name,leaderguid,EmblemStyle,EmblemColor,BorderStyle,BorderColor,"
|
||||
// 7 8 9 10 11 12
|
||||
"BackgroundColor,info,motd,createdate,BankMoney,COUNT(guild_bank_tab.guildid) "
|
||||
"FROM guild LEFT JOIN guild_bank_tab ON guild.guildid = guild_bank_tab.guildid GROUP BY guild.guildid ORDER BY guildid ASC");
|
||||
|
||||
if( !result )
|
||||
{
|
||||
|
|
@ -2872,27 +2876,54 @@ void ObjectMgr::LoadGuilds()
|
|||
return;
|
||||
}
|
||||
|
||||
// load guild ranks
|
||||
// 0 1 2 3 4
|
||||
QueryResult *guildRanksResult = CharacterDatabase.Query("SELECT guildid,rid,rname,rights,BankMoneyPerDay FROM guild_rank ORDER BY guildid ASC, rid ASC");
|
||||
|
||||
// load guild members
|
||||
// 0 1 2 3 4 5 6
|
||||
QueryResult *guildMembersResult = CharacterDatabase.Query("SELECT guildid,guild_member.guid,rank,pnote,offnote,BankResetTimeMoney,BankRemMoney,"
|
||||
// 7 8 9 10 11 12
|
||||
"BankResetTimeTab0,BankRemSlotsTab0,BankResetTimeTab1,BankRemSlotsTab1,BankResetTimeTab2,BankRemSlotsTab2,"
|
||||
// 13 14 15 16 17 18
|
||||
"BankResetTimeTab3,BankRemSlotsTab3,BankResetTimeTab4,BankRemSlotsTab4,BankResetTimeTab5,BankRemSlotsTab5,"
|
||||
// 19 20 21 22 23
|
||||
"characters.name, characters.level, characters.class, characters.zone, characters.logout_time "
|
||||
"FROM guild_member LEFT JOIN characters ON characters.guid = guild_member.guid ORDER BY guildid ASC");
|
||||
|
||||
// load guild bank tab rights
|
||||
// 0 1 2 3 4
|
||||
QueryResult *guildBankTabRightsResult = CharacterDatabase.Query("SELECT guildid,TabId,rid,gbright,SlotPerDay FROM guild_bank_right ORDER BY guildid ASC, TabId ASC");
|
||||
|
||||
barGoLink bar( result->GetRowCount() );
|
||||
|
||||
do
|
||||
{
|
||||
Field *fields = result->Fetch();
|
||||
//Field *fields = result->Fetch();
|
||||
|
||||
bar.step();
|
||||
++count;
|
||||
|
||||
newguild = new Guild;
|
||||
if(!newguild->LoadGuildFromDB(fields[0].GetUInt32()))
|
||||
newGuild = new Guild;
|
||||
if (!newGuild->LoadGuildFromDB(result) ||
|
||||
!newGuild->LoadRanksFromDB(guildRanksResult) ||
|
||||
!newGuild->LoadMembersFromDB(guildMembersResult) ||
|
||||
!newGuild->LoadBankRightsFromDB(guildBankTabRightsResult) ||
|
||||
!newGuild->CheckGuildStructure()
|
||||
)
|
||||
{
|
||||
newguild->Disband();
|
||||
delete newguild;
|
||||
newGuild->Disband();
|
||||
delete newGuild;
|
||||
continue;
|
||||
}
|
||||
AddGuild(newguild);
|
||||
AddGuild(newGuild);
|
||||
|
||||
}while( result->NextRow() );
|
||||
|
||||
delete result;
|
||||
delete guildRanksResult;
|
||||
delete guildMembersResult;
|
||||
delete guildBankTabRightsResult;
|
||||
|
||||
//delete unused LogGuid records in guild_eventlog and guild_bank_eventlog table
|
||||
//you can comment these lines if you don't plan to change CONFIG_GUILD_EVENT_LOG_COUNT and CONFIG_GUILD_BANK_EVENT_LOG_COUNT
|
||||
|
|
@ -2907,7 +2938,11 @@ void ObjectMgr::LoadArenaTeams()
|
|||
{
|
||||
uint32 count = 0;
|
||||
|
||||
QueryResult *result = CharacterDatabase.Query( "SELECT arenateamid FROM arena_team" );
|
||||
// 0 1 2 3 4 5
|
||||
QueryResult *result = CharacterDatabase.Query( "SELECT arena_team.arenateamid,name,captainguid,type,BackgroundColor,EmblemStyle,"
|
||||
// 6 7 8 9 10 11 12 13 14
|
||||
"EmblemColor,BorderStyle,BorderColor, rating,games,wins,played,wins2,rank "
|
||||
"FROM arena_team LEFT JOIN arena_team_stats ON arena_team.arenateamid = arena_team_stats.arenateamid ORDER BY arena_team.arenateamid ASC" );
|
||||
|
||||
if( !result )
|
||||
{
|
||||
|
|
@ -2921,6 +2956,12 @@ void ObjectMgr::LoadArenaTeams()
|
|||
return;
|
||||
}
|
||||
|
||||
// load arena_team members
|
||||
QueryResult *arenaTeamMembersResult = CharacterDatabase.Query(
|
||||
// 0 1 2 3 4 5 6 7 8
|
||||
"SELECT arenateamid,member.guid,played_week,wons_week,played_season,wons_season,personal_rating,name,class "
|
||||
"FROM arena_team_member member LEFT JOIN characters chars on member.guid = chars.guid ORDER BY member.arenateamid ASC");
|
||||
|
||||
barGoLink bar( result->GetRowCount() );
|
||||
|
||||
do
|
||||
|
|
@ -2930,16 +2971,19 @@ void ObjectMgr::LoadArenaTeams()
|
|||
bar.step();
|
||||
++count;
|
||||
|
||||
ArenaTeam *newarenateam = new ArenaTeam;
|
||||
if(!newarenateam->LoadArenaTeamFromDB(fields[0].GetUInt32()))
|
||||
ArenaTeam *newArenaTeam = new ArenaTeam;
|
||||
if (!newArenaTeam->LoadArenaTeamFromDB(result) ||
|
||||
!newArenaTeam->LoadMembersFromDB(arenaTeamMembersResult))
|
||||
{
|
||||
delete newarenateam;
|
||||
newArenaTeam->Disband(NULL);
|
||||
delete newArenaTeam;
|
||||
continue;
|
||||
}
|
||||
AddArenaTeam(newarenateam);
|
||||
AddArenaTeam(newArenaTeam);
|
||||
}while( result->NextRow() );
|
||||
|
||||
delete result;
|
||||
delete arenaTeamMembersResult;
|
||||
|
||||
sLog.outString();
|
||||
sLog.outString( ">> Loaded %u arenateam definitions", count );
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __REVISION_NR_H__
|
||||
#define __REVISION_NR_H__
|
||||
#define REVISION_NR "8559"
|
||||
#define REVISION_NR "8560"
|
||||
#endif // __REVISION_NR_H__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue