diff --git a/src/server/game/Handlers/ChatHandler.cpp b/src/server/game/Handlers/ChatHandler.cpp index c0bff56950..3cb9445a5d 100644 --- a/src/server/game/Handlers/ChatHandler.cpp +++ b/src/server/game/Handlers/ChatHandler.cpp @@ -21,6 +21,7 @@ #include "Channel.h" #include "ChannelMgr.h" #include "Chat.h" +#include "ChatPackets.h" #include "Common.h" #include "DatabaseEnv.h" #include "DBCStores.h" @@ -721,39 +722,7 @@ void WorldSession::HandleEmoteOpcode(WorldPacket& recvData) _player->SetUInt32Value(UNIT_NPC_EMOTESTATE, 0); } -namespace Trinity -{ - class EmoteChatBuilder - { - public: - EmoteChatBuilder(Player const& player, uint32 text_emote, uint32 emote_num, Unit const* target) - : i_player(player), i_text_emote(text_emote), i_emote_num(emote_num), i_target(target) { } - - void operator()(WorldPacket& data, LocaleConstant loc_idx) - { - std::string const name(i_target ? i_target->GetNameForLocaleIdx(loc_idx) : ""); - uint32 namlen = name.size(); - - data.Initialize(SMSG_TEXT_EMOTE, 20 + namlen); - data << i_player.GetGUID(); - data << uint32(i_text_emote); - data << uint32(i_emote_num); - data << uint32(namlen); - if (namlen > 1) - data << name; - else - data << uint8(0x00); - } - - private: - Player const& i_player; - uint32 i_text_emote; - uint32 i_emote_num; - Unit const* i_target; - }; -} // namespace Trinity - -void WorldSession::HandleTextEmoteOpcode(WorldPacket& recvData) +void WorldSession::HandleSendTextEmoteOpcode(WorldPackets::Chat::SendTextEmote& packet) { if (!GetPlayer()->IsAlive()) return; @@ -765,22 +734,15 @@ void WorldSession::HandleTextEmoteOpcode(WorldPacket& recvData) return; } - uint32 text_emote, emoteNum; - ObjectGuid guid; + sScriptMgr->OnPlayerTextEmote(GetPlayer(), packet.SoundIndex, packet.EmoteID, packet.Target); - recvData >> text_emote; - recvData >> emoteNum; - recvData >> guid; - - sScriptMgr->OnPlayerTextEmote(GetPlayer(), text_emote, emoteNum, guid); - - EmotesTextEntry const* em = sEmotesTextStore.LookupEntry(text_emote); + EmotesTextEntry const* em = sEmotesTextStore.LookupEntry(packet.EmoteID); if (!em) return; - uint32 emote_anim = em->EmoteID; + Emote emote = static_cast(em->EmoteID); - switch (emote_anim) + switch (emote) { case EMOTE_STATE_SLEEP: case EMOTE_STATE_SIT: @@ -789,36 +751,34 @@ void WorldSession::HandleTextEmoteOpcode(WorldPacket& recvData) break; case EMOTE_STATE_DANCE: case EMOTE_STATE_READ: - GetPlayer()->SetUInt32Value(UNIT_NPC_EMOTESTATE, emote_anim); + GetPlayer()->SetUInt32Value(UNIT_NPC_EMOTESTATE, emote); break; default: // Only allow text-emotes for "dead" entities (feign death included) if (GetPlayer()->HasUnitState(UNIT_STATE_DIED)) break; - GetPlayer()->HandleEmoteCommand(emote_anim); + GetPlayer()->HandleEmoteCommand(emote); break; } - Unit* unit = ObjectAccessor::GetUnit(*_player, guid); + Unit* unit = ObjectAccessor::GetUnit(*_player, packet.Target); - CellCoord p = Trinity::ComputeCellCoord(GetPlayer()->GetPositionX(), GetPlayer()->GetPositionY()); + WorldPackets::Chat::STextEmote textEmote; + textEmote.SourceGUID = _player->GetGUID(); + textEmote.EmoteID = packet.EmoteID; + textEmote.SoundIndex = packet.SoundIndex; + if (unit) + textEmote.Target = unit->GetName(); - Cell cell(p); - cell.SetNoCreate(); + _player->SendMessageToSetInRange(textEmote.Write(), sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_TEXTEMOTE), true); - Trinity::EmoteChatBuilder emote_builder(*GetPlayer(), text_emote, emoteNum, unit); - Trinity::LocalizedPacketDo emote_do(emote_builder); - Trinity::PlayerDistWorker > emote_worker(GetPlayer(), sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_TEXTEMOTE), emote_do); - TypeContainerVisitor >, WorldTypeMapContainer> message(emote_worker); - cell.Visit(p, message, *GetPlayer()->GetMap(), *GetPlayer(), sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_TEXTEMOTE)); - - GetPlayer()->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_DO_EMOTE, text_emote, 0, 0, unit); + GetPlayer()->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_DO_EMOTE, packet.EmoteID, 0, 0, unit); //Send scripted event call if (unit && unit->GetTypeId() == TYPEID_UNIT && ((Creature*)unit)->AI()) - ((Creature*)unit)->AI()->ReceiveEmote(GetPlayer(), text_emote); + ((Creature*)unit)->AI()->ReceiveEmote(GetPlayer(), packet.EmoteID); - if (emote_anim != EMOTE_ONESHOT_NONE) + if (emote != EMOTE_ONESHOT_NONE) _player->RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags::Anim); } diff --git a/src/server/game/Server/Packets/AllPackets.h b/src/server/game/Server/Packets/AllPackets.h index a3f8a3eaa4..a7261522bd 100644 --- a/src/server/game/Server/Packets/AllPackets.h +++ b/src/server/game/Server/Packets/AllPackets.h @@ -24,6 +24,7 @@ #include "AuthenticationPackets.h" #include "BattlegroundPackets.h" #include "CharacterPackets.h" +#include "ChatPackets.h" #include "CombatLogPackets.h" #include "CombatPackets.h" #include "GuildPackets.h" diff --git a/src/server/game/Server/Packets/ChatPackets.cpp b/src/server/game/Server/Packets/ChatPackets.cpp new file mode 100644 index 0000000000..2d99a9c87c --- /dev/null +++ b/src/server/game/Server/Packets/ChatPackets.cpp @@ -0,0 +1,36 @@ +/* +* This file is part of the TrinityCore 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 General Public License as published by the +* Free Software Foundation; either version 2 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 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 . +*/ + +#include "ChatPackets.h" + +void WorldPackets::Chat::SendTextEmote::Read() +{ + _worldPacket >> EmoteID; + _worldPacket >> SoundIndex; + _worldPacket >> Target; +} + +WorldPacket const* WorldPackets::Chat::STextEmote::Write() +{ + _worldPacket << SourceGUID; + _worldPacket << int32(EmoteID); + _worldPacket << int32(SoundIndex); + _worldPacket << int32(Target.length() + 1); + _worldPacket << Target; + + return &_worldPacket; +} diff --git a/src/server/game/Server/Packets/ChatPackets.h b/src/server/game/Server/Packets/ChatPackets.h new file mode 100644 index 0000000000..a493ea0e12 --- /dev/null +++ b/src/server/game/Server/Packets/ChatPackets.h @@ -0,0 +1,54 @@ +/* +* This file is part of the TrinityCore 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 General Public License as published by the +* Free Software Foundation; either version 2 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 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 . +*/ + +#ifndef ChatPackets_h__ +#define ChatPackets_h__ + +#include "Packet.h" + +namespace WorldPackets +{ + namespace Chat + { + class SendTextEmote final : public ClientPacket + { + public: + SendTextEmote(WorldPacket&& packet) : ClientPacket(CMSG_SEND_TEXT_EMOTE, std::move(packet)) { } + + void Read() override; + + ObjectGuid Target; + int32 EmoteID = 0; + int32 SoundIndex = 0; + }; + + class STextEmote final : public ServerPacket + { + public: + STextEmote() : ServerPacket(SMSG_TEXT_EMOTE, 21) { } + + WorldPacket const* Write() override; + + ObjectGuid SourceGUID; + std::string Target; + int32 SoundIndex = 0; + int32 EmoteID = 0; + }; + } +} + +#endif // ArchaeologyPackets_h__ diff --git a/src/server/game/Server/Protocol/Opcodes.cpp b/src/server/game/Server/Protocol/Opcodes.cpp index a583f18d7a..333e9f268a 100644 --- a/src/server/game/Server/Protocol/Opcodes.cpp +++ b/src/server/game/Server/Protocol/Opcodes.cpp @@ -610,7 +610,7 @@ void OpcodeTable::Initialize() DEFINE_HANDLER(CMSG_TAXINODE_STATUS_QUERY, STATUS_LOGGEDIN, PROCESS_THREADSAFE, &WorldSession::HandleTaxiNodeStatusQueryOpcode ); DEFINE_HANDLER(CMSG_TAXIQUERYAVAILABLENODES, STATUS_LOGGEDIN, PROCESS_THREADSAFE, &WorldSession::HandleTaxiQueryAvailableNodes ); DEFINE_HANDLER(CMSG_TELEPORT_TO_UNIT, STATUS_UNHANDLED, PROCESS_INPLACE, &WorldSession::Handle_NULL ); - DEFINE_HANDLER(CMSG_TEXT_EMOTE, STATUS_LOGGEDIN, PROCESS_INPLACE, &WorldSession::HandleTextEmoteOpcode ); + DEFINE_HANDLER(CMSG_SEND_TEXT_EMOTE, STATUS_LOGGEDIN, PROCESS_INPLACE, &WorldSession::HandleSendTextEmoteOpcode ); DEFINE_HANDLER(CMSG_TIME_ADJUSTMENT_RESPONSE, STATUS_UNHANDLED, PROCESS_INPLACE, &WorldSession::Handle_NULL ); DEFINE_HANDLER(CMSG_TIME_SYNC_RESP, STATUS_LOGGEDIN, PROCESS_THREADSAFE, &WorldSession::HandleTimeSyncResp ); DEFINE_HANDLER(CMSG_TIME_SYNC_RESP_FAILED, STATUS_UNHANDLED, PROCESS_INPLACE, &WorldSession::Handle_NULL ); diff --git a/src/server/game/Server/Protocol/Opcodes.h b/src/server/game/Server/Protocol/Opcodes.h index 5f861e1d7d..e52ab1ea21 100644 --- a/src/server/game/Server/Protocol/Opcodes.h +++ b/src/server/game/Server/Protocol/Opcodes.h @@ -540,7 +540,7 @@ enum OpcodeClient : uint16 CMSG_TAXIQUERYAVAILABLENODES = 0x6C06, CMSG_TAXISHOWNODES = 0x0000, CMSG_TELEPORT_TO_UNIT = 0x4206, - CMSG_TEXT_EMOTE = 0x2E24, + CMSG_SEND_TEXT_EMOTE = 0x2E24, CMSG_TIME_ADJUSTMENT_RESPONSE = 0x3818, CMSG_TIME_SYNC_RESP = 0x3B0C, CMSG_TIME_SYNC_RESP_FAILED = 0x710A, diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h index 710b65c3b4..e81c0d9f7a 100644 --- a/src/server/game/Server/WorldSession.h +++ b/src/server/game/Server/WorldSession.h @@ -99,6 +99,11 @@ namespace WorldPackets enum class LoginFailureReason : uint8; } + namespace Chat + { + class SendTextEmote; + } + namespace Combat { class AttackSwing; @@ -996,7 +1001,7 @@ class TC_GAME_API WorldSession void SendPlayerAmbiguousNotice(std::string const& name); void SendWrongFactionNotice(); void SendChatRestrictedNotice(ChatRestrictionType restriction); - void HandleTextEmoteOpcode(WorldPacket& recvPacket); + void HandleSendTextEmoteOpcode(WorldPackets::Chat::SendTextEmote& packet); void HandleChatIgnoredOpcode(WorldPacket& recvPacket); void HandleUnregisterAddonPrefixesOpcode(WorldPacket& recvPacket);