X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fmodules%2Fircv3.h;h=71bff21722ffaa148d5c8cc575f7c918ca0a9d29;hb=635cb9d65f6d7f6758ae8ed874da00c8d94b6e39;hp=e03ee16fa061c3d69e1d1fd7bf2ff55fa1f75b9d;hpb=124c17e14134a4999afc1a5e981ab7c75b3694b9;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/modules/ircv3.h b/include/modules/ircv3.h index e03ee16fa..71bff2172 100644 --- a/include/modules/ircv3.h +++ b/include/modules/ircv3.h @@ -1,7 +1,8 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2015 Attila Molnar + * Copyright (C) 2018-2019 Sadie Powell + * Copyright (C) 2015, 2018 Attila Molnar * * 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 @@ -19,27 +20,84 @@ #pragma once +#include "modules/cap.h" + namespace IRCv3 { class WriteNeighborsWithCap; + template + class CapTag; } class IRCv3::WriteNeighborsWithCap : public User::ForEachNeighborHandler { const Cap::Capability& cap; - const std::string& msg; + ClientProtocol::Event& protoev; void Execute(LocalUser* user) CXX11_OVERRIDE { if (cap.get(user)) - user->Write(msg); + user->Send(protoev); } public: - WriteNeighborsWithCap(User* user, const std::string& message, const Cap::Capability& capability) + WriteNeighborsWithCap(User* user, ClientProtocol::Event& ev, const Cap::Capability& capability, bool include_self = false) : cap(capability) - , msg(message) + , protoev(ev) + { + user->ForEachNeighbor(*this, include_self); + } +}; + +/** Base class for simple message tags. + * Message tags provided by classes derived from this class will be sent to clients that have negotiated + * a client capability, also managed by this class. + * + * Derived classes specify the name of the capability and the message tag and provide a public GetValue() + * method with the following signature: const std::string* GetValue(ClientProtocol::Message& msg). + * The returned value determines whether to attach the tag to the message. If it is NULL, the tag won't + * be attached. If it is non-NULL the tag will be attached with the value in the string. If the string is + * empty the tag is attached without a value. + * + * Providers inheriting from this class don't accept incoming tags by default. + * + * For more control, inherit from ClientProtocol::MessageTagProvider directly. + * + * Template parameter T is the derived class. + */ +template +class IRCv3::CapTag : public ClientProtocol::MessageTagProvider +{ + protected: + Cap::Capability cap; + const std::string tagname; + + bool ShouldSendTag(LocalUser* user, const ClientProtocol::MessageTagData& tagdata) CXX11_OVERRIDE + { + return cap.get(user); + } + + void OnPopulateTags(ClientProtocol::Message& msg) CXX11_OVERRIDE + { + T& tag = static_cast(*this); + const std::string* const val = tag.GetValue(msg); + if (val) + msg.AddTag(tagname, this, *val); + } + + public: + /** Constructor. + * @param mod Module that owns the tag. + * @param capname Name of the client capability. + * A client capability with this name will be created. It will be available to all clients and it won't + * have a value. + * See Cap::Capability for more info on client capabilities. + * @param Tagname Name of the message tag, to use in the protocol. + */ + CapTag(Module* mod, const std::string& capname, const std::string& Tagname) + : ClientProtocol::MessageTagProvider(mod) + , cap(mod, capname) + , tagname(Tagname) { - user->ForEachNeighbor(*this, false); } };