aboutsummaryrefslogtreecommitdiff
path: root/src/server/scripts/World/chat_log.cpp
blob: 74178d7333f9debaec44769f2b9c52d635845128 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 * 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 <http://www.gnu.org/licenses/>.
 */

#include "ScriptMgr.h"
#include "Channel.h"
#include "Group.h"
#include "Guild.h"
#include "Log.h"
#include "Player.h"

#define TC_LOG_CHAT(TYPE, MESSAGE, ...)                           \
    if (lang != LANG_ADDON && lang != LANG_ADDON_LOGGED)          \
        TC_LOG_DEBUG("chat.log." TYPE, MESSAGE, __VA_ARGS__);     \
    else                                                          \
        TC_LOG_DEBUG("chat.log.addon." TYPE, MESSAGE, __VA_ARGS__);

class ChatLogScript : public PlayerScript
{
    public:
        ChatLogScript() : PlayerScript("ChatLogScript") { }

        void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg) override
        {
            switch (type)
            {
                case CHAT_MSG_SAY:
                    TC_LOG_CHAT("say", "Player {} says (language {}): {}",
                        player->GetName(), lang, msg);
                    break;

                case CHAT_MSG_EMOTE:
                    TC_LOG_CHAT("emote", "Player {} emotes: {}",
                        player->GetName(), msg);
                    break;

                case CHAT_MSG_YELL:
                    TC_LOG_CHAT("yell", "Player {} yells (language {}): {}",
                        player->GetName(), lang, msg);
                    break;
            }
        }

        void OnChat(Player* player, uint32 /*type*/, uint32 lang, std::string& msg, Player* receiver) override
        {
            TC_LOG_CHAT("whisper", "Player {} tells {}: {}",
               player->GetName(), receiver ? receiver->GetName().c_str() : "<unknown>", msg);
        }

        void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Group* group) override
        {
            //! NOTE:
            //! LANG_ADDON can only be sent by client in "PARTY", "RAID", "GUILD", "BATTLEGROUND", "WHISPER"
            switch (type)
            {
                case CHAT_MSG_PARTY:
                    TC_LOG_CHAT("party", "Player {} tells group with leader {}: {}",
                        player->GetName(), group ? group->GetLeaderName() : "<unknown>", msg);
                    break;

                case CHAT_MSG_PARTY_LEADER:
                    TC_LOG_CHAT("party", "Leader {} tells group: {}",
                        player->GetName(), msg);
                    break;

                case CHAT_MSG_RAID:
                    TC_LOG_CHAT("raid", "Player {} tells raid with leader {}: {}",
                        player->GetName(), group ? group->GetLeaderName() : "<unknown>", msg);
                    break;

                case CHAT_MSG_RAID_LEADER:
                    TC_LOG_CHAT("raid", "Leader player {} tells raid: {}",
                        player->GetName(), msg);
                    break;

                case CHAT_MSG_RAID_WARNING:
                    TC_LOG_CHAT("raid", "Leader player {} warns raid with: {}",
                        player->GetName(), msg);
                    break;

                case CHAT_MSG_INSTANCE_CHAT:
                    TC_LOG_CHAT("bg", "Player {} tells instance with leader {}: {}",
                        player->GetName(), group ? group->GetLeaderName() : "<unknown>", msg);
                    break;

                case CHAT_MSG_INSTANCE_CHAT_LEADER:
                    TC_LOG_CHAT("bg", "Leader player {} tells instance: {}",
                        player->GetName(), msg);
                    break;
            }
        }

        void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Guild* guild) override
        {
            switch (type)
            {
                case CHAT_MSG_GUILD:
                    TC_LOG_CHAT("guild", "Player {} tells guild {}: {}",
                        player->GetName(), guild ? guild->GetName().c_str() : "<unknown>", msg);
                    break;

                case CHAT_MSG_OFFICER:
                    TC_LOG_CHAT("guild.officer", "Player {} tells guild {} officers: {}",
                        player->GetName(), guild ? guild->GetName().c_str() : "<unknown>", msg);
                    break;
            }
        }

        void OnChat(Player* player, uint32 /*type*/, uint32 lang, std::string& msg, Channel* channel) override
        {
            bool isSystem = channel &&
                            (channel->HasFlag(CHANNEL_FLAG_TRADE) ||
                             channel->HasFlag(CHANNEL_FLAG_GENERAL) ||
                             channel->HasFlag(CHANNEL_FLAG_CITY) ||
                             channel->HasFlag(CHANNEL_FLAG_LFG));

            if (isSystem)
            {
                TC_LOG_CHAT("system", "Player {} tells channel {}: {}",
                    player->GetName(), channel->GetName(), msg);
            }
            else
            {
                std::string channelName = channel ? channel->GetName() : "<unknown>";
                TC_LOG_CHAT("channel." + channelName, "Player {} tells channel {}: {}",
                    player->GetName(), channelName, msg);
            }
        }
};

void AddSC_chat_log()
{
    new ChatLogScript();
}

#undef TC_LOG_CHAT