Skip to content

Commit 8565ba9

Browse files
committed
Core/PacketIO: Converted BattlegroundPackets to classes
1 parent de9340c commit 8565ba9

36 files changed

+1190
-648
lines changed

src/server/game/Battlefield/Battlefield.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "Battlefield.h"
1919
#include "BattlefieldMgr.h"
2020
#include "Battleground.h"
21+
#include "BattlegroundPackets.h"
2122
#include "CellImpl.h"
2223
#include "CreatureTextMgr.h"
2324
#include "DBCStores.h"
@@ -630,11 +631,10 @@ void Battlefield::RemovePlayerFromResurrectQueue(ObjectGuid playerGuid)
630631

631632
void Battlefield::SendAreaSpiritHealerQueryOpcode(Player* player, ObjectGuid guid)
632633
{
633-
WorldPacket data(SMSG_AREA_SPIRIT_HEALER_TIME, 12);
634-
uint32 time = m_LastResurrectTimer; // resurrect every 30 seconds
635-
636-
data << guid << time;
637-
player->SendDirectMessage(&data);
634+
WorldPackets::Battleground::AreaSpiritHealerTime areaSpiritHealerTime;
635+
areaSpiritHealerTime.HealerGuid = guid;
636+
areaSpiritHealerTime.TimeLeft = m_LastResurrectTimer;
637+
player->SendDirectMessage(areaSpiritHealerTime.Write());
638638
}
639639

640640
// ----------------------

src/server/game/Battlegrounds/Arena.cpp

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,44 +18,28 @@
1818
#include "Arena.h"
1919
#include "ArenaScore.h"
2020
#include "ArenaTeamMgr.h"
21+
#include "BattlegroundPackets.h"
2122
#include "Log.h"
2223
#include "ObjectAccessor.h"
2324
#include "Player.h"
2425
#include "World.h"
2526
#include "WorldSession.h"
2627
#include "WorldStatePackets.h"
2728

28-
void ArenaScore::AppendToPacket(WorldPacket& data)
29+
void ArenaScore::AppendToPacket(WorldPackets::Battleground::PVPLogData_Player& playerData)
2930
{
30-
data << uint64(PlayerGuid);
31+
playerData.PlayerGUID = PlayerGuid;
3132

32-
data << uint32(KillingBlows);
33-
data << uint8(TeamId);
34-
data << uint32(DamageDone);
35-
data << uint32(HealingDone);
33+
playerData.Kills = KillingBlows;
34+
playerData.HonorOrFaction = TeamId;
35+
playerData.DamageDone = DamageDone;
36+
playerData.HealingDone = HealingDone;
3637

37-
BuildObjectivesBlock(data);
38+
BuildObjectivesBlock(playerData);
3839
}
3940

40-
void ArenaScore::BuildObjectivesBlock(WorldPacket& data)
41+
void ArenaScore::BuildObjectivesBlock(WorldPackets::Battleground::PVPLogData_Player& /*playerData*/)
4142
{
42-
data << uint32(0); // Objectives Count
43-
}
44-
45-
void ArenaTeamScore::BuildRatingInfoBlock(WorldPacket& data)
46-
{
47-
uint32 ratingLost = std::abs(std::min(RatingChange, 0));
48-
uint32 ratingWon = std::max(RatingChange, 0);
49-
50-
// should be old rating, new rating, and client will calculate rating change itself
51-
data << uint32(ratingLost);
52-
data << uint32(ratingWon);
53-
data << uint32(MatchmakerRating);
54-
}
55-
56-
void ArenaTeamScore::BuildTeamInfoBlock(WorldPacket& data)
57-
{
58-
data << TeamName;
5943
}
6044

6145
Arena::Arena()

src/server/game/Battlegrounds/ArenaScore.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
#include "BattlegroundScore.h"
2222
#include <sstream>
2323

