refactor(Core/Packet): Chat (#9509)

* Chat

* .

* Update GameObject.cpp

* Update Object.cpp

* Update Player.cpp
This commit is contained in:
IntelligentQuantum 2022-01-08 13:41:06 +03:30 committed by GitHub
parent 03efc110a0
commit 725b1266b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 153 additions and 48 deletions

View file

@ -2103,8 +2103,7 @@ bool GameObject::IsInRange(float x, float y, float z, float radius) const
&& dz < (info->maxZ * scale) + radius && dz > (info->minZ * scale) - radius;
}
// pussywizard!
void GameObject::SendMessageToSetInRange(WorldPacket* data, float dist, bool /*self*/, bool includeMargin, Player const* skipped_rcvr)
void GameObject::SendMessageToSetInRange(WorldPacket const* data, float dist, bool /*self*/, bool includeMargin, Player const* skipped_rcvr) const
{
dist += GetObjectSize();
if (includeMargin)

View file

@ -928,7 +928,7 @@ public:
void SendCustomAnim(uint32 anim);
[[nodiscard]] bool IsInRange(float x, float y, float z, float radius) const;
void SendMessageToSetInRange(WorldPacket* data, float dist, bool /*self*/, bool includeMargin = false, Player const* skipped_rcvr = nullptr) override; // pussywizard!
void SendMessageToSetInRange(WorldPacket const* data, float dist, bool /*self*/, bool includeMargin = false, Player const* skipped_rcvr = nullptr) const override; // pussywizard!
void ModifyHealth(int32 change, Unit* attackerOrHealer = nullptr, uint32 spellId = 0);
void SetDestructibleBuildingModifyState(bool allow) { m_allowModifyDestructibleBuilding = allow; }

View file

@ -2196,8 +2196,7 @@ void Unit::BuildHeartBeatMsg(WorldPacket* data) const
BuildMovementPacket(data);
}
// pussywizard!
void WorldObject::SendMessageToSetInRange(WorldPacket* data, float dist, bool /*self*/, bool includeMargin, Player const* skipped_rcvr)
void WorldObject::SendMessageToSetInRange(WorldPacket const* data, float dist, bool /*self*/, bool includeMargin, Player const* skipped_rcvr) const
{
dist += GetObjectSize();
if (includeMargin)

View file

@ -755,9 +755,9 @@ public:
virtual void CleanupsBeforeDelete(bool finalCleanup = true); // used in destructor or explicitly before mass creature delete to remove cross-references to already deleted units
virtual void SendMessageToSet(WorldPacket* data, bool self) { if (IsInWorld()) SendMessageToSetInRange(data, GetVisibilityRange(), self, true); } // pussywizard!
virtual void SendMessageToSetInRange(WorldPacket* data, float dist, bool /*self*/, bool includeMargin = false, Player const* skipped_rcvr = nullptr); // pussywizard!
virtual void SendMessageToSet(WorldPacket* data, Player const* skipped_rcvr) { if (IsInWorld()) SendMessageToSetInRange(data, GetVisibilityRange(), false, true, skipped_rcvr); } // pussywizard!
virtual void SendMessageToSet(WorldPacket const* data, bool self) const { if (IsInWorld()) SendMessageToSetInRange(data, GetVisibilityRange(), self, true); } // pussywizard!
virtual void SendMessageToSetInRange(WorldPacket const* data, float dist, bool /*self*/, bool includeMargin = false, Player const* skipped_rcvr = nullptr) const; // pussywizard!
virtual void SendMessageToSet(WorldPacket const* data, Player const* skipped_rcvr) const { if (IsInWorld()) SendMessageToSetInRange(data, GetVisibilityRange(), false, true, skipped_rcvr); } // pussywizard!
virtual uint8 getLevelForTarget(WorldObject const* /*target*/) const { return 1; }

View file

@ -5499,8 +5499,7 @@ void Player::SaveRecallPosition()
m_recallO = GetOrientation();
}
// pussywizard!
void Player::SendMessageToSetInRange(WorldPacket* data, float dist, bool self, bool includeMargin, Player const* skipped_rcvr)
void Player::SendMessageToSetInRange(WorldPacket const* data, float dist, bool self, bool includeMargin, Player const* skipped_rcvr) const
{
if (self)
GetSession()->SendPacket(data);
@ -5512,8 +5511,7 @@ void Player::SendMessageToSetInRange(WorldPacket* data, float dist, bool self, b
Cell::VisitWorldObjects(this, notifier, dist);
}
// pussywizard!
void Player::SendMessageToSetInRange_OwnTeam(WorldPacket* data, float dist, bool self)
void Player::SendMessageToSetInRange_OwnTeam(WorldPacket const* data, float dist, bool self) const
{
if (self)
GetSession()->SendPacket(data);

View file

@ -1969,10 +1969,10 @@ public:
void ProcessTerrainStatusUpdate() override;
void SendMessageToSet(WorldPacket* data, bool self) override { SendMessageToSetInRange(data, GetVisibilityRange(), self, true); } // pussywizard!
void SendMessageToSetInRange(WorldPacket* data, float dist, bool self, bool includeMargin = false, Player const* skipped_rcvr = nullptr) override; // pussywizard!
void SendMessageToSetInRange_OwnTeam(WorldPacket* data, float dist, bool self); // pussywizard! param includeMargin not needed here
void SendMessageToSet(WorldPacket* data, Player const* skipped_rcvr) override { SendMessageToSetInRange(data, GetVisibilityRange(), skipped_rcvr != this, true, skipped_rcvr); } // pussywizard!
void SendMessageToSet(WorldPacket const* data, bool self) const override { SendMessageToSetInRange(data, GetVisibilityRange(), self, true); } // pussywizard!
void SendMessageToSetInRange(WorldPacket const* data, float dist, bool self, bool includeMargin = false, Player const* skipped_rcvr = nullptr) const override; // pussywizard!
void SendMessageToSetInRange_OwnTeam(WorldPacket const* data, float dist, bool self) const; // pussywizard! param includeMargin not needed here
void SendMessageToSet(WorldPacket const* data, Player const* skipped_rcvr) const override { SendMessageToSetInRange(data, GetVisibilityRange(), skipped_rcvr != this, true, skipped_rcvr); } // pussywizard!
void SendTeleportAckPacket();

View file

@ -24,6 +24,7 @@
#include "CellImpl.h"
#include "CharacterCache.h"
#include "Chat.h"
#include "ChatPackets.h"
#include "ChatTextBuilder.h"
#include "Common.h"
#include "ConditionMgr.h"
@ -1724,12 +1725,12 @@ void Unit::DealMeleeDamage(CalcDamageInfo* damageInfo, bool durabilityLoss)
}
}
void Unit::HandleEmoteCommand(uint32 anim_id)
void Unit::HandleEmoteCommand(uint32 emoteId)
{
WorldPacket data(SMSG_EMOTE, 4 + 8);
data << uint32(anim_id);
data << GetGUID();
SendMessageToSet(&data, true);
WorldPackets::Chat::Emote packet;
packet.EmoteID = emoteId;
packet.Guid = GetGUID();
SendMessageToSet(packet.Write(), true);
}
bool Unit::IsDamageReducedByArmor(SpellSchoolMask schoolMask, SpellInfo const* spellInfo, uint8 effIndex)

