]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/snomasks.h
Merge insp20
[user/henk/code/inspircd.git] / include / snomasks.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2010 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
6  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
7  *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
8  *
9  * This file is part of InspIRCd.  InspIRCd is free software: you can
10  * redistribute it and/or modify it under the terms of the GNU General Public
11  * License as published by the Free Software Foundation, version 2.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22
23 #pragma once
24
25 class SnomaskManager;
26 class Snomask
27 {
28         /** Description of this snomask, e.g.: OPER, ANNOUNCEMENT, XLINE
29          */
30         std::string Description;
31
32         /** Information about the last sent message,
33          * used for sending "last message repeated X times" messages
34          */
35         std::string LastMessage;
36         char LastLetter;
37         unsigned int Count;
38
39         /** Log and send a message to all opers who have the given snomask set
40          * @param letter The target users of this message
41          * @param desc The description of this snomask, will be prepended to the message
42          * @param msg The message to send
43          */
44         static void Send(char letter, const std::string& desc, const std::string& msg);
45
46  public:
47         /** Create a new Snomask
48          */
49         Snomask();
50
51         /** Sends a message to all opers with this snomask.
52          * @param message The message to send
53          * @param remote If true the message will go to the uppercase variant of this snomask
54          */
55         void SendMessage(const std::string& message, char letter);
56
57         /** Sends out the (last message repeated N times) message
58          */
59         void Flush();
60
61         /** Returns the description of this snomask
62          * @param letter The letter of this snomask. If uppercase, the description of the remote
63          * variant of this snomask will be returned (i.e.: "REMOTE" will be prepended to the description).
64          * @return The description of this snomask
65          */
66         std::string GetDescription(char letter) const;
67
68         friend class SnomaskManager;
69 };
70
71 /** Snomask manager handles routing of SNOMASK (usermode +s) messages to opers.
72  * Modules and the core can enable and disable snomask characters. If they do,
73  * then sending snomasks using these characters becomes possible.
74  */
75 class CoreExport SnomaskManager
76 {
77         Snomask masks[26];
78
79  public:
80         /** Create a new SnomaskManager
81          */
82         SnomaskManager();
83
84         /** Enable a snomask.
85          * @param letter The snomask letter to enable. Once enabled,
86          * server notices may be routed to users with this letter in
87          * their list, and users may add this letter to their list.
88          * @param description The descriptive text sent along with any
89          * server notices, at the start of the notice, e.g. "GLOBOPS".
90          */
91         void EnableSnomask(char letter, const std::string &description);
92
93         /** Write to all users with a given snomask (local server only)
94          * @param letter The snomask letter to write to
95          * @param text The text to send to the users
96          */
97         void WriteToSnoMask(char letter, const std::string &text);
98
99         /** Write to all users with a given snomask (local server only)
100          * @param letter The snomask letter to write to
101          * @param text A format string containing text to send
102          * @param ... Format arguments
103          */
104         void WriteToSnoMask(char letter, const char* text, ...) CUSTOM_PRINTF(3, 4);
105
106         /** Write to all users with a given snomask (sent globally)
107          * @param letter The snomask letter to write to
108          * @param text The text to send to the users
109          */
110         void WriteGlobalSno(char letter, const std::string &text);
111
112         /** Write to all users with a given snomask (sent globally)
113          * @param letter The snomask letter to write to
114          * @param text A format string containing text to send
115          * @param ... Format arguments
116          */
117         void WriteGlobalSno(char letter, const char* text, ...) CUSTOM_PRINTF(3, 4);
118
119         /** Called once per 5 seconds from the mainloop, this flushes any cached
120          * snotices. The way the caching works is as follows:
121          * Calls to WriteToSnoMask write to a cache, if the call is the same as it was
122          * for the previous call, then a count is incremented. If it is different,
123          * the previous message it just sent normally via NOTICE (with count if > 1)
124          * and the new message is cached. This acts as a sender in case the number of notices
125          * is not particularly significant, in order to keep notices going out.
126          */
127         void FlushSnotices();
128
129         /** Check whether a given character is an enabled (initialized) snomask.
130          * Valid snomask chars are lower- or uppercase letters and have a description.
131          * Snomasks are initialized with EnableSnomask().
132          * @param ch The character to check
133          * @return True if the given char is allowed to be set via +s.
134          */
135         bool IsSnomaskUsable(char ch) const;
136 };