]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/snomasks.cpp
Remove more unnecessary header traffic
[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 "inspircd.h"
15 #include <stdarg.h>
16 #include "snomasks.h"
17
18 SnomaskManager::SnomaskManager(InspIRCd* Instance) : ServerInstance(Instance)
19 {
20         SnoMasks.clear();
21         this->SetupDefaults();
22 }
23
24 SnomaskManager::~SnomaskManager()
25 {
26 }
27
28 bool SnomaskManager::EnableSnomask(char letter, const std::string &type)
29 {
30         if (SnoMasks.find(letter) == SnoMasks.end())
31         {
32                 SnoMasks[letter] = type;
33                 return true;
34         }
35         return false;
36 }
37
38 bool SnomaskManager::DisableSnomask(char letter)
39 {
40         SnoList::iterator n = SnoMasks.find(letter);
41         if (n != SnoMasks.end())
42         {
43                 SnoMasks.erase(n);
44                 return true;
45         }
46         return false;
47 }
48
49 void SnomaskManager::WriteToSnoMask(char letter, const std::string &text)
50 {
51         /* Only send to snomask chars which are enabled */
52         SnoList::iterator n = SnoMasks.find(letter);
53         if (n != SnoMasks.end())
54         {
55                 /* Only opers can receive snotices, so we iterate the oper list */
56                 for (std::vector<userrec*>::iterator i = ServerInstance->all_opers.begin(); i != ServerInstance->all_opers.end(); i++)
57                 {
58                         userrec* a = *i;
59                         if (IS_LOCAL(a) && a->IsModeSet('s') && a->IsModeSet('n') && a->IsNoticeMaskSet(n->first))
60                         {
61                                 /* send server notices to all with +ns */
62                                 a->WriteServ("NOTICE %s :*** %s: %s",a->nick, n->second.c_str(), text.c_str());
63                         }
64                 }
65         }
66 }
67
68 void SnomaskManager::WriteToSnoMask(char letter, const char* text, ...)
69 {
70         char textbuffer[MAXBUF];
71         va_list argsPtr;
72
73         va_start(argsPtr, text);
74         vsnprintf(textbuffer, MAXBUF, text, argsPtr);
75         va_end(argsPtr);
76
77         this->WriteToSnoMask(letter, std::string(textbuffer));
78 }
79
80 bool SnomaskManager::IsEnabled(char letter)
81 {
82         return (SnoMasks.find(letter) != SnoMasks.end());
83 }
84
85 void SnomaskManager::SetupDefaults()
86 {
87         this->EnableSnomask('c',"CONNECT");                     /* Local connect notices */
88         this->EnableSnomask('C',"REMOTECONNECT");       /* Remote connect notices */
89         this->EnableSnomask('q',"QUIT");                        /* Local quit notices */
90         this->EnableSnomask('Q',"REMOTEQUIT");          /* Remote quit notices */
91         this->EnableSnomask('k',"KILL");                        /* Kill notices */
92         this->EnableSnomask('K',"REMOTEKILL");          /* Remote 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