mirror of
https://github.com/mangosfour/server.git
synced 2025-12-15 10:37:02 +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
|
|
@ -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;
|
||||
}
|
||||
|
||||
// *************************************************
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue