TrinityCore
ChatTextBuilder.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 "ChatTextBuilder.h"
19#include "CreatureTextMgr.h"
20#include "DB2Stores.h"
21#include "LanguageMgr.h"
22#include "ObjectMgr.h"
23#include "Player.h"
24#include "WorldSession.h"
25#include <cstdarg>
26
27namespace Trinity
28{
29ChatPacketSender::ChatPacketSender(ChatMsg chatType, ::Language language, WorldObject const* sender, WorldObject const* receiver,
30 std::string message, uint32 achievementId /*= 0*/, LocaleConstant locale /*= LOCALE_enUS*/)
31 : Type(chatType), Language(language), Sender(sender), Receiver(receiver), Text(std::move(message)), AchievementId(achievementId), Locale(locale)
32{
35}
36
37void ChatPacketSender::operator()(Player const* player) const
38{
40 {
42 return;
43 }
44
46 {
47 TranslatedPacket.emplace();
50 TranslatedPacket->Write();
51 }
52
53 player->SendDirectMessage(TranslatedPacket->GetRawPacket());
54}
55
57{
58 BroadcastTextEntry const* bct = sBroadcastTextStore.LookupEntry(_textId);
60}
61
63{
64 return new ChatPacketSender(_msgType, _language, _source, _target, _text, 0, locale);
65}
66
68{
69 char const* text = sObjectMgr->GetTrinityString(_textId, locale);
70
71 if (_args)
72 {
73 // we need copy va_list before use or original va_list will corrupted
74 va_list ap;
75 va_copy(ap, *_args);
76
77 static size_t const BufferSize = 2048;
78 char strBuffer[BufferSize];
79 vsnprintf(strBuffer, BufferSize, text, ap);
80 va_end(ap);
81
82 return new ChatPacketSender(_msgType, LANG_UNIVERSAL, _source, _target, strBuffer, 0, locale);
83 }
84
85 return new ChatPacketSender(_msgType, LANG_UNIVERSAL, _source, _target, text, 0, locale);
86}
87
89{
90 return new ChatPacketSender(_msgType, _language, _talker, _target, sCreatureTextMgr->GetLocalizedChatString(_source->GetEntry(), _gender, _textGroup, _textId, locale), 0, locale);
91}
92}
LocaleConstant
Definition: Common.h:48
#define sCreatureTextMgr
DB2Storage< BroadcastTextEntry > sBroadcastTextStore("BroadcastText.db2", &BroadcastTextLoadInfo::Instance)
uint32_t uint32
Definition: Define.h:142
#define sLanguageMgr
Definition: LanguageMgr.h:97
#define sObjectMgr
Definition: ObjectMgr.h:1946
Language
@ LANG_ADDON_LOGGED
@ LANG_UNIVERSAL
@ LANG_ADDON
ChatMsg
static char const * GetBroadcastTextValue(BroadcastTextEntry const *broadcastText, LocaleConstant locale=DEFAULT_LOCALE, uint8 gender=GENDER_MALE, bool forceGender=false)
Definition: DB2Stores.cpp:2008
uint32 GetEntry() const
Definition: Object.h:161
void SendDirectMessage(WorldPacket const *data) const
Definition: Player.cpp:6324
WorldSession * GetSession() const
Definition: Player.h:2101
bool CanUnderstandLanguage(Language language) const
Definition: Player.cpp:21841
WorldObject const * _source
WorldObject const * _target
ChatPacketSender * operator()(LocaleConstant locale) const
ChatPacketSender(ChatMsg chatType, ::Language language, WorldObject const *sender, WorldObject const *receiver, std::string message, uint32 achievementId=0, LocaleConstant locale=LOCALE_enUS)
WorldPackets::Chat::Chat UntranslatedPacket
WorldObject const * Sender
WorldObject const * Receiver
Optional< WorldPackets::Chat::Chat > TranslatedPacket
void operator()(Player const *player) const
ChatPacketSender * operator()(LocaleConstant locale) const
ChatPacketSender * operator()(LocaleConstant locale) const
ChatPacketSender * operator()(LocaleConstant locale) const
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
WorldPacket const * GetRawPacket() const
Definition: Packet.h:38
LocaleConstant GetSessionDbcLocale() const
STL namespace.