2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
5 * Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
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.
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
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/>.
23 class ModuleChanLog : public Module
26 * Multimap so people can redirect a snomask to multiple channels.
28 typedef insp::flat_multimap<char, std::string> ChanLogTargets;
29 ChanLogTargets logstreams;
32 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
36 ChanLogTargets newlogs;
38 ConfigTagList tags = ServerInstance->Config->ConfTags("chanlog");
39 for (ConfigIter i = tags.first; i != tags.second; ++i)
41 channel = i->second->getString("channel");
42 snomasks = i->second->getString("snomasks");
44 if (channel.empty() || snomasks.empty())
46 throw ModuleException("Malformed chanlog tag at " + i->second->getTagLocation());
49 for (std::string::const_iterator it = snomasks.begin(); it != snomasks.end(); it++)
51 newlogs.insert(std::make_pair(*it, channel));
52 ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Logging %c to %s", *it, channel.c_str());
55 logstreams.swap(newlogs);
59 ModResult OnSendSnotice(char &sno, std::string &desc, const std::string &msg) CXX11_OVERRIDE
61 std::pair<ChanLogTargets::const_iterator, ChanLogTargets::const_iterator> itpair = logstreams.equal_range(sno);
62 if (itpair.first == itpair.second)
63 return MOD_RES_PASSTHRU;
65 const std::string snotice = "\002" + desc + "\002: " + msg;
67 for (ChanLogTargets::const_iterator it = itpair.first; it != itpair.second; ++it)
69 Channel *c = ServerInstance->FindChan(it->second);
72 ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, ServerInstance->Config->ServerName, c, snotice);
73 c->Write(ServerInstance->GetRFCEvents().privmsg, privmsg);
74 ServerInstance->PI->SendMessage(c, 0, snotice);
78 return MOD_RES_PASSTHRU;
81 Version GetVersion() CXX11_OVERRIDE
83 return Version("Logs snomask output to channel(s)", VF_VENDOR);
87 MODULE_INIT(ModuleChanLog)