refactor(Core/Packets): Rewrite various query packets to modern class. (#22719)

This commit is contained in:
Benjamin Jackson
2025-08-24 08:50:16 -04:00
committed by GitHub
parent 915b39202a
commit 9ed31bd63e
7 changed files with 184 additions and 40 deletions

View File

@@ -24,6 +24,7 @@
#include "Opcodes.h"
#include "Pet.h"
#include "Player.h"
#include "QueryPackets.h"
#include "World.h"
#include "WorldPacket.h"
#include "WorldSession.h"
@@ -32,62 +33,55 @@ void WorldSession::SendNameQueryOpcode(ObjectGuid guid)
{
CharacterCacheEntry const* playerData = sCharacterCache->GetCharacterCacheByGuid(guid);
WorldPacket data(SMSG_NAME_QUERY_RESPONSE, (8 + 1 + 1 + 1 + 1 + 1 + 10));
data << guid.WriteAsPacked();
WorldPackets::Query::NameQueryResponse nameQueryResponse;
nameQueryResponse.Guid = guid.WriteAsPacked();
if (!playerData)
{
data << uint8(1); // name unknown
SendPacket(&data);
nameQueryResponse.NameUnknown = true;
SendPacket(nameQueryResponse.Write());
return;
}
Player* player = ObjectAccessor::FindConnectedPlayer(guid);
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(player ? player->getRace() : playerData->Race);
data << uint8(playerData->Sex);
data << uint8(playerData->Class);
nameQueryResponse.NameUnknown = false;
nameQueryResponse.Name = playerData->Name;
nameQueryResponse.Race = player ? player->getRace() : playerData->Race;
nameQueryResponse.Sex = player ? player->getGender() : playerData->Sex;
nameQueryResponse.Class = player ? player->getClass() : playerData->Class;
// pussywizard: optimization
/*Player* player = ObjectAccessor::FindConnectedPlayer(guid);
if (DeclinedName const* names = (player ? player->GetDeclinedNames() : nullptr))
{
data << uint8(1); // Name is declined
for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
data << names->name[i];
nameQueryResponse.Declined = true;
nameQueryResponse.DeclinedNames = *names;
}
else*/
data << uint8(0); // Name is not declined
else
nameQueryResponse.Declined = false;
SendPacket(&data);
SendPacket(nameQueryResponse.Write());
}
void WorldSession::HandleNameQueryOpcode(WorldPacket& recvData)
void WorldSession::HandleNameQueryOpcode(WorldPackets::Query::NameQuery& packet)
{
ObjectGuid guid;
recvData >> guid;
// This is disable by default to prevent lots of console spam
// LOG_INFO("network.opcode", "HandleNameQueryOpcode {}", guid);
SendNameQueryOpcode(guid);
SendNameQueryOpcode(packet.Guid);
}
void WorldSession::HandleQueryTimeOpcode(WorldPacket& /*recvData*/)
void WorldSession::HandleTimeQueryOpcode(WorldPackets::Query::TimeQuery& /*packet*/)
{
SendQueryTimeResponse();
SendTimeQueryResponse();
}
void WorldSession::SendQueryTimeResponse()
void WorldSession::SendTimeQueryResponse()
{
auto timeResponse = sWorld->GetNextDailyQuestsResetTime() - GameTime::GetGameTime();
WorldPacket data(SMSG_QUERY_TIME_RESPONSE, 4 + 4);
data << uint32(GameTime::GetGameTime().count());
data << uint32(timeResponse.count());
SendPacket(&data);
WorldPackets::Query::TimeQueryResponse timeQueryResponse;
timeQueryResponse.ServerTime = GameTime::GetGameTime().count();
timeQueryResponse.TimeResponse = timeResponse.count();
SendPacket(timeQueryResponse.Write());
}
/// Only _static_ data is sent in this packet !!!
@@ -402,13 +396,10 @@ void WorldSession::HandlePageTextQueryOpcode(WorldPacket& recvData)
}
}
void WorldSession::HandleCorpseMapPositionQuery(WorldPacket& recvData)
void WorldSession::HandleCorpseMapPositionQuery(WorldPackets::Query::CorpseMapPositionQuery& /*packet*/)
{
LOG_DEBUG("network", "WORLD: Recv CMSG_CORPSE_MAP_POSITION_QUERY");
uint32 unk;
recvData >> unk;
WorldPacket data(SMSG_CORPSE_MAP_POSITION_QUERY_RESPONSE, 4 + 4 + 4 + 4);
data << float(0);
data << float(0);

View File

@@ -172,7 +172,7 @@ void WorldSession::HandleGMTicketDeleteOpcode(WorldPacket& /*recv_data*/)
void WorldSession::HandleGMTicketGetTicketOpcode(WorldPacket& /*recv_data*/)
{
SendQueryTimeResponse();
SendTimeQueryResponse();
if (GmTicket* ticket = sTicketMgr->GetTicketByPlayer(GetPlayer()->GetGUID()))
{