]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chanlog.cpp
a62fbf9b2084381acc8457e6eec22d0fc6b2c4d9
[user/henk/code/inspircd.git] / src / modules / m_chanlog.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
5  *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
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
23 class ModuleChanLog : public Module
24 {
25         /*
26          * Multimap so people can redirect a snomask to multiple channels.
27          */
28         typedef std::multimap<char, std::string> ChanLogTargets;
29         ChanLogTargets logstreams;
30
31  public:
32         void init() CXX11_OVERRIDE
33         {
34                 OnRehash(NULL);
35         }
36
37         void OnRehash(User *user) CXX11_OVERRIDE
38         {
39                 std::string snomasks;
40                 std::string channel;
41
42                 logstreams.clear();
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                                 ServerInstance->Logs->Log("CONFIG", LOG_DEFAULT, "Malformed chanlog tag, ignoring");
53                                 continue;
54                         }
55
56                         for (std::string::const_iterator it = snomasks.begin(); it != snomasks.end(); it++)
57                         {
58                                 logstreams.insert(std::make_pair(*it, channel));
59                                 ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Logging %c to %s", *it, channel.c_str());
60                         }
61                 }
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 = "\2" + desc + "\2: " + 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                                 c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name.c_str(), snotice.c_str());
79                                 ServerInstance->PI->SendChannelPrivmsg(c, 0, snotice);
80                         }
81                 }
82
83                 return MOD_RES_PASSTHRU;
84         }
85
86         Version GetVersion() CXX11_OVERRIDE
87         {
88                 return Version("Logs snomask output to channel(s).", VF_VENDOR);
89         }
90 };
91
92 MODULE_INIT(ModuleChanLog)