]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/snomasks.h
334bbf0dc447fed600b02ef46c06aa87429044bb
[user/henk/code/inspircd.git] / include / snomasks.h
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 #ifndef __SNOMASKS_H__
15 #define __SNOMASKS_H__
16
17 #include <string>
18 #include <vector>
19 #include <map>
20 #include "configreader.h"
21 #include "inspircd.h"
22
23 class Snomask
24 {
25  private:
26         InspIRCd *ServerInstance;
27
28  public:
29         char MySnomask;
30         std::string Description;
31         std::string LastMessage;
32         unsigned int Count;
33
34         /** Create a new Snomask
35          */
36         Snomask(InspIRCd* Instance, char snomask, const std::string &description)
37         {
38                 ServerInstance = Instance;
39                 MySnomask = snomask;
40                 Description = description;
41         }
42
43         /** Sends a message to all opers with this snomask.
44          */
45         void SendMessage(const std::string &message);
46
47         /** Sends out a pending message
48          */
49         void Flush();
50 };
51
52 /** A list of snomasks which are valid, and their descriptive texts
53  */
54 typedef std::map<char, Snomask *> SnoList;
55
56 /** Snomask manager handles routing of SNOMASK (usermode +n) messages to opers.
57  * Modules and the core can enable and disable snomask characters. If they do,
58  * then sending snomasks using these characters becomes possible.
59  */
60 class CoreExport SnomaskManager : public Extensible
61 {
62  private:
63         /** Creator/owner
64          */
65         InspIRCd* ServerInstance;
66
67         /** Currently active snomask list
68          */
69         SnoList SnoMasks;
70
71         /** Set up the default (core available) snomask chars
72          */
73         void SetupDefaults();
74  public:
75         /** Create a new SnomaskManager
76          */
77         SnomaskManager(InspIRCd* Instance);
78
79         /** Delete SnomaskManager
80          */
81         ~SnomaskManager();
82
83         /** Enable a snomask.
84          * @param letter The snomask letter to enable. Once enabled,
85          * server notices may be routed to users with this letter in
86          * their list, and users may add this letter to their list.
87          * @param description The descriptive text sent along with any
88          * server notices, at the start of the notice, e.g. "GLOBOPS".
89          * @return True if the snomask was enabled, false if it already
90          * exists.
91          */
92         bool EnableSnomask(char letter, const std::string &description);
93
94         /** Disable a snomask.
95          * @param letter The snomask letter to disable.
96          * @return True if the snomask was disabled, false if it didn't
97          * exist.
98          */
99         bool DisableSnomask(char letter);
100
101         /** Write to all users with a given snomask.
102          * @param letter The snomask letter to write to
103          * @param text The text to send to the users
104          */
105         void WriteToSnoMask(char letter, const std::string &text);
106
107         /** Write to all users with a given snomask.
108          * @param letter The snomask letter to write to
109          * @param text A format string containing text to send
110          * @param ... Format arguments
111          */
112         void WriteToSnoMask(char letter, const char* text, ...);
113
114         /** Called once per 5 seconds from the mainloop, this flushes any cached
115          * snotices. The way the caching works is as follows:
116          * Calls to WriteToSnoMask write to a cache, if the call is the same as it was
117          * for the previous call, then a count is incremented. If it is different,
118          * the previous message it just sent normally via NOTICE (with count if > 1)
119          * and the new message is cached. This acts as a sender in case the number of notices
120          * is not particularly significant, in order to keep notices going out.
121          */
122         void FlushSnotices();
123
124         /** Check if a snomask is enabled.
125          * @param letter The snomask letter to check.
126          * @return True if the snomask has been enabled.
127          */
128         bool IsEnabled(char letter);
129 };
130
131 #endif