aboutsummaryrefslogtreecommitdiff
path: root/src/modules/m_geoban.cpp
diff options
context:
space:
mode:
authorGravatar Sadie Powell2022-03-27 15:30:41 +0100
committerGravatar Sadie Powell2022-03-27 15:30:41 +0100
commitf06ea52d0ab08db213b2c2fd81a4dee95910af16 (patch)
tree1d91cc063670e5458ac4124ce1705db74734102b /src/modules/m_geoban.cpp
parentMerge branch 'insp3' into master. (diff)
parentAdd support for matching against geolocation data with WHO. (diff)
Merge branch 'insp3' into master.
Diffstat (limited to 'src/modules/m_geoban.cpp')
-rw-r--r--src/modules/m_geoban.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/modules/m_geoban.cpp b/src/modules/m_geoban.cpp
index ab3194cf2..47a2524c6 100644
--- a/src/modules/m_geoban.cpp
+++ b/src/modules/m_geoban.cpp
@@ -21,6 +21,7 @@
#include "inspircd.h"
#include "modules/extban.h"
#include "modules/geolocation.h"
+#include "modules/who.h"
#include "modules/whois.h"
class CountryExtBan final
@@ -48,6 +49,7 @@ public:
class ModuleGeoBan final
: public Module
+ , public Who::MatchEventListener
, public Whois::EventListener
{
private:
@@ -57,12 +59,23 @@ private:
public:
ModuleGeoBan()
: Module(VF_VENDOR | VF_OPTCOMMON, "Adds extended ban G: (country) which matches against two letter country codes.")
+ , Who::MatchEventListener(this)
, Whois::EventListener(this)
, geoapi(this)
, extban(this, geoapi)
{
}
+ ModResult OnWhoMatch(const Who::Request& request, LocalUser* source, User* user) 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) override
{
if (whois.GetTarget()->server->IsService())