From 6939a79a67d863ee9585b40b6c4af3bcaacf6a17 Mon Sep 17 00:00:00 2001 From: delthas Date: Wed, 2 Nov 2022 13:18:37 +0100 Subject: Add support for the IRCv3 extended-monitor specification. Co-authored-by: Sadie Powell --- include/modules/monitor.h | 92 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 include/modules/monitor.h (limited to 'include/modules') diff --git a/include/modules/monitor.h b/include/modules/monitor.h new file mode 100644 index 000000000..dd52fec6c --- /dev/null +++ b/include/modules/monitor.h @@ -0,0 +1,92 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2022 Sadie Powell + * Copyright (C) 2021 delthas + * + * 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 . + */ + + +#pragma once + +namespace Monitor +{ + class APIBase; + class API; + class ForEachHandler; + class WriteWatchersWithCap; +} + +class Monitor::APIBase + : public DataProvider +{ + public: + APIBase(Module* parent) + : DataProvider(parent, "monitor") + { + } + + /** Runs the provided handler for all watchers of a user + * @param user The user to check watchers for. + * @param handler The handler to execute for each watcher of that event. + * @param extended_only Whether to only run the handler for watchers using the extended-notify cap. + */ + virtual void ForEachWatcher(User* user, ForEachHandler& handler, bool extended_only = true) = 0; +}; + +class Monitor::API CXX11_FINAL + : public dynamic_reference +{ + public: + API(Module* parent) + : dynamic_reference(parent, "monitor") + { + } +}; + +class Monitor::ForEachHandler +{ + public: + /** Method to execute for each watcher of a user. + * Derived classes must implement this. + * @param user Current watcher of the user + */ + virtual void Execute(LocalUser* user) = 0; +}; + + +class Monitor::WriteWatchersWithCap + : public Monitor::ForEachHandler +{ + private: + const Cap::Capability& cap; + ClientProtocol::Event& ev; + already_sent_t sentid; + + void Execute(LocalUser* user) CXX11_OVERRIDE + { + if (user->already_sent != sentid && cap.get(user)) + user->Send(ev); + } + + public: + WriteWatchersWithCap(Monitor::API& monitorapi, User* user, ClientProtocol::Event& event, const Cap::Capability& capability, already_sent_t id) + : cap(capability) + , ev(event) + , sentid(id) + { + if (monitorapi) + monitorapi->ForEachWatcher(user, *this); + } +}; -- cgit v1.3.1-10-gc9f91