]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/snomasks.cpp
Remove InspIRCd::WriteOpers in favour of snomask O
[user/henk/code/inspircd.git] / src / snomasks.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 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 /* $Core: libIRCDsnomasks */
15
16 #include "inspircd.h"
17 #include <stdarg.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 void SnomaskManager::FlushSnotices()
31 {
32         for (std::map<char, Snomask *>::iterator i = SnoMasks.begin(); i != SnoMasks.end(); i++)
33         {
34                 i->second->Flush();
35         }
36 }
37
38 bool SnomaskManager::EnableSnomask(char letter, const std::string &type)
39 {
40         if (SnoMasks.find(letter) == SnoMasks.end())
41         {
42                 Snomask *s = new Snomask(ServerInstance, letter, type);
43                 SnoMasks[letter] = s;
44                 return true;
45         }
46         return false;
47 }
48
49 bool SnomaskManager::DisableSnomask(char letter)
50 {
51         SnoList::iterator n = SnoMasks.find(letter);
52         if (n != SnoMasks.end())
53         {
54                 delete n->second; // destroy the snomask
55                 SnoMasks.erase(n);
56                 return true;
57         }
58         return false;
59 }
60
61 void SnomaskManager::WriteToSnoMask(char letter, const std::string &text)
62 {
63         /* Only send to snomask chars which are enabled */
64         SnoList::iterator n = SnoMasks.find(letter);
65         if (n != SnoMasks.end())
66         {
67                 n->second->SendMessage(text);
68         }
69 }
70
71 void SnomaskManager::WriteToSnoMask(char letter, const char* text, ...)
72 {
73         char textbuffer[MAXBUF];
74         va_list argsPtr;
75
76         va_start(argsPtr, text);
77         vsnprintf(textbuffer, MAXBUF, text, argsPtr);
78         va_end(argsPtr);
79
80         this->WriteToSnoMask(letter, std::string(textbuffer));
81 }
82
83 bool SnomaskManager::IsEnabled(char letter)
84 {
85         return (SnoMasks.find(letter) != SnoMasks.end());
86 }
87
88 void SnomaskManager::SetupDefaults()
89 {
90         this->EnableSnomask('c',"CONNECT");                     /* Local connect notices */
91         this->EnableSnomask('C',"REMOTECONNECT");               /* Remote connect notices */
92         this->EnableSnomask('q',"QUIT");                        /* Local quit notices */
93         this->EnableSnomask('Q',"REMOTEQUIT");                  /* Remote quit notices */
94         this->EnableSnomask('k',"KILL");                        /* Kill notices */
95         this->EnableSnomask('K',"REMOTEKILL");                  /* Remote kill notices */
96         this->EnableSnomask('l',"LINK");                        /* Link notices */
97         this->EnableSnomask('o',"OPER");                        /* Oper up/down notices */
98         this->EnableSnomask('O',"ALLOPERS");                    /* formerly WriteOpers() - generic notices to all opers */
99         this->EnableSnomask('d',"DEBUG");                       /* Debug notices */
100         this->EnableSnomask('x',"XLINE");                       /* Xline notice (g/z/q/k/e) */
101         this->EnableSnomask('t',"STATS");                       /* Local or remote stats request */
102         this->EnableSnomask('f',"FLOOD");                       /* Flooding notices */
103 }
104
105 /*************************************************************************************/
106
107 void Snomask::SendMessage(const std::string &message)
108 {
109         if (message != LastMessage)
110         {
111                 this->Flush();
112                 LastMessage = message;
113         }
114         else
115         {
116                 Count++;
117         }
118 }
119
120 void Snomask::Flush()
121 {
122         if (this->LastMessage.empty())
123                 return;
124
125         ServerInstance->Log(DEBUG, "Flusing snomask %s", this->Description.c_str());
126
127         /* Only opers can receive snotices, so we iterate the oper list */
128         for (std::list<User*>::iterator i = ServerInstance->all_opers.begin(); i != ServerInstance->all_opers.end(); i++)
129         {
130                 User* a = *i;
131                 if (IS_LOCAL(a) && a->IsModeSet('s') && a->IsModeSet('n') && a->IsNoticeMaskSet(MySnomask))
132                 {
133                         a->WriteServ("NOTICE %s :*** %s: %s", a->nick, this->Description.c_str(), this->LastMessage.c_str());
134                         if (Count > 1)
135                         {
136                                 a->WriteServ("NOTICE %s :*** %s: (last message repeated %u times)", a->nick, this->Description.c_str(), Count);
137                         }
138                 }
139         }
140
141         LastMessage = "";
142         Count = 1;
143 }