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 std::multimap<char, std::string> logstreams;
35 Implementation eventlist[] = { I_OnRehash, I_OnSendSnotice };
36 ServerInstance->Modules->Attach(eventlist, this, 2);
41 virtual ~ModuleChanLog()
45 virtual void OnRehash(User *user)
53 for (int i = 0; i < MyConf.Enumerate("chanlog"); i++)
55 channel = MyConf.ReadValue("chanlog", "channel", i);
56 snomasks = MyConf.ReadValue("chanlog", "snomasks", i);
58 if (channel.empty() || snomasks.empty())
60 ServerInstance->Logs->Log("m_chanlog", DEFAULT, "Malformed chanlog tag, ignoring");
64 for (std::string::const_iterator it = snomasks.begin(); it != snomasks.end(); it++)
66 logstreams.insert(std::make_pair(*it, channel));
67 ServerInstance->Logs->Log("m_chanlog", DEFAULT, "Logging %c to %s", *it, channel.c_str());
73 virtual ModResult OnSendSnotice(char &sno, std::string &desc, const std::string &msg)
75 std::multimap<char, std::string>::const_iterator it = logstreams.find(sno);
78 if (it == logstreams.end())
79 return MOD_RES_PASSTHRU;
81 snprintf(buf, MAXBUF, "\2%s\2: %s", desc.c_str(), msg.c_str());
83 while (it != logstreams.end())
91 Channel *c = ServerInstance->FindChan(it->second);
94 c->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "PRIVMSG %s :%s", c->name.c_str(), buf);
95 ServerInstance->PI->SendChannelPrivmsg(c, 0, buf);
101 return MOD_RES_PASSTHRU;
104 virtual Version GetVersion()
106 return Version("Logs snomask output to channel(s).", VF_VENDOR);
111 MODULE_INIT(ModuleChanLog)
122 * This is for the "old" chanlog module which intercepted messages going to the logfile..
123 * I don't consider it all that useful, and it's quite dangerous if setup incorrectly, so
124 * this is defined out but left intact in case someone wants to develop it further someday.
126 * -- w00t (aug 23rd, 2008)
128 #define OLD_CHANLOG 0
131 class ChannelLogStream : public LogStream
137 ChannelLogStream(int loglevel, const std::string &chan) : LogStream(loglevel), channel(chan)
141 virtual void OnLog(int loglevel, const std::string &type, const std::string &msg)
143 Channel *c = ServerInstance->FindChan(channel);
144 static bool Logging = false;
146 if (loglevel < this->loglvl)
154 Logging = true; // this avoids (rare chance) loops with logging server IO on networks
156 snprintf(buf, MAXBUF, "\2%s\2: %s", type.c_str(), msg.c_str());
158 c->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "PRIVMSG %s :%s", c->name.c_str(), buf);
159 ServerInstance->PI->SendChannelPrivmsg(c, 0, buf);