7 #include "helperfuncs.h"
10 /* $ModDesc: Forces connecting clients to send a PONG message back to the server before they can complete their connection */
12 char* RandString(unsigned int length)
14 unsigned char* tmp = new unsigned char[(length/4)*3];
16 for(unsigned int i = 0; i < (length/4)*3; i++)
17 tmp[i] = (unsigned char)rand();
19 unsigned char* out = new unsigned char[length+1];
21 to64frombits(out, tmp, (length/4)*3);
30 class ModuleWaitPong : public Module
39 ModuleWaitPong(Server* Me)
46 virtual void OnRehash(const std::string ¶m)
48 Conf = new ConfigReader;
50 sendsnotice = Conf->ReadFlag("waitpong", "sendsnotice", 0);
52 if(Conf->GetError() == CONF_VALUE_NOT_FOUND)
55 killonbadreply = Conf->ReadFlag("waitpong", "killonbadreply", 0);
57 if(Conf->GetError() == CONF_VALUE_NOT_FOUND)
58 killonbadreply = true;
63 void Implements(char* List)
65 List[I_OnUserRegister] = List[I_OnCheckReady] = List[I_OnPreCommand] = List[I_OnRehash] = List[I_OnUserDisconnect] = List[I_OnCleanup] = 1;
68 virtual void OnUserRegister(userrec* user)
70 char* pingrpl = RandString(10);
72 user->Write("PING :%s", pingrpl);
75 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);
77 user->Extend("waitpong_pingstr", pingrpl);
80 virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec* user, bool validated)
85 user->GetExt("waitpong_pingstr", pingrpl);
89 if(strcmp(pingrpl, parameters[0]) == 0)
92 user->Shrink("waitpong_pingstr");
98 userrec::QuitUser(user, "Incorrect ping reply for registration");
107 virtual bool OnCheckReady(userrec* user)
110 return (!user->GetExt("waitpong_pingstr", pingrpl));
113 virtual void OnUserDisconnect(userrec* user)
116 user->GetExt("waitpong_pingstr", pingrpl);
121 user->Shrink("waitpong_pingstr");
125 virtual void OnCleanup(int target_type, void* item)
127 if(target_type == TYPE_USER)
129 userrec* user = (userrec*)item;
131 user->GetExt("waitpong_pingstr", pingrpl);
136 user->Shrink("waitpong_pingstr");
141 virtual ~ModuleWaitPong()
145 virtual Version GetVersion()
147 return Version(1, 0, 0, 1, VF_VENDOR);
152 class ModuleWaitPongFactory : public ModuleFactory
155 ModuleWaitPongFactory()
159 ~ModuleWaitPongFactory()
163 virtual Module * CreateModule(Server* Me)
165 return new ModuleWaitPong(Me);
170 extern "C" void * init_module( void )
172 return new ModuleWaitPongFactory;