2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
6 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
7 * Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
9 * This file is part of InspIRCd. InspIRCd is free software: you can
10 * redistribute it and/or modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation, version 2.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 void SnomaskManager::FlushSnotices()
28 for (int i=0; i < 26; i++)
32 void SnomaskManager::EnableSnomask(char letter, const std::string &type)
34 if (letter >= 'a' && letter <= 'z')
35 masks[letter - 'a'].Description = type;
38 void SnomaskManager::WriteToSnoMask(char letter, const std::string &text)
40 if (letter >= 'a' && letter <= 'z')
41 masks[letter - 'a'].SendMessage(text, letter);
42 if (letter >= 'A' && letter <= 'Z')
43 masks[letter - 'A'].SendMessage(text, letter);
46 void SnomaskManager::WriteGlobalSno(char letter, const std::string& text)
48 WriteToSnoMask(letter, text);
49 letter = toupper(letter);
50 ServerInstance->PI->SendSNONotice(std::string(1, letter), text);
53 void SnomaskManager::WriteToSnoMask(char letter, const char* text, ...)
55 std::string textbuffer;
56 VAFORMAT(textbuffer, text, text);
57 this->WriteToSnoMask(letter, textbuffer);
60 void SnomaskManager::WriteGlobalSno(char letter, const char* text, ...)
62 std::string textbuffer;
63 VAFORMAT(textbuffer, text, text);
64 this->WriteGlobalSno(letter, textbuffer);
67 SnomaskManager::SnomaskManager()
69 EnableSnomask('c',"CONNECT"); /* Local connect notices */
70 EnableSnomask('q',"QUIT"); /* Local quit notices */
71 EnableSnomask('k',"KILL"); /* Kill notices */
72 EnableSnomask('l',"LINK"); /* Linking notices */
73 EnableSnomask('o',"OPER"); /* Oper up/down notices */
74 EnableSnomask('a',"ANNOUNCEMENT"); /* formerly WriteOpers() - generic notices to all opers */
75 EnableSnomask('d',"DEBUG"); /* Debug notices */
76 EnableSnomask('x',"XLINE"); /* Xline notice (g/z/q/k/e) */
77 EnableSnomask('t',"STATS"); /* Local or remote stats request */
78 EnableSnomask('f',"FLOOD"); /* Flooding notices */
81 /*************************************************************************************/
83 void Snomask::SendMessage(const std::string &message, char mysnomask)
85 if (ServerInstance->Config->NoSnoticeStack || message != LastMessage || mysnomask != LastLetter)
88 LastMessage = message;
89 LastLetter = mysnomask;
91 std::string desc = Description;
93 desc = std::string("SNO-") + (char)tolower(mysnomask);
94 if (isupper(mysnomask))
95 desc = "REMOTE" + desc;
97 ServerInstance->Logs->Log("snomask", LOG_DEFAULT, "%s: %s", desc.c_str(), message.c_str());
99 FIRST_MOD_RESULT(OnSendSnotice, MOD_RESULT, (mysnomask, desc, message));
101 LastBlocked = (MOD_RESULT == MOD_RES_DENY);
105 /* Only opers can receive snotices, so we iterate the oper list */
106 std::list<User*>::iterator i = ServerInstance->Users->all_opers.begin();
108 while (i != ServerInstance->Users->all_opers.end())
111 if (IS_LOCAL(a) && a->IsModeSet('s') && a->IsNoticeMaskSet(mysnomask) && !a->quitting)
113 a->WriteNotice("*** " + desc + ": " + message);
123 void Snomask::Flush()
127 std::string desc = Description;
129 desc = std::string("SNO-") + (char)tolower(LastLetter);
130 if (isupper(LastLetter))
131 desc = "REMOTE" + desc;
132 std::string mesg = "(last message repeated "+ConvToStr(Count)+" times)";
134 ServerInstance->Logs->Log("snomask", LOG_DEFAULT, "%s: %s", desc.c_str(), mesg.c_str());
136 FOREACH_MOD(I_OnSendSnotice, OnSendSnotice(LastLetter, desc, mesg));
140 /* Only opers can receive snotices, so we iterate the oper list */
141 std::list<User*>::iterator i = ServerInstance->Users->all_opers.begin();
143 while (i != ServerInstance->Users->all_opers.end())
146 if (IS_LOCAL(a) && a->IsModeSet('s') && a->IsNoticeMaskSet(LastLetter) && !a->quitting)
148 a->WriteNotice("*** " + desc + ": " + mesg);