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)
29 Implementation eventlist[] = { I_OnUserRegister, I_OnCheckReady, I_OnPreCommand, I_OnRehash };
30 ServerInstance->Modules->Attach(eventlist, this, 4);
33 void OnRehash(User* user)
37 sendsnotice = Conf.ReadFlag("waitpong", "sendsnotice", 0);
39 if(Conf.GetError() == CONF_VALUE_NOT_FOUND)
42 killonbadreply = Conf.ReadFlag("waitpong", "killonbadreply", 0);
44 if(Conf.GetError() == CONF_VALUE_NOT_FOUND)
45 killonbadreply = true;
48 ModResult OnUserRegister(LocalUser* user)
50 std::string pingrpl = ServerInstance->GenRandomStr(10);
52 user->Write("PING :%s", pingrpl.c_str());
55 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());
57 ext.set(user, pingrpl);
58 return MOD_RES_PASSTHRU;
61 ModResult OnPreCommand(std::string &command, std::vector<std::string> ¶meters, LocalUser* user, bool validated, const std::string &original_line)
63 if (command == "PONG")
65 std::string* pingrpl = ext.get(user);
69 if (!parameters.empty() && *pingrpl == parameters[0])
77 ServerInstance->Users->QuitUser(user, "Incorrect ping reply for registration");
82 return MOD_RES_PASSTHRU;
85 ModResult OnCheckReady(LocalUser* user)
87 return ext.get(user) ? MOD_RES_DENY : MOD_RES_PASSTHRU;
96 return Version("Require pong prior to registration", VF_VENDOR);
101 MODULE_INIT(ModuleWaitPong)