1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
20 # pragma comment(lib, "GeoIP.lib")
23 /* $ModDesc: Provides a way to restrict users by country using GeoIP lookup */
24 /* $LinkerFlags: -lGeoIP */
26 class ModuleGeoIP : public Module
32 ModuleGeoIP() : ext("geoip_cc", this), gi(NULL)
38 gi = GeoIP_new(GEOIP_STANDARD);
40 throw ModuleException("Unable to initialize geoip, are you missing GeoIP.dat?");
42 ServerInstance->Modules->AddService(ext);
43 Implementation eventlist[] = { I_OnSetConnectClass };
44 ServerInstance->Modules->Attach(eventlist, this, 1);
54 return Version("Provides a way to assign users to connect classes by country using GeoIP lookup", VF_VENDOR);
57 ModResult OnSetConnectClass(LocalUser* user, ConnectClass* myclass)
59 std::string* cc = ext.get(user);
62 const char* c = GeoIP_country_code_by_addr(gi, user->GetIPString());
65 cc = new std::string(c);
68 std::string geoip = myclass->config->getString("geoip");
70 return MOD_RES_PASSTHRU;
71 irc::commasepstream list(geoip);
73 while (list.GetToken(country))
75 return MOD_RES_PASSTHRU;
80 MODULE_INIT(ModuleGeoIP)