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