diff options
author | IntelligentQuantum <IntelligentQuantum@ProtonMail.Com> | 2022-01-03 20:20:56 +0330 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-03 11:50:56 -0500 |
commit | e57582accb7c275008c433c04478977cb5c8922b (patch) | |
tree | f3b2658cf9f40356c92e5e6fb9b584406b8f776f /src | |
parent | 7209f65896e18e172f9d142fac458bc279bc1e41 (diff) |
Core/Packet: WorldState (#9435)
* Core/Packet: WorldState
* Test
* WRONG
Co-authored-by: acidmanifesto <joshua.lee.betts@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Battlegrounds/Battleground.cpp | 21 | ||||
-rw-r--r-- | src/server/game/Battlegrounds/Battleground.h | 7 | ||||
-rw-r--r-- | src/server/game/Battlegrounds/BattlegroundMgr.cpp | 7 | ||||
-rw-r--r-- | src/server/game/Battlegrounds/BattlegroundMgr.h | 1 | ||||
-rw-r--r-- | src/server/game/Battlegrounds/Zones/BattlegroundEY.cpp | 8 | ||||
-rw-r--r-- | src/server/game/Entities/Player/Player.h | 2 | ||||
-rw-r--r-- | src/server/game/Entities/Player/PlayerUpdates.cpp | 11 | ||||
-rw-r--r-- | src/server/game/Events/GameEventMgr.cpp | 9 | ||||
-rw-r--r-- | src/server/game/Server/Packets/AllPackets.h | 1 | ||||
-rw-r--r-- | src/server/game/Server/Packets/WorldStatePackets.cpp | 46 | ||||
-rw-r--r-- | src/server/game/Server/Packets/WorldStatePackets.h | 62 | ||||
-rw-r--r-- | src/server/game/World/IWorld.h | 6 | ||||
-rw-r--r-- | src/server/game/World/World.cpp | 6 | ||||
-rw-r--r-- | src/server/game/World/World.h | 6 | ||||
-rw-r--r-- | src/test/mocks/WorldMock.h | 6 |
15 files changed, 148 insertions, 51 deletions
diff --git a/src/server/game/Battlegrounds/Battleground.cpp b/src/server/game/Battlegrounds/Battleground.cpp index 5aa3f3069c..7746a77bf0 100644 --- a/src/server/game/Battlegrounds/Battleground.cpp +++ b/src/server/game/Battlegrounds/Battleground.cpp @@ -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) diff --git a/src/server/game/Battlegrounds/Battleground.h b/src/server/game/Battlegrounds/Battleground.h index b3734621e0..7cd1587d82 100644 --- a/src/server/game/Battlegrounds/Battleground.h +++ b/src/server/game/Battlegrounds/Battleground.h @@ -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); diff --git a/src/server/game/Battlegrounds/BattlegroundMgr.cpp b/src/server/game/Battlegrounds/BattlegroundMgr.cpp index 43fcaffb51..496dc3bed2 100644 --- a/src/server/game/Battlegrounds/BattlegroundMgr.cpp +++ b/src/server/game/Battlegrounds/BattlegroundMgr.cpp @@ -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); diff --git a/src/server/game/Battlegrounds/BattlegroundMgr.h b/src/server/game/Battlegrounds/BattlegroundMgr.h index 77d6d4a0ed..41c007ae4a 100644 --- a/src/server/game/Battlegrounds/BattlegroundMgr.h +++ b/src/server/game/Battlegrounds/BattlegroundMgr.h @@ -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); diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundEY.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundEY.cpp index 1d6d617b96..40898644d4 100644 --- a/src/server/game/Battlegrounds/Zones/BattlegroundEY.cpp +++ b/src/server/game/Battlegrounds/Zones/BattlegroundEY.cpp @@ -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... diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index e55108e0c4..5d15aa8a29 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -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(); diff --git a/src/server/game/Entities/Player/PlayerUpdates.cpp b/src/server/game/Entities/Player/PlayerUpdates.cpp index bbf0383bda..9e8bac89dd 100644 --- a/src/server/game/Entities/Player/PlayerUpdates.cpp +++ b/src/server/game/Entities/Player/PlayerUpdates.cpp @@ -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() diff --git a/src/server/game/Events/GameEventMgr.cpp b/src/server/game/Events/GameEventMgr.cpp index 8229a69d00..23f1d1b28f 100644 --- a/src/server/game/Events/GameEventMgr.cpp +++ b/src/server/game/Events/GameEventMgr.cpp @@ -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()); } } } diff --git a/src/server/game/Server/Packets/AllPackets.h b/src/server/game/Server/Packets/AllPackets.h index e6b5273aa4..8ea2d21fcd 100644 --- a/src/server/game/Server/Packets/AllPackets.h +++ b/src/server/game/Server/Packets/AllPackets.h @@ -18,6 +18,7 @@ #ifndef AllPackets_h__ #define AllPackets_h__ +#include "WorldStatePackets.h" #include "TotemPackets.h" #include "BankPackets.h" #include "GuildPackets.h" diff --git a/src/server/game/Server/Packets/WorldStatePackets.cpp b/src/server/game/Server/Packets/WorldStatePackets.cpp new file mode 100644 index 0000000000..fde6964096 --- /dev/null +++ b/src/server/game/Server/Packets/WorldStatePackets.cpp @@ -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; +} diff --git a/src/server/game/Server/Packets/WorldStatePackets.h b/src/server/game/Server/Packets/WorldStatePackets.h new file mode 100644 index 0000000000..89382a7835 --- /dev/null +++ b/src/server/game/Server/Packets/WorldStatePackets.h @@ -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__ diff --git a/src/server/game/World/IWorld.h b/src/server/game/World/IWorld.h index ffad84b57e..2ec6503427 100644 --- a/src/server/game/World/IWorld.h +++ b/src/server/game/World/IWorld.h @@ -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; diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index 6cd84e9fd6..f51da28d70 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -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; diff --git a/src/server/game/World/World.h b/src/server/game/World/World.h index 6c5713c254..b9b9a16c50 100644 --- a/src/server/game/World/World.h +++ b/src/server/game/World/World.h @@ -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); diff --git a/src/test/mocks/WorldMock.h b/src/test/mocks/WorldMock.h index 82a024a867..9ae2d53de2 100644 --- a/src/test/mocks/WorldMock.h +++ b/src/test/mocks/WorldMock.h @@ -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)); |