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('o',"OPER"); /* Oper up/down notices */
73 EnableSnomask('a',"ANNOUNCEMENT"); /* formerly WriteOpers() - generic notices to all opers */
74 EnableSnomask('d',"DEBUG"); /* Debug notices */
75 EnableSnomask('x',"XLINE"); /* Xline notice (g/z/q/k/e) */
76 EnableSnomask('t',"STATS"); /* Local or remote stats request */
79 bool SnomaskManager::IsSnomaskUsable(char ch) const
81 return ((isalpha(ch)) && (!masks[tolower(ch) - 'a'].Description.empty()));
89 void Snomask::SendMessage(const std::string& message, char letter)
91 if ((!ServerInstance->Config->NoSnoticeStack) && (message == LastMessage) && (letter == LastLetter))
99 std::string desc = GetDescription(letter);
100 ModResult MOD_RESULT;
101 FIRST_MOD_RESULT(OnSendSnotice, MOD_RESULT, (letter, desc, message));
102 if (MOD_RESULT == MOD_RES_DENY)
105 Snomask::Send(letter, desc, message);
106 LastMessage = message;
111 void Snomask::Flush()
115 std::string desc = GetDescription(LastLetter);
116 std::string msg = "(last message repeated " + ConvToStr(Count) + " times)";
118 FOREACH_MOD(OnSendSnotice, (LastLetter, desc, msg));
119 Snomask::Send(LastLetter, desc, msg);
126 void Snomask::Send(char letter, const std::string& desc, const std::string& msg)
128 std::string log = desc;
129 log.append(": ").append(msg);
130 ServerInstance->Logs->Log("snomask", LOG_DEFAULT, log);
132 std::string finalmsg = "*** ";
133 finalmsg.append(log);
134 /* Only opers can receive snotices, so we iterate the oper list */
135 const std::list<User*>& opers = ServerInstance->Users->all_opers;
136 for (std::list<User*>::const_iterator i = opers.begin(); i != opers.end(); ++i)
139 // IsNoticeMaskSet() returns false for opers who aren't +s, no need to check for it seperately
140 if (IS_LOCAL(user) && user->IsNoticeMaskSet(letter))
141 user->WriteNotice(finalmsg);
145 std::string Snomask::GetDescription(char letter) const
150 if (!Description.empty())
153 ret += std::string("SNO-") + (char)tolower(letter);