1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
/*
* InspIRCd -- Internet Relay Chat Daemon
*
* Copyright (C) 2018-2022, 2024-2025 Sadie Powell <sadie@witchery.services>
* Copyright (C) 2016 Attila Molnar <attilamolnar@hush.com>
*
* 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.
*
* 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/>.
*/
#pragma once
// These numerics are used in multiple source files.
enum
{
// From RFC 1459
RPL_LUSEROP = 252,
RPL_AWAY = 301,
RPL_LISTSTART = 321,
RPL_LIST = 322,
RPL_LISTEND = 323,
RPL_VERSION = 351,
RPL_LINKS = 364,
RPL_ENDOFLINKS = 365,
RPL_TIME = 391,
ERR_NOSUCHNICK = 401,
ERR_NOSUCHCHANNEL = 403,
ERR_NORECIPIENT = 411,
ERR_NOTEXTTOSEND = 412,
ERR_UNKNOWNCOMMAND = 421,
ERR_NONICKNAMEGIVEN = 431,
ERR_ERRONEUSNICKNAME = 432,
ERR_NICKNAMEINUSE = 433,
ERR_USERNOTINCHANNEL = 441,
ERR_NOTONCHANNEL = 442,
ERR_NOTREGISTERED = 451,
ERR_NEEDMOREPARAMS = 461,
ERR_YOUREBANNEDCREEP = 465,
ERR_UNKNOWNMODE = 472,
ERR_BANNEDFROMCHAN = 474,
ERR_BADCHANMASK = 476,
ERR_NOPRIVILEGES = 481,
ERR_CHANOPRIVSNEEDED = 482,
// From RFC 2812.
ERR_NOSUCHSERVER = 402,
ERR_NOSUCHSERVICE = 408,
ERR_UNAVAILRESOURCE = 437,
ERR_BANLISTFULL = 478,
ERR_RESTRICTED = 484,
// From irc2?
RPL_SAVENICK = 43,
// From ircu.
RPL_YOURDISPLAYEDHOST = 396,
// From UnrealIRCd.
ERR_CANTCHANGENICK = 447,
// InspIRCd-specific.
ERR_UNKNOWNSNOMASK = 501,
RPL_SYNTAX = 650,
ERR_LISTMODEALREADYSET = 697,
ERR_LISTMODENOTSET = 698,
ERR_CANTUNLOADMODULE = 972,
RPL_UNLOADEDMODULE = 973,
ERR_CANTLOADMODULE = 974,
RPL_LOADEDMODULE = 975,
};
namespace Numeric
{
class Numeric;
}
class Numeric::Numeric
{
/** Numeric number
*/
unsigned int numeric;
/** Parameters of the numeric
*/
CommandBase::Params params;
/** Source server of the numeric, if NULL (the default) then it is the local server
*/
Server* sourceserver = nullptr;
public:
/** Constructor
* @param num Numeric number (RPL_*, ERR_*)
*/
Numeric(unsigned int num)
: numeric(num)
{
}
/** Add a tag.
* @param tagname Raw name of the tag to use in the protocol.
* @param tagprov Provider of the tag.
* @param val Tag value. If empty no value will be sent with the tag.
* @param tagdata Tag provider specific data, will be passed to MessageTagProvider::ShouldSendTag(). Optional, defaults to NULL.
*/
Numeric& AddTag(const std::string& tagname, ClientProtocol::MessageTagProvider* tagprov, const std::string& val, void* tagdata = nullptr)
{
params.GetTags().emplace(tagname, ClientProtocol::MessageTagData(tagprov, val, tagdata));
return *this;
}
/** Add all tags in a TagMap to the tags in this message. Existing tags will not be overwritten.
* @param newtags New tags to add.
*/
Numeric& AddTags(const ClientProtocol::TagMap& newtags)
{
params.GetTags().insert(newtags.begin(), newtags.end());
return *this;
}
/** Converts the given arguments to a string and adds them to the numeric.
* @param args One or more arguments to the numeric.
*/
template <typename... Args>
Numeric& push(Args&&... args)
{
(params.push_back(ConvToStr(args)), ...);
return *this;
}
/** Formats the string with the specified arguments and adds them to the numeric.
* @param text A format string to format and then push.
* @param args One or more arguments to format the string with.
*/
template <typename... Args>
Numeric& push_fmt(const char* text, Args&&... args)
{
push(fmt::vformat(text, fmt::make_format_args(args...)));
return *this;
}
/** Set the source server of the numeric. The source server defaults to the local server.
* @param server Server to set as source
*/
void SetServer(Server* server) { sourceserver = server; }
/** Get the source server of the numeric
* @return Source server or NULL if the source is the local server
*/
Server* GetServer() const { return sourceserver; }
/** Get the number of the numeric as an unsigned integer
* @return Numeric number as an unsigned integer
*/
unsigned int GetNumeric() const { return numeric; }
/** Get the parameters of the numeric
* @return Parameters of the numeric as a const vector of strings
*/
const CommandBase::Params& GetParams() const { return params; }
/** Get the parameters of the numeric
* @return Parameters of the numeric as a vector of strings
*/
CommandBase::Params& GetParams() { return params; }
};
|