2012-04-19 20:58:29 +02:00
|
|
|
/*
|
|
|
|
* InspIRCd -- Internet Relay Chat Daemon
|
2007-07-16 17:30:04 +00:00
|
|
|
*
|
2024-09-07 11:10:36 +01:00
|
|
|
* Copyright (C) 2013, 2017, 2020-2021, 2023-2024 Sadie Powell <sadie@witchery.services>
|
2024-06-07 10:37:56 +01:00
|
|
|
* Copyright (C) 2013 Attila Molnar <attilamolnar@hush.com>
|
2020-01-11 22:02:47 +00:00
|
|
|
* Copyright (C) 2012 Robby <robby@chatbelgie.be>
|
|
|
|
* Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
|
2012-04-19 20:58:29 +02:00
|
|
|
* Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
|
|
|
|
* Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
|
2022-12-30 11:31:28 +00:00
|
|
|
* Copyright (C) 2006 Craig Edwards <brain@inspircd.org>
|
2007-07-16 17:30:04 +00:00
|
|
|
*
|
2012-04-19 20:58:29 +02:00
|
|
|
* This file is part of InspIRCd. InspIRCd is free software: you can
|
|
|
|
* redistribute it and/or modify it under the terms of the GNU General Public
|
|
|
|
* License as published by the Free Software Foundation, version 2.
|
2007-07-16 17:30:04 +00:00
|
|
|
*
|
2012-04-19 20:58:29 +02:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-07-16 17:30:04 +00:00
|
|
|
*/
|
|
|
|
|
2012-04-19 20:58:29 +02:00
|
|
|
|
2013-04-02 20:12:15 +01:00
|
|
|
#pragma once
|
2007-07-16 17:30:04 +00:00
|
|
|
|
2013-07-20 20:30:18 +02:00
|
|
|
class SnomaskManager;
|
2021-12-20 20:00:03 +00:00
|
|
|
class Snomask final
|
2008-01-04 14:49:40 +00:00
|
|
|
{
|
2013-07-20 20:30:18 +02:00
|
|
|
/** Description of this snomask, e.g.: OPER, ANNOUNCEMENT, XLINE
|
|
|
|
*/
|
2008-01-04 20:34:25 +00:00
|
|
|
std::string Description;
|
2013-07-20 20:30:18 +02:00
|
|
|
|
|
|
|
/** Information about the last sent message,
|
|
|
|
* used for sending "last message repeated X times" messages
|
|
|
|
*/
|
2008-01-05 15:54:37 +00:00
|
|
|
std::string LastMessage;
|
2010-02-25 19:42:08 +00:00
|
|
|
char LastLetter;
|
2020-02-06 11:25:42 +00:00
|
|
|
unsigned int Count = 0;
|
2008-01-04 14:49:40 +00:00
|
|
|
|
2013-07-20 20:30:18 +02:00
|
|
|
/** Log and send a message to all opers who have the given snomask set
|
|
|
|
* @param letter The target users of this message
|
|
|
|
* @param desc The description of this snomask, will be prepended to the message
|
|
|
|
* @param msg The message to send
|
|
|
|
*/
|
|
|
|
static void Send(char letter, const std::string& desc, const std::string& msg);
|
|
|
|
|
2022-01-25 13:59:42 +00:00
|
|
|
public:
|
2008-01-05 15:54:37 +00:00
|
|
|
/** Sends a message to all opers with this snomask.
|
2013-07-20 20:30:18 +02:00
|
|
|
* @param message The message to send
|
2017-08-25 13:03:53 +01:00
|
|
|
* @param letter The snomask character to send the message to.
|
2008-01-05 15:54:37 +00:00
|
|
|
*/
|
2013-07-20 20:30:18 +02:00
|
|
|
void SendMessage(const std::string& message, char letter);
|
2008-01-05 16:57:42 +00:00
|
|
|
|
2009-03-10 22:55:55 +00:00
|
|
|
/** Sends out the (last message repeated N times) message
|
2008-01-05 16:57:42 +00:00
|
|
|
*/
|
|
|
|
void Flush();
|
2013-07-20 20:30:18 +02:00
|
|
|
|
|
|
|
/** Returns the description of this snomask
|
2013-08-08 15:10:48 +02:00
|
|
|
* @param letter The letter of this snomask. If uppercase, the description of the remote
|
|
|
|
* variant of this snomask will be returned (i.e.: "REMOTE" will be prepended to the description).
|
2013-07-20 20:30:18 +02:00
|
|
|
* @return The description of this snomask
|
|
|
|
*/
|
|
|
|
std::string GetDescription(char letter) const;
|
|
|
|
|
|
|
|
friend class SnomaskManager;
|
2008-01-04 14:49:40 +00:00
|
|
|
};
|
|
|
|
|
2012-04-19 10:30:08 +02:00
|
|
|
/** Snomask manager handles routing of SNOMASK (usermode +s) messages to opers.
|
2007-07-16 17:30:04 +00:00
|
|
|
* Modules and the core can enable and disable snomask characters. If they do,
|
|
|
|
* then sending snomasks using these characters becomes possible.
|
|
|
|
*/
|
2021-12-20 20:00:03 +00:00
|
|
|
class CoreExport SnomaskManager final
|
2007-07-16 17:30:04 +00:00
|
|
|
{
|
2010-02-25 19:42:08 +00:00
|
|
|
Snomask masks[26];
|
|
|
|
|
2022-01-25 13:59:42 +00:00
|
|
|
public:
|
2007-07-16 17:30:04 +00:00
|
|
|
/** Create a new SnomaskManager
|
|
|
|
*/
|
2009-09-26 14:13:13 +00:00
|
|
|
SnomaskManager();
|
2008-01-04 14:49:40 +00:00
|
|
|
|
2007-07-16 17:30:04 +00:00
|
|
|
/** Enable a snomask.
|
|
|
|
* @param letter The snomask letter to enable. Once enabled,
|
|
|
|
* server notices may be routed to users with this letter in
|
|
|
|
* their list, and users may add this letter to their list.
|
|
|
|
* @param description The descriptive text sent along with any
|
|
|
|
* server notices, at the start of the notice, e.g. "GLOBOPS".
|
|
|
|
*/
|
2022-09-29 12:01:29 +01:00
|
|
|
void EnableSnomask(char letter, const std::string& description);
|
2008-01-04 14:49:40 +00:00
|
|
|
|
2009-04-18 19:51:24 +00:00
|
|
|
/** Write to all users with a given snomask (local server only)
|
2007-07-16 17:30:04 +00:00
|
|
|
* @param letter The snomask letter to write to
|
|
|
|
* @param text The text to send to the users
|
|
|
|
*/
|
2022-09-29 12:01:29 +01:00
|
|
|
void WriteToSnoMask(char letter, const std::string& text);
|
2008-01-04 14:49:40 +00:00
|
|
|
|
2009-04-18 19:51:24 +00:00
|
|
|
/** Write to all users with a given snomask (local server only)
|
2007-07-16 17:30:04 +00:00
|
|
|
* @param letter The snomask letter to write to
|
|
|
|
* @param text A format string containing text to send
|
2023-01-23 09:37:15 +00:00
|
|
|
* @param args Format arguments
|
2007-07-16 17:30:04 +00:00
|
|
|
*/
|
2023-01-23 09:37:15 +00:00
|
|
|
template <typename... Args>
|
|
|
|
void WriteToSnoMask(char letter, const char* text, Args&&... args)
|
|
|
|
{
|
2024-08-22 09:41:36 +01:00
|
|
|
WriteToSnoMask(letter, fmt::vformat(text, fmt::make_format_args(args...)));
|
2023-01-23 09:37:15 +00:00
|
|
|
}
|
2008-01-04 14:49:40 +00:00
|
|
|
|
2009-04-18 19:51:24 +00:00
|
|
|
/** Write to all users with a given snomask (sent globally)
|
|
|
|
* @param letter The snomask letter to write to
|
|
|
|
* @param text The text to send to the users
|
|
|
|
*/
|
2022-09-29 12:01:29 +01:00
|
|
|
void WriteGlobalSno(char letter, const std::string& text);
|
2009-04-18 19:51:24 +00:00
|
|
|
|
|
|
|
/** Write to all users with a given snomask (sent globally)
|
|
|
|
* @param letter The snomask letter to write to
|
|
|
|
* @param text A format string containing text to send
|
2023-01-23 09:37:15 +00:00
|
|
|
* @param args Format arguments
|
2009-04-18 19:51:24 +00:00
|
|
|
*/
|
2023-01-23 09:37:15 +00:00
|
|
|
template <typename... Args>
|
|
|
|
void WriteGlobalSno(char letter, const char* text, Args&&... args)
|
|
|
|
{
|
2024-08-22 09:41:36 +01:00
|
|
|
WriteGlobalSno(letter, fmt::vformat(text, fmt::make_format_args(args...)));
|
2023-01-23 09:37:15 +00:00
|
|
|
}
|
2009-04-18 19:51:24 +00:00
|
|
|
|
2008-01-04 14:49:40 +00:00
|
|
|
/** Called once per 5 seconds from the mainloop, this flushes any cached
|
|
|
|
* snotices. The way the caching works is as follows:
|
|
|
|
* Calls to WriteToSnoMask write to a cache, if the call is the same as it was
|
|
|
|
* for the previous call, then a count is incremented. If it is different,
|
|
|
|
* the previous message it just sent normally via NOTICE (with count if > 1)
|
|
|
|
* and the new message is cached. This acts as a sender in case the number of notices
|
|
|
|
* is not particularly significant, in order to keep notices going out.
|
|
|
|
*/
|
|
|
|
void FlushSnotices();
|
2013-07-20 20:30:18 +02:00
|
|
|
|
2023-01-02 22:33:19 +00:00
|
|
|
/** Check whether a given character is a valid snomask.
|
|
|
|
* @param ch The character to check
|
|
|
|
* @return True if the given char is allowed to be set via +s.
|
|
|
|
*/
|
|
|
|
static bool IsSnomask(char ch);
|
|
|
|
|
2013-07-20 20:30:18 +02:00
|
|
|
/** Check whether a given character is an enabled (initialized) snomask.
|
|
|
|
* Valid snomask chars are lower- or uppercase letters and have a description.
|
|
|
|
* Snomasks are initialized with EnableSnomask().
|
|
|
|
* @param ch The character to check
|
|
|
|
* @return True if the given char is allowed to be set via +s.
|
|
|
|
*/
|
|
|
|
bool IsSnomaskUsable(char ch) const;
|
2007-07-16 17:30:04 +00:00
|
|
|
};
|