mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-23 02:25:38 +01:00
Store cached static data queries, instead of building them in every query opcode (#18637)
- Added config option to enable / disable cache - Reinitialize data on reload command use - Always send WDB fields in item query
This commit is contained in:
@@ -97,51 +97,14 @@ void WorldSession::HandleCreatureQueryOpcode(WorldPacket& recvData)
|
||||
CreatureTemplate const* ci = sObjectMgr->GetCreatureTemplate(entry);
|
||||
if (ci)
|
||||
{
|
||||
std::string Name, Title;
|
||||
Name = ci->Name;
|
||||
Title = ci->Title;
|
||||
|
||||
int loc_idx = GetSessionDbLocaleIndex();
|
||||
if (loc_idx >= 0)
|
||||
{
|
||||
if (CreatureLocale const* cl = sObjectMgr->GetCreatureLocale(entry))
|
||||
{
|
||||
ObjectMgr::GetLocaleString(cl->Name, loc_idx, Name);
|
||||
ObjectMgr::GetLocaleString(cl->Title, loc_idx, Title);
|
||||
}
|
||||
}
|
||||
TC_LOG_DEBUG("network", "WORLD: CMSG_CREATURE_QUERY '%s' - Entry: %u.", ci->Name.c_str(), entry);
|
||||
// guess size
|
||||
WorldPacket data(SMSG_CREATURE_QUERY_RESPONSE, 100);
|
||||
data << uint32(entry); // creature entry
|
||||
data << Name;
|
||||
data << uint8(0) << uint8(0) << uint8(0); // name2, name3, name4, always empty
|
||||
data << Title;
|
||||
data << ci->IconName; // "Directions" for guard, string for Icons 2.3.0
|
||||
data << uint32(ci->type_flags); // flags
|
||||
data << uint32(ci->type); // CreatureType.dbc
|
||||
data << uint32(ci->family); // CreatureFamily.dbc
|
||||
data << uint32(ci->rank); // Creature Rank (elite, boss, etc)
|
||||
data << uint32(ci->KillCredit[0]); // new in 3.1, kill credit
|
||||
data << uint32(ci->KillCredit[1]); // new in 3.1, kill credit
|
||||
data << uint32(ci->Modelid1); // Modelid1
|
||||
data << uint32(ci->Modelid2); // Modelid2
|
||||
data << uint32(ci->Modelid3); // Modelid3
|
||||
data << uint32(ci->Modelid4); // Modelid4
|
||||
data << float(ci->ModHealth); // dmg/hp modifier
|
||||
data << float(ci->ModMana); // dmg/mana modifier
|
||||
data << uint8(ci->RacialLeader);
|
||||
|
||||
CreatureQuestItemList const* items = sObjectMgr->GetCreatureQuestItemList(entry);
|
||||
if (items)
|
||||
for (uint32 i = 0; i < MAX_CREATURE_QUEST_ITEMS; ++i)
|
||||
data << (i < items->size() ? uint32((*items)[i]) : uint32(0));
|
||||
if (sWorld->getBoolConfig(CONFIG_CACHE_DATA_QUERIES))
|
||||
SendPacket(&ci->QueryData[static_cast<uint32>(GetSessionDbLocaleIndex())]);
|
||||
else
|
||||
for (uint32 i = 0; i < MAX_CREATURE_QUEST_ITEMS; ++i)
|
||||
data << uint32(0);
|
||||
|
||||
data << uint32(ci->movementId); // CreatureMovementInfo.dbc
|
||||
SendPacket(&data);
|
||||
{
|
||||
WorldPacket queryPacket = ci->BuildQueryData(GetSessionDbLocaleIndex());
|
||||
SendPacket(&queryPacket);
|
||||
}
|
||||
TC_LOG_DEBUG("network", "WORLD: Sent SMSG_CREATURE_QUERY_RESPONSE");
|
||||
}
|
||||
else
|
||||
@@ -166,44 +129,13 @@ void WorldSession::HandleGameObjectQueryOpcode(WorldPacket& recvData)
|
||||
const GameObjectTemplate* info = sObjectMgr->GetGameObjectTemplate(entry);
|
||||
if (info)
|
||||
{
|
||||
std::string Name;
|
||||
std::string IconName;
|
||||
std::string CastBarCaption;
|
||||
|
||||
Name = info->name;
|
||||
IconName = info->IconName;
|
||||
CastBarCaption = info->castBarCaption;
|
||||
|
||||
LocaleConstant localeConstant = GetSessionDbLocaleIndex();
|
||||
if (localeConstant >= LOCALE_enUS)
|
||||
if (GameObjectLocale const* gameObjectLocale = sObjectMgr->GetGameObjectLocale(entry))
|
||||
{
|
||||
ObjectMgr::GetLocaleString(gameObjectLocale->Name, localeConstant, Name);
|
||||
ObjectMgr::GetLocaleString(gameObjectLocale->CastBarCaption, localeConstant, CastBarCaption);
|
||||
}
|
||||
|
||||
TC_LOG_DEBUG("network", "WORLD: CMSG_GAMEOBJECT_QUERY '%s' - Entry: %u. ", info->name.c_str(), entry);
|
||||
WorldPacket data (SMSG_GAMEOBJECT_QUERY_RESPONSE, 150);
|
||||
data << uint32(entry);
|
||||
data << uint32(info->type);
|
||||
data << uint32(info->displayId);
|
||||
data << Name;
|
||||
data << uint8(0) << uint8(0) << uint8(0); // name2, name3, name4
|
||||
data << IconName; // 2.0.3, string. Icon name to use instead of default icon for go's (ex: "Attack" makes sword)
|
||||
data << CastBarCaption; // 2.0.3, string. Text will appear in Cast Bar when using GO (ex: "Collecting")
|
||||
data << info->unk1; // 2.0.3, string
|
||||
data.append(info->raw.data, MAX_GAMEOBJECT_DATA);
|
||||
data << float(info->size); // go size
|
||||
|
||||
GameObjectQuestItemList const* items = sObjectMgr->GetGameObjectQuestItemList(entry);
|
||||
if (items)
|
||||
for (size_t i = 0; i < MAX_GAMEOBJECT_QUEST_ITEMS; ++i)
|
||||
data << (i < items->size() ? uint32((*items)[i]) : uint32(0));
|
||||
if (sWorld->getBoolConfig(CONFIG_CACHE_DATA_QUERIES))
|
||||
SendPacket(&info->QueryData[static_cast<uint32>(GetSessionDbLocaleIndex())]);
|
||||
else
|
||||
for (size_t i = 0; i < MAX_GAMEOBJECT_QUEST_ITEMS; ++i)
|
||||
data << uint32(0);
|
||||
|
||||
SendPacket(&data);
|
||||
{
|
||||
WorldPacket queryPacket = info->BuildQueryData(GetSessionDbLocaleIndex());
|
||||
SendPacket(&queryPacket);
|
||||
}
|
||||
TC_LOG_DEBUG("network", "WORLD: Sent SMSG_GAMEOBJECT_QUERY_RESPONSE");
|
||||
}
|
||||
else
|
||||
@@ -421,7 +353,7 @@ void WorldSession::HandleQuestPOIQuery(WorldPacket& recvData)
|
||||
for (uint32 i = 0; i < count; ++i)
|
||||
questIds.insert(recvData.read<uint32>()); // quest id
|
||||
|
||||
WorldPacket data(SMSG_QUEST_POI_QUERY_RESPONSE, 4 + (4 + 4)*questIds.size());
|
||||
WorldPacket data(SMSG_QUEST_POI_QUERY_RESPONSE, 4 + (4 + 4 + 40)*questIds.size());
|
||||
data << uint32(questIds.size()); // count
|
||||
|
||||
for (auto itr = questIds.begin(); itr != questIds.end(); ++itr)
|
||||
@@ -437,29 +369,15 @@ void WorldSession::HandleQuestPOIQuery(WorldPacket& recvData)
|
||||
|
||||
if (questOk)
|
||||
{
|
||||
QuestPOIVector const* POI = sObjectMgr->GetQuestPOIVector(questId);
|
||||
|
||||
if (POI)
|
||||
if (QuestPOIWrapper const* poiWrapper = sObjectMgr->GetQuestPOIWrapper(questId))
|
||||
{
|
||||
data << uint32(questId); // quest ID
|
||||
data << uint32(POI->size()); // POI count
|
||||
|
||||
for (QuestPOIVector::const_iterator itr = POI->begin(); itr != POI->end(); ++itr)
|
||||
|
||||
if (sWorld->getBoolConfig(CONFIG_CACHE_DATA_QUERIES))
|
||||
data.append(poiWrapper->QueryDataBuffer);
|
||||
else
|
||||
{
|
||||
data << uint32(itr->Id); // POI index
|
||||
data << int32(itr->ObjectiveIndex); // objective index
|
||||
data << uint32(itr->MapId); // mapid
|
||||
data << uint32(itr->AreaId); // areaid
|
||||
data << uint32(itr->FloorId); // floorid
|
||||
data << uint32(itr->Unk3); // unknown
|
||||
data << uint32(itr->Unk4); // unknown
|
||||
data << uint32(itr->points.size()); // POI points count
|
||||
|
||||
for (std::vector<QuestPOIPoint>::const_iterator itr2 = itr->points.begin(); itr2 != itr->points.end(); ++itr2)
|
||||
{
|
||||
data << int32(itr2->x); // POI point x
|
||||
data << int32(itr2->y); // POI point y
|
||||
}
|
||||
ByteBuffer POIByteBuffer = poiWrapper->BuildQueryData(questId);
|
||||
data.append(POIByteBuffer);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user