]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/snomasks.cpp
Partially revert "Quote paths in the makefile".
[user/henk/code/inspircd.git] / src / snomasks.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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>
8  *
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.
12  *
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
16  * details.
17  *
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/>.
20  */
21
22
23 #include "inspircd.h"
24 #include <stdarg.h>
25
26 void SnomaskManager::FlushSnotices()
27 {
28         for (int i=0; i < 26; i++)
29                 masks[i].Flush();
30 }
31
32 void SnomaskManager::EnableSnomask(char letter, const std::string &type)
33 {
34         if (letter >= 'a' && letter <= 'z')
35                 masks[letter - 'a'].Description = type;
36 }
37
38 void SnomaskManager::WriteToSnoMask(char letter, const std::string &text)
39 {
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);
44 }
45
46 void SnomaskManager::WriteGlobalSno(char letter, const std::string& text)
47 {
48         WriteToSnoMask(letter, text);
49         letter = toupper(letter);
50         ServerInstance->PI->SendSNONotice(std::string(1, letter), text);
51 }
52
53 void SnomaskManager::WriteToSnoMask(char letter, const char* text, ...)
54 {
55         char textbuffer[MAXBUF];
56         va_list argsPtr;
57
58         va_start(argsPtr, text);
59         vsnprintf(textbuffer, MAXBUF, text, argsPtr);
60         va_end(argsPtr);
61
62         this->WriteToSnoMask(letter, std::string(textbuffer));
63 }
64
65 void SnomaskManager::WriteGlobalSno(char letter, const char* text, ...)
66 {
67         char textbuffer[MAXBUF];
68         va_list argsPtr;
69
70         va_start(argsPtr, text);
71         vsnprintf(textbuffer, MAXBUF, text, argsPtr);
72         va_end(argsPtr);
73
74         this->WriteGlobalSno(letter, std::string(textbuffer));
75 }
76
77 SnomaskManager::SnomaskManager()
78 {
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 */
89 }
90
91 /*************************************************************************************/
92
93 void Snomask::SendMessage(const std::string &message, char mysnomask)
94 {
95         if (ServerInstance->Config->NoSnoticeStack || message != LastMessage || mysnomask != LastLetter)
96         {
97                 this->Flush();
98                 LastMessage = message;
99                 LastLetter = mysnomask;
100
101                 std::string desc = Description;
102                 if (desc.empty())
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());
108
109                 FIRST_MOD_RESULT(OnSendSnotice, MOD_RESULT, (mysnomask, desc, message));
110
111                 LastBlocked = (MOD_RESULT == MOD_RES_DENY);
112
113                 if (!LastBlocked)
114                 {
115                         /* Only opers can receive snotices, so we iterate the oper list */
116                         std::list<User*>::iterator i = ServerInstance->Users->all_opers.begin();
117
118                         while (i != ServerInstance->Users->all_opers.end())
119                         {
120                                 User* a = *i;
121                                 if (IS_LOCAL(a) && a->IsModeSet('s') && a->IsNoticeMaskSet(mysnomask) && !a->quitting)
122                                 {
123                                         a->WriteServ("NOTICE %s :*** %s: %s", a->nick.c_str(), desc.c_str(), message.c_str());
124                                 }
125
126                                 i++;
127                         }
128                 }
129         }
130         Count++;
131 }
132
133 void Snomask::Flush()
134 {
135         if (Count > 1)
136         {
137                 std::string desc = Description;
138                 if (desc.empty())
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)";
143
144                 ServerInstance->Logs->Log("snomask", DEFAULT, "%s: %s", desc.c_str(), mesg.c_str());
145
146                 FOREACH_MOD(I_OnSendSnotice, OnSendSnotice(LastLetter, desc, mesg));
147
148                 if (!LastBlocked)
149                 {
150                         /* Only opers can receive snotices, so we iterate the oper list */
151                         std::list<User*>::iterator i = ServerInstance->Users->all_opers.begin();
152
153                         while (i != ServerInstance->Users->all_opers.end())
154                         {
155                                 User* a = *i;
156                                 if (IS_LOCAL(a) && a->IsModeSet('s') && a->IsNoticeMaskSet(LastLetter) && !a->quitting)
157                                 {
158                                         a->WriteServ("NOTICE %s :*** %s: %s", a->nick.c_str(), desc.c_str(), mesg.c_str());
159                                 }
160
161                                 i++;
162                         }
163                 }
164
165         }
166         LastMessage.clear();
167         LastBlocked = false;
168         Count = 0;
169 }