2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2019 Peter Powell <petpow@saberuk.com>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "modules/geolocation.h"
22 #include "modules/whois.h"
27 RPL_WHOISCOUNTRY = 344
32 , public Whois::EventListener
35 Geolocation::API geoapi;
39 : Whois::EventListener(this)
44 Version GetVersion() CXX11_OVERRIDE
46 return Version("Provides a way to ban users by country", VF_OPTCOMMON|VF_VENDOR);
49 void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
51 tokens["EXTBAN"].push_back('G');
54 ModResult OnCheckBan(User* user, Channel*, const std::string& mask) CXX11_OVERRIDE
56 if ((mask.length() > 2) && (mask[0] == 'G') && (mask[1] == ':'))
58 Geolocation::Location* location = geoapi ? geoapi->GetLocation(user) : NULL;
59 const std::string code = location ? location->GetCode() : "XX";
61 // Does this user match against the ban?
62 if (InspIRCd::Match(code, mask.substr(2)))
65 return MOD_RES_PASSTHRU;
68 void OnWhois(Whois::Context& whois) CXX11_OVERRIDE
70 Geolocation::Location* location = geoapi ? geoapi->GetLocation(whois.GetTarget()) : NULL;
72 whois.SendLine(RPL_WHOISCOUNTRY, location->GetCode(), "is connecting from " + location->GetName());
74 whois.SendLine(RPL_WHOISCOUNTRY, "*", "is connecting from an unknown country");
78 MODULE_INIT(ModuleGeoBan)