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 /* $ModDesc: Logs snomask output to channel(s). */
25 class ModuleChanLog : public Module
28 * Multimap so people can redirect a snomask to multiple channels.
30 typedef std::multimap<char, std::string> ChanLogTargets;
31 ChanLogTargets logstreams;
36 Implementation eventlist[] = { I_OnRehash, I_OnSendSnotice };
37 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
42 virtual void OnRehash(User *user)
49 ConfigTagList tags = ServerInstance->Config->ConfTags("chanlog");
50 for (ConfigIter i = tags.first; i != tags.second; ++i)
52 channel = i->second->getString("channel");
53 snomasks = i->second->getString("snomasks");
55 if (channel.empty() || snomasks.empty())
57 ServerInstance->Logs->Log("m_chanlog", DEFAULT, "Malformed chanlog tag, ignoring");
61 for (std::string::const_iterator it = snomasks.begin(); it != snomasks.end(); it++)
63 logstreams.insert(std::make_pair(*it, channel));
64 ServerInstance->Logs->Log("m_chanlog", DEFAULT, "Logging %c to %s", *it, channel.c_str());
70 virtual ModResult OnSendSnotice(char &sno, std::string &desc, const std::string &msg)
72 std::pair<ChanLogTargets::const_iterator, ChanLogTargets::const_iterator> itpair = logstreams.equal_range(sno);
73 if (itpair.first == itpair.second)
74 return MOD_RES_PASSTHRU;
77 snprintf(buf, MAXBUF, "\2%s\2: %s", desc.c_str(), msg.c_str());
79 for (ChanLogTargets::const_iterator it = itpair.first; it != itpair.second; ++it)
81 Channel *c = ServerInstance->FindChan(it->second);
84 c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name.c_str(), buf);
85 ServerInstance->PI->SendChannelPrivmsg(c, 0, buf);
89 return MOD_RES_PASSTHRU;
92 virtual Version GetVersion()
94 return Version("Logs snomask output to channel(s).", VF_VENDOR);
99 MODULE_INIT(ModuleChanLog)
110 * This is for the "old" chanlog module which intercepted messages going to the logfile..
111 * I don't consider it all that useful, and it's quite dangerous if setup incorrectly, so
112 * this is defined out but left intact in case someone wants to develop it further someday.
114 * -- w00t (aug 23rd, 2008)
116 #define OLD_CHANLOG 0
119 class ChannelLogStream : public LogStream
125 ChannelLogStream(int loglevel, const std::string &chan) : LogStream(loglevel), channel(chan)
129 virtual void OnLog(int loglevel, const std::string &type, const std::string &msg)
131 Channel *c = ServerInstance->FindChan(channel);
132 static bool Logging = false;
134 if (loglevel < this->loglvl)
142 Logging = true; // this avoids (rare chance) loops with logging server IO on networks
144 snprintf(buf, MAXBUF, "\2%s\2: %s", type.c_str(), msg.c_str());
146 c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name.c_str(), buf);
147 ServerInstance->PI->SendChannelPrivmsg(c, 0, buf);