]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chanlog.cpp
Add a typedef for the data provider map.
[user/henk/code/inspircd.git] / src / modules / m_chanlog.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2018 linuxdaemon <linuxdaemon.irc@gmail.com>
5  *   Copyright (C) 2013, 2018 Sadie Powell <sadie@witchery.services>
6  *   Copyright (C) 2012-2014, 2018 Attila Molnar <attilamolnar@hush.com>
7  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
8  *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
9  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
10  *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
11  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
12  *
13  * This file is part of InspIRCd.  InspIRCd is free software: you can
14  * redistribute it and/or modify it under the terms of the GNU General Public
15  * License as published by the Free Software Foundation, version 2.
16  *
17  * This program is distributed in the hope that it will be useful, but WITHOUT
18  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
20  * details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24  */
25
26
27 #include "inspircd.h"
28
29 class ModuleChanLog : public Module
30 {
31         /*
32          * Multimap so people can redirect a snomask to multiple channels.
33          */
34         typedef insp::flat_multimap<char, std::string> ChanLogTargets;
35         ChanLogTargets logstreams;
36
37  public:
38         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
39         {
40                 std::string snomasks;
41                 std::string channel;
42                 ChanLogTargets newlogs;
43
44                 ConfigTagList tags = ServerInstance->Config->ConfTags("chanlog");
45                 for (ConfigIter i = tags.first; i != tags.second; ++i)
46                 {
47                         channel = i->second->getString("channel");
48                         snomasks = i->second->getString("snomasks");
49
50                         if (channel.empty() || snomasks.empty())
51                         {
52                                 throw ModuleException("Malformed chanlog tag at " + i->second->getTagLocation());
53                         }
54
55                         for (std::string::const_iterator it = snomasks.begin(); it != snomasks.end(); it++)
56                         {
57                                 newlogs.insert(std::make_pair(*it, channel));
58                                 ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Logging %c to %s", *it, channel.c_str());
59                         }
60                 }
61                 logstreams.swap(newlogs);
62
63         }
64
65         ModResult OnSendSnotice(char &sno, std::string &desc, const std::string &msg) CXX11_OVERRIDE
66         {
67                 std::pair<ChanLogTargets::const_iterator, ChanLogTargets::const_iterator> itpair = logstreams.equal_range(sno);
68                 if (itpair.first == itpair.second)
69                         return MOD_RES_PASSTHRU;
70
71                 const std::string snotice = "\002" + desc + "\002: " + msg;
72
73                 for (ChanLogTargets::const_iterator it = itpair.first; it != itpair.second; ++it)
74                 {
75                         Channel *c = ServerInstance->FindChan(it->second);
76                         if (c)
77                         {
78                                 ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, ServerInstance->Config->ServerName, c, snotice);
79                                 c->Write(ServerInstance->GetRFCEvents().privmsg, privmsg);
80                                 ServerInstance->PI->SendMessage(c, 0, snotice);
81                         }
82                 }
83
84                 return MOD_RES_PASSTHRU;
85         }
86
87         Version GetVersion() CXX11_OVERRIDE
88         {
89                 return Version("Allows messages sent to snomasks to be logged to a channel.", VF_VENDOR);
90         }
91 };
92
93 MODULE_INIT(ModuleChanLog)