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 --- src/modules/m_monitor.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/modules/m_monitor.cpp') diff --git a/src/modules/m_monitor.cpp b/src/modules/m_monitor.cpp index 823a6fe5d..93212f633 100644 --- a/src/modules/m_monitor.cpp +++ b/src/modules/m_monitor.cpp @@ -20,6 +20,8 @@ #include "inspircd.h" +#include "modules/cap.h" +#include "modules/monitor.h" namespace IRCv3 { @@ -369,10 +371,13 @@ class CommandMonitor : public SplitCommand } }; -class ModuleMonitor : public Module +class ModuleMonitor + : public Module + , public Monitor::APIBase { IRCv3::Monitor::Manager manager; CommandMonitor cmd; + Cap::Capability extendedcap; void SendAlert(unsigned int numeric, const std::string& nick) { @@ -389,8 +394,10 @@ class ModuleMonitor : public Module public: ModuleMonitor() - : manager(this, "monitor") + : Monitor::APIBase(this) + , manager(this, "monitor") , cmd(this, manager) + , extendedcap(this, "draft/extended-monitor") { } @@ -428,6 +435,20 @@ class ModuleMonitor : public Module tokens["MONITOR"] = ConvToStr(cmd.maxmonitor); } + void ForEachWatcher(User* user, Monitor::ForEachHandler& handler, bool extended_only) CXX11_OVERRIDE + { + const IRCv3::Monitor::WatcherList* list = manager.GetWatcherList(user->nick); + if (!list) + return; + + for (IRCv3::Monitor::WatcherList::const_iterator i = list->begin(); i != list->end(); ++i) + { + LocalUser* curr = *i; + if(!extended_only || extendedcap.get(curr)) + handler.Execute(curr); + } + } + Version GetVersion() CXX11_OVERRIDE { return Version("Adds the /MONITOR command which allows users to find out when their friends are connected to the server.", VF_VENDOR); -- cgit v1.3.1-10-gc9f91