24-
struct TC_GAME_API ArenaScore : public BattlegroundScore
24+
struct TC_GAME_API ArenaScore final : public BattlegroundScore
2525
{
2626
friend class Arena;
2727

2828
protected:
2929
ArenaScore(ObjectGuid playerGuid, uint32 team) : BattlegroundScore(playerGuid), TeamId(team == ALLIANCE ? PVP_TEAM_ALLIANCE : PVP_TEAM_HORDE) { }
3030

31-
void AppendToPacket(WorldPacket& data) final override;
32-
void BuildObjectivesBlock(WorldPacket& data) final override;
31+
void AppendToPacket(WorldPackets::Battleground::PVPLogData_Player& playerData) override;
32+
void BuildObjectivesBlock(WorldPackets::Battleground::PVPLogData_Player& playerData) override;
3333

3434
// For Logging purpose
3535
std::string ToString() const override
@@ -50,8 +50,6 @@ struct TC_GAME_API ArenaTeamScore
5050
protected:
5151
ArenaTeamScore() : RatingChange(0), MatchmakerRating(0) { }
5252

53-
virtual ~ArenaTeamScore() { }
54-
5553
void Reset()
5654
{
5755
RatingChange = 0;
@@ -66,9 +64,6 @@ struct TC_GAME_API ArenaTeamScore
6664
TeamName = teamName;
6765
}
6866

69-
void BuildRatingInfoBlock(WorldPacket& data);
70-
void BuildTeamInfoBlock(WorldPacket& data);
71-
7267
int32 RatingChange;
7368
uint32 MatchmakerRating;
7469
std::string TeamName;

src/server/game/Battlegrounds/ArenaTeam.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "ArenaTeam.h"
1919
#include "ArenaTeamMgr.h"
2020
#include "BattlegroundMgr.h"
21+
#include "BattlegroundPackets.h"
2122
#include "CalendarPackets.h"
2223
#include "CharacterCache.h"
2324
#include "DatabaseEnv.h"
@@ -337,11 +338,11 @@ void ArenaTeam::DelMember(ObjectGuid guid, bool cleanDb)
337338
if (queue.GetPlayerGroupInfoData(playerMember->GetGUID(), &ginfo))
338339
if (!ginfo.IsInvitedToBGInstanceGUID)
339340
{
340-
WorldPacket data;
341341
playerMember->RemoveBattlegroundQueueId(bgQueue);
342-
sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, nullptr, i, STATUS_NONE, 0, 0, 0, 0);
342+
WorldPackets::Battleground::BattlefieldStatusNone battlefieldStatus;
343+
BattlegroundMgr::BuildBattlegroundStatusNone(&battlefieldStatus, i);
343344
queue.RemovePlayer(playerMember->GetGUID(), true);
344-
playerMember->GetSession()->SendPacket(&data);
345+
playerMember->SendDirectMessage(battlefieldStatus.Write());
345346
}
346347
}
347348
}

src/server/game/Battlegrounds/Battleground.cpp

Lines changed: 58 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "Battleground.h"
1919
#include "ArenaScore.h"
2020
#include "BattlegroundMgr.h"
21+
#include "BattlegroundPackets.h"
2122
#include "BattlegroundScore.h"
2223
#include "ChatTextBuilder.h"
2324
#include "Creature.h"
@@ -42,18 +43,21 @@
4243
#include "WorldStatePackets.h"
4344
#include <cstdarg>
4445

45-
void BattlegroundScore::AppendToPacket(WorldPacket& data)
46+
void BattlegroundScore::AppendToPacket(WorldPackets::Battleground::PVPLogData_Player& playerData)
4647
{
47-
data << uint64(PlayerGuid);
48+
playerData.PlayerGUID = PlayerGuid;
4849

49-
data << uint32(KillingBlows);
50-
data << uint32(HonorableKills);
51-
data << uint32(Deaths);
52-
data << uint32(BonusHonor);
53-
data << uint32(DamageDone);
54-
data << uint32(HealingDone);
50+
playerData.Kills = KillingBlows;
51+
playerData.HonorOrFaction = WorldPackets::Battleground::PVPLogData_Honor
52+
{
53+
.HonorKills = HonorableKills,
54+
.Deaths = Deaths,
55+
.ContributionPoints = BonusHonor
56+
};
57+
playerData.DamageDone = DamageDone;
58+
playerData.HealingDone = HealingDone;
5559

56-
BuildObjectivesBlock(data);
60+
BuildObjectivesBlock(playerData);
5761
}
5862

