mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-30 13:47:23 +01:00
Core: Optimize guild loading
--HG-- branch : trunk
This commit is contained in:
@@ -872,42 +872,6 @@ void Guild::DisplayGuildEventLog(WorldSession *session)
|
||||
sLog.outDebug("WORLD: Sent (MSG_GUILD_EVENT_LOG_QUERY)");
|
||||
}
|
||||
|
||||
// Load guild eventlog from DB
|
||||
void Guild::LoadGuildEventLogFromDB()
|
||||
{
|
||||
// 0 1 2 3 4 5
|
||||
QueryResult result = CharacterDatabase.PQuery("SELECT LogGuid, EventType, PlayerGuid1, PlayerGuid2, NewRank, TimeStamp FROM guild_eventlog WHERE guildid=%u ORDER BY TimeStamp DESC,LogGuid DESC LIMIT %u", m_Id, GUILD_EVENTLOG_MAX_RECORDS);
|
||||
if (!result)
|
||||
return;
|
||||
bool isNextLogGuidSet = false;
|
||||
//uint32 configCount = sWorld.getIntConfig(CONFIG_GUILD_EVENT_LOG_COUNT);
|
||||
// First event in list will be the oldest and the latest event is last event in list
|
||||
do
|
||||
{
|
||||
Field *fields = result->Fetch();
|
||||
if (!isNextLogGuidSet)
|
||||
{
|
||||
m_GuildEventLogNextGuid = fields[0].GetUInt32();
|
||||
isNextLogGuidSet = true;
|
||||
}
|
||||
// Fill entry
|
||||
GuildEventLogEntry NewEvent;
|
||||
NewEvent.EventType = fields[1].GetUInt8();
|
||||
NewEvent.PlayerGuid1 = fields[2].GetUInt32();
|
||||
NewEvent.PlayerGuid2 = fields[3].GetUInt32();
|
||||
NewEvent.NewRank = fields[4].GetUInt8();
|
||||
NewEvent.TimeStamp = fields[5].GetUInt64();
|
||||
|
||||
// There can be a problem if more events have same TimeStamp the ORDER can be broken when fields[0].GetUInt32() == configCount, but
|
||||
// events with same timestamp can appear when there is lag, and we naivly suppose that mangos isn't laggy
|
||||
// but if problem appears, player will see set of guild events that have same timestamp in bad order
|
||||
|
||||
// Add entry to list
|
||||
m_GuildEventLog.push_front(NewEvent);
|
||||
|
||||
} while (result->NextRow());
|
||||
}
|
||||
|
||||
// Add entry to guild eventlog
|
||||
void Guild::LogGuildEvent(uint8 EventType, uint32 PlayerGuid1, uint32 PlayerGuid2, uint8 NewRank)
|
||||
{
|
||||
@@ -1121,87 +1085,6 @@ uint32 Guild::GetBankRights(uint32 rankId, uint8 TabId) const
|
||||
return m_Ranks[rankId].TabRight[TabId];
|
||||
}
|
||||
|
||||
// *************************************************
|
||||
// Guild bank loading related
|
||||
|
||||
// This load should be called on startup only
|
||||
void Guild::LoadGuildBankFromDB()
|
||||
{
|
||||
// 0 1 2 3
|
||||
QueryResult result = CharacterDatabase.PQuery("SELECT TabId, TabName, TabIcon, TabText FROM guild_bank_tab WHERE guildid='%u' ORDER BY TabId", m_Id);
|
||||
if (!result)
|
||||
{
|
||||
m_TabListMap.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
Field *fields = result->Fetch();
|
||||
uint8 tabId = fields[0].GetUInt8();
|
||||
if (tabId >= GetPurchasedTabs())
|
||||
{
|
||||
sLog.outError("Table `guild_bank_tab` have not purchased tab %u for guild %u, skipped", tabId, m_Id);
|
||||
continue;
|
||||
}
|
||||
|
||||
GuildBankTab *NewTab = new GuildBankTab;
|
||||
|
||||
NewTab->Name = fields[1].GetCppString();
|
||||
NewTab->Icon = fields[2].GetCppString();
|
||||
NewTab->Text = fields[3].GetCppString();
|
||||
|
||||
m_TabListMap[tabId] = NewTab;
|
||||
} while (result->NextRow());
|
||||
|
||||
// data needs to be at first place for Item::LoadFromDB
|
||||
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
||||
result = CharacterDatabase.PQuery("SELECT creatorGuid, giftCreatorGuid, count, duration, charges, flags, enchantments, randomPropertyId, durability, playedTime, text, TabId, SlotId, item_guid, item_entry FROM guild_bank_item JOIN item_instance ON item_guid = guid WHERE guildid='%u' ORDER BY TabId", m_Id);
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
do
|
||||
{
|
||||
Field *fields = result->Fetch();
|
||||
uint8 TabId = fields[11].GetUInt8();
|
||||
uint8 SlotId = fields[12].GetUInt8();
|
||||
uint32 ItemGuid = fields[13].GetUInt32();
|
||||
uint32 ItemEntry = fields[14].GetUInt32();
|
||||
|
||||
if (TabId >= GetPurchasedTabs())
|
||||
{
|
||||
sLog.outError("Guild::LoadGuildBankFromDB: Invalid tab for item (GUID: %u id: #%u) in guild bank, skipped.", ItemGuid,ItemEntry);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (SlotId >= GUILD_BANK_MAX_SLOTS)
|
||||
{
|
||||
sLog.outError("Guild::LoadGuildBankFromDB: Invalid slot for item (GUID: %u id: #%u) in guild bank, skipped.", ItemGuid,ItemEntry);
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemPrototype const *proto = sObjectMgr.GetItemPrototype(ItemEntry);
|
||||
|
||||
if (!proto)
|
||||
{
|
||||
sLog.outError("Guild::LoadGuildBankFromDB: Unknown item (GUID: %u id: #%u) in guild bank, skipped.", ItemGuid,ItemEntry);
|
||||
continue;
|
||||
}
|
||||
|
||||
Item *pItem = NewItemOrBag(proto);
|
||||
if (!pItem->LoadFromDB(ItemGuid, 0, result, ItemEntry))
|
||||
{
|
||||
CharacterDatabase.PExecute("DELETE FROM guild_bank_item WHERE guildid='%u' AND TabId='%u' AND SlotId='%u'", m_Id, uint32(TabId), uint32(SlotId));
|
||||
sLog.outError("Item GUID %u not found in item_instance, deleting from Guild Bank!", ItemGuid);
|
||||
delete pItem;
|
||||
continue;
|
||||
}
|
||||
|
||||
pItem->AddToWorld();
|
||||
m_TabListMap[TabId]->Slots[SlotId] = pItem;
|
||||
}while (result->NextRow());
|
||||
}
|
||||
|
||||
// *************************************************
|
||||
// Money deposit/withdraw related
|
||||
|
||||
@@ -1428,89 +1311,6 @@ bool Guild::LoadBankRightsFromDB(QueryResult guildBankTabRightsResult)
|
||||
// *************************************************
|
||||
// Bank log related
|
||||
|
||||
void Guild::LoadGuildBankEventLogFromDB()
|
||||
{
|
||||
// Money log is in TabId = GUILD_BANK_MONEY_LOGS_TAB
|
||||
|
||||
//uint32 configCount = sWorld.getIntConfig(CONFIG_GUILD_BANK_EVENT_LOG_COUNT);
|
||||
//cycle through all purchased guild bank item tabs
|
||||
for (uint32 tabId = 0; tabId < uint32(GetPurchasedTabs()); ++tabId)
|
||||
{
|
||||
// 0 1 2 3 4 5 6
|
||||
QueryResult result = CharacterDatabase.PQuery("SELECT LogGuid, EventType, PlayerGuid, ItemOrMoney, ItemStackCount, DestTabId, TimeStamp FROM guild_bank_eventlog WHERE guildid='%u' AND TabId='%u' ORDER BY TimeStamp DESC,LogGuid DESC LIMIT %u", m_Id, tabId, GUILD_BANK_MAX_LOGS);
|
||||
if (!result)
|
||||
continue;
|
||||
|
||||
bool isNextLogGuidSet = false;
|
||||
do
|
||||
{
|
||||
Field *fields = result->Fetch();
|
||||
|
||||
GuildBankEventLogEntry NewEvent;
|
||||
NewEvent.EventType = fields[1].GetUInt8();
|
||||
NewEvent.PlayerGuid = fields[2].GetUInt32();
|
||||
NewEvent.ItemOrMoney = fields[3].GetUInt32();
|
||||
NewEvent.ItemStackCount = fields[4].GetUInt16();
|
||||
NewEvent.DestTabId = fields[5].GetUInt8();
|
||||
NewEvent.TimeStamp = fields[6].GetUInt64();
|
||||
|
||||
//if newEvent is moneyEvent, move it to moneyEventTab in DB and report error
|
||||
if (NewEvent.isMoneyEvent())
|
||||
{
|
||||
uint32 logGuid = fields[0].GetUInt32();
|
||||
CharacterDatabase.PExecute("UPDATE guild_bank_eventlog SET TabId='%u' WHERE guildid='%u' AND TabId='%u' AND LogGuid='%u'", GUILD_BANK_MONEY_LOGS_TAB, m_Id, tabId, logGuid);
|
||||
sLog.outError("GuildBankEventLog ERROR: MoneyEvent LogGuid %u for Guild %u had incorrectly set its TabId to %u, correcting it to %u TabId", logGuid, m_Id, tabId, GUILD_BANK_MONEY_LOGS_TAB);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
//add event to list
|
||||
//events are ordered from oldest (in beginning) to latest (in the end)
|
||||
m_GuildBankEventLog_Item[tabId].push_front(NewEvent);
|
||||
|
||||
if (!isNextLogGuidSet)
|
||||
{
|
||||
m_GuildBankEventLogNextGuid_Item[tabId] = fields[0].GetUInt32();
|
||||
//we don't have to do m_GuildBankEventLogNextGuid_Item[tabId] %= configCount; - it will be done when creating new record
|
||||
isNextLogGuidSet = true;
|
||||
}
|
||||
} while (result->NextRow());
|
||||
}
|
||||
|
||||
//special handle for guild bank money log
|
||||
// 0 1 2 3 4 5 6
|
||||
QueryResult result = CharacterDatabase.PQuery("SELECT LogGuid, EventType, PlayerGuid, ItemOrMoney, ItemStackCount, DestTabId, TimeStamp FROM guild_bank_eventlog WHERE guildid='%u' AND TabId='%u' ORDER BY TimeStamp DESC,LogGuid DESC LIMIT %u", m_Id, GUILD_BANK_MONEY_LOGS_TAB, GUILD_BANK_MAX_LOGS);
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
bool isNextMoneyLogGuidSet = false;
|
||||
do
|
||||
{
|
||||
Field *fields = result->Fetch();
|
||||
if (!isNextMoneyLogGuidSet)
|
||||
{
|
||||
m_GuildBankEventLogNextGuid_Money = fields[0].GetUInt32();
|
||||
//we don't have to do m_GuildBankEventLogNextGuid_Money %= configCount; - it will be done when creating new record
|
||||
isNextMoneyLogGuidSet = true;
|
||||
}
|
||||
GuildBankEventLogEntry NewEvent;
|
||||
|
||||
NewEvent.EventType = fields[1].GetUInt8();
|
||||
NewEvent.PlayerGuid = fields[2].GetUInt32();
|
||||
NewEvent.ItemOrMoney = fields[3].GetUInt32();
|
||||
NewEvent.ItemStackCount = fields[4].GetUInt16();
|
||||
NewEvent.DestTabId = fields[5].GetUInt8();
|
||||
NewEvent.TimeStamp = fields[6].GetUInt64();
|
||||
|
||||
//if newEvent is not moneyEvent, then report error
|
||||
if (!NewEvent.isMoneyEvent())
|
||||
sLog.outError("GuildBankEventLog ERROR: MoneyEvent LogGuid %u for Guild %u is not MoneyEvent - ignoring...", fields[0].GetUInt32(), m_Id);
|
||||
else
|
||||
//add event to list
|
||||
//events are ordered from oldest (in beginning) to latest (in the end)
|
||||
m_GuildBankEventLog_Money.push_front(NewEvent);
|
||||
|
||||
} while (result->NextRow());
|
||||
}
|
||||
|
||||
void Guild::DisplayGuildBankLogs(WorldSession *session, uint8 TabId)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user