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