Core/Packets: converted CMSG_WHO and SMSG_WHO to packet class

This commit is contained in:
Ovahlord committed 2020-04-18 19:23:54 +02:00
1 parent ee9f0b9bf0
commit 631236fa8a
7 files changed
+301 -122

No files matched your search

@@ -28,6 +28,7 @@
#include "QuestPackets.h"
#include "QueryPackets.h"
#include "SystemPackets.h"
#include "WhoPackets.h"
#include "WorldStatePackets.h"
#endif // AllPackets_h__
@@ -15,6 +15,8 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "CharacterCache.h"
#include "Player.h"
#include "QueryPackets.h"
void WorldPackets::Query::DBQueryBulk::Read()
@@ -75,3 +77,31 @@ WorldPacket const* WorldPackets::Query::HotfixNotifyBlob::Write()
return &_worldPacket;
}
bool WorldPackets::Query::PlayerGuidLookupData::Initialize(ObjectGuid const& guid, Player const* player /*= nullptr*/)
{
CharacterCacheEntry const* characterInfo = sCharacterCache->GetCharacterCacheByGuid(guid);
if (!characterInfo)
return false;
if (player)
{
ASSERT(player->GetGUID() == guid);
Name = player->GetName();
Race = player->getRace();
Sex = player->getGender();
ClassID = player->getClass();
Level = player->getLevel();
}
else
{
Name = characterInfo->Name;
Race = characterInfo->Race;
Sex = characterInfo->Sex;
ClassID = characterInfo->Class;
Level = characterInfo->Level;
}
return true;
}
@@ -21,6 +21,9 @@
#include "Packet.h"
#include "DB2Stores.h"
#include "ObjectGuid.h"
#include "SharedDefines.h"
class Player;
namespace WorldPackets
{
@@ -65,6 +68,17 @@ namespace WorldPackets
HotfixData const* Hotfixes = nullptr;
};
struct PlayerGuidLookupData
{
bool Initialize(ObjectGuid const& guid, Player const* player = nullptr);
std::string Name;
uint8 Race = RACE_NONE;
uint8 Sex = GENDER_NONE;
uint8 ClassID = CLASS_NONE;
uint8 Level = 0;
};
}
}
@@ -0,0 +1,87 @@
/*
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "WhoPackets.h"
ByteBuffer& operator>>(ByteBuffer& data, WorldPackets::Who::WhoWord& word)
{
data >> word.Word;
return data;
}
ByteBuffer& operator>>(ByteBuffer& data, WorldPackets::Who::WhoRequest& request)
{
data >> request.MinLevel;
data >> request.MaxLevel;
data >> request.Guild;
data >> request.Name;
data >> request.RaceFilter;
data >> request.ClassFilter;
uint32 areas = 0;
data >> areas;
request.Areas.resize(areas);
for (size_t i = 0; i < request.Areas.size(); ++i)
data >> request.Areas[i];
uint32 words = 0;
data >> words;
request.Words.resize(words);
for (size_t i = 0; i < request.Words.size(); ++i)
data >> request.Words[i];
return data;
}
void WorldPackets::Who::WhoRequestPkt::Read()
{
_worldPacket >> Request;
}
ByteBuffer& operator<<(ByteBuffer& data, WorldPackets::Who::WhoEntry const& entry)
{
data << entry.PlayerData.Name;
data << entry.GuildName;
data << uint32(entry.PlayerData.Level);
data << uint32(entry.PlayerData.ClassID);
data << uint32(entry.PlayerData.Race);
data << uint8(entry.PlayerData.Sex);
data << uint32(entry.AreaID);
return data;
}
ByteBuffer& operator<<(ByteBuffer& data, WorldPackets::Who::WhoResponse const& response)
{
data << uint32(response.Entries.size()); // Number of displayed characters
data << uint32(response.Entries.size()); // Number of matching characters (when using filters) TODO
for (WorldPackets::Who::WhoEntry const& whoEntry : response.Entries)
data << whoEntry;
return data;
}
WorldPacket const* WorldPackets::Who::WhoResponsePkt::Write()
{
_worldPacket << Response;
return &_worldPacket;
}
@@ -0,0 +1,79 @@
/*
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WhoPackets_h__
#define WhoPackets_h__
#include "Packet.h"
#include "QueryPackets.h"
namespace WorldPackets
{
namespace Who
{
struct WhoWord
{
std::string Word;
};
struct WhoRequest
{
int32 MinLevel = 0;
int32 MaxLevel = 0;
std::string Name;
std::string Guild;
int32 RaceFilter = -1;
int32 ClassFilter = -1;
std::vector<WhoWord> Words;
std::vector<int32> Areas;
};
class WhoRequestPkt final : public ClientPacket
{
public:
WhoRequestPkt(WorldPacket&& packet) : ClientPacket(CMSG_WHO, std::move(packet)) { }
void Read() override;
WhoRequest Request;
};
struct WhoEntry
{
Query::PlayerGuidLookupData PlayerData;
std::string GuildName;
int32 AreaID = 0;
};
struct WhoResponse
{
std::vector<WhoEntry> Entries;
};
class WhoResponsePkt final : public ServerPacket
{
public:
WhoResponsePkt() : ServerPacket(SMSG_WHO, 1) { }
WorldPacket const* Write() override;
WhoResponse Response;
};
}
}
#endif // WhoPackets_h__
+6 -1
View File
@@ -171,6 +171,11 @@ namespace WorldPackets
{
class DBQueryBulk;
}
namespace Who
{
class WhoRequestPkt;
}
}
enum AccountDataType
@@ -656,7 +661,7 @@ class TC_GAME_API WorldSession
void HandleLootOpcode(WorldPacket& recvPacket);
void HandleLootReleaseOpcode(WorldPacket& recvPacket);
void HandleLootMasterGiveOpcode(WorldPacket& recvPacket);
void HandleWhoOpcode(WorldPacket& recvPacket);
void HandleWhoOpcode(WorldPackets::Who::WhoRequestPkt& whoRequest);
void HandleLogoutRequestOpcode(WorldPacket& recvPacket);
void HandlePlayerLogoutOpcode(WorldPacket& recvPacket);
void HandleLogoutCancelOpcode(WorldPacket& recvPacket);