1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 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 std::string RandString()
51 for(unsigned int i = 0; i < 10; i++)
52 out[i] = ((rand() % 26) + 65);
58 ModResult OnUserRegister(LocalUser* user)
60 std::string pingrpl = RandString();
62 user->Write("PING :%s", pingrpl.c_str());
65 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());
67 ext.set(user, pingrpl);
68 return MOD_RES_PASSTHRU;
71 ModResult OnPreCommand(std::string &command, std::vector<std::string> ¶meters, User* user, bool validated, const std::string &original_line)
73 if (command == "PONG")
75 std::string* pingrpl = ext.get(user);
79 if (!parameters.empty() && *pingrpl == parameters[0])
87 ServerInstance->Users->QuitUser(user, "Incorrect ping reply for registration");
92 return MOD_RES_PASSTHRU;
95 ModResult OnCheckReady(LocalUser* user)
97 return ext.get(user) ? MOD_RES_DENY : MOD_RES_PASSTHRU;
106 return Version("Require pong prior to registration", VF_VENDOR);
111 MODULE_INIT(ModuleWaitPong)