Core/Packet: WorldState (#9435)

* Core/Packet: WorldState

* Test

* WRONG

Co-authored-by: acidmanifesto <joshua.lee.betts@gmail.com>
This commit is contained in:
IntelligentQuantum
2022-01-03 20:20:56 +03:30
committed by GitHub
parent 7209f65896
commit e57582accb
15 changed files with 148 additions and 51 deletions

View File

@@ -43,6 +43,7 @@
#include "Util.h"
#include "World.h"
#include "WorldPacket.h"
#include "WorldStatePackets.h"
namespace Acore
{
@@ -625,13 +626,13 @@ void Battleground::SetTeamStartLoc(TeamId teamId, float X, float Y, float Z, flo
m_TeamStartLocO[teamId] = O;
}
void Battleground::SendPacketToAll(WorldPacket* packet)
void Battleground::SendPacketToAll(WorldPacket const* packet)
{
for (BattlegroundPlayerMap::const_iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
itr->second->GetSession()->SendPacket(packet);
}
void Battleground::SendPacketToTeam(TeamId teamId, WorldPacket* packet, Player* sender, bool self)
void Battleground::SendPacketToTeam(TeamId teamId, WorldPacket const* packet, Player* sender, bool self)
{
for (BattlegroundPlayerMap::const_iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
if (itr->second->GetBgTeamId() == teamId && (self || sender != itr->second))
@@ -719,18 +720,12 @@ uint32 Battleground::GetRealRepFactionForPlayer(uint32 factionId, Player* player
return factionId;
}
void Battleground::UpdateWorldState(uint32 Field, uint32 Value)
void Battleground::UpdateWorldState(uint32 variable, uint32 value)
{
WorldPacket data;
sBattlegroundMgr->BuildUpdateWorldStatePacket(&data, Field, Value);
SendPacketToAll(&data);
}
void Battleground::UpdateWorldStateForPlayer(uint32 Field, uint32 Value, Player* player)
{
WorldPacket data;
sBattlegroundMgr->BuildUpdateWorldStatePacket(&data, Field, Value);
player->GetSession()->SendPacket(&data);
WorldPackets::WorldState::UpdateWorldState worldstate;
worldstate.VariableID = variable;
worldstate.Value = value;
SendPacketToAll(worldstate.Write());
}
void Battleground::EndBattleground(TeamId winnerTeamId)

View File

@@ -477,8 +477,8 @@ public:
// Packet Transfer
// method that should fill worldpacket with actual world states (not yet implemented for all battlegrounds!)
virtual void FillInitialWorldStates(WorldPacket& /*data*/) {}
void SendPacketToTeam(TeamId teamId, WorldPacket* packet, Player* sender = nullptr, bool self = true);
void SendPacketToAll(WorldPacket* packet);
void SendPacketToTeam(TeamId teamId, WorldPacket const* packet, Player* sender = nullptr, bool self = true);
void SendPacketToAll(WorldPacket const* packet);
void YellToAll(Creature* creature, const char* text, uint32 language);
template<class Do>
@@ -491,8 +491,7 @@ public:
void RewardReputationToTeam(uint32 factionId, uint32 reputation, TeamId teamId);
uint32 GetRealRepFactionForPlayer(uint32 factionId, Player* player);
void UpdateWorldState(uint32 Field, uint32 Value);
void UpdateWorldStateForPlayer(uint32 Field, uint32 Value, Player* player);
void UpdateWorldState(uint32 variable, uint32 value);
virtual void EndBattleground(TeamId winnerTeamId);
void BlockMovement(Player* player);

View File

@@ -384,13 +384,6 @@ void BattlegroundMgr::BuildGroupJoinedBattlegroundPacket(WorldPacket* data, Grou
*data << uint64(0); // player guid
}
void BattlegroundMgr::BuildUpdateWorldStatePacket(WorldPacket* data, uint32 field, uint32 value)
{
data->Initialize(SMSG_UPDATE_WORLD_STATE, 4 + 4);
*data << uint32(field);
*data << uint32(value);
}
void BattlegroundMgr::BuildPlaySoundPacket(WorldPacket* data, uint32 soundid)
{
data->Initialize(SMSG_PLAY_SOUND, 4);

View File

@@ -75,7 +75,6 @@ public:
void BuildPlayerLeftBattlegroundPacket(WorldPacket* data, ObjectGuid guid);
void BuildBattlegroundListPacket(WorldPacket* data, ObjectGuid guid, Player* player, BattlegroundTypeId bgTypeId, uint8 fromWhere);
void BuildGroupJoinedBattlegroundPacket(WorldPacket* data, GroupJoinBattlegroundResult result);
void BuildUpdateWorldStatePacket(WorldPacket* data, uint32 field, uint32 value);
void BuildPvpLogDataPacket(WorldPacket* data, Battleground* bg);
void BuildBattlegroundStatusPacket(WorldPacket* data, Battleground* bg, uint8 queueSlot, uint8 statusId, uint32 time1, uint32 time2, uint8 arenaType, TeamId teamId, bool isRated = false, BattlegroundTypeId forceBgTypeId = BATTLEGROUND_TYPE_NONE);
void BuildPlaySoundPacket(WorldPacket* data, uint32 soundid);

View File

@@ -134,14 +134,14 @@ void BattlegroundEY::UpdatePointsState()
const BattlegroundPlayerMap& bgPlayerMap = GetPlayers();
for (BattlegroundPlayerMap::const_iterator itr = bgPlayerMap.begin(); itr != bgPlayerMap.end(); ++itr)
{
UpdateWorldStateForPlayer(PROGRESS_BAR_SHOW, BG_EY_PROGRESS_BAR_DONT_SHOW, itr->second);
itr->second->SendUpdateWorldState(PROGRESS_BAR_SHOW, BG_EY_PROGRESS_BAR_DONT_SHOW);
for (uint8 point = 0; point < EY_POINTS_MAX; ++point)
if (GameObject* pointObject = pointsVec[point])
if (itr->second->CanCaptureTowerPoint() && itr->second->IsWithinDistInMap(pointObject, BG_EY_POINT_RADIUS))
{
UpdateWorldStateForPlayer(PROGRESS_BAR_SHOW, BG_EY_PROGRESS_BAR_SHOW, itr->second);
UpdateWorldStateForPlayer(PROGRESS_BAR_PERCENT_GREY, BG_EY_PROGRESS_BAR_PERCENT_GREY, itr->second);
UpdateWorldStateForPlayer(PROGRESS_BAR_STATUS, _capturePointInfo[point]._barStatus, itr->second);
itr->second->SendUpdateWorldState(PROGRESS_BAR_SHOW, BG_EY_PROGRESS_BAR_SHOW);
itr->second->SendUpdateWorldState(PROGRESS_BAR_PERCENT_GREY, BG_EY_PROGRESS_BAR_PERCENT_GREY);
itr->second->SendUpdateWorldState(PROGRESS_BAR_STATUS, _capturePointInfo[point]._barStatus);
++_capturePointInfo[point]._playersCount[itr->second->GetTeamId()];
// Xinef: ugly hax... area trigger is no longer called by client...

View File

@@ -2175,7 +2175,7 @@ public:
void DeleteEquipmentSet(uint64 setGuid);
void SendInitWorldStates(uint32 zone, uint32 area);
void SendUpdateWorldState(uint32 Field, uint32 Value);
void SendUpdateWorldState(uint32 variable, uint32 value) const;
void SendDirectMessage(WorldPacket const* data) const;
void SendBGWeekendWorldStates();
void SendBattlefieldWorldStates();

View File

@@ -35,6 +35,7 @@
#include "UpdateFieldFlags.h"
#include "Vehicle.h"
#include "WeatherMgr.h"
#include "WorldStatePackets.h"
// TODO: this import is not necessary for compilation and marked as unused by the IDE
// however, for some reasons removing it would cause a damn linking issue
@@ -2262,12 +2263,12 @@ void Player::UpdateSpecCount(uint8 count)
SendTalentsInfoData(false);
}
void Player::SendUpdateWorldState(uint32 Field, uint32 Value)
void Player::SendUpdateWorldState(uint32 variable, uint32 value) const
{
WorldPacket data(SMSG_UPDATE_WORLD_STATE, 8);
data << Field;
data << Value;
GetSession()->SendPacket(&data);
WorldPackets::WorldState::UpdateWorldState worldstate;
worldstate.VariableID = variable;
worldstate.Value = value;
SendDirectMessage(worldstate.Write());
}
void Player::ProcessTerrainStatusUpdate()

View File

@@ -31,7 +31,7 @@
#include "UnitAI.h"
#include "Util.h"
#include "World.h"
#include "WorldPacket.h"
#include "WorldStatePackets.h"
#include <time.h>
GameEventMgr* GameEventMgr::instance()
@@ -1620,9 +1620,10 @@ void GameEventMgr::UpdateWorldStates(uint16 event_id, bool Activate)
BattlemasterListEntry const* bl = sBattlemasterListStore.LookupEntry(bgTypeId);
if (bl && bl->HolidayWorldStateId)
{
WorldPacket data;
sBattlegroundMgr->BuildUpdateWorldStatePacket(&data, bl->HolidayWorldStateId, Activate ? 1 : 0);
sWorld->SendGlobalMessage(&data);
WorldPackets::WorldState::UpdateWorldState worldstate;
worldstate.VariableID = bl->HolidayWorldStateId;
worldstate.Value = Activate ? 1 : 0;
sWorld->SendGlobalMessage(worldstate.Write());
}
}
}

View File

@@ -18,6 +18,7 @@
#ifndef AllPackets_h__
#define AllPackets_h__
#include "WorldStatePackets.h"
#include "TotemPackets.h"
#include "BankPackets.h"
#include "GuildPackets.h"

View File

@@ -0,0 +1,46 @@
/*
* This file is part of the AzerothCore 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 Affero General Public License as published by the
* Free Software Foundation; either version 3 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 Affero 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 "WorldStatePackets.h"
WorldPackets::WorldState::InitWorldStates::InitWorldStates() : ServerPacket(SMSG_INIT_WORLD_STATES, 4 + 4 + 4 + 2) { }
WorldPacket const* WorldPackets::WorldState::InitWorldStates::Write()
{
_worldPacket.reserve(4 + 4 + 4 + 2 + Worldstates.size() * 8);
_worldPacket << int32(MapID);
_worldPacket << int32(ZoneID);
_worldPacket << int32(AreaID);
_worldPacket << uint16(Worldstates.size());
for (WorldStateInfo const& wsi : Worldstates)
{
_worldPacket << int32(wsi.VariableID);
_worldPacket << int32(wsi.Value);
}
return &_worldPacket;
}
WorldPacket const* WorldPackets::WorldState::UpdateWorldState::Write()
{
_worldPacket << int32(VariableID);
_worldPacket << int32(Value);
return &_worldPacket;
}

View File

@@ -0,0 +1,62 @@
/*
* This file is part of the AzerothCore 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 Affero General Public License as published by the
* Free Software Foundation; either version 3 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 Affero 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 WorldStatePackets_h__
#define WorldStatePackets_h__
#include "Packet.h"
namespace WorldPackets
{
namespace WorldState
{
class InitWorldStates final : public ServerPacket
{
public:
struct WorldStateInfo
{
WorldStateInfo(int32 variableID, int32 value) : VariableID(variableID), Value(value) { }
int32 VariableID;
int32 Value;
};
InitWorldStates();
WorldPacket const* Write() override;
int32 MapID = 0;
int32 ZoneID = 0;
int32 AreaID = 0;
std::vector<WorldStateInfo> Worldstates;
};
class UpdateWorldState final : public ServerPacket
{
public:
UpdateWorldState() : ServerPacket(SMSG_UPDATE_WORLD_STATE, 4 + 4) { }
WorldPacket const* Write() override;
int32 VariableID = 0;
int32 Value = 0;
};
}
}
#endif // WorldStatePackets_h__

View File

@@ -542,9 +542,9 @@ public:
virtual void SendWorldTextOptional(uint32 string_id, uint32 flag, ...) = 0;
virtual void SendGlobalText(const char* text, WorldSession* self) = 0;
virtual void SendGMText(uint32 string_id, ...) = 0;
virtual void SendGlobalMessage(WorldPacket* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL) = 0;
virtual void SendGlobalGMMessage(WorldPacket* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL) = 0;
virtual bool SendZoneMessage(uint32 zone, WorldPacket* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL) = 0;
virtual void SendGlobalMessage(WorldPacket const* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL) = 0;
virtual void SendGlobalGMMessage(WorldPacket const* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL) = 0;
virtual bool SendZoneMessage(uint32 zone, WorldPacket const* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL) = 0;
virtual void SendZoneText(uint32 zone, const char* text, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL) = 0;
virtual void SendServerMessage(ServerMessageType type, const char* text = "", Player* player = nullptr) = 0;
virtual bool IsShuttingDown() const = 0;

View File

@@ -2482,7 +2482,7 @@ void World::ForceGameEventUpdate()
}
/// Send a packet to all players (except self if mentioned)
void World::SendGlobalMessage(WorldPacket* packet, WorldSession* self, TeamId teamId)
void World::SendGlobalMessage(WorldPacket const* packet, WorldSession* self, TeamId teamId)
{
SessionMap::const_iterator itr;
for (itr = m_sessions.begin(); itr != m_sessions.end(); ++itr)
@@ -2499,7 +2499,7 @@ void World::SendGlobalMessage(WorldPacket* packet, WorldSession* self, TeamId te
}
/// Send a packet to all GMs (except self if mentioned)
void World::SendGlobalGMMessage(WorldPacket* packet, WorldSession* self, TeamId teamId)
void World::SendGlobalGMMessage(WorldPacket const* packet, WorldSession* self, TeamId teamId)
{
SessionMap::iterator itr;
for (itr = m_sessions.begin(); itr != m_sessions.end(); ++itr)
@@ -2648,7 +2648,7 @@ void World::SendGlobalText(const char* text, WorldSession* self)
}
/// Send a packet to all players (or players selected team) in the zone (except self if mentioned)
bool World::SendZoneMessage(uint32 zone, WorldPacket* packet, WorldSession* self, TeamId teamId)
bool World::SendZoneMessage(uint32 zone, WorldPacket const* packet, WorldSession* self, TeamId teamId)
{
bool foundPlayerToSend = false;
SessionMap::const_iterator itr;

View File

@@ -256,9 +256,9 @@ public:
void SendWorldText(uint32 string_id, ...);
void SendGlobalText(const char* text, WorldSession* self);
void SendGMText(uint32 string_id, ...);
void SendGlobalMessage(WorldPacket* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL);
void SendGlobalGMMessage(WorldPacket* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL);
bool SendZoneMessage(uint32 zone, WorldPacket* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL);
void SendGlobalMessage(WorldPacket const* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL);
void SendGlobalGMMessage(WorldPacket const* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL);
bool SendZoneMessage(uint32 zone, WorldPacket const* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL);
void SendZoneText(uint32 zone, const char* text, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL);
void SendServerMessage(ServerMessageType type, const char* text = "", Player* player = nullptr);

View File

@@ -80,9 +80,9 @@ public:
void SendWorldTextOptional(uint32 string_id, uint32 flag, ...) override {}
MOCK_METHOD(void, SendGlobalText, (const char* text, WorldSession* self), ());
void SendGMText(uint32 string_id, ...) override {}
MOCK_METHOD(void, SendGlobalMessage, (WorldPacket* packet, WorldSession* self, TeamId teamId), ());
MOCK_METHOD(void, SendGlobalGMMessage, (WorldPacket* packet, WorldSession* self, TeamId teamId), ());
MOCK_METHOD(bool, SendZoneMessage, (uint32 zone, WorldPacket* packet, WorldSession* self, TeamId teamId), ());
MOCK_METHOD(void, SendGlobalMessage, (WorldPacket const* packet, WorldSession* self, TeamId teamId), ());
MOCK_METHOD(void, SendGlobalGMMessage, (WorldPacket const* packet, WorldSession* self, TeamId teamId), ());
MOCK_METHOD(bool, SendZoneMessage, (uint32 zone, WorldPacket const* packet, WorldSession* self, TeamId teamId), ());
MOCK_METHOD(void, SendZoneText, (uint32 zone, const char* text, WorldSession* self, TeamId teamId), ());
MOCK_METHOD(void, SendServerMessage, (ServerMessageType type, const char* text, Player* player));
MOCK_METHOD(bool, IsShuttingDown, (), (const));