1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
25 /* $ModDesc: Forces connecting clients to send a PONG message back to the server before they can complete their connection */
29 char* RandString(unsigned int length)
31 unsigned char* out = new unsigned char[length+1];
32 for(unsigned int i = 0; i < length; i++)
33 out[i] = ((rand() % 26) + 65);
39 class ModuleWaitPong : public Module
48 ModuleWaitPong(InspIRCd* Me)
55 virtual void OnRehash(const std::string ¶m)
57 Conf = new ConfigReader(ServerInstance);
59 sendsnotice = Conf->ReadFlag("waitpong", "sendsnotice", 0);
61 if(Conf->GetError() == CONF_VALUE_NOT_FOUND)
64 killonbadreply = Conf->ReadFlag("waitpong", "killonbadreply", 0);
66 if(Conf->GetError() == CONF_VALUE_NOT_FOUND)
67 killonbadreply = true;
72 void Implements(char* List)
74 List[I_OnUserRegister] = List[I_OnCheckReady] = List[I_OnPreCommand] = List[I_OnRehash] = List[I_OnUserDisconnect] = List[I_OnCleanup] = 1;
77 virtual int OnUserRegister(userrec* user)
79 char* pingrpl = RandString(10);
81 user->Write("PING :%s", pingrpl);
84 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);
86 user->Extend("waitpong_pingstr", pingrpl);
90 virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec* user, bool validated, const std::string &original_line)
95 user->GetExt("waitpong_pingstr", pingrpl);
99 if(strcmp(pingrpl, parameters[0]) == 0)
102 user->Shrink("waitpong_pingstr");
108 userrec::QuitUser(ServerInstance, user, "Incorrect ping reply for registration");
117 virtual bool OnCheckReady(userrec* user)
120 return (!user->GetExt("waitpong_pingstr", pingrpl));
123 virtual void OnUserDisconnect(userrec* user)
126 user->GetExt("waitpong_pingstr", pingrpl);
131 user->Shrink("waitpong_pingstr");
135 virtual void OnCleanup(int target_type, void* item)
137 if(target_type == TYPE_USER)
139 userrec* user = (userrec*)item;
141 user->GetExt("waitpong_pingstr", pingrpl);
146 user->Shrink("waitpong_pingstr");
151 virtual ~ModuleWaitPong()
155 virtual Version GetVersion()
157 return Version(1, 1, 0, 1, VF_VENDOR, API_VERSION);
162 class ModuleWaitPongFactory : public ModuleFactory
165 ModuleWaitPongFactory()
169 ~ModuleWaitPongFactory()
173 virtual Module * CreateModule(InspIRCd* Me)
175 return new ModuleWaitPong(Me);
180 extern "C" void * init_module( void )
182 return new ModuleWaitPongFactory;