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