2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2018-2019 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2015, 2018 Attila Molnar <attilamolnar@hush.com>
7 * This file is part of InspIRCd. InspIRCd is free software: you can
8 * redistribute it and/or modify it under the terms of the GNU General Public
9 * License as published by the Free Software Foundation, version 2.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "modules/cap.h"
27 class WriteNeighborsWithCap;
32 class IRCv3::WriteNeighborsWithCap : public User::ForEachNeighborHandler
34 const Cap::Capability& cap;
35 ClientProtocol::Event& protoev;
37 void Execute(LocalUser* user) CXX11_OVERRIDE
44 WriteNeighborsWithCap(User* user, ClientProtocol::Event& ev, const Cap::Capability& capability, bool include_self = false)
48 user->ForEachNeighbor(*this, include_self);
52 /** Base class for simple message tags.
53 * Message tags provided by classes derived from this class will be sent to clients that have negotiated
54 * a client capability, also managed by this class.
56 * Derived classes specify the name of the capability and the message tag and provide a public GetValue()
57 * method with the following signature: const std::string* GetValue(ClientProtocol::Message& msg).
58 * The returned value determines whether to attach the tag to the message. If it is NULL, the tag won't
59 * be attached. If it is non-NULL the tag will be attached with the value in the string. If the string is
60 * empty the tag is attached without a value.
62 * Providers inheriting from this class don't accept incoming tags by default.
64 * For more control, inherit from ClientProtocol::MessageTagProvider directly.
66 * Template parameter T is the derived class.
69 class IRCv3::CapTag : public ClientProtocol::MessageTagProvider
73 const std::string tagname;
75 bool ShouldSendTag(LocalUser* user, const ClientProtocol::MessageTagData& tagdata) CXX11_OVERRIDE
80 void OnPopulateTags(ClientProtocol::Message& msg) CXX11_OVERRIDE
82 T& tag = static_cast<T&>(*this);
83 const std::string* const val = tag.GetValue(msg);
85 msg.AddTag(tagname, this, *val);
90 * @param mod Module that owns the tag.
91 * @param capname Name of the client capability.
92 * A client capability with this name will be created. It will be available to all clients and it won't
94 * See Cap::Capability for more info on client capabilities.
95 * @param Tagname Name of the message tag, to use in the protocol.
97 CapTag(Module* mod, const std::string& capname, const std::string& Tagname)
98 : ClientProtocol::MessageTagProvider(mod)