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
29 * Multimap so people can redirect a snomask to multiple channels.
31 typedef std::multimap<char, std::string> ChanLogTargets;
32 ChanLogTargets logstreams;
37 Implementation eventlist[] = { I_OnRehash, I_OnSendSnotice };
38 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
43 virtual ~ModuleChanLog()
47 virtual void OnRehash(User *user)
54 ConfigTagList tags = ServerInstance->Config->ConfTags("chanlog");
55 for (ConfigIter i = tags.first; i != tags.second; ++i)
57 channel = i->second->getString("channel");
58 snomasks = i->second->getString("snomasks");
60 if (channel.empty() || snomasks.empty())
62 ServerInstance->Logs->Log("m_chanlog", DEFAULT, "Malformed chanlog tag, ignoring");
66 for (std::string::const_iterator it = snomasks.begin(); it != snomasks.end(); it++)
68 logstreams.insert(std::make_pair(*it, channel));
69 ServerInstance->Logs->Log("m_chanlog", DEFAULT, "Logging %c to %s", *it, channel.c_str());
75 virtual ModResult OnSendSnotice(char &sno, std::string &desc, const std::string &msg)
77 std::pair<ChanLogTargets::const_iterator, ChanLogTargets::const_iterator> itpair = logstreams.equal_range(sno);
78 if (itpair.first == itpair.second)
79 return MOD_RES_PASSTHRU;
82 snprintf(buf, MAXBUF, "\2%s\2: %s", desc.c_str(), msg.c_str());
84 for (ChanLogTargets::const_iterator it = itpair.first; it != itpair.second; ++it)
86 Channel *c = ServerInstance->FindChan(it->second);
89 c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name.c_str(), buf);
90 ServerInstance->PI->SendChannelPrivmsg(c, 0, buf);
94 return MOD_RES_PASSTHRU;
97 virtual Version GetVersion()
99 return Version("Logs snomask output to channel(s).", VF_VENDOR);
104 MODULE_INIT(ModuleChanLog)
115 * This is for the "old" chanlog module which intercepted messages going to the logfile..
116 * I don't consider it all that useful, and it's quite dangerous if setup incorrectly, so
117 * this is defined out but left intact in case someone wants to develop it further someday.
119 * -- w00t (aug 23rd, 2008)
121 #define OLD_CHANLOG 0
124 class ChannelLogStream : public LogStream
130 ChannelLogStream(int loglevel, const std::string &chan) : LogStream(loglevel), channel(chan)
134 virtual void OnLog(int loglevel, const std::string &type, const std::string &msg)
136 Channel *c = ServerInstance->FindChan(channel);
137 static bool Logging = false;
139 if (loglevel < this->loglvl)
147 Logging = true; // this avoids (rare chance) loops with logging server IO on networks
149 snprintf(buf, MAXBUF, "\2%s\2: %s", type.c_str(), msg.c_str());
151 c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name.c_str(), buf);
152 ServerInstance->PI->SendChannelPrivmsg(c, 0, buf);