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/>.
25 void SnomaskManager::FlushSnotices()
27 for (int i=0; i < 26; i++)
31 void SnomaskManager::EnableSnomask(char letter, const std::string &type)
33 if (letter >= 'a' && letter <= 'z')
34 masks[letter - 'a'].Description = type;
37 void SnomaskManager::WriteToSnoMask(char letter, const std::string &text)
39 if (letter >= 'a' && letter <= 'z')
40 masks[letter - 'a'].SendMessage(text, letter);
41 if (letter >= 'A' && letter <= 'Z')
42 masks[letter - 'A'].SendMessage(text, letter);
45 void SnomaskManager::WriteGlobalSno(char letter, const std::string& text)
47 WriteToSnoMask(letter, text);
48 letter = toupper(letter);
49 ServerInstance->PI->SendSNONotice(letter, text);
52 void SnomaskManager::WriteToSnoMask(char letter, const char* text, ...)
54 std::string textbuffer;
55 VAFORMAT(textbuffer, text, text);
56 this->WriteToSnoMask(letter, textbuffer);
59 void SnomaskManager::WriteGlobalSno(char letter, const char* text, ...)
61 std::string textbuffer;
62 VAFORMAT(textbuffer, text, text);
63 this->WriteGlobalSno(letter, textbuffer);
66 SnomaskManager::SnomaskManager()
68 EnableSnomask('c',"CONNECT"); /* Local connect notices */
69 EnableSnomask('q',"QUIT"); /* Local quit notices */
70 EnableSnomask('k',"KILL"); /* Kill notices */
71 EnableSnomask('o',"OPER"); /* Oper up/down notices */
72 EnableSnomask('a',"ANNOUNCEMENT"); /* formerly WriteOpers() - generic notices to all opers */
73 EnableSnomask('x',"XLINE"); /* X-line notices (G/Z/Q/K/E/R/SHUN/CBan) */
74 EnableSnomask('t',"STATS"); /* Local or remote stats request */
77 bool SnomaskManager::IsSnomaskUsable(char ch) const
79 return ((isalpha(ch)) && (!masks[tolower(ch) - 'a'].Description.empty()));
87 void Snomask::SendMessage(const std::string& message, char letter)
89 if ((!ServerInstance->Config->NoSnoticeStack) && (message == LastMessage) && (letter == LastLetter))
97 std::string desc = GetDescription(letter);
99 FIRST_MOD_RESULT(OnSendSnotice, MOD_RESULT, (letter, desc, message));
100 if (MOD_RESULT == MOD_RES_DENY)
103 Snomask::Send(letter, desc, message);
104 LastMessage = message;
109 void Snomask::Flush()
113 std::string desc = GetDescription(LastLetter);
114 std::string msg = "(last message repeated " + ConvToStr(Count) + " times)";
116 FOREACH_MOD(OnSendSnotice, (LastLetter, desc, msg));
117 Snomask::Send(LastLetter, desc, msg);
124 void Snomask::Send(char letter, const std::string& desc, const std::string& msg)
126 ServerInstance->Logs->Log(desc, LOG_DEFAULT, msg);
127 const std::string finalmsg = InspIRCd::Format("*** %s: %s", desc.c_str(), msg.c_str());
129 /* Only opers can receive snotices, so we iterate the oper list */
130 const UserManager::OperList& opers = ServerInstance->Users->all_opers;
131 for (UserManager::OperList::const_iterator i = opers.begin(); i != opers.end(); ++i)
134 // IsNoticeMaskSet() returns false for opers who aren't +s, no need to check for it seperately
135 if (IS_LOCAL(user) && user->IsNoticeMaskSet(letter))
136 user->WriteNotice(finalmsg);
140 std::string Snomask::GetDescription(char letter) const
145 if (!Description.empty())
148 ret += std::string("SNO-") + (char)tolower(letter);