1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 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")
31 virtual void OnRehash(userrec* user, const std::string ¶m)
33 ConfigReader Conf(ServerInstance);
35 sendsnotice = Conf.ReadFlag("waitpong", "sendsnotice", 0);
37 if(Conf.GetError() == CONF_VALUE_NOT_FOUND)
40 killonbadreply = Conf.ReadFlag("waitpong", "killonbadreply", 0);
42 if(Conf.GetError() == CONF_VALUE_NOT_FOUND)
43 killonbadreply = true;
46 void Implements(char* List)
48 List[I_OnUserRegister] = List[I_OnCheckReady] = List[I_OnPreCommand] = List[I_OnRehash] = List[I_OnUserDisconnect] = List[I_OnCleanup] = 1;
51 char* RandString(unsigned int length)
53 unsigned char* out = new unsigned char[length+1];
54 for(unsigned int i = 0; i < length; i++)
55 out[i] = ((rand() % 26) + 65);
61 virtual int OnUserRegister(userrec* user)
63 char* pingrpl = RandString(10);
65 user->Write("PING :%s", pingrpl);
68 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, pingrpl, pingrpl);
70 user->Extend(extenstr, pingrpl);
74 virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec* user, bool validated, const std::string &original_line)
79 user->GetExt(extenstr, pingrpl);
83 if(strcmp(pingrpl, parameters[0]) == 0)
86 user->Shrink(extenstr);
92 userrec::QuitUser(ServerInstance, user, "Incorrect ping reply for registration");
100 virtual bool OnCheckReady(userrec* user)
103 return (!user->GetExt(extenstr, pingrpl));
106 virtual void OnUserDisconnect(userrec* user)
109 user->GetExt(extenstr, pingrpl);
114 user->Shrink(extenstr);
118 virtual void OnCleanup(int target_type, void* item)
120 if(target_type == TYPE_USER)
122 userrec* user = (userrec*)item;
124 user->GetExt(extenstr, pingrpl);
129 user->Shrink(extenstr);
134 virtual ~ModuleWaitPong()
138 virtual Version GetVersion()
140 return Version(1, 1, 0, 1, VF_VENDOR, API_VERSION);
145 MODULE_INIT(ModuleWaitPong)