TrinityCore
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 "Creature.h"
20#include "Group.h"
21#include "Player.h"
22#include "World.h"
23#include "WorldSession.h"
24
26{
29 switch (GetOpcode())
30 {
37 break;
38 default:
39 break;
40 }
42}
43
45{
46 _worldPacket >> Language;
47 uint32 targetLen = _worldPacket.ReadBits(9);
48 uint32 textLen = _worldPacket.ReadBits(11);
49 Target = _worldPacket.ReadString(targetLen);
50 Text = _worldPacket.ReadString(textLen);
51}
52
54{
55 _worldPacket >> Language;
56 _worldPacket >> ChannelGUID;
57 uint32 targetLen = _worldPacket.ReadBits(9);
58 uint32 textLen = _worldPacket.ReadBits(11);
59 if (_worldPacket.ReadBit())
60 IsSecure = _worldPacket.ReadBit();
61
62 Target = _worldPacket.ReadString(targetLen);
63 Text = _worldPacket.ReadString(textLen);
64}
65
67{
68 uint32 prefixLen = data.ReadBits(5);
69 uint32 textLen = data.ReadBits(8);
70 params.IsLogged = data.ReadBit();
71 params.Type = ChatMsg(data.read<int32>());
72 params.Prefix = data.ReadString(prefixLen);
73 params.Text = data.ReadString(textLen, false);
74
75 return data;
76}
77
79{
80 _worldPacket >> Params;
81}
82
84{
85 uint32 targetLen = _worldPacket.ReadBits(9);
86 _worldPacket.ResetBitPos();
87
88 _worldPacket >> Params;
89 _worldPacket >> *ChannelGUID;
90 Target = _worldPacket.ReadString(targetLen);
91}
92
94{
95 uint32 len = _worldPacket.ReadBits(11);
96 Text = _worldPacket.ReadString(len);
97}
98
100{
101 uint32 len = _worldPacket.ReadBits(11);
102 Text = _worldPacket.ReadString(len);
103}
104
106{
107 uint32 len = _worldPacket.ReadBits(11);
108 Text = _worldPacket.ReadString(len);
109}
110
111WorldPackets::Chat::Chat::Chat(Chat const& chat) : ServerPacket(SMSG_CHAT, chat._worldPacket.size()),
112 SlashCmd(chat.SlashCmd), _Language(chat._Language), SenderGUID(chat.SenderGUID),
113 SenderGuildGUID(chat.SenderGuildGUID), SenderAccountGUID(chat.SenderAccountGUID), TargetGUID(chat.TargetGUID),
114 SenderVirtualAddress(chat.SenderVirtualAddress), TargetVirtualAddress(chat.TargetVirtualAddress), SenderName(chat.SenderName), TargetName(chat.TargetName),
115 Prefix(chat.Prefix), _Channel(chat._Channel), ChatText(chat.ChatText), AchievementID(chat.AchievementID), _ChatFlags(chat._ChatFlags),
116 DisplayTime(chat.DisplayTime), HideChatLog(chat.HideChatLog), FakeSenderName(chat.FakeSenderName)
117{
118}
119
120void WorldPackets::Chat::Chat::Initialize(ChatMsg chatType, Language language, WorldObject const* sender, WorldObject const* receiver, std::string_view message,
121 uint32 achievementId /*= 0*/, std::string_view channelName /*= ""*/, LocaleConstant locale /*= DEFAULT_LOCALE*/, std::string_view addonPrefix /*= ""*/)
122{
123 // Clear everything because same packet can be used multiple times
124 Clear();
125
126 SenderGUID.Clear();
127 SenderAccountGUID.Clear();
128 SenderGuildGUID.Clear();
129 TargetGUID.Clear();
130 SenderName.clear();
131 TargetName.clear();
132 _ChatFlags = CHAT_FLAG_NONE;
133
134 SlashCmd = chatType;
135 _Language = language;
136
137 if (sender)
138 SetSender(sender, locale);
139
140 if (receiver)
141 SetReceiver(receiver, locale);
142
143 SenderVirtualAddress = GetVirtualRealmAddress();
144 TargetVirtualAddress = GetVirtualRealmAddress();
145 AchievementID = achievementId;
146 _Channel = std::move(channelName);
147 Prefix = std::move(addonPrefix);
148 ChatText = message;
149}
150
152{
153 SenderGUID = sender->GetGUID();
154
155 if (Creature const* creatureSender = sender->ToCreature())
156 SenderName = creatureSender->GetNameForLocaleIdx(locale);
157
158 if (Player const* playerSender = sender->ToPlayer())
159 {
160 SenderAccountGUID = playerSender->GetSession()->GetAccountGUID();
161 _ChatFlags = playerSender->GetChatFlags();
162
163 SenderGuildGUID = ObjectGuid::Create<HighGuid::Guild>(playerSender->GetGuildId());
164 }
165}
166
168{
169 TargetGUID = receiver->GetGUID();
170 if (Creature const* creatureReceiver = receiver->ToCreature())
171 TargetName = creatureReceiver->GetNameForLocaleIdx(locale);
172}
173
175{
176 _worldPacket << uint8(SlashCmd);
177 _worldPacket << uint32(_Language);
178 _worldPacket << SenderGUID;
179 _worldPacket << SenderGuildGUID;
180 _worldPacket << SenderAccountGUID;
181 _worldPacket << TargetGUID;
182 _worldPacket << uint32(TargetVirtualAddress);
183 _worldPacket << uint32(SenderVirtualAddress);
184 _worldPacket << int32(AchievementID);
185 _worldPacket << float(DisplayTime);
186 _worldPacket << int32(SpellID);
187 _worldPacket.WriteBits(SenderName.length(), 11);
188 _worldPacket.WriteBits(TargetName.length(), 11);
189 _worldPacket.WriteBits(Prefix.length(), 5);
190 _worldPacket.WriteBits(_Channel.length(), 7);
191 _worldPacket.WriteBits(ChatText.length(), 12);
192 _worldPacket.WriteBits(_ChatFlags, 15);
193 _worldPacket.WriteBit(HideChatLog);
194 _worldPacket.WriteBit(FakeSenderName);
195 _worldPacket.WriteBit(Unused_801.has_value());
196 _worldPacket.WriteBit(ChannelGUID.has_value());
197 _worldPacket.FlushBits();
198
199 _worldPacket.WriteString(SenderName);
200 _worldPacket.WriteString(TargetName);
201 _worldPacket.WriteString(Prefix);
202 _worldPacket.WriteString(_Channel);
203 _worldPacket.WriteString(ChatText);
204
205 if (Unused_801)
206 _worldPacket << uint32(*Unused_801);
207
208 if (ChannelGUID)
209 _worldPacket << *ChannelGUID;
210
211 return &_worldPacket;
212}
213
215{
216 _worldPacket << Guid;
217 _worldPacket << uint32(EmoteID);
218 _worldPacket << uint32(SpellVisualKitIDs.size());
219 _worldPacket << int32(SequenceVariation);
220 if (!SpellVisualKitIDs.empty())
221 _worldPacket.append(SpellVisualKitIDs.data(), SpellVisualKitIDs.size());
222
223 return &_worldPacket;
224}
225
227{
228 _worldPacket >> Target;
229 _worldPacket >> EmoteID;
230 _worldPacket >> SoundIndex;
231 SpellVisualKitIDs.resize(_worldPacket.read<uint32>());
232 _worldPacket >> SequenceVariation;
233 for (int32& spellVisualKitId : SpellVisualKitIDs)
234 _worldPacket >> spellVisualKitId;
235}
236
238{
239 _worldPacket << SourceGUID;
240 _worldPacket << SourceAccountGUID;
241 _worldPacket << EmoteID;
242 _worldPacket << SoundIndex;
243 _worldPacket << TargetGUID;
244
245 return &_worldPacket;
246}
247
249{
250 _worldPacket.WriteBits(NotifyText.size(), 12);
251 _worldPacket.FlushBits();
252
253 _worldPacket.WriteString(NotifyText);
254
255 return &_worldPacket;
256}
257
259{
260 _worldPacket.WriteBits(Name.length(), 9);
261 _worldPacket.FlushBits();
262
263 _worldPacket.WriteString(Name);
264
265 return &_worldPacket;
266}
267
269{
270 _worldPacket << int32(MessageID);
271
272 _worldPacket.WriteBits(StringParam.length(), 11);
273 _worldPacket.FlushBits();
274
275 _worldPacket.WriteString(StringParam);
276
277 return &_worldPacket;
278}
279
281{
282 Prefixes.resize(_worldPacket.read<uint32>());
283 for (std::string& prefix : Prefixes)
284 prefix.assign(_worldPacket.ReadString(_worldPacket.ReadBits(5)));
285}
286
288{
289 _worldPacket << int32(ZoneID);
290 _worldPacket.WriteBits(MessageText.length(), 12);
291 _worldPacket.FlushBits();
292 _worldPacket.WriteString(MessageText);
293
294 return &_worldPacket;
295}
296
298{
299 _worldPacket >> IgnoredGUID;
300 _worldPacket >> Reason;
301}
302
304{
305 _worldPacket.WriteBits(Name.length(), 9);
306 _worldPacket.WriteString(Name);
307
308 return &_worldPacket;
309}
310
312{
313 _worldPacket << int32(Reason);
314
315 return &_worldPacket;
316}
317
319{
320 _worldPacket >> WhisperTarget;
321}
322
324{
325 _worldPacket << WhisperTarget;
326 _worldPacket << int32(Status);
327
328 return &_worldPacket;
329}
330
332{
333 ChatDisabled = _worldPacket.ReadBit();
334}
335
337{
338 _worldPacket.WriteBit(Success);
339 _worldPacket.WriteBit(ChatDisabled);
340 _worldPacket.FlushBits();
341
342 return &_worldPacket;
343}
ByteBuffer & operator>>(ByteBuffer &data, WorldPackets::Chat::ChatAddonMessageParams &params)
Definition: ChatPackets.cpp:66
LocaleConstant
Definition: Common.h:48
uint8_t uint8
Definition: Define.h:144
int32_t int32
Definition: Define.h:138
uint32_t uint32
Definition: Define.h:142
std::unordered_set< uint32 > params[2]
Definition: DisableMgr.cpp:50
Language
@ CHAT_FLAG_NONE
ChatMsg
uint32 ReadBits(int32 bits)
Definition: ByteBuffer.h:209
bool WriteBit(bool bit)
Definition: ByteBuffer.h:175
void WriteBits(std::size_t value, int32 bits)
Definition: ByteBuffer.h:203
std::string ReadString(uint32 length, bool requireValidUtf8=true)
Definition: ByteBuffer.cpp:78
bool ReadBit()
Definition: ByteBuffer.h:191
static Creature * ToCreature(Object *o)
Definition: Object.h:219
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:159
static Player * ToPlayer(Object *o)
Definition: Object.h:213
WorldPacket const * Write() override
WorldPacket const * Write() override
WorldPacket const * Write() override
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 const * Write() override
WorldPacket const * Write() override
WorldPacket const * Write() override
OpcodeClient GetOpcode() const
Definition: Packet.h:68
WorldPacket _worldPacket
Definition: Packet.h:43
@ CMSG_CHAT_MESSAGE_INSTANCE_CHAT
Definition: Opcodes.h:222
@ CMSG_CHAT_MESSAGE_RAID_WARNING
Definition: Opcodes.h:226
@ CMSG_CHAT_MESSAGE_SAY
Definition: Opcodes.h:227
@ CMSG_CHAT_MESSAGE_RAID
Definition: Opcodes.h:225
@ CMSG_CHAT_MESSAGE_PARTY
Definition: Opcodes.h:224
@ SMSG_CHAT
Definition: Opcodes.h:1106
uint32 GetVirtualRealmAddress()
Definition: World.cpp:3968
constexpr std::size_t size()
Definition: UpdateField.h:796
const Emote EmoteID[6]