From d9be3ed77fac2601d813b2c85e2d9e1a02d61668 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Thu, 24 Mar 2022 02:33:59 +0000 Subject: Add support for matching against geolocation data with WHO. Closes #1969. --- src/modules/m_geoban.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/modules/m_geoban.cpp') diff --git a/src/modules/m_geoban.cpp b/src/modules/m_geoban.cpp index 7e44ffa1f..1e0e6cd74 100644 --- a/src/modules/m_geoban.cpp +++ b/src/modules/m_geoban.cpp @@ -20,10 +20,12 @@ #include "inspircd.h" #include "modules/geolocation.h" +#include "modules/who.h" #include "modules/whois.h" class ModuleGeoBan : public Module + , public Who::MatchEventListener , public Whois::EventListener { private: @@ -31,7 +33,8 @@ class ModuleGeoBan public: ModuleGeoBan() - : Whois::EventListener(this) + : Who::MatchEventListener(this) + , Whois::EventListener(this) , geoapi(this) { } @@ -60,6 +63,16 @@ class ModuleGeoBan return MOD_RES_PASSTHRU; } + ModResult OnWhoMatch(const Who::Request& request, LocalUser* source, User* user) CXX11_OVERRIDE + { + if (!request.flags['G']) + return MOD_RES_PASSTHRU; + + Geolocation::Location* location = geoapi ? geoapi->GetLocation(user) : NULL; + const std::string code = location ? location->GetCode() : "XX"; + return InspIRCd::Match(code, request.matchtext, ascii_case_insensitive_map) ? MOD_RES_ALLOW : MOD_RES_DENY; + } + void OnWhois(Whois::Context& whois) CXX11_OVERRIDE { if (whois.GetTarget()->server->IsULine()) -- cgit v1.3.1-10-gc9f91