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 * ---------------------------------------------------
16 /* $ModDesc: Forces connecting clients to send a PONG message back to the server before they can complete their connection */
18 class ModuleWaitPong : public Module
26 : ext("waitpong_pingstr", this)
28 ServerInstance->Modules->AddService(ext);
30 Implementation eventlist[] = { I_OnUserRegister, I_OnCheckReady, I_OnPreCommand, I_OnRehash };
31 ServerInstance->Modules->Attach(eventlist, this, 4);
34 void OnRehash(User* user)
38 sendsnotice = Conf.ReadFlag("waitpong", "sendsnotice", 0);
40 if(Conf.GetError() == CONF_VALUE_NOT_FOUND)
43 killonbadreply = Conf.ReadFlag("waitpong", "killonbadreply", 0);
45 if(Conf.GetError() == CONF_VALUE_NOT_FOUND)
46 killonbadreply = true;
49 ModResult OnUserRegister(LocalUser* user)
51 std::string pingrpl = ServerInstance->GenRandomStr(10);
53 user->Write("PING :%s", pingrpl.c_str());
56 user->WriteServ("NOTICE %s :*** If you are having problems connecting due to ping timeouts, please type /quote PONG %s or /raw PONG %s now.", user->nick.c_str(), pingrpl.c_str(), pingrpl.c_str());
58 ext.set(user, pingrpl);
59 return MOD_RES_PASSTHRU;
62 ModResult OnPreCommand(std::string &command, std::vector<std::string> ¶meters, LocalUser* user, bool validated, const std::string &original_line)
64 if (command == "PONG")
66 std::string* pingrpl = ext.get(user);
70 if (!parameters.empty() && *pingrpl == parameters[0])
78 ServerInstance->Users->QuitUser(user, "Incorrect ping reply for registration");
83 return MOD_RES_PASSTHRU;
86 ModResult OnCheckReady(LocalUser* user)
88 return ext.get(user) ? MOD_RES_DENY : MOD_RES_PASSTHRU;
97 return Version("Require pong prior to registration", VF_VENDOR);
102 MODULE_INIT(ModuleWaitPong)