]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_ircv3_echomessage.cpp
702552ea7c62a05bab7c732afbab1885c475fc6f
[user/henk/code/inspircd.git] / src / modules / m_ircv3_echomessage.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2015 Attila Molnar <attilamolnar@hush.com>
5  *   Copyright (C) 2013-2015 Peter Powell <petpow@saberuk.com>
6  *
7  * This file is part of InspIRCd.  InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21 #include "inspircd.h"
22 #include "modules/cap.h"
23
24 class ModuleIRCv3EchoMessage : public Module
25 {
26         Cap::Capability cap;
27
28  public:
29         ModuleIRCv3EchoMessage()
30                 : cap(this, "echo-message")
31         {
32         }
33
34         void OnUserPostMessage(User* user, const MessageTarget& target, const MessageDetails& details) CXX11_OVERRIDE
35         {
36                 if (!cap.get(user))
37                         return;
38
39                 // Caps are only set on local users
40                 LocalUser* const localuser = static_cast<LocalUser*>(user);
41
42                 const std::string& text = details.echooriginal ? details.originaltext : details.text;
43                 if (target.type == MessageTarget::TYPE_USER)
44                 {
45                         User* destuser = target.Get<User>();
46                         ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, destuser, text, details.type);
47                         privmsg.AddTags(details.tags_in);
48                         localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg);
49                 }
50                 else if (target.type == MessageTarget::TYPE_CHANNEL)
51                 {
52                         Channel* chan = target.Get<Channel>();
53                         ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, chan, text, details.type, target.status);
54                         privmsg.AddTags(details.tags_in);
55                         localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg);
56                 }
57                 else
58                 {
59                         const std::string* servername = target.Get<std::string>();
60                         ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, *servername, text, details.type);
61                         privmsg.AddTags(details.tags_in);
62                         localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg);
63                 }
64         }
65
66         void OnUserMessageBlocked(User* user, const MessageTarget& target, const MessageDetails& details) CXX11_OVERRIDE
67         {
68                 // Prevent spammers from knowing that their spam was blocked.
69                 if (details.echooriginal)
70                         OnUserPostMessage(user, target, details);
71         }
72
73         Version GetVersion() CXX11_OVERRIDE
74         {
75                 return Version("Provides the echo-message IRCv3.2 extension", VF_VENDOR);
76         }
77 };
78
79 MODULE_INIT(ModuleIRCv3EchoMessage)