5963
template<class Do>
@@ -461,11 +465,10 @@ inline void Battleground::_ProcessJoin(uint32 diff)
461465
if (Player* player = ObjectAccessor::FindPlayer(itr->first))
462466
{
463467
// BG Status packet
464-
WorldPacket status;
465468
BattlegroundQueueTypeId bgQueueTypeId = BattlegroundMgr::BGQueueTypeId(m_TypeID, GetBracketId(), GetArenaType());
466-
uint32 queueSlot = player->GetBattlegroundQueueIndex(bgQueueTypeId);
467-
sBattlegroundMgr->BuildBattlegroundStatusPacket(&status, this, queueSlot, STATUS_IN_PROGRESS, 0, GetStartTime(), GetArenaType(), player->GetBGTeam());
468-
player->SendDirectMessage(&status);
469+
WorldPackets::Battleground::BattlefieldStatusActive battlefieldStatus;
470+
BattlegroundMgr::BuildBattlegroundStatusActive(&battlefieldStatus, this, player, player->GetBattlegroundQueueIndex(bgQueueTypeId), bgQueueTypeId);
471+
player->SendDirectMessage(battlefieldStatus.Write());
469472

470473
player->RemoveAurasDueToSpell(SPELL_ARENA_PREPARATION);
471474
player->ResetAllPowers();
@@ -716,8 +719,9 @@ void Battleground::EndBattleground(uint32 winner)
716719
//we must set it this way, because end time is sent in packet!
717720
m_EndTime = TIME_TO_AUTOREMOVE;
718721

719-
WorldPacket pvpLogData;
720-
BuildPvPLogDataPacket(pvpLogData);
722+
WorldPackets::Battleground::PVPMatchStatistics pvpMatchStatistics;
723+
BuildPvPLogDataPacket(pvpMatchStatistics);
724+
pvpMatchStatistics.Write();
721725

722726
BattlegroundQueueTypeId bgQueueTypeId = BattlegroundMgr::BGQueueTypeId(GetTypeID(), GetBracketId(), GetArenaType());
723727

@@ -798,11 +802,12 @@ void Battleground::EndBattleground(uint32 winner)
798802

799803
BlockMovement(player);
800804

801-
player->SendDirectMessage(&pvpLogData);
805+
player->SendDirectMessage(pvpMatchStatistics.GetRawPacket());
806+
807+
WorldPackets::Battleground::BattlefieldStatusActive battlefieldStatus;
808+
BattlegroundMgr::BuildBattlegroundStatusActive(&battlefieldStatus, this, player, player->GetBattlegroundQueueIndex(bgQueueTypeId), bgQueueTypeId);
809+
player->SendDirectMessage(battlefieldStatus.Write());
802810

803-
WorldPacket data;
804-
sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, this, player->GetBattlegroundQueueIndex(bgQueueTypeId), STATUS_IN_PROGRESS, TIME_TO_AUTOREMOVE, GetStartTime(), GetArenaType(), player->GetBGTeam());
805-
player->SendDirectMessage(&data);
806811
player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_BATTLEGROUND, player->GetMapId());
807812
}
808813
}
@@ -886,9 +891,9 @@ void Battleground::RemovePlayerAtLeave(ObjectGuid guid, bool Transport, bool Sen
886891

887892
if (SendPacket)
888893
{
889-
WorldPacket data;
890-
sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, this, player->GetBattlegroundQueueIndex(bgQueueTypeId), STATUS_NONE, 0, 0, 0, 0);
891-
player->SendDirectMessage(&data);
894+
WorldPackets::Battleground::BattlefieldStatusNone battlefieldStatus;
895+
BattlegroundMgr::BuildBattlegroundStatusNone(&battlefieldStatus, player->GetBattlegroundQueueIndex(bgQueueTypeId));
896+
player->SendDirectMessage(battlefieldStatus.Write());
892897
}
893898

894899
// this call is important, because player, when joins to battleground, this method is not called, so it must be called when leaving bg
@@ -910,9 +915,9 @@ void Battleground::RemovePlayerAtLeave(ObjectGuid guid, bool Transport, bool Sen
910915
sBattlegroundMgr->ScheduleQueueUpdate(0, bgQueueTypeId);
911916
}
912917
// Let others know
913-
WorldPacket data;
914-
sBattlegroundMgr->BuildPlayerLeftBattlegroundPacket(&data, guid);
915-
SendPacketToTeam(team, &data, player, false);
918+
WorldPackets::Battleground::BattlegroundPlayerLeft playerLeft;
919+
playerLeft.Guid = guid;
920+
SendPacketToTeam(team, playerLeft.Write(), player, false);
916921
}
917922

918923
if (player)
@@ -1001,9 +1006,9 @@ void Battleground::AddPlayer(Player* player)
10011006
if (!isInBattleground)
10021007
UpdatePlayersCountByTeam(team, false); // +1 player
10031008

1004-
WorldPacket data;
1005-
sBattlegroundMgr->BuildPlayerJoinedBattlegroundPacket(&data, player);
1006-
SendPacketToTeam(team, &data, player, false);
1009+
WorldPackets::Battleground::BattlegroundPlayerJoined playerJoined;
1010+
playerJoined.Guid = player->GetGUID();
1011+
SendPacketToTeam(team, playerJoined.Write(), player, false);
10071012

10081013
player->RemoveAurasByType(SPELL_AURA_MOUNTED);
10091014

@@ -1200,33 +1205,33 @@ bool Battleground::HasFreeSlots() const
12001205
return GetPlayersSize() < GetMaxPlayers();
12011206
}
12021207

1203-
void Battleground::BuildPvPLogDataPacket(WorldPacket& data)
1208+
void Battleground::BuildPvPLogDataPacket(WorldPackets::Battleground::PVPMatchStatistics& pvpLogData)
12041209
{
1205-
uint8 type = (isArena() ? 1 : 0);
1206-
1207-
data.Initialize(MSG_PVP_LOG_DATA, 1 + 1 + 4 + 40 * GetPlayerScoresSize());
1208-
data << uint8(type); // type (battleground = 0 / arena = 1)
1209-
1210-
if (type) // arena
1210+
if (isArena())
12111211
{
1212-
for (uint8 i = 0; i < PVP_TEAMS_COUNT; ++i)
1213-
_arenaTeamScores[i].BuildRatingInfoBlock(data);
1212+
WorldPackets::Battleground::PVPLogData_Arena& arena = pvpLogData.Arena.emplace();
12141213

12151214
for (uint8 i = 0; i < PVP_TEAMS_COUNT; ++i)
1216-
_arenaTeamScores[i].BuildTeamInfoBlock(data);
1215+
{
1216+
ArenaTeamScore const& score = _arenaTeamScores[i];
1217+
1218+
uint32 ratingLost = std::abs(std::min(score.RatingChange, 0));
1219+
uint32 ratingWon = std::max(score.RatingChange, 0);
1220+
1221+
// should be old rating, new rating, and client will calculate rating change itself
1222+
arena.Ratings.Prematch[i] = ratingLost;
1223+
arena.Ratings.Postmatch[i] = ratingWon;
1224+
arena.Ratings.PrematchMMR[i] = score.MatchmakerRating;
1225+
1226+
arena.TeamName[i] = score.TeamName;
1227+
}
12171228
}
12181229

12191230
if (GetStatus() == STATUS_WAIT_LEAVE)
1220-
{
1221-
data << uint8(1); // bg ended
1222-
data << uint8(GetWinner()); // who win
1223-
}
1224-
else
1225-
data << uint8(0); // bg not ended
1231+
pvpLogData.Winner = GetWinner();
12261232

1227-
data << uint32(GetPlayerScoresSize());
1228-
for (auto const& score : PlayerScores)
1229-
score.second->AppendToPacket(data);
1233+
for (auto const& [_, score] : PlayerScores)
1234+
score->AppendToPacket(pvpLogData.Players.emplace_back());
12301235
}
12311236

12321237
bool Battleground::UpdatePlayerScore(Player* player, uint32 type, uint32 value, bool doAddHonor)
@@ -1729,16 +1734,17 @@ void Battleground::PlayerAddedToBGCheckIfBGIsRunning(Player* player)
17291734
if (GetStatus() != STATUS_WAIT_LEAVE)
17301735
return;
17311736

1732-
WorldPacket data;
17331737
BattlegroundQueueTypeId bgQueueTypeId = BattlegroundMgr::BGQueueTypeId(GetTypeID(), GetBracketId(), GetArenaType());
17341738

17351739
BlockMovement(player);
17361740

1737-
BuildPvPLogDataPacket(data);
1738-
player->SendDirectMessage(&data);
1741+
WorldPackets::Battleground::PVPMatchStatistics pvpMatchStatistics;
1742+
BuildPvPLogDataPacket(pvpMatchStatistics);
1743+
player->SendDirectMessage(pvpMatchStatistics.Write());
17391744

1740-
sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, this, player->GetBattlegroundQueueIndex(bgQueueTypeId), STATUS_IN_PROGRESS, GetEndTime(), GetStartTime(), GetArenaType(), player->GetBGTeam());
1741-
player->SendDirectMessage(&data);
1745+
WorldPackets::Battleground::BattlefieldStatusActive battlefieldStatus;
1746+
BattlegroundMgr::BuildBattlegroundStatusActive(&battlefieldStatus, this, player, player->GetBattlegroundQueueIndex(bgQueueTypeId), bgQueueTypeId);
1747+
player->SendDirectMessage(battlefieldStatus.Write());
17421748
}
17431749

17441750
uint32 Battleground::GetAlivePlayersCountByTeam(uint32 Team) const

src/server/game/Battlegrounds/Battleground.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929

3030
namespace WorldPackets
3131
{
32+
namespace Battleground
33+
{
34+
class PVPMatchStatistics;
35+
}
3236
namespace WorldState
3337
{
3438
class InitWorldStates;
@@ -399,7 +403,7 @@ class TC_GAME_API Battleground
399403
Group* GetBgRaid(uint32 TeamID) const { return TeamID == ALLIANCE ? m_BgRaids[TEAM_ALLIANCE] : m_BgRaids[TEAM_HORDE]; }
400404
void SetBgRaid(uint32 TeamID, Group* bg_raid);
401405

402-
void BuildPvPLogDataPacket(WorldPacket& data);
406+
void BuildPvPLogDataPacket(WorldPackets::Battleground::PVPMatchStatistics& pvpLogData);
403407
virtual bool UpdatePlayerScore(Player* player, uint32 type, uint32 value, bool doAddHonor = true);
404408

405409
static TeamId GetTeamIndexByTeamId(uint32 Team) { return Team == ALLIANCE ? TEAM_ALLIANCE : TEAM_HORDE; }

0 commit comments

Comments
 (0)