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