Skip to content

Commit 7ea4b1d

Browse files
committed
Core/PacketIO: Migrate CMSG_INSPECT, SMSG_INSPECT_TALENT and SMSG_TALENTS_INFO to packet classes
1 parent 9d385c7 commit 7ea4b1d

12 files changed

Lines changed: 316 additions & 127 deletions

File tree

src/server/game/Entities/Pet/Pet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ bool Pet::resetTalents(bool involuntarily /*= false*/)
17121712
player->PetSpellInitialize();
17131713

17141714
if (involuntarily)
1715-
player->SendDirectMessage(WorldPackets::Talents::InvoluntarilyReset(true).Write());
1715+
player->SendDirectMessage(WorldPackets::Talent::InvoluntarilyReset(true).Write());
17161716

17171717
return true;
17181718
}
@@ -1751,7 +1751,7 @@ void Pet::resetTalentsForAllPetsOf(Player* owner, Pet* onlinePet /*= nullptr*/,
17511751
return;
17521752

17531753
if (!onlinePet)
1754-
owner->SendDirectMessage(WorldPackets::Talents::InvoluntarilyReset(true).Write());
1754+
owner->SendDirectMessage(WorldPackets::Talent::InvoluntarilyReset(true).Write());
17551755

17561756
bool need_comma = false;
17571757
std::ostringstream ss;

src/server/game/Entities/Player/Player.cpp

Lines changed: 27 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -3780,7 +3780,7 @@ bool Player::ResetTalents(bool involuntarily /*= false*/)
37803780
SetFreeTalentPoints(talentPointsForLevel);
37813781

37823782
if (involuntarily)
3783-
SendDirectMessage(WorldPackets::Talents::InvoluntarilyReset(false).Write());
3783+
SendDirectMessage(WorldPackets::Talent::InvoluntarilyReset(false).Write());
37843784

37853785
return true;
37863786
}
@@ -9179,7 +9179,7 @@ void Player::SetBindPoint(ObjectGuid guid) const
91799179

91809180
void Player::SendTalentWipeConfirm(ObjectGuid trainerGuid) const
91819181
{
9182-
SendDirectMessage(WorldPackets::Talents::RespecWipeConfirm(trainerGuid, ResetTalentsCost()).Write());
9182+
SendDirectMessage(WorldPackets::Talent::RespecWipeConfirm(trainerGuid, ResetTalentsCost()).Write());
91839183
}
91849184

91859185
void Player::ResetPetTalents()
@@ -25275,11 +25275,11 @@ bool Player::CanSeeSpellClickOn(Creature const* c) const
2527525275
return false;
2527625276
}
2527725277

25278-
void Player::BuildPlayerTalentsInfoData(WorldPacket* data)
25278+
void Player::BuildPlayerTalentsInfoData(WorldPackets::Talent::TalentInfoUpdate& talentInfo)
2527925279
{
25280-
*data << uint32(GetFreeTalentPoints()); // unspentTalentPoints
25281-
*data << uint8(GetSpecsCount()); // talent group count (0, 1 or 2)
25282-
*data << uint8(GetActiveSpec()); // talent group index (0 or 1)
25280+
talentInfo.UnspentTalentPoints = GetFreeTalentPoints(); // unspentTalentPoints
25281+
talentInfo.TalentGroups.resize(GetSpecsCount()); // talent group count (0, 1 or 2)
25282+
talentInfo.ActiveGroup = GetActiveSpec(); // talent group index (0 or 1)
2528325283

2528425284
if (GetSpecsCount())
2528525285
{
@@ -25289,9 +25289,7 @@ void Player::BuildPlayerTalentsInfoData(WorldPacket* data)
2528925289
// loop through all specs (only 1 for now)
2529025290
for (uint32 specIdx = 0; specIdx < GetSpecsCount(); ++specIdx)
2529125291
{
25292-
uint8 talentIdCount = 0;
25293-
size_t pos = data->wpos();
25294-
*data << uint8(talentIdCount); // [PH], talentIdCount
25292+
WorldPackets::Talent::TalentGroupInfo& talentGroupInfo = talentInfo.TalentGroups[specIdx];
2529525293

2529625294
// find class talent tabs (all players have 3 talent tabs)
2529725295
uint32 const* talentTabIds = GetTalentTabPages(GetClass());
@@ -25302,19 +25300,19 @@ void Player::BuildPlayerTalentsInfoData(WorldPacket* data)
2530225300

2530325301
for (uint32 talentId = 0; talentId < sTalentStore.GetNumRows(); ++talentId)
2530425302
{
25305-
TalentEntry const* talentInfo = sTalentStore.LookupEntry(talentId);
25306-
if (!talentInfo)
25303+
TalentEntry const* talent = sTalentStore.LookupEntry(talentId);
25304+
if (!talent)
2530725305
continue;
2530825306

2530925307
// skip another tab talents
25310-
if (talentInfo->TabID != talentTabId)
25308+
if (talent->TabID != talentTabId)
2531125309
continue;
2531225310

2531325311
// find max talent rank (0~4)
2531425312
int8 curtalent_maxrank = -1;
25315-
for (int8 rank = MAX_TALENT_RANK-1; rank >= 0; --rank)
25313+
for (int8 rank = MAX_TALENT_RANK - 1; rank >= 0; --rank)
2531625314
{
25317-
if (talentInfo->SpellRank[rank] && HasTalent(talentInfo->SpellRank[rank], specIdx))
25315+
if (talent->SpellRank[rank] && HasTalent(talent->SpellRank[rank], specIdx))
2531825316
{
2531925317
curtalent_maxrank = rank;
2532025318
break;
@@ -25325,40 +25323,23 @@ void Player::BuildPlayerTalentsInfoData(WorldPacket* data)
2532525323
if (curtalent_maxrank < 0)
2532625324
continue;
2532725325

25328-
*data << uint32(talentInfo->ID); // Talent.dbc
25329-
*data << uint8(curtalent_maxrank); // talentMaxRank (0-4)
25330-
25331-
++talentIdCount;
25326+
talentGroupInfo.Talents.push_back({ .TalentID = talent->ID, .Rank = curtalent_maxrank });
2533225327
}
2533325328
}
2533425329

25335-
data->put<uint8>(pos, talentIdCount); // put real count
25336-
25337-
*data << uint8(MAX_GLYPH_SLOT_INDEX); // glyphs count
25338-
2533925330
for (uint8 i = 0; i < MAX_GLYPH_SLOT_INDEX; ++i)
25340-
*data << uint16(GetGlyph(specIdx, i)); // GlyphProperties.dbc
25331+
talentGroupInfo.GlyphIDs[i] = GetGlyph(specIdx, i); // GlyphProperties.dbc
2534125332
}
2534225333
}
2534325334
}
2534425335

25345-
void Player::BuildPetTalentsInfoData(WorldPacket* data)
25336+
void Player::BuildPetTalentsInfoData(WorldPackets::Talent::PetTalentInfoUpdate& petTalentInfo) const
2534625337
{
25347-
uint32 unspentTalentPoints = 0;
25348-
size_t pointsPos = data->wpos();
25349-
*data << uint32(unspentTalentPoints); // [PH], unspentTalentPoints
25350-
25351-
uint8 talentIdCount = 0;
25352-
size_t countPos = data->wpos();
25353-
*data << uint8(talentIdCount); // [PH], talentIdCount
25354-
2535525338
Pet* pet = GetPet();
2535625339
if (!pet)
2535725340
return;
2535825341

25359-
unspentTalentPoints = pet->GetFreeTalentPoints();
25360-
25361-
data->put<uint32>(pointsPos, unspentTalentPoints); // put real points
25342+
petTalentInfo.UnspentTalentPoints = pet->GetFreeTalentPoints();
2536225343

2536325344
CreatureTemplate const* ci = pet->GetCreatureTemplate();
2536425345
if (!ci)
@@ -25379,19 +25360,19 @@ void Player::BuildPetTalentsInfoData(WorldPacket* data)
2537925360

2538025361
for (uint32 talentId = 0; talentId < sTalentStore.GetNumRows(); ++talentId)
2538125362
{
25382-
TalentEntry const* talentInfo = sTalentStore.LookupEntry(talentId);
25383-
if (!talentInfo)
25363+
TalentEntry const* talent = sTalentStore.LookupEntry(talentId);
25364+
if (!talent)
2538425365
continue;
2538525366

2538625367
// skip another tab talents
25387-
if (talentInfo->TabID != talentTabId)
25368+
if (talent->TabID != talentTabId)
2538825369
continue;
2538925370

2539025371
// find max talent rank (0~4)
2539125372
int8 curtalent_maxrank = -1;
25392-
for (int8 rank = MAX_TALENT_RANK-1; rank >= 0; --rank)
25373+
for (int8 rank = MAX_TALENT_RANK - 1; rank >= 0; --rank)
2539325374
{
25394-
if (talentInfo->SpellRank[rank] && pet->HasSpell(talentInfo->SpellRank[rank]))
25375+
if (talent->SpellRank[rank] && pet->HasSpell(talent->SpellRank[rank]))
2539525376
{
2539625377
curtalent_maxrank = rank;
2539725378
break;
@@ -25402,70 +25383,23 @@ void Player::BuildPetTalentsInfoData(WorldPacket* data)
2540225383
if (curtalent_maxrank < 0)
2540325384
continue;
2540425385

25405-
*data << uint32(talentInfo->ID); // Talent.dbc
25406-
*data << uint8(curtalent_maxrank); // talentMaxRank (0-4)
25407-
25408-
++talentIdCount;
25386+
petTalentInfo.Talents.push_back({ .TalentID = talent->ID, .Rank = curtalent_maxrank });
2540925387
}
2541025388

25411-
data->put<uint8>(countPos, talentIdCount); // put real count
25412-
2541325389
break;
2541425390
}
2541525391
}
2541625392

2541725393
void Player::SendTalentsInfoData(bool pet)
2541825394
{
25419-
WorldPacket data(SMSG_TALENTS_INFO, 50);
25420-
data << uint8(pet ? 1 : 0);
25395+
WorldPackets::Talent::UpdateTalentData updateTalentData;
25396+
2542125397
if (pet)
25422-
BuildPetTalentsInfoData(&data);
25398+
BuildPetTalentsInfoData(updateTalentData.Info.emplace<1>());
2542325399
else
25424-
BuildPlayerTalentsInfoData(&data);
25425-
SendDirectMessage(&data);
25426-
}
25427-
25428-
void Player::BuildEnchantmentsInfoData(WorldPacket* data)
25429-
{
25430-
uint32 slotUsedMask = 0;
25431-
size_t slotUsedMaskPos = data->wpos();
25432-
*data << uint32(slotUsedMask); // slotUsedMask < 0x80000
25433-
25434-
for (uint32 i = 0; i < EQUIPMENT_SLOT_END; ++i)
25435-
{
25436-
Item* item = GetItemByPos(INVENTORY_SLOT_BAG_0, i);
25437-
25438-
if (!item)
25439-
continue;
25440-
25441-
slotUsedMask |= (1 << i);
25442-
25443-
*data << uint32(item->GetEntry()); // item entry
25444-
25445-
uint16 enchantmentMask = 0;
25446-
size_t enchantmentMaskPos = data->wpos();
25447-
*data << uint16(enchantmentMask); // enchantmentMask < 0x1000
25448-
25449-
for (uint32 j = 0; j < MAX_ENCHANTMENT_SLOT; ++j)
25450-
{
25451-
uint32 enchId = item->GetEnchantmentId(EnchantmentSlot(j));
25452-
25453-
if (!enchId)
25454-
continue;
25455-
25456-
enchantmentMask |= (1 << j);
25457-
25458-
*data << uint16(enchId); // enchantmentId?
25459-
}
25460-
25461-
data->put<uint16>(enchantmentMaskPos, enchantmentMask);
25462-
25463-
*data << int16(item->GetItemRandomPropertyId()); // Random item property id
25464-
*data << item->GetGuidValue(ITEM_FIELD_CREATOR).WriteAsPacked(); // item creator
25465-
*data << uint32(item->GetItemSuffixFactor()); // SuffixFactor
25466-
}
25400+
BuildPlayerTalentsInfoData(updateTalentData.Info.emplace<0>());
2546725401

25468-
data->put<uint32>(slotUsedMaskPos, slotUsedMask);
25402+
SendDirectMessage(updateTalentData.Write());
2546925403
}
2547025404

2547125405
void Player::SendEquipmentSetList()

src/server/game/Entities/Player/Player.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ namespace WorldPackets
8686
{
8787
struct CharacterCreateInfo;
8888
}
89+
90+
namespace Talent
91+
{
92+
struct PetTalentInfoUpdate;
93+
struct TalentInfoUpdate;
94+
}
8995
}
9096

9197
typedef std::deque<Mail*> PlayerMails;
@@ -1224,7 +1230,6 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
12241230
void ApplyEnchantment(Item* item, bool apply);
12251231
void UpdateSkillEnchantments(uint16 skill_id, uint16 curr_value, uint16 new_value);
12261232
void SendEnchantmentDurations();
1227-
void BuildEnchantmentsInfoData(WorldPacket* data);
12281233
void AddItemDurations(Item* item);
12291234
void RemoveItemDurations(Item* item);
12301235
void SendItemDurations();
@@ -1501,8 +1506,8 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
15011506
uint32 ResetTalentsCost() const;
15021507
void IncreaseResetTalentsCostAndCounters(uint32 lastResetTalentsCost);
15031508
void InitTalentForLevel();
1504-
void BuildPlayerTalentsInfoData(WorldPacket* data);
1505-
void BuildPetTalentsInfoData(WorldPacket* data);
1509+
void BuildPlayerTalentsInfoData(WorldPackets::Talent::TalentInfoUpdate& talentInfo);
1510+
void BuildPetTalentsInfoData(WorldPackets::Talent::PetTalentInfoUpdate& petTalentInfo) const;
15061511
void SendTalentsInfoData(bool pet);
15071512
bool LearnTalent(uint32 talentId, uint32 talentRank);
15081513
void LearnPetTalent(ObjectGuid petGuid, uint32 talentId, uint32 talentRank);

src/server/game/Handlers/MiscHandler.cpp

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "GossipDef.h"
3434
#include "Group.h"
3535
#include "GuildMgr.h"
36+
#include "InspectPackets.h"
3637
#include "Language.h"
3738
#include "Log.h"
3839
#include "MapManager.h"
@@ -913,42 +914,39 @@ void WorldSession::HandlePlayedTime(WorldPackets::Character::PlayedTimeClient& p
913914
SendPacket(playedTime.Write());
914915
}
915916

916-
void WorldSession::HandleInspectOpcode(WorldPacket& recvData)
917+
void WorldSession::HandleInspectOpcode(WorldPackets::Inspect::Inspect& inspect)
917918
{
918-
ObjectGuid guid;
919-
recvData >> guid;
920-
921-
TC_LOG_DEBUG("network", "WORLD: Received CMSG_INSPECT");
922-
923-
Player* player = ObjectAccessor::GetPlayer(*_player, guid);
919+
Player* player = ObjectAccessor::GetPlayer(*_player, inspect.Target);
924920
if (!player)
925921
{
926-
TC_LOG_DEBUG("network", "CMSG_INSPECT: No player found from {}", guid.ToString());
922+
TC_LOG_DEBUG("network", "CMSG_INSPECT: No player found from {}", inspect.Target.ToString());
927923
return;
928924
}
929925

926+
TC_LOG_DEBUG("network", "WorldSession::HandleInspectOpcode: Target {}.", inspect.Target.ToString());
927+
930928
if (!GetPlayer()->IsWithinDistInMap(player, INSPECT_DISTANCE, false))
931929
return;
932930

933931
if (GetPlayer()->IsValidAttackTarget(player))
934932
return;
935933

936-
uint32 talent_points = 0x47;
937-
uint32 guid_size = player->GetPackGUID().size();
938-
WorldPacket data(SMSG_INSPECT_TALENT, guid_size+4+talent_points);
939-
data << player->GetPackGUID();
934+
WorldPackets::Inspect::InspectResult inspectResult;
935+
inspectResult.InspecteeGUID = inspect.Target;
940936

941-
if (GetPlayer()->CanBeGameMaster() || sWorld->getIntConfig(CONFIG_TALENTS_INSPECTING) + (GetPlayer()->GetTeamId() == player->GetTeamId()) > 1)
942-
player->BuildPlayerTalentsInfoData(&data);
943-
else
937+
for (uint8 i = 0; i < EQUIPMENT_SLOT_END; ++i)
944938
{
945-
data << uint32(0); // unspentTalentPoints
946-
data << uint8(0); // talentGroupCount
947-
data << uint8(0); // talentGroupIndex
939+
if (Item* item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
940+
{
941+
inspectResult.ItemSlots[i] = true;
942+
inspectResult.Items.emplace_back(item);
943+
}
948944
}
949945

950-
player->BuildEnchantmentsInfoData(&data);
951-
SendPacket(&data);
946+
if (GetPlayer()->CanBeGameMaster() || sWorld->getIntConfig(CONFIG_TALENTS_INSPECTING) + (GetPlayer()->GetTeamId() == player->GetTeamId()) > 1)
947+
player->BuildPlayerTalentsInfoData(inspectResult.TalentInfo);
948+
949+
SendPacket(inspectResult.Write());
952950
}
953951

954952
void WorldSession::HandleInspectHonorStatsOpcode(WorldPacket& recvData)

src/server/game/Handlers/SkillHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void WorldSession::HandleLearnPreviewTalents(WorldPacket& recvPacket)
6262
recvPacket.rfinish();
6363
}
6464

65-
void WorldSession::HandleTalentWipeConfirmOpcode(WorldPackets::Talents::ConfirmRespecWipe& confirmRespecWipe)
65+
void WorldSession::HandleTalentWipeConfirmOpcode(WorldPackets::Talent::ConfirmRespecWipe& confirmRespecWipe)
6666
{
6767
TC_LOG_DEBUG("network", "MSG_TALENT_WIPE_CONFIRM");
6868

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "CombatLogPackets.h"
2929
#include "CombatPackets.h"
3030
#include "GuildPackets.h"
31+
#include "InspectPackets.h"
3132
#include "LFGPackets.h"
3233
#include "MailPackets.h"
3334
#include "MiscPackets.h"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "ObjectGuid.h"
2323
#include "Position.h"
2424
#include "SharedDefines.h"
25+
#include <memory>
2526

2627
namespace WorldPackets
2728
{

0 commit comments

Comments
 (0)