mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-17 02:50:29 +00:00
refactor(Core/Packets): Rewrite MSG_RANDOM_ROLL to new packet class (#10590)
* refactor(Core/Packets): Rewrite MSG_RANDOM_ROLL
* cherry-pick commit (c0f516caee)
Co-Authored-By: ForesterDev <11771800+ForesterDev@users.noreply.github.com>
Co-Authored-By: DJScias <439655+DJScias@users.noreply.github.com>
* handle crash check in DoRandomRoll()
* Update MiscPackets.h
* Update Player.h
Co-authored-by: ForesterDev <11771800+ForesterDev@users.noreply.github.com>
Co-authored-by: DJScias <439655+DJScias@users.noreply.github.com>
This commit is contained in:
@@ -57,6 +57,7 @@
|
||||
#include "Log.h"
|
||||
#include "LootItemStorage.h"
|
||||
#include "MapMgr.h"
|
||||
#include "MiscPackets.h"
|
||||
#include "ObjectAccessor.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "Opcodes.h"
|
||||
@@ -15698,6 +15699,25 @@ void Player::RemoveRestFlag(RestFlag restFlag)
|
||||
}
|
||||
}
|
||||
|
||||
uint32 Player::DoRandomRoll(uint32 minimum, uint32 maximum)
|
||||
{
|
||||
ASSERT(minimum <= maximum || maximum <= 10000);
|
||||
|
||||
uint32 roll = urand(minimum, maximum);
|
||||
|
||||
WorldPackets::Misc::RandomRoll randomRoll;
|
||||
randomRoll.Min = minimum;
|
||||
randomRoll.Max = maximum;
|
||||
randomRoll.Result = roll;
|
||||
randomRoll.Roller = GetGUID();
|
||||
if (Group* group = GetGroup())
|
||||
group->BroadcastPacket(randomRoll.Write(), false);
|
||||
else
|
||||
SendDirectMessage(randomRoll.Write());
|
||||
|
||||
return roll;
|
||||
}
|
||||
|
||||
void Player::SetArenaTeamInfoField(uint8 slot, ArenaTeamInfoType type, uint32 value)
|
||||
{
|
||||
if (sScriptMgr->NotSetArenaTeamInfoField(this, slot, type, value))
|
||||
|
||||
@@ -2371,6 +2371,8 @@ public:
|
||||
void SendCinematicStart(uint32 CinematicSequenceId);
|
||||
void SendMovieStart(uint32 MovieId);
|
||||
|
||||
uint32 DoRandomRoll(uint32 minimum, uint32 maximum);
|
||||
|
||||
[[nodiscard]] uint16 GetMaxSkillValueForLevel() const;
|
||||
bool IsFFAPvP();
|
||||
bool IsPvP();
|
||||
|
||||
@@ -1698,7 +1698,7 @@ void Group::UpdatePlayerOutOfRange(Player* player)
|
||||
}
|
||||
}
|
||||
|
||||
void Group::BroadcastPacket(WorldPacket* packet, bool ignorePlayersInBGRaid, int group, ObjectGuid ignore)
|
||||
void Group::BroadcastPacket(WorldPacket const* packet, bool ignorePlayersInBGRaid, int group, ObjectGuid ignore)
|
||||
{
|
||||
for (GroupReference* itr = GetFirstMember(); itr != nullptr; itr = itr->next())
|
||||
{
|
||||
@@ -1711,7 +1711,7 @@ void Group::BroadcastPacket(WorldPacket* packet, bool ignorePlayersInBGRaid, int
|
||||
}
|
||||
}
|
||||
|
||||
void Group::BroadcastReadyCheck(WorldPacket* packet)
|
||||
void Group::BroadcastReadyCheck(WorldPacket const* packet)
|
||||
{
|
||||
for (GroupReference* itr = GetFirstMember(); itr != nullptr; itr = itr->next())
|
||||
{
|
||||
|
||||
@@ -269,8 +269,8 @@ public:
|
||||
void SendUpdateToPlayer(ObjectGuid playerGUID, MemberSlot* slot = nullptr);
|
||||
void UpdatePlayerOutOfRange(Player* player);
|
||||
// ignore: GUID of player that will be ignored
|
||||
void BroadcastPacket(WorldPacket* packet, bool ignorePlayersInBGRaid, int group = -1, ObjectGuid ignore = ObjectGuid::Empty);
|
||||
void BroadcastReadyCheck(WorldPacket* packet);
|
||||
void BroadcastPacket(WorldPacket const* packet, bool ignorePlayersInBGRaid, int group = -1, ObjectGuid ignore = ObjectGuid::Empty);
|
||||
void BroadcastReadyCheck(WorldPacket const* packet);
|
||||
void OfflineReadyCheck();
|
||||
|
||||
/*********************************************************/
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "Log.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "Opcodes.h"
|
||||
#include "MiscPackets.h"
|
||||
#include "Pet.h"
|
||||
#include "Player.h"
|
||||
#include "ScriptMgr.h"
|
||||
@@ -560,31 +561,13 @@ void WorldSession::HandleMinimapPingOpcode(WorldPacket& recvData)
|
||||
GetPlayer()->GetGroup()->BroadcastPacket(&data, true, -1, GetPlayer()->GetGUID());
|
||||
}
|
||||
|
||||
void WorldSession::HandleRandomRollOpcode(WorldPacket& recvData)
|
||||
void WorldSession::HandleRandomRollOpcode(WorldPackets::Misc::RandomRollClient& packet)
|
||||
{
|
||||
LOG_DEBUG("network", "WORLD: Received MSG_RANDOM_ROLL");
|
||||
uint32 minimum, maximum;
|
||||
minimum = packet.Min;
|
||||
maximum = packet.Max;
|
||||
|
||||
uint32 minimum, maximum, roll;
|
||||
recvData >> minimum;
|
||||
recvData >> maximum;
|
||||
|
||||
/** error handling **/
|
||||
if (minimum > maximum || maximum > 10000) // < 32768 for urand call
|
||||
return;
|
||||
/********************/
|
||||
|
||||
// everything's fine, do it
|
||||
roll = urand(minimum, maximum);
|
||||
|
||||
WorldPacket data(MSG_RANDOM_ROLL, 4 + 4 + 4 + 8);
|
||||
data << uint32(minimum);
|
||||
data << uint32(maximum);
|
||||
data << uint32(roll);
|
||||
data << GetPlayer()->GetGUID();
|
||||
if (GetPlayer()->GetGroup())
|
||||
GetPlayer()->GetGroup()->BroadcastPacket(&data, false);
|
||||
else
|
||||
SendPacket(&data);
|
||||
GetPlayer()->DoRandomRoll(minimum, maximum);
|
||||
}
|
||||
|
||||
void WorldSession::HandleRaidTargetUpdateOpcode(WorldPacket& recvData)
|
||||
|
||||
@@ -30,3 +30,19 @@ WorldPacket const* WorldPackets::Misc::Weather::Write()
|
||||
|
||||
return &_worldPacket;
|
||||
}
|
||||
|
||||
void WorldPackets::Misc::RandomRollClient::Read()
|
||||
{
|
||||
_worldPacket >> Min;
|
||||
_worldPacket >> Max;
|
||||
}
|
||||
|
||||
WorldPacket const* WorldPackets::Misc::RandomRoll::Write()
|
||||
{
|
||||
_worldPacket << uint32(Min);
|
||||
_worldPacket << uint32(Max);
|
||||
_worldPacket << uint32(Result);
|
||||
_worldPacket << Roller;
|
||||
|
||||
return &_worldPacket;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#define MiscPackets_h__
|
||||
|
||||
#include "Packet.h"
|
||||
#include "ObjectGuid.h"
|
||||
#include "Weather.h"
|
||||
|
||||
enum WeatherState : uint32;
|
||||
@@ -39,6 +40,30 @@ namespace WorldPackets
|
||||
float Intensity = 0.0f;
|
||||
WeatherState WeatherID = WeatherState(0);
|
||||
};
|
||||
|
||||
class RandomRollClient final : public ClientPacket
|
||||
{
|
||||
public:
|
||||
RandomRollClient(WorldPacket&& packet) : ClientPacket(MSG_RANDOM_ROLL, std::move(packet)) { }
|
||||
|
||||
void Read() override;
|
||||
|
||||
uint32 Min = 0;
|
||||
uint32 Max = 0;
|
||||
};
|
||||
|
||||
class RandomRoll final : public ServerPacket
|
||||
{
|
||||
public:
|
||||
RandomRoll() : ServerPacket(MSG_RANDOM_ROLL, 4 + 4 + 4 + 8) { }
|
||||
|
||||
WorldPacket const* Write() override;
|
||||
|
||||
uint32 Min = 0;
|
||||
uint32 Max = 0;
|
||||
uint32 Result = 0;
|
||||
ObjectGuid Roller;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -134,6 +134,11 @@ namespace WorldPackets
|
||||
class GuildSetGuildMaster;
|
||||
class SaveGuildEmblem;
|
||||
}
|
||||
|
||||
namespace Misc
|
||||
{
|
||||
class RandomRollClient;
|
||||
}
|
||||
}
|
||||
|
||||
enum AccountDataType
|
||||
@@ -888,7 +893,7 @@ public: // opcodes handlers
|
||||
void HandleWardenDataOpcode(WorldPacket& recvData);
|
||||
void HandleWorldTeleportOpcode(WorldPacket& recvData);
|
||||
void HandleMinimapPingOpcode(WorldPacket& recvData);
|
||||
void HandleRandomRollOpcode(WorldPacket& recvData);
|
||||
void HandleRandomRollOpcode(WorldPackets::Misc::RandomRollClient& packet);
|
||||
void HandleFarSightOpcode(WorldPacket& recvData);
|
||||
void HandleSetDungeonDifficultyOpcode(WorldPacket& recvData);
|
||||
void HandleSetRaidDifficultyOpcode(WorldPacket& recvData);
|
||||
|
||||
Reference in New Issue
Block a user