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