]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_ircv3_echomessage.cpp
Fix erasing event subscribers erasing all with the same priority.
[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) || !details.echo)
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.echo_original ? details.original_text : details.text;
43                 const ClientProtocol::TagMap& tags = details.echo_original ? details.tags_in : details.tags_out;
44                 if (target.type == MessageTarget::TYPE_USER)
45                 {
46                         User* destuser = target.Get<User>();
47                         ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, destuser, text, details.type);
48                         privmsg.AddTags(tags);
49                         localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg);
50                 }
51                 else if (target.type == MessageTarget::TYPE_CHANNEL)
52                 {
53                         Channel* chan = target.Get<Channel>();
54                         ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, chan, text, details.type, target.status);
55                         privmsg.AddTags(tags);
56                         localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg);
57                 }
58                 else
59                 {
60                         const std::string* servername = target.Get<std::string>();
61                         ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, *servername, text, details.type);
62                         privmsg.AddTags(tags);
63                         localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg);
64                 }
65         }
66
67         void OnUserMessageBlocked(User* user, const MessageTarget& target, const MessageDetails& details) CXX11_OVERRIDE
68         {
69                 // Prevent spammers from knowing that their spam was blocked.
70                 if (details.echo_original)
71                         OnUserPostMessage(user, target, details);
72         }
73
74         Version GetVersion() CXX11_OVERRIDE
75         {
76                 return Version("Provides the echo-message IRCv3 extension", VF_VENDOR);
77         }
78 };
79
80 MODULE_INIT(ModuleIRCv3EchoMessage)