2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2020 Matt Schatz <genius3000@g3k.solutions>
5 * Copyright (C) 2019, 2021 Sadie Powell <sadie@witchery.services>
7 * This file is part of InspIRCd. InspIRCd is free software: you can
8 * redistribute it and/or modify it under the terms of the GNU General Public
9 * License as published by the Free Software Foundation, version 2.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "modules/geolocation.h"
23 #include "modules/whois.h"
28 RPL_WHOISCOUNTRY = 344
33 , public Whois::EventListener
36 Geolocation::API geoapi;
40 : Whois::EventListener(this)
45 Version GetVersion() CXX11_OVERRIDE
47 return Version("Adds extended ban G: which matches against two letter country codes.", VF_OPTCOMMON|VF_VENDOR);
50 void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
52 tokens["EXTBAN"].push_back('G');
55 ModResult OnCheckBan(User* user, Channel*, const std::string& mask) CXX11_OVERRIDE
57 if ((mask.length() > 2) && (mask[0] == 'G') && (mask[1] == ':'))
59 Geolocation::Location* location = geoapi ? geoapi->GetLocation(user) : NULL;
60 const std::string code = location ? location->GetCode() : "XX";
62 // Does this user match against the ban?
63 if (InspIRCd::Match(code, mask.substr(2)))
66 return MOD_RES_PASSTHRU;
69 void OnWhois(Whois::Context& whois) CXX11_OVERRIDE
71 if (whois.GetTarget()->server->IsULine())
74 Geolocation::Location* location = geoapi ? geoapi->GetLocation(whois.GetTarget()) : NULL;
76 whois.SendLine(RPL_WHOISCOUNTRY, location->GetCode(), "is connecting from " + location->GetName());
78 whois.SendLine(RPL_WHOISCOUNTRY, "*", "is connecting from an unknown country");
82 MODULE_INIT(ModuleGeoBan)