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