TrinityCore
Loading...
Searching...
No Matches
ChatPackets.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "ChatPackets.h"
19#include "Player.h"
20#include "RBAC.h"
21#include "WorldSession.h"
22
24{
25 SlashCmd = static_cast<ChatMsg>(_worldPacket.read<int32>());
26 Language = static_cast<::Language>(_worldPacket.read<int32>());
27
28 switch (SlashCmd)
29 {
30 case CHAT_MSG_SAY:
31 case CHAT_MSG_EMOTE:
32 case CHAT_MSG_YELL:
33 case CHAT_MSG_PARTY:
35 case CHAT_MSG_GUILD:
37 case CHAT_MSG_RAID:
42 case CHAT_MSG_AFK:
43 case CHAT_MSG_DND:
45 break;
50 break;
51 default:
52 break;
53 }
54}
55
56WorldPackets::Chat::Chat::Chat(Chat const& chat) : ServerPacket(chat.GetOpcode(), chat._worldPacket.size()),
57 SlashCmd(chat.SlashCmd), _Language(chat._Language), SenderGUID(chat.SenderGUID), TargetGUID(chat.TargetGUID),
58 SenderName(chat.SenderName), TargetName(chat.TargetName),
59 _Channel(chat._Channel), ChatText(chat.ChatText), AchievementID(chat.AchievementID), ChatTag(chat.ChatTag)
60{
61}
62
63void WorldPackets::Chat::Chat::Initialize(ChatMsg chatType, Language language, WorldObject const* sender, WorldObject const* receiver, std::string_view message,
64 uint32 achievementId /*= 0*/, std::string_view channelName /*= ""*/, LocaleConstant locale /*= DEFAULT_LOCALE*/, std::string_view addonPrefix /*= ""*/)
65{
66 // Clear everything because same packet can be used multiple times
67 Clear();
68 _worldPacket.SetOpcode(SMSG_MESSAGECHAT);
69
70 SenderGUID.Clear();
71 TargetGUID.Clear();
72 SenderName.clear();
73 TargetName.clear();
74 ChatTag = CHAT_TAG_NONE;
75
76 SlashCmd = chatType;
77 _Language = language;
78
79 if (sender)
80 SetSender(sender, locale);
81
82 if (receiver)
83 SetReceiver(receiver, locale);
84
85 AchievementID = achievementId;
86 _Channel = channelName;
87 ChatText = message;
88 if (!addonPrefix.empty())
89 {
90 // addon prefix is not really a separate thing in 3.3.5
91 // it can be either passed as part of the message directly (from client packet)
92 // or separately in addonPrefix argument (server initiated send) to minimize API difference between 3.3.5 and master branch
93 ChatText.insert(0, 1, '\t').insert(0, addonPrefix);
94 }
95}
96
98{
99 SenderGUID = sender->GetGUID();
100 SenderName = sender->GetNameForLocaleIdx(locale);
101
102 if (Player const* playerSender = sender->ToPlayer())
103 {
104 ChatTag = playerSender->GetChatTag();
105 if (playerSender->GetSession()->HasPermission(rbac::RBAC_PERM_COMMAND_GM_CHAT))
106 _worldPacket.SetOpcode(SMSG_GM_MESSAGECHAT);
107 }
108}
109
111{
112 TargetGUID = receiver->GetGUID();
113 TargetName = receiver->GetNameForLocaleIdx(locale);
114}
115
117{
118 _worldPacket << uint8(SlashCmd);
119 _worldPacket << int32(_Language);
120 _worldPacket << SenderGUID;
121 _worldPacket << uint32(0); // some flags
122 switch (SlashCmd)
123 {
132 _worldPacket << uint32(SenderName.length() + 1);
133 _worldPacket << SenderName;
134 TargetGUIDPos = _worldPacket.wpos();
135 _worldPacket << TargetGUID;
136 if (!TargetGUID.IsEmpty() && !TargetGUID.IsPlayer() && !TargetGUID.IsPet())
137 {
138 _worldPacket << uint32(TargetName.length() + 1);
139 _worldPacket << TargetName;
140 }
141 break;
143 _worldPacket << uint32(SenderName.length() + 1);
144 _worldPacket << SenderName;
145 TargetGUIDPos = _worldPacket.wpos();
146 _worldPacket << TargetGUID;
147 break;
151 TargetGUIDPos = _worldPacket.wpos();
152 _worldPacket << TargetGUID;
153 if (!TargetGUID.IsEmpty() && !TargetGUID.IsPlayer())
154 {
155 _worldPacket << uint32(TargetName.length() + 1);
156 _worldPacket << TargetName;
157 }
158 break;
161 TargetGUIDPos = _worldPacket.wpos();
162 _worldPacket << TargetGUID;
163 break;
164 default:
165 if (GetOpcode() == SMSG_GM_MESSAGECHAT)
166 {
167 _worldPacket << uint32(SenderName.length() + 1);
168 _worldPacket << SenderName;
169 }
170
171 if (SlashCmd == CHAT_MSG_CHANNEL)
172 {
173 ASSERT(!_Channel.empty());
174 _worldPacket << _Channel;
175 }
176
177 TargetGUIDPos = _worldPacket.wpos();
178 _worldPacket << TargetGUID;
179 break;
180 }
181
182 _worldPacket << uint32(ChatText.length() + 1);
183 _worldPacket << ChatText;
184 _worldPacket << uint8(ChatTag);
185
186 if (SlashCmd == CHAT_MSG_ACHIEVEMENT || SlashCmd == CHAT_MSG_GUILD_ACHIEVEMENT)
187 _worldPacket << uint32(AchievementID);
188
189 return &_worldPacket;
190}
191
193{
194 _worldPacket << EmoteID;
195 _worldPacket << Guid;
196
197 return &_worldPacket;
198}
199
201{
202 _worldPacket >> EmoteID;
203}
204
206{
207 _worldPacket << int32(MessageID);
208 _worldPacket << StringParam;
209
210 return &_worldPacket;
211}
212
214{
215 _worldPacket >> EmoteID;
216 _worldPacket >> SoundIndex;
217 _worldPacket >> Target;
218}
219
221{
222 _worldPacket << SourceGUID;
223 _worldPacket << int32(EmoteID);
224 _worldPacket << int32(SoundIndex);
225 _worldPacket << uint32(TargetName.size() + 1 /*size in bytes, not string length*/);
226 _worldPacket << TargetName;
227
228 return &_worldPacket;
229}
LocaleConstant
Definition Common.h:48
uint8_t uint8
Definition Define.h:135
int32_t int32
Definition Define.h:129
uint32_t uint32
Definition Define.h:133
#define ASSERT
Definition Errors.h:68
Role Based Access Control related classes definition.
Language
@ LANG_ADDON
ChatMsg
@ CHAT_MSG_RAID_WARNING
@ CHAT_MSG_RAID
@ CHAT_MSG_MONSTER_WHISPER
@ CHAT_MSG_SAY
@ CHAT_MSG_RAID_BOSS_WHISPER
@ CHAT_MSG_WHISPER_FOREIGN
@ CHAT_MSG_GUILD_ACHIEVEMENT
@ CHAT_MSG_BG_SYSTEM_ALLIANCE
@ CHAT_MSG_PARTY_LEADER
@ CHAT_MSG_RAID_LEADER
@ CHAT_MSG_DND
@ CHAT_MSG_YELL
@ CHAT_MSG_PARTY
@ CHAT_MSG_WHISPER
@ CHAT_MSG_EMOTE
@ CHAT_MSG_GUILD
@ CHAT_MSG_MONSTER_PARTY
@ CHAT_MSG_OFFICER
@ CHAT_MSG_ACHIEVEMENT
@ CHAT_MSG_RAID_BOSS_EMOTE
@ CHAT_MSG_BATTLENET
@ CHAT_MSG_MONSTER_EMOTE
@ CHAT_MSG_AFK
@ CHAT_MSG_BATTLEGROUND
@ CHAT_MSG_BATTLEGROUND_LEADER
@ CHAT_MSG_MONSTER_SAY
@ CHAT_MSG_MONSTER_YELL
@ CHAT_MSG_BG_SYSTEM_HORDE
@ CHAT_MSG_BG_SYSTEM_NEUTRAL
@ CHAT_MSG_CHANNEL
@ CHAT_TAG_NONE
std::string ReadCString(bool requireValidUtf8=true)
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:78
static Player * ToPlayer(Object *o)
Definition Object.h:183
std::string const & GetNameForLocaleIdx(LocaleConstant) const override
Definition Object.h:387
std::string Target
Whisper target or channel name.
Definition ChatPackets.h:42
WorldPacket const * Write() override
void Initialize(ChatMsg chatType, Language language, WorldObject const *sender, WorldObject const *receiver, std::string_view message, uint32 achievementId=0, std::string_view channelName="", LocaleConstant locale=DEFAULT_LOCALE, std::string_view addonPrefix="")
WorldPacket const * Write() override
void SetReceiver(WorldObject const *receiver, LocaleConstant locale)
void SetSender(WorldObject const *sender, LocaleConstant locale)
WorldPacket const * Write() override
WorldPacket const * Write() override
WorldPacket _worldPacket
Definition Packet.h:42
@ SMSG_GM_MESSAGECHAT
Definition Opcodes.h:976
@ SMSG_MESSAGECHAT
Definition Opcodes.h:179
@ RBAC_PERM_COMMAND_GM_CHAT
Definition RBAC.h:246