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 char textbuffer[MAXBUF];
58 va_start(argsPtr, text);
59 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
62 this->WriteToSnoMask(letter, std::string(textbuffer));
65 void SnomaskManager::WriteGlobalSno(char letter, const char* text, ...)
67 char textbuffer[MAXBUF];
70 va_start(argsPtr, text);
71 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
74 this->WriteGlobalSno(letter, std::string(textbuffer));
77 SnomaskManager::SnomaskManager()
79 EnableSnomask('c',"CONNECT"); /* Local connect notices */
80 EnableSnomask('q',"QUIT"); /* Local quit notices */
81 EnableSnomask('k',"KILL"); /* Kill notices */
82 EnableSnomask('l',"LINK"); /* Linking notices */
83 EnableSnomask('o',"OPER"); /* Oper up/down notices */
84 EnableSnomask('a',"ANNOUNCEMENT"); /* formerly WriteOpers() - generic notices to all opers */
85 EnableSnomask('d',"DEBUG"); /* Debug notices */
86 EnableSnomask('x',"XLINE"); /* Xline notice (g/z/q/k/e) */
87 EnableSnomask('t',"STATS"); /* Local or remote stats request */
88 EnableSnomask('f',"FLOOD"); /* Flooding notices */
91 /*************************************************************************************/
93 void Snomask::SendMessage(const std::string &message, char mysnomask)
95 if (ServerInstance->Config->NoSnoticeStack || message != LastMessage || mysnomask != LastLetter)
98 LastMessage = message;
99 LastLetter = mysnomask;
101 std::string desc = Description;
103 desc = std::string("SNO-") + (char)tolower(mysnomask);
104 if (isupper(mysnomask))
105 desc = "REMOTE" + desc;
106 ModResult MOD_RESULT;
107 ServerInstance->Logs->Log("snomask", DEFAULT, "%s: %s", desc.c_str(), message.c_str());
109 FIRST_MOD_RESULT(OnSendSnotice, MOD_RESULT, (mysnomask, desc, message));
111 LastBlocked = (MOD_RESULT == MOD_RES_DENY);
115 /* Only opers can receive snotices, so we iterate the oper list */
116 std::list<User*>::iterator i = ServerInstance->Users->all_opers.begin();
118 while (i != ServerInstance->Users->all_opers.end())
121 if (IS_LOCAL(a) && a->IsModeSet('s') && a->IsNoticeMaskSet(mysnomask) && !a->quitting)
123 a->WriteServ("NOTICE %s :*** %s: %s", a->nick.c_str(), desc.c_str(), message.c_str());
133 void Snomask::Flush()
137 std::string desc = Description;
139 desc = std::string("SNO-") + (char)tolower(LastLetter);
140 if (isupper(LastLetter))
141 desc = "REMOTE" + desc;
142 std::string mesg = "(last message repeated "+ConvToStr(Count)+" times)";
144 ServerInstance->Logs->Log("snomask", DEFAULT, "%s: %s", desc.c_str(), mesg.c_str());
146 FOREACH_MOD(I_OnSendSnotice, OnSendSnotice(LastLetter, desc, mesg));
150 /* Only opers can receive snotices, so we iterate the oper list */
151 std::list<User*>::iterator i = ServerInstance->Users->all_opers.begin();
153 while (i != ServerInstance->Users->all_opers.end())
156 if (IS_LOCAL(a) && a->IsModeSet('s') && a->IsNoticeMaskSet(LastLetter) && !a->quitting)
158 a->WriteServ("NOTICE %s :*** %s: %s", a->nick.c_str(), desc.c_str(), mesg.c_str());