1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/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
25 ModuleWaitPong(InspIRCd* Me)
26 : Module(Me), extenstr("waitpong_pingstr")
29 Implementation eventlist[] = { I_OnUserRegister, I_OnCheckReady, I_OnPreCommand, I_OnRehash, I_OnUserDisconnect, I_OnCleanup };
30 ServerInstance->Modules->Attach(eventlist, this, 6);
33 virtual void OnRehash(User* user, const std::string ¶m)
35 ConfigReader Conf(ServerInstance);
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;
49 char* RandString(unsigned int length)
51 unsigned char* out = new unsigned char[length+1];
52 for(unsigned int i = 0; i < length; i++)
53 out[i] = ((rand() % 26) + 65);
59 virtual int OnUserRegister(User* user)
61 char* pingrpl = RandString(10);
63 user->Write("PING :%s", pingrpl);
66 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, pingrpl);
68 user->Extend(extenstr, pingrpl);
72 virtual int OnPreCommand(std::string &command, std::vector<std::string> ¶meters, User* user, bool validated, const std::string &original_line)
74 if (command == "PONG")
77 user->GetExt(extenstr, pingrpl);
81 if (!parameters.empty() && (strcmp(pingrpl, parameters[0].c_str()) == 0))
84 user->Shrink(extenstr);
90 ServerInstance->Users->QuitUser(user, "Incorrect ping reply for registration");
98 virtual bool OnCheckReady(User* user)
101 return (!user->GetExt(extenstr, pingrpl));
104 virtual void OnUserDisconnect(User* user)
107 user->GetExt(extenstr, pingrpl);
112 user->Shrink(extenstr);
116 virtual void OnCleanup(int target_type, void* item)
118 if (target_type == TYPE_USER)
120 User* user = (User*)item;
122 user->GetExt(extenstr, pingrpl);
127 user->Shrink(extenstr);
132 virtual ~ModuleWaitPong()
136 virtual Version GetVersion()
138 return Version("$Id$", VF_VENDOR, API_VERSION);
143 MODULE_INIT(ModuleWaitPong)