2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2015 Attila Molnar <attilamolnar@hush.com>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "modules/cap.h"
26 class WriteNeighborsWithCap;
31 class IRCv3::WriteNeighborsWithCap : public User::ForEachNeighborHandler
33 const Cap::Capability& cap;
34 ClientProtocol::Event& protoev;
36 void Execute(LocalUser* user) CXX11_OVERRIDE
43 WriteNeighborsWithCap(User* user, ClientProtocol::Event& ev, const Cap::Capability& capability)
47 user->ForEachNeighbor(*this, false);
51 /** Base class for simple message tags.
52 * Message tags provided by classes derived from this class will be sent to clients that have negotiated
53 * a client capability, also managed by this class.
55 * Derived classes specify the name of the capability and the message tag and provide a public GetValue()
56 * method with the following signature: const std::string* GetValue(ClientProtocol::Message& msg).
57 * The returned value determines whether to attach the tag to the message. If it is NULL, the tag won't
58 * be attached. If it is non-NULL the tag will be attached with the value in the string. If the string is
59 * empty the tag is attached without a value.
61 * Providers inheriting from this class don't accept incoming tags by default.
63 * For more control, inherit from ClientProtocol::MessageTagProvider directly.
65 * Template parameter T is the derived class.
68 class IRCv3::CapTag : public ClientProtocol::MessageTagProvider
71 const std::string tagname;
73 bool ShouldSendTag(LocalUser* user, const ClientProtocol::MessageTagData& tagdata) CXX11_OVERRIDE
78 void OnClientProtocolPopulateTags(ClientProtocol::Message& msg) CXX11_OVERRIDE
80 T& tag = static_cast<T&>(*this);
81 const std::string* const val = tag.GetValue(msg);
83 msg.AddTag(tagname, this, *val);
88 * @param mod Module that owns the tag.
89 * @param capname Name of the client capability.
90 * A client capability with this name will be created. It will be available to all clients and it won't
92 * See Cap::Capability for more info on client capabilities.
93 * @param Tagname Name of the message tag, to use in the protocol.
95 CapTag(Module* mod, const std::string& capname, const std::string& Tagname)
96 : ClientProtocol::MessageTagProvider(mod)