2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
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/>.
27 # pragma comment(lib, "GeoIP.lib")
30 /* $ModDesc: Provides a way to restrict users by country using GeoIP lookup */
31 /* $LinkerFlags: -lGeoIP */
33 class ModuleGeoIP : public Module
39 ModuleGeoIP() : ext("geoip_cc", this), gi(NULL)
45 gi = GeoIP_new(GEOIP_STANDARD);
47 throw ModuleException("Unable to initialize geoip, are you missing GeoIP.dat?");
49 ServerInstance->Modules->AddService(ext);
50 Implementation eventlist[] = { I_OnSetConnectClass };
51 ServerInstance->Modules->Attach(eventlist, this, 1);
61 return Version("Provides a way to assign users to connect classes by country using GeoIP lookup", VF_VENDOR);
64 ModResult OnSetConnectClass(LocalUser* user, ConnectClass* myclass)
66 std::string* cc = ext.get(user);
69 const char* c = GeoIP_country_code_by_addr(gi, user->GetIPString());
72 cc = new std::string(c);
75 std::string geoip = myclass->config->getString("geoip");
77 return MOD_RES_PASSTHRU;
78 irc::commasepstream list(geoip);
80 while (list.GetToken(country))
82 return MOD_RES_PASSTHRU;
87 MODULE_INIT(ModuleGeoIP)