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 * ---------------------------------------------------
22 /* $ModDesc: Forces connecting clients to send a PONG message back to the server before they can complete their connection */
26 char* RandString(unsigned int length)
28 unsigned char* out = new unsigned char[length+1];
29 for(unsigned int i = 0; i < length; i++)
30 out[i] = ((rand() % 26) + 65);
36 class ModuleWaitPong : public Module
45 ModuleWaitPong(InspIRCd* Me)
52 virtual void OnRehash(const std::string ¶m)
54 Conf = new ConfigReader(ServerInstance);
56 sendsnotice = Conf->ReadFlag("waitpong", "sendsnotice", 0);
58 if(Conf->GetError() == CONF_VALUE_NOT_FOUND)
61 killonbadreply = Conf->ReadFlag("waitpong", "killonbadreply", 0);
63 if(Conf->GetError() == CONF_VALUE_NOT_FOUND)
64 killonbadreply = true;
69 void Implements(char* List)
71 List[I_OnUserRegister] = List[I_OnCheckReady] = List[I_OnPreCommand] = List[I_OnRehash] = List[I_OnUserDisconnect] = List[I_OnCleanup] = 1;
74 virtual int OnUserRegister(userrec* user)
76 char* pingrpl = RandString(10);
78 user->Write("PING :%s", pingrpl);
81 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);
83 user->Extend("waitpong_pingstr", pingrpl);
87 virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec* user, bool validated, const std::string &original_line)
92 user->GetExt("waitpong_pingstr", pingrpl);
96 if(strcmp(pingrpl, parameters[0]) == 0)
99 user->Shrink("waitpong_pingstr");
105 userrec::QuitUser(ServerInstance, user, "Incorrect ping reply for registration");
114 virtual bool OnCheckReady(userrec* user)
117 return (!user->GetExt("waitpong_pingstr", pingrpl));
120 virtual void OnUserDisconnect(userrec* user)
123 user->GetExt("waitpong_pingstr", pingrpl);
128 user->Shrink("waitpong_pingstr");
132 virtual void OnCleanup(int target_type, void* item)
134 if(target_type == TYPE_USER)
136 userrec* user = (userrec*)item;
138 user->GetExt("waitpong_pingstr", pingrpl);
143 user->Shrink("waitpong_pingstr");
148 virtual ~ModuleWaitPong()
152 virtual Version GetVersion()
154 return Version(1, 1, 0, 1, VF_VENDOR, API_VERSION);
159 class ModuleWaitPongFactory : public ModuleFactory
162 ModuleWaitPongFactory()
166 ~ModuleWaitPongFactory()
170 virtual Module * CreateModule(InspIRCd* Me)
172 return new ModuleWaitPong(Me);
177 extern "C" void * init_module( void )
179 return new ModuleWaitPongFactory;