mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-16 18:40:28 +00:00
496 lines
17 KiB
C++
496 lines
17 KiB
C++
/*
|
|
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license: http://github.com/azerothcore/azerothcore-wotlk/LICENSE-GPL2
|
|
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
|
|
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
|
*/
|
|
|
|
#include "Common.h"
|
|
#include "Language.h"
|
|
#include "DatabaseEnv.h"
|
|
#include "WorldPacket.h"
|
|
#include "WorldSession.h"
|
|
#include "Opcodes.h"
|
|
#include "Log.h"
|
|
#include "World.h"
|
|
#include "ObjectMgr.h"
|
|
#include "Player.h"
|
|
#include "UpdateMask.h"
|
|
#include "NPCHandler.h"
|
|
#include "Pet.h"
|
|
#include "MapManager.h"
|
|
|
|
void WorldSession::SendNameQueryOpcode(uint64 guid)
|
|
{
|
|
GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(GUID_LOPART(guid));
|
|
|
|
WorldPacket data(SMSG_NAME_QUERY_RESPONSE, (8+1+1+1+1+1+10));
|
|
data.appendPackGUID(guid);
|
|
if (!playerData)
|
|
{
|
|
data << uint8(1); // name unknown
|
|
SendPacket(&data);
|
|
return;
|
|
}
|
|
|
|
data << uint8(0); // name known
|
|
data << playerData->name; // played name
|
|
data << uint8(0); // realm name - only set for cross realm interaction (such as Battlegrounds)
|
|
data << uint8(playerData->race);
|
|
data << uint8(playerData->gender);
|
|
data << uint8(playerData->playerClass);
|
|
|
|
// pussywizard: optimization
|
|
/*Player* player = ObjectAccessor::FindPlayerInOrOutOfWorld(guid);
|
|
if (DeclinedName const* names = (player ? player->GetDeclinedNames() : NULL))
|
|
{
|
|
data << uint8(1); // Name is declined
|
|
for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
|
|
data << names->name[i];
|
|
}
|
|
else*/
|
|
data << uint8(0); // Name is not declined
|
|
|
|
SendPacket(&data);
|
|
}
|
|
|
|
void WorldSession::HandleNameQueryOpcode(WorldPacket& recvData)
|
|
{
|
|
uint64 guid;
|
|
recvData >> guid;
|
|
|
|
// This is disable by default to prevent lots of console spam
|
|
// sLog->outString("HandleNameQueryOpcode %u", guid);
|
|
|
|
SendNameQueryOpcode(guid);
|
|
}
|
|
|
|
void WorldSession::HandleQueryTimeOpcode(WorldPacket & /*recvData*/)
|
|
{
|
|
SendQueryTimeResponse();
|
|
}
|
|
|
|
void WorldSession::SendQueryTimeResponse()
|
|
{
|
|
WorldPacket data(SMSG_QUERY_TIME_RESPONSE, 4+4);
|
|
data << uint32(time(NULL));
|
|
data << uint32(sWorld->GetNextDailyQuestsResetTime() - time(NULL));
|
|
SendPacket(&data);
|
|
}
|
|
|
|
/// Only _static_ data is sent in this packet !!!
|
|
void WorldSession::HandleCreatureQueryOpcode(WorldPacket & recvData)
|
|
{
|
|
uint32 entry;
|
|
recvData >> entry;
|
|
uint64 guid;
|
|
recvData >> guid;
|
|
|
|
CreatureTemplate const* ci = sObjectMgr->GetCreatureTemplate(entry);
|
|
if (ci)
|
|
{
|
|
std::string Name, Title;
|
|
Name = ci->Name;
|
|
Title = ci->SubName;
|
|
|
|
LocaleConstant 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);
|
|
}
|
|
}
|
|
// 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 (size_t i = 0; i < MAX_CREATURE_QUEST_ITEMS; ++i)
|
|
data << (i < items->size() ? uint32((*items)[i]) : uint32(0));
|
|
else
|
|
for (size_t i = 0; i < MAX_CREATURE_QUEST_ITEMS; ++i)
|
|
data << uint32(0);
|
|
|
|
data << uint32(ci->movementId); // CreatureMovementInfo.dbc
|
|
SendPacket(&data);
|
|
}
|
|
else
|
|
{
|
|
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
|
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CREATURE_QUERY - NO CREATURE INFO! (GUID: %u, ENTRY: %u)", GUID_LOPART(guid), entry);
|
|
#endif
|
|
WorldPacket data(SMSG_CREATURE_QUERY_RESPONSE, 4);
|
|
data << uint32(entry | 0x80000000);
|
|
SendPacket(&data);
|
|
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
|
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Sent SMSG_CREATURE_QUERY_RESPONSE");
|
|
#endif
|
|
}
|
|
}
|
|
|
|
/// Only _static_ data is sent in this packet !!!
|
|
void WorldSession::HandleGameObjectQueryOpcode(WorldPacket & recvData)
|
|
{
|
|
uint32 entry;
|
|
recvData >> entry;
|
|
uint64 guid;
|
|
recvData >> guid;
|
|
|
|
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);
|
|
}
|
|
|
|
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
|
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_GAMEOBJECT_QUERY '%s' - Entry: %u. ", info->name.c_str(), entry);
|
|
#endif
|
|
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));
|
|
else
|
|
for (size_t i = 0; i < MAX_GAMEOBJECT_QUEST_ITEMS; ++i)
|
|
data << uint32(0);
|
|
|
|
SendPacket(&data);
|
|
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
|
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Sent SMSG_GAMEOBJECT_QUERY_RESPONSE");
|
|
#endif
|
|
}
|
|
else
|
|
{
|
|
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
|
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_GAMEOBJECT_QUERY - Missing gameobject info for (GUID: %u, ENTRY: %u)",
|
|
GUID_LOPART(guid), entry);
|
|
#endif
|
|
WorldPacket data (SMSG_GAMEOBJECT_QUERY_RESPONSE, 4);
|
|
data << uint32(entry | 0x80000000);
|
|
SendPacket(&data);
|
|
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
|
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Sent SMSG_GAMEOBJECT_QUERY_RESPONSE");
|
|
#endif
|
|
}
|
|
}
|
|
|
|
void WorldSession::HandleCorpseQueryOpcode(WorldPacket & /*recvData*/)
|
|
{
|
|
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
|
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Received MSG_CORPSE_QUERY");
|
|
#endif
|
|
|
|
Corpse* corpse = GetPlayer()->GetCorpse();
|
|
|
|
if (!corpse)
|
|
{
|
|
WorldPacket data(MSG_CORPSE_QUERY, 1);
|
|
data << uint8(0); // corpse not found
|
|
SendPacket(&data);
|
|
return;
|
|
}
|
|
|
|
uint32 mapid = corpse->GetMapId();
|
|
float x = corpse->GetPositionX();
|
|
float y = corpse->GetPositionY();
|
|
float z = corpse->GetPositionZ();
|
|
uint32 corpsemapid = mapid;
|
|
|
|
// if corpse at different map
|
|
if (mapid != _player->GetMapId())
|
|
{
|
|
// search entrance map for proper show entrance
|
|
if (MapEntry const* corpseMapEntry = sMapStore.LookupEntry(mapid))
|
|
{
|
|
if (corpseMapEntry->IsDungeon() && corpseMapEntry->entrance_map >= 0)
|
|
{
|
|
// if corpse map have entrance
|
|
if (Map const* entranceMap = sMapMgr->CreateBaseMap(corpseMapEntry->entrance_map))
|
|
{
|
|
mapid = corpseMapEntry->entrance_map;
|
|
x = corpseMapEntry->entrance_x;
|
|
y = corpseMapEntry->entrance_y;
|
|
z = entranceMap->GetHeight(GetPlayer()->GetPhaseMask(), x, y, MAX_HEIGHT);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
WorldPacket data(MSG_CORPSE_QUERY, 1+(6*4));
|
|
data << uint8(1); // corpse found
|
|
data << int32(mapid);
|
|
data << float(x);
|
|
data << float(y);
|
|
data << float(z);
|
|
data << int32(corpsemapid);
|
|
data << uint32(0); // unknown
|
|
SendPacket(&data);
|
|
}
|
|
|
|
void WorldSession::HandleNpcTextQueryOpcode(WorldPacket & recvData)
|
|
{
|
|
uint32 textID;
|
|
uint64 guid;
|
|
|
|
recvData >> textID;
|
|
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
|
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_NPC_TEXT_QUERY ID '%u'", textID);
|
|
#endif
|
|
|
|
recvData >> guid;
|
|
|
|
GossipText const* pGossip = sObjectMgr->GetGossipText(textID);
|
|
|
|
WorldPacket data(SMSG_NPC_TEXT_UPDATE, 100); // guess size
|
|
data << textID;
|
|
|
|
if (!pGossip)
|
|
{
|
|
for (uint8 i = 0; i < MAX_GOSSIP_TEXT_OPTIONS; ++i)
|
|
{
|
|
data << float(0);
|
|
data << "Greetings $N";
|
|
data << "Greetings $N";
|
|
data << uint32(0);
|
|
data << uint32(0);
|
|
data << uint32(0);
|
|
data << uint32(0);
|
|
data << uint32(0);
|
|
data << uint32(0);
|
|
data << uint32(0);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
std::string text0[MAX_GOSSIP_TEXT_OPTIONS], text1[MAX_GOSSIP_TEXT_OPTIONS];
|
|
LocaleConstant locale = GetSessionDbLocaleIndex();
|
|
|
|
for (uint8 i = 0; i < MAX_GOSSIP_TEXT_OPTIONS; ++i)
|
|
{
|
|
BroadcastText const* bct = sObjectMgr->GetBroadcastText(pGossip->Options[i].BroadcastTextID);
|
|
if (bct)
|
|
{
|
|
text0[i] = bct->GetText(locale, GENDER_MALE, true);
|
|
text1[i] = bct->GetText(locale, GENDER_FEMALE, true);
|
|
}
|
|
else
|
|
{
|
|
text0[i] = pGossip->Options[i].Text_0;
|
|
text1[i] = pGossip->Options[i].Text_1;
|
|
}
|
|
|
|
if (locale != DEFAULT_LOCALE && !bct)
|
|
{
|
|
if (NpcTextLocale const* npcTextLocale = sObjectMgr->GetNpcTextLocale(textID))
|
|
{
|
|
ObjectMgr::GetLocaleString(npcTextLocale->Text_0[i], locale, text0[i]);
|
|
ObjectMgr::GetLocaleString(npcTextLocale->Text_1[i], locale, text1[i]);
|
|
}
|
|
}
|
|
|
|
data << pGossip->Options[i].Probability;
|
|
|
|
if (text0[i].empty())
|
|
data << text1[i];
|
|
else
|
|
data << text0[i];
|
|
|
|
if (text1[i].empty())
|
|
data << text0[i];
|
|
else
|
|
data << text1[i];
|
|
|
|
data << pGossip->Options[i].Language;
|
|
|
|
for (uint8 j = 0; j < MAX_GOSSIP_TEXT_EMOTES; ++j)
|
|
{
|
|
data << pGossip->Options[i].Emotes[j]._Delay;
|
|
data << pGossip->Options[i].Emotes[j]._Emote;
|
|
}
|
|
}
|
|
}
|
|
|
|
SendPacket(&data);
|
|
|
|
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
|
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Sent SMSG_NPC_TEXT_UPDATE");
|
|
#endif
|
|
}
|
|
|
|
/// Only _static_ data is sent in this packet !!!
|
|
void WorldSession::HandlePageTextQueryOpcode(WorldPacket & recvData)
|
|
{
|
|
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
|
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Received CMSG_PAGE_TEXT_QUERY");
|
|
#endif
|
|
|
|
uint32 pageID;
|
|
recvData >> pageID;
|
|
recvData.read_skip<uint64>(); // guid
|
|
|
|
while (pageID)
|
|
{
|
|
PageText const* pageText = sObjectMgr->GetPageText(pageID);
|
|
// guess size
|
|
WorldPacket data(SMSG_PAGE_TEXT_QUERY_RESPONSE, 50);
|
|
data << pageID;
|
|
|
|
if (!pageText)
|
|
{
|
|
data << "Item page missing.";
|
|
data << uint32(0);
|
|
pageID = 0;
|
|
}
|
|
else
|
|
{
|
|
std::string Text = pageText->Text;
|
|
|
|
int loc_idx = GetSessionDbLocaleIndex();
|
|
if (loc_idx >= 0)
|
|
if (PageTextLocale const* player = sObjectMgr->GetPageTextLocale(pageID))
|
|
ObjectMgr::GetLocaleString(player->Text, loc_idx, Text);
|
|
|
|
data << Text;
|
|
data << uint32(pageText->NextPage);
|
|
pageID = pageText->NextPage;
|
|
}
|
|
SendPacket(&data);
|
|
|
|
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
|
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Sent SMSG_PAGE_TEXT_QUERY_RESPONSE");
|
|
#endif
|
|
}
|
|
}
|
|
|
|
void WorldSession::HandleCorpseMapPositionQuery(WorldPacket & recvData)
|
|
{
|
|
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
|
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Recv CMSG_CORPSE_MAP_POSITION_QUERY");
|
|
#endif
|
|
|
|
uint32 unk;
|
|
recvData >> unk;
|
|
|
|
WorldPacket data(SMSG_CORPSE_MAP_POSITION_QUERY_RESPONSE, 4+4+4+4);
|
|
data << float(0);
|
|
data << float(0);
|
|
data << float(0);
|
|
data << float(0);
|
|
SendPacket(&data);
|
|
}
|
|
|
|
void WorldSession::HandleQuestPOIQuery(WorldPacket& recvData)
|
|
{
|
|
uint32 count;
|
|
recvData >> count; // quest count, max=25
|
|
|
|
if (count > MAX_QUEST_LOG_SIZE)
|
|
{
|
|
recvData.rfinish();
|
|
return;
|
|
}
|
|
|
|
// Read quest ids and add the in a unordered_set so we don't send POIs for the same quest multiple times
|
|
UNORDERED_SET<uint32> questIds;
|
|
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());
|
|
data << uint32(questIds.size()); // count
|
|
|
|
for (UNORDERED_SET<uint32>::const_iterator itr = questIds.begin(); itr != questIds.end(); ++itr)
|
|
{
|
|
uint32 questId = *itr;
|
|
bool questOk = false;
|
|
|
|
uint16 questSlot = _player->FindQuestSlot(questId);
|
|
|
|
if (questSlot != MAX_QUEST_LOG_SIZE)
|
|
questOk =_player->GetQuestSlotQuestId(questSlot) == questId;
|
|
|
|
if (questOk)
|
|
{
|
|
QuestPOIVector const* POI = sObjectMgr->GetQuestPOIVector(questId);
|
|
|
|
if (POI)
|
|
{
|
|
data << uint32(questId); // quest ID
|
|
data << uint32(POI->size()); // POI count
|
|
|
|
for (QuestPOIVector::const_iterator itr = POI->begin(); itr != POI->end(); ++itr)
|
|
{
|
|
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
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
data << uint32(questId); // quest ID
|
|
data << uint32(0); // POI count
|
|
}
|
|
}
|
|
else
|
|
{
|
|
data << uint32(questId); // quest ID
|
|
data << uint32(0); // POI count
|
|
}
|
|
}
|
|
|
|
SendPacket(&data);
|
|
}
|