Skip to content

Commit f03d493

Browse files
DDuarteShauren
authored andcommitted
Core/Packets: SMSG_NAME_QUERY_RESPONSE (PlayerNameResponse) handler
(cherry picked from commit ec60d64)
1 parent a5c9417 commit f03d493

3 files changed

Lines changed: 62 additions & 22 deletions

File tree

src/server/game/Handlers/QueryHandler.cpp

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,35 +35,26 @@
3535

3636
void WorldSession::SendNameQueryOpcode(ObjectGuid guid)
3737
{
38-
Player* player = ObjectAccessor::FindConnectedPlayer(guid);
39-
CharacterCacheEntry const* nameData = sCharacterCache->GetCharacterCacheByGuid(guid);
38+
WorldPackets::Query::QueryPlayerNameResponse response;
39+
response.Player = guid;
4040

41-
WorldPacket data(SMSG_NAME_QUERY_RESPONSE, (8+1+1+1+1+1+10));
42-
data << guid.WriteAsPacked();
43-
if (!nameData)
41+
if (CharacterCacheEntry const* characterInfo = sCharacterCache->GetCharacterCacheByGuid(guid))
4442
{
45-
data << uint8(1); // name unknown
46-
SendPacket(&data);
47-
return;
48-
}
43+
response.Result = RESPONSE_SUCCESS; // name known
4944

50-
data << uint8(0); // name known
51-
data << nameData->Name; // played name
52-
data << uint8(0); // realm name - only set for cross realm interaction (such as Battlegrounds)
53-
data << uint8(nameData->Race);
54-
data << uint8(nameData->Sex);
55-
data << uint8(nameData->Class);
45+
WorldPackets::Query::PlayerGuidLookupData& data = response.Data.emplace();
46+
data.Name = characterInfo->Name;
47+
data.Race = characterInfo->Race;
48+
data.Sex = characterInfo->Sex;
49+
data.ClassID = characterInfo->Class;
5650

57-
if (DeclinedName const* names = (player ? player->GetDeclinedNames() : nullptr))
58-
{
59-
data << uint8(1); // Name is declined
60-
for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
61-
data << names->name[i];
51+
if (Player* player = ObjectAccessor::FindConnectedPlayer(guid))
52+
data.DeclinedNames = player->GetDeclinedNames();
6253
}
6354
else
64-
data << uint8(0); // Name is not declined
55+
response.Result = RESPONSE_FAILURE; // name unknown
6556

66-
SendPacket(&data);
57+
SendPacket(response.Write());
6758
}
6859

6960
void WorldSession::HandleNameQueryOpcode(WorldPackets::Query::QueryPlayerName& queryPlayerName)

src/server/game/Server/Packets/QueryPackets.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,33 @@ void WorldPackets::Query::QueryPlayerName::Read()
5454
_worldPacket >> Player;
5555
}
5656

57+
ByteBuffer& operator<<(ByteBuffer& data, WorldPackets::Query::PlayerGuidLookupData const& lookupData)
58+
{
59+
data << lookupData.Name;
60+
data << lookupData.RealmName;
61+
data << uint8(lookupData.Race);
62+
data << uint8(lookupData.Sex);
63+
data << uint8(lookupData.ClassID);
64+
data << uint8(lookupData.DeclinedNames != nullptr);
65+
66+
if (lookupData.DeclinedNames)
67+
for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
68+
data << lookupData.DeclinedNames->name[i];
69+
70+
return data;
71+
}
72+
73+
WorldPacket const* WorldPackets::Query::QueryPlayerNameResponse::Write()
74+
{
75+
_worldPacket << Player.WriteAsPacked();
76+
_worldPacket << uint8(Result);
77+
78+
if (Data)
79+
_worldPacket << *Data;
80+
81+
return &_worldPacket;
82+
}
83+
5784
void WorldPackets::Query::QueryGameObject::Read()
5885
{
5986
_worldPacket >> GameObjectID;

src/server/game/Server/Packets/QueryPackets.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,28 @@ namespace WorldPackets
8282
ObjectGuid Player;
8383
};
8484

85+
struct PlayerGuidLookupData
86+
{
87+
std::string_view Name;
88+
std::string_view RealmName;
89+
uint8 Race = RACE_NONE;
90+
uint8 Sex = GENDER_NONE;
91+
uint8 ClassID = CLASS_NONE;
92+
DeclinedName const* DeclinedNames = nullptr;
93+
};
94+
95+
class QueryPlayerNameResponse final : public ServerPacket
96+
{
97+
public:
98+
explicit QueryPlayerNameResponse() : ServerPacket(SMSG_NAME_QUERY_RESPONSE, 60) { }
99+
100+
WorldPacket const* Write() override;
101+
102+
ObjectGuid Player;
103+
uint8 Result = 0; // 0 - full packet, != 0 - only guid
104+
Optional<PlayerGuidLookupData> Data;
105+
};
106+
85107
class QueryGameObject final : public ClientPacket
86108
{
87109
public:

0 commit comments

Comments
 (0)