]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/snomasks.cpp
Removed a pointless check in ./configure --clean that made it only work with one...
[user/henk/code/inspircd.git] / src / snomasks.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include <stdarg.h>
15 #include "configreader.h"
16 #include "users.h"
17 #include "snomasks.h"
18
19 SnomaskManager::SnomaskManager(InspIRCd* Instance) : ServerInstance(Instance)
20 {
21         SnoMasks.clear();
22         this->SetupDefaults();
23 }
24
25 SnomaskManager::~SnomaskManager()
26 {
27 }
28
29 bool SnomaskManager::EnableSnomask(char letter, const std::string &type)
30 {
31         if (SnoMasks.find(letter) == SnoMasks.end())
32         {
33                 SnoMasks[letter] = type;
34                 return true;
35         }
36         return false;
37 }
38
39 bool SnomaskManager::DisableSnomask(char letter)
40 {
41         SnoList::iterator n = SnoMasks.find(letter);
42         if (n != SnoMasks.end())
43         {
44                 SnoMasks.erase(n);
45                 return true;
46         }
47         return false;
48 }
49
50 void SnomaskManager::WriteToSnoMask(char letter, const std::string &text)
51 {
52         /* Only send to snomask chars which are enabled */
53         SnoList::iterator n = SnoMasks.find(letter);
54         if (n != SnoMasks.end())
55         {
56                 /* Only opers can receive snotices, so we iterate the oper list */
57                 for (std::vector<userrec*>::iterator i = ServerInstance->all_opers.begin(); i != ServerInstance->all_opers.end(); i++)
58                 {
59                         userrec* a = *i;
60                         if (IS_LOCAL(a) && a->modes[UM_SERVERNOTICE] && a->modes[UM_SNOMASK] && a->IsNoticeMaskSet(n->first))
61                         {
62                                 /* send server notices to all with +ns */
63                                 a->WriteServ("NOTICE %s :*** %s: %s",a->nick, n->second.c_str(), text.c_str());
64                         }
65                 }
66         }
67 }
68
69 void SnomaskManager::WriteToSnoMask(char letter, const char* text, ...)
70 {
71         char textbuffer[MAXBUF];
72         va_list argsPtr;
73
74         va_start(argsPtr, text);
75         vsnprintf(textbuffer, MAXBUF, text, argsPtr);
76         va_end(argsPtr);
77
78         this->WriteToSnoMask(letter, std::string(textbuffer));
79 }
80
81 bool SnomaskManager::IsEnabled(char letter)
82 {
83         return (SnoMasks.find(letter) != SnoMasks.end());
84 }
85
86 void SnomaskManager::SetupDefaults()
87 {
88         this->EnableSnomask('c',"CONNECT");             /* Local connect notices */
89         this->EnableSnomask('C',"REMOTECONNECT");       /* Remote connect notices */
90         this->EnableSnomask('q',"QUIT");                /* Local quit notices */
91         this->EnableSnomask('Q',"REMOTEQUIT");          /* Remote quit notices */
92         this->EnableSnomask('k',"KILL");                /* Kill notices */
93         this->EnableSnomask('l',"LINK");                /* Link notices */
94         this->EnableSnomask('o',"OPER");                /* Oper up/down notices */
95         this->EnableSnomask('d',"DEBUG");               /* Debug notices */
96         this->EnableSnomask('x',"XLINE");               /* Xline notice (g/z/q/k/e) */
97         this->EnableSnomask('t',"STATS");               /* Local or remote stats request */
98         this->EnableSnomask('f',"FLOOD");               /* Flooding notices */
99 }
100