1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/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). */
19 * This is for the "old" chanlog module which intercepted messages going to the logfile..
20 * I don't consider it all that useful, and it's quite dangerous if setup incorrectly, so
21 * this is defined out but left intact in case someone wants to develop it further someday.
23 * -- w00t (aug 23rd, 2008)
28 class ChannelLogStream : public LogStream
34 ChannelLogStream(InspIRCd *Instance, int loglevel, const std::string &chan) : LogStream(Instance, loglevel), channel(chan)
38 virtual void OnLog(int loglevel, const std::string &type, const std::string &msg)
40 Channel *c = ServerInstance->FindChan(channel);
41 static bool Logging = false;
43 if (loglevel < this->loglvl)
51 Logging = true; // this avoids (rare chance) loops with logging server IO on networks
53 snprintf(buf, MAXBUF, "\2%s\2: %s", type.c_str(), msg.c_str());
55 c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name.c_str(), buf);
56 ServerInstance->PI->SendChannelPrivmsg(c, 0, buf);
63 class ModuleChanLog : public Module
67 * Multimap so people can redirect a snomask to multiple channels.
69 std::multimap<char, std::string> logstreams;
72 ModuleChanLog(InspIRCd* Me) : Module(Me)
74 Implementation eventlist[] = { I_OnRehash, I_OnSendSnotice };
75 ServerInstance->Modules->Attach(eventlist, this, 2);
80 virtual ~ModuleChanLog()
84 virtual void OnRehash(User *user, const std::string ¶meter)
86 ConfigReader MyConf(ServerInstance);
92 for (int i = 0; i < MyConf.Enumerate("chanlog"); i++)
94 channel = MyConf.ReadValue("chanlog", "channel", i);
95 snomasks = MyConf.ReadValue("chanlog", "snomasks", i);
97 if (channel.empty() || snomasks.empty())
99 ServerInstance->Logs->Log("m_chanlog", DEFAULT, "Malformed chanlog tag, ignoring");
103 for (std::string::const_iterator it = snomasks.begin(); it != snomasks.end(); i++)
105 logstreams.insert(std::make_pair(*it, channel));
106 ServerInstance->Logs->Log("m_chanlog", DEFAULT, "Logging %c to %s", *it, channel.c_str());
113 virtual int OnSendSnotice(char &sno, std::string &desc, const std::string &msg)
115 std::multimap<char, std::string>::const_iterator it = logstreams.find(sno);
118 if (it == logstreams.end())
121 snprintf(buf, MAXBUF, "\2%s\2: %s", desc.c_str(), msg.c_str());
123 while (it != logstreams.end())
125 if (it->first != sno)
131 Channel *c = ServerInstance->FindChan(it->second);
134 c->WriteChannelWithServ(ServerInstance->Config->ServerName, "PRIVMSG %s :%s", c->name.c_str(), buf);
135 ServerInstance->PI->SendChannelPrivmsg(c, 0, buf);
144 virtual Version GetVersion()
146 return Version(1,2,0,1,VF_VENDOR,API_VERSION);
151 MODULE_INIT(ModuleChanLog)