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