]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/snomasks.cpp
OOPS! We try again, since I'm smoking craq. LF is 0x0a NOT CR.
[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 "configreader.h"
17 #include "users.h"
18 #include "snomasks.h"
19
20 SnomaskManager::SnomaskManager(InspIRCd* Instance) : ServerInstance(Instance)
21 {
22         SnoMasks.clear();
23         this->SetupDefaults();
24 }
25
26 SnomaskManager::~SnomaskManager()
27 {
28 }
29
30 bool SnomaskManager::EnableSnomask(char letter, const std::string &type)
31 {
32         if (SnoMasks.find(letter) == SnoMasks.end())
33         {
34                 SnoMasks[letter] = type;
35                 return true;
36         }
37         return false;
38 }
39
40 bool SnomaskManager::DisableSnomask(char letter)
41 {
42         SnoList::iterator n = SnoMasks.find(letter);
43         if (n != SnoMasks.end())
44         {
45                 SnoMasks.erase(n);
46                 return true;
47         }
48         return false;
49 }
50
51 void SnomaskManager::WriteToSnoMask(char letter, const std::string &text)
52 {
53         /* Only send to snomask chars which are enabled */
54         SnoList::iterator n = SnoMasks.find(letter);
55         if (n != SnoMasks.end())
56         {
57                 /* Only opers can receive snotices, so we iterate the oper list */
58                 for (std::vector<userrec*>::iterator i = ServerInstance->all_opers.begin(); i != ServerInstance->all_opers.end(); i++)
59                 {
60                         userrec* a = *i;
61                         if (IS_LOCAL(a) && a->modes[UM_SERVERNOTICE] && a->modes[UM_SNOMASK] && a->IsNoticeMaskSet(n->first))
62                         {
63                                 /* send server notices to all with +ns */
64                                 a->WriteServ("NOTICE %s :*** %s: %s",a->nick, n->second.c_str(), text.c_str());
65                         }
66                 }
67         }
68 }
69
70 void SnomaskManager::WriteToSnoMask(char letter, const char* text, ...)
71 {
72         char textbuffer[MAXBUF];
73         va_list argsPtr;
74
75         va_start(argsPtr, text);
76         vsnprintf(textbuffer, MAXBUF, text, argsPtr);
77         va_end(argsPtr);
78
79         this->WriteToSnoMask(letter, std::string(textbuffer));
80 }
81
82 bool SnomaskManager::IsEnabled(char letter)
83 {
84         return (SnoMasks.find(letter) != SnoMasks.end());
85 }
86
87 void SnomaskManager::SetupDefaults()
88 {
89         this->EnableSnomask('c',"CONNECT");                     /* Local connect notices */
90         this->EnableSnomask('C',"REMOTECONNECT");       /* Remote connect notices */
91         this->EnableSnomask('q',"QUIT");                        /* Local quit notices */
92         this->EnableSnomask('Q',"REMOTEQUIT");          /* Remote quit notices */
93         this->EnableSnomask('k',"KILL");                        /* Kill notices */
94         this->EnableSnomask('K',"REMOTEKILL");          /* Remote kill notices */
95         this->EnableSnomask('l',"LINK");                        /* Link notices */
96         this->EnableSnomask('o',"OPER");                        /* Oper up/down notices */
97         this->EnableSnomask('d',"DEBUG");                       /* Debug notices */
98         this->EnableSnomask('x',"XLINE");                       /* Xline notice (g/z/q/k/e) */
99         this->EnableSnomask('t',"STATS");                       /* Local or remote stats request */
100         this->EnableSnomask('f',"FLOOD");                       /* Flooding notices */
101 }
102