1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /* $ModDesc: Logs snomask output to channel(s). */
18 class ModuleChanLog : public Module
22 * Multimap so people can redirect a snomask to multiple channels.
24 std::multimap<char, std::string> logstreams;
27 ModuleChanLog(InspIRCd* Me) : Module(Me)
29 Implementation eventlist[] = { I_OnRehash, I_OnSendSnotice };
30 ServerInstance->Modules->Attach(eventlist, this, 2);
35 virtual ~ModuleChanLog()
39 virtual void OnRehash(User *user)
41 ConfigReader MyConf(ServerInstance);
47 for (int i = 0; i < MyConf.Enumerate("chanlog"); i++)
49 channel = MyConf.ReadValue("chanlog", "channel", i);
50 snomasks = MyConf.ReadValue("chanlog", "snomasks", i);
52 if (channel.empty() || snomasks.empty())
54 ServerInstance->Logs->Log("m_chanlog", DEFAULT, "Malformed chanlog tag, ignoring");
58 for (std::string::const_iterator it = snomasks.begin(); it != snomasks.end(); it++)
60 logstreams.insert(std::make_pair(*it, channel));
61 ServerInstance->Logs->Log("m_chanlog", DEFAULT, "Logging %c to %s", *it, channel.c_str());
67 virtual int OnSendSnotice(char &sno, std::string &desc, const std::string &msg)
69 std::multimap<char, std::string>::const_iterator it = logstreams.find(sno);
72 if (it == logstreams.end())
75 snprintf(buf, MAXBUF, "\2%s\2: %s", desc.c_str(), msg.c_str());
77 while (it != logstreams.end())
85 Channel *c = ServerInstance->FindChan(it->second);
88 c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name.c_str(), buf);
89 ServerInstance->PI->SendChannelPrivmsg(c, 0, buf);
98 virtual Version GetVersion()
100 return Version("$Id$", VF_VENDOR,API_VERSION);
105 MODULE_INIT(ModuleChanLog)
116 * This is for the "old" chanlog module which intercepted messages going to the logfile..
117 * I don't consider it all that useful, and it's quite dangerous if setup incorrectly, so
118 * this is defined out but left intact in case someone wants to develop it further someday.
120 * -- w00t (aug 23rd, 2008)
122 #define OLD_CHANLOG 0
125 class ChannelLogStream : public LogStream
131 ChannelLogStream(InspIRCd *Instance, int loglevel, const std::string &chan) : LogStream(Instance, loglevel), channel(chan)
135 virtual void OnLog(int loglevel, const std::string &type, const std::string &msg)
137 Channel *c = ServerInstance->FindChan(channel);
138 static bool Logging = false;
140 if (loglevel < this->loglvl)
148 Logging = true; // this avoids (rare chance) loops with logging server IO on networks
150 snprintf(buf, MAXBUF, "\2%s\2: %s", type.c_str(), msg.c_str());
152 c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name.c_str(), buf);
153 ServerInstance->PI->SendChannelPrivmsg(c, 0, buf);