View file

@ -1664,7 +1664,7 @@ public:
void TriggerAurasProcOnEvent(std::list<AuraApplication*>* myProcAuras, std::list<AuraApplication*>* targetProcAuras, Unit* actionTarget, uint32 typeMaskActor, uint32 typeMaskActionTarget, uint32 spellTypeMask, uint32 spellPhaseMask, uint32 hitMask, Spell* spell, DamageInfo* damageInfo, HealInfo* healInfo);
void TriggerAurasProcOnEvent(ProcEventInfo& eventInfo, std::list<AuraApplication*>& procAuras);
void HandleEmoteCommand(uint32 anim_id);
void HandleEmoteCommand(uint32 emoteId);
void AttackerStateUpdate (Unit* victim, WeaponAttackType attType = BASE_ATTACK, bool extra = false);
void CalculateMeleeDamage(Unit* victim, uint32 damage, CalcDamageInfo* damageInfo, WeaponAttackType attackType = BASE_ATTACK, const bool sittingVictim = false);

View file

@ -96,13 +96,13 @@ namespace Acore
struct MessageDistDeliverer
{
WorldObject* i_source;
WorldPacket* i_message;
WorldObject const* i_source;
WorldPacket const* i_message;
uint32 i_phaseMask;
float i_distSq;
TeamId teamId;
Player const* skipped_receiver;
MessageDistDeliverer(WorldObject* src, WorldPacket* msg, float dist, bool own_team_only = false, Player const* skipped = nullptr)
MessageDistDeliverer(WorldObject const* src, WorldPacket const* msg, float dist, bool own_team_only = false, Player const* skipped = nullptr)
: i_source(src), i_message(msg), i_phaseMask(src->GetPhaseMask()), i_distSq(dist * dist)
, teamId((own_team_only && src->GetTypeId() == TYPEID_PLAYER) ? src->ToPlayer()->GetTeamId() : TEAM_NEUTRAL)
, skipped_receiver(skipped)

View file

@ -19,6 +19,7 @@
#include "CellImpl.h"
#include "ChannelMgr.h"
#include "Chat.h"
#include "ChatPackets.h"
#include "Common.h"
#include "GridNotifiersImpl.h"
#include "Group.h"
@ -669,23 +670,22 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData)
}
}
void WorldSession::HandleEmoteOpcode(WorldPacket& recvData)
void WorldSession::HandleEmoteOpcode(WorldPackets::Chat::EmoteClient& packet)
{
if (!GetPlayer()->IsAlive() || GetPlayer()->HasUnitState(UNIT_STATE_DIED))
return;
if (GetPlayer()->IsSpectator())
return;
uint32 emote;
recvData >> emote;
uint32 emoteId = packet.EmoteID;
// restrict to the only emotes hardcoded in client
if (emote != EMOTE_ONESHOT_NONE && emote != EMOTE_ONESHOT_WAVE)
if (emoteId != EMOTE_ONESHOT_NONE && emoteId != EMOTE_ONESHOT_WAVE)
return;
sScriptMgr->OnPlayerEmote(GetPlayer(), emote);
GetPlayer()->HandleEmoteCommand(emote);
if (!_player->IsAlive() || _player->HasUnitState(UNIT_STATE_DIED))
return;
sScriptMgr->OnPlayerEmote(_player, emoteId);
_player->HandleEmoteCommand(emoteId);
}
namespace Acore

View file

@ -18,6 +18,7 @@
#ifndef AllPackets_h__
#define AllPackets_h__
#include "ChatPackets.h"
#include "CharacterPackets.h"
#include "MiscPackets.h"
#include "WorldStatePackets.h"

View file

@ -0,0 +1,39 @@
/*
* 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 "ChatPackets.h"
WorldPacket const* WorldPackets::Chat::Emote::Write()
{
_worldPacket << EmoteID;
_worldPacket << Guid;
return &_worldPacket;
}
void WorldPackets::Chat::EmoteClient::Read()
{
_worldPacket >> EmoteID;
}
WorldPacket const* WorldPackets::Chat::ChatServerMessage::Write()
{
_worldPacket << int32(MessageID);
_worldPacket << StringParam;
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 ChatPackets_h__
#define ChatPackets_h__
#include "Packet.h"
#include "ObjectGuid.h"
namespace WorldPackets
{
namespace Chat
{
class Emote final : public ServerPacket
{
public:
Emote() : ServerPacket(SMSG_EMOTE, 4 + 8) { }
WorldPacket const* Write() override;
uint32 EmoteID = 0;
ObjectGuid Guid;
};
class EmoteClient final : public ClientPacket
{
public:
EmoteClient(WorldPacket&& packet) : ClientPacket(CMSG_EMOTE, std::move(packet)) { }
void Read() override;
uint32 EmoteID = 0;
};
class ChatServerMessage final : public ServerPacket
{
public:
ChatServerMessage() : ServerPacket(SMSG_CHAT_SERVER_MESSAGE, 4 + 20) { }
WorldPacket const* Write() override;
int32 MessageID = 0;
std::string StringParam;
};
}
}
#endif // ChatPackets_h__

View file

@ -785,7 +785,7 @@ void OpcodeTable::Initialize()
/*0x28E*/ DEFINE_HANDLER(CMSG_GROUP_RAID_CONVERT, STATUS_LOGGEDIN, PROCESS_THREADUNSAFE, &WorldSession::HandleGroupRaidConvertOpcode );
/*0x28F*/ DEFINE_HANDLER(CMSG_GROUP_ASSISTANT_LEADER, STATUS_LOGGEDIN, PROCESS_THREADUNSAFE, &WorldSession::HandleGroupAssistantLeaderOpcode );
/*0x290*/ DEFINE_HANDLER(CMSG_BUYBACK_ITEM, STATUS_LOGGEDIN, PROCESS_INPLACE, &WorldSession::HandleBuybackItem );
/*0x291*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_SERVER_MESSAGE, STATUS_NEVER);
/*0x291*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_CHAT_SERVER_MESSAGE, STATUS_NEVER);
/*0x292*/ DEFINE_HANDLER(CMSG_SET_SAVED_INSTANCE_EXTEND, STATUS_LOGGEDIN, PROCESS_THREADUNSAFE, &WorldSession::HandleSetSavedInstanceExtend );
/*0x293*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_LFG_OFFER_CONTINUE, STATUS_NEVER);
/*0x294*/ DEFINE_HANDLER(CMSG_TEST_DROP_RATE, STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_NULL );

View file

@ -684,7 +684,7 @@ enum Opcodes : uint16
CMSG_GROUP_RAID_CONVERT = 0x28E,
CMSG_GROUP_ASSISTANT_LEADER = 0x28F,
CMSG_BUYBACK_ITEM = 0x290,
SMSG_SERVER_MESSAGE = 0x291,
SMSG_CHAT_SERVER_MESSAGE = 0x291,
CMSG_SET_SAVED_INSTANCE_EXTEND = 0x292,
SMSG_LFG_OFFER_CONTINUE = 0x293,
CMSG_TEST_DROP_RATE = 0x294,

View file

@ -71,6 +71,11 @@ namespace lfg
namespace WorldPackets
{
namespace Chat
{
class EmoteClient;
}
namespace Character
{
class LogoutCancel;
@ -583,7 +588,7 @@ public: // opcodes handlers
void HandleZoneUpdateOpcode(WorldPacket& recvPacket);
void HandleSetSelectionOpcode(WorldPacket& recvPacket);
void HandleStandStateChangeOpcode(WorldPacket& recvPacket);
void HandleEmoteOpcode(WorldPacket& recvPacket);
void HandleEmoteOpcode(WorldPackets::Chat::EmoteClient& packet);
void HandleContactListOpcode(WorldPacket& recvPacket);
void HandleAddFriendOpcode(WorldPacket& recvPacket);
void HandleDelFriendOpcode(WorldPacket& recvPacket);

View file

@ -547,7 +547,7 @@ public:
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 void SendServerMessage(ServerMessageType messageID, std::string stringParam = "", Player* player = nullptr) = 0;
virtual bool IsShuttingDown() const = 0;
virtual uint32 GetShutDownTimeLeft() const = 0;
virtual void ShutdownServ(uint32 time, uint32 options, uint8 exitcode, const std::string& reason = std::string()) = 0;

View file

@ -34,6 +34,7 @@
#include "ChannelMgr.h"
#include "CharacterDatabaseCleaner.h"
#include "Chat.h"
#include "ChatPackets.h"
#include "Common.h"
#include "ConditionMgr.h"
#include "Config.h"
@ -2814,7 +2815,7 @@ void World::ShutdownMsg(bool show, Player* player, const std::string& reason)
ServerMessageType msgid = (m_ShutdownMask & SHUTDOWN_MASK_RESTART) ? SERVER_MSG_RESTART_TIME : SERVER_MSG_SHUTDOWN_TIME;
SendServerMessage(msgid, str.c_str(), player);
SendServerMessage(msgid, str, player);
LOG_DEBUG("server.worldserver", "Server is %s in %s", (m_ShutdownMask & SHUTDOWN_MASK_RESTART ? "restart" : "shuttingdown"), str.c_str());
}
}
@ -2839,17 +2840,17 @@ void World::ShutdownCancel()
}
/// Send a server message to the user(s)
void World::SendServerMessage(ServerMessageType type, const char* text, Player* player)
void World::SendServerMessage(ServerMessageType messageID, std::string stringParam /*= ""*/, Player* player /*= nullptr*/)
{
WorldPacket data(SMSG_SERVER_MESSAGE, 50); // guess size
data << uint32(type);
if (type <= SERVER_MSG_STRING)
data << text;
WorldPackets::Chat::ChatServerMessage chatServerMessage;
chatServerMessage.MessageID = int32(messageID);
if (messageID <= SERVER_MSG_STRING)
chatServerMessage.StringParam = stringParam;
if (player)
player->GetSession()->SendPacket(&data);
player->SendDirectMessage(chatServerMessage.Write());
else
SendGlobalMessage(&data);
SendGlobalMessage(chatServerMessage.Write());
}
void World::UpdateSessions(uint32 diff)

View file

@ -260,7 +260,7 @@ public:
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);
void SendServerMessage(ServerMessageType messageID, std::string stringParam = "", Player* player = nullptr);
void SendWorldTextOptional(uint32 string_id, uint32 flag, ...);

View file

@ -84,7 +84,7 @@ public:
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(void, SendServerMessage, (ServerMessageType messageID, std::string stringParam, Player* player));
MOCK_METHOD(bool, IsShuttingDown, (), (const));
MOCK_METHOD(uint32, GetShutDownTimeLeft, (), (const));
MOCK_METHOD(void, ShutdownServ, (uint32 time, uint32 options, uint8 exitcode, const std::string& reason), ());