TrinityCore
chat_log.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 "ScriptMgr.h"
19#include "Channel.h"
20#include "Group.h"
21#include "Guild.h"
22#include "Log.h"
23#include "Player.h"
24
25#define TC_LOG_CHAT(TYPE, ...) \
26 if (lang != LANG_ADDON && lang != LANG_ADDON_LOGGED) \
27 TC_LOG_DEBUG("chat.log." TYPE, __VA_ARGS__); \
28 else \
29 TC_LOG_DEBUG("chat.log.addon." TYPE, __VA_ARGS__);
30
32{
33 public:
34 ChatLogScript() : PlayerScript("ChatLogScript") { }
35
36 void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg) override
37 {
38 switch (type)
39 {
40 case CHAT_MSG_SAY:
41 TC_LOG_CHAT("say", "Player {} says (language {}): {}",
42 player->GetName(), lang, msg);
43 break;
44
45 case CHAT_MSG_EMOTE:
46 TC_LOG_CHAT("emote", "Player {} emotes: {}",
47 player->GetName(), msg);
48 break;
49
50 case CHAT_MSG_YELL:
51 TC_LOG_CHAT("yell", "Player {} yells (language {}): {}",
52 player->GetName(), lang, msg);
53 break;
54 }
55 }
56
57 void OnChat(Player* player, uint32 /*type*/, uint32 lang, std::string& msg, Player* receiver) override
58 {
59 TC_LOG_CHAT("whisper", "Player {} tells {}: {}",
60 player->GetName(), receiver ? receiver->GetName().c_str() : "<unknown>", msg);
61 }
62
63 void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Group* group) override
64 {
67 switch (type)
68 {
69 case CHAT_MSG_PARTY:
70 TC_LOG_CHAT("party", "Player {} tells group with leader {}: {}",
71 player->GetName(), group ? group->GetLeaderName() : "<unknown>", msg);
72 break;
73
75 TC_LOG_CHAT("party", "Leader {} tells group: {}",
76 player->GetName(), msg);
77 break;
78
79 case CHAT_MSG_RAID:
80 TC_LOG_CHAT("raid", "Player {} tells raid with leader {}: {}",
81 player->GetName(), group ? group->GetLeaderName() : "<unknown>", msg);
82 break;
83
85 TC_LOG_CHAT("raid", "Leader player {} tells raid: {}",
86 player->GetName(), msg);
87 break;
88
90 TC_LOG_CHAT("raid", "Leader player {} warns raid with: {}",
91 player->GetName(), msg);
92 break;
93
95 TC_LOG_CHAT("bg", "Player {} tells instance with leader {}: {}",
96 player->GetName(), group ? group->GetLeaderName() : "<unknown>", msg);
97 break;
98
100 TC_LOG_CHAT("bg", "Leader player {} tells instance: {}",
101 player->GetName(), msg);
102 break;
103 }
104 }
105
106 void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Guild* guild) override
107 {
108 switch (type)
109 {
110 case CHAT_MSG_GUILD:
111 TC_LOG_CHAT("guild", "Player {} tells guild {}: {}",
112 player->GetName(), guild ? guild->GetName().c_str() : "<unknown>", msg);
113 break;
114
115 case CHAT_MSG_OFFICER:
116 TC_LOG_CHAT("guild.officer", "Player {} tells guild {} officers: {}",
117 player->GetName(), guild ? guild->GetName().c_str() : "<unknown>", msg);
118 break;
119 }
120 }
121
122 void OnChat(Player* player, uint32 /*type*/, uint32 lang, std::string& msg, Channel* channel) override
123 {
124 bool isSystem = channel &&
125 (channel->HasFlag(CHANNEL_FLAG_TRADE) ||
126 channel->HasFlag(CHANNEL_FLAG_GENERAL) ||
127 channel->HasFlag(CHANNEL_FLAG_CITY) ||
128 channel->HasFlag(CHANNEL_FLAG_LFG));
129
130 if (isSystem)
131 {
132 TC_LOG_CHAT("system", "Player {} tells channel {}: {}",
133 player->GetName(), channel->GetName(), msg);
134 }
135 else
136 {
137 std::string channelName = channel ? channel->GetName() : "<unknown>";
138 TC_LOG_CHAT("channel." + channelName, "Player {} tells channel {}: {}",
139 player->GetName(), channelName, msg);
140 }
141 }
142};
143
145{
146 new ChatLogScript();
147}
148
149#undef TC_LOG_CHAT
@ CHANNEL_FLAG_TRADE
Definition: Channel.h:88
@ CHANNEL_FLAG_GENERAL
Definition: Channel.h:90
@ CHANNEL_FLAG_LFG
Definition: Channel.h:92
@ CHANNEL_FLAG_CITY
Definition: Channel.h:91
uint32_t uint32
Definition: Define.h:142
@ CHAT_MSG_RAID_WARNING
@ CHAT_MSG_RAID
@ CHAT_MSG_SAY
@ CHAT_MSG_INSTANCE_CHAT_LEADER
@ CHAT_MSG_PARTY_LEADER
@ CHAT_MSG_RAID_LEADER
@ CHAT_MSG_INSTANCE_CHAT
@ CHAT_MSG_YELL
@ CHAT_MSG_PARTY
@ CHAT_MSG_EMOTE
@ CHAT_MSG_GUILD
@ CHAT_MSG_OFFICER
#define TC_LOG_CHAT(TYPE,...)
Definition: chat_log.cpp:25
void AddSC_chat_log()
Definition: chat_log.cpp:144
std::string GetName(LocaleConstant locale=DEFAULT_LOCALE) const
Definition: Channel.cpp:114
bool HasFlag(uint8 flag) const
Definition: Channel.h:186
void OnChat(Player *player, uint32 type, uint32 lang, std::string &msg) override
Definition: chat_log.cpp:36
void OnChat(Player *player, uint32 type, uint32 lang, std::string &msg, Guild *guild) override
Definition: chat_log.cpp:106
void OnChat(Player *player, uint32, uint32 lang, std::string &msg, Player *receiver) override
Definition: chat_log.cpp:57
void OnChat(Player *player, uint32 type, uint32 lang, std::string &msg, Group *group) override
Definition: chat_log.cpp:63
void OnChat(Player *player, uint32, uint32 lang, std::string &msg, Channel *channel) override
Definition: chat_log.cpp:122
Definition: Group.h:197
const char * GetLeaderName() const
Definition: Group.cpp:1668
Definition: Guild.h:329
std::string const & GetName() const
Definition: Guild.h:755
std::string const & GetName() const
Definition: Object.h:555