]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/snomasks.cpp
Snomask support cometh! and it leave a sticky white mess all over the floor :(
[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 }
31
32 SnomaskManager::~SnomaskManager()
33 {
34 }
35
36 bool SnomaskManager::EnableSnomask(char letter, const std::string &type)
37 {
38         if (SnoMasks.find(letter) == SnoMasks.end())
39         {
40                 SnoMasks[letter] = type;
41                 return true;
42         }
43         return false;
44 }
45
46 bool SnomaskManager::DisableSnomask(char letter)
47 {
48         SnoList::iterator n = SnoMasks.find(letter);
49         if (n != SnoMasks.end())
50         {
51                 SnoMasks.erase(n);
52                 return true;
53         }
54         return false;
55 }
56
57 void SnomaskManager::WriteToSnoMask(char letter, const std::string &text)
58 {
59         /* Only send to snomask chars which are enabled */
60         SnoList::iterator n = SnoMasks.find(letter);
61         if (n != SnoMasks.end())
62         {
63                 /* Only opers can receive snotices, so we iterate the oper list */
64                 for (std::vector<userrec*>::iterator i = ServerInstance->all_opers.begin(); i != ServerInstance->all_opers.end(); i++)
65                 {
66                         userrec* a = *i;
67                         if (IS_LOCAL(a) && a->modes[UM_SERVERNOTICE] && a->modes[UM_SNOMASK] && a->IsNoticeMaskSet(n->first))
68                         {
69                                 /* send server notices to all with +ns */
70                                 a->WriteServ("NOTICE %s :*** %s: %s",a->nick, n->second.c_str(), text.c_str());
71                         }
72                 }
73         }
74 }
75
76 void SnomaskManager::WriteToSnoMask(char letter, const char* text, ...)
77 {
78         char textbuffer[MAXBUF];
79         va_list argsPtr;
80
81         va_start(argsPtr, text);
82         vsnprintf(textbuffer, MAXBUF, text, argsPtr);
83         va_end(argsPtr);
84
85         this->WriteToSnoMask(letter, std::string(textbuffer));
86 }
87
88 bool SnomaskManager::IsEnabled(char letter)
89 {
90         return (SnoMasks.find(letter) != SnoMasks.end());
91 }
92