7 #include "helperfuncs.h"
9 /* $ModDesc: Forces connecting clients to send a PONG message back to the server before they can complete their connection */
11 char* RandString(unsigned int length)
13 unsigned char* tmp = new unsigned char[(length/4)*3];
15 for(unsigned int i = 0; i < (length/4)*3; i++)
16 tmp[i] = (unsigned char)rand();
18 unsigned char* out = new unsigned char[length+1];
20 to64frombits(out, tmp, (length/4)*3);
29 class ModuleWaitPong : public Module
38 ModuleWaitPong(Server* Me)
45 virtual void OnRehash(const std::string ¶m)
47 Conf = new ConfigReader;
49 sendsnotice = Conf->ReadFlag("waitpong", "sendsnotice", 0);
51 if(Conf->GetError() == CONF_VALUE_NOT_FOUND)
54 killonbadreply = Conf->ReadFlag("waitpong", "killonbadreply", 0);
56 if(Conf->GetError() == CONF_VALUE_NOT_FOUND)
57 killonbadreply = true;
62 void Implements(char* List)
64 List[I_OnUserRegister] = List[I_OnCheckReady] = List[I_OnPreCommand] = List[I_OnRehash] = List[I_OnUserDisconnect] = List[I_OnCleanup] = 1;
67 virtual void OnUserRegister(userrec* user)
69 char* pingrpl = RandString(10);
71 Write(user->fd, "PING :%s", pingrpl);
74 WriteServ(user->fd, "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);
76 user->Extend("waitpong_pingstr", pingrpl);
79 virtual int OnPreCommand(const std::string &command, char** parameters, int pcnt, userrec* user, bool validated)
83 char* pingrpl = user->GetExt("waitpong_pingstr");
87 if(strcmp(pingrpl, parameters[0]) == 0)
90 user->Shrink("waitpong_pingstr");
96 Srv->QuitUser(user, "Incorrect ping reply for registration");
105 virtual bool OnCheckReady(userrec* user)
107 return (!user->GetExt("waitpong_pingstr"));
110 virtual void OnUserDisconnect(userrec* user)
112 char* pingrpl = user->GetExt("waitpong_pingstr");
117 user->Shrink("waitpong_pingstr");
121 virtual void OnCleanup(int target_type, void* item)
123 if(target_type == TYPE_USER)
125 userrec* user = (userrec*)item;
126 char* pingrpl = user->GetExt("waitpong_pingstr");
131 user->Shrink("waitpong_pingstr");
136 virtual ~ModuleWaitPong()
140 virtual Version GetVersion()
142 return Version(1, 0, 0, 1, VF_VENDOR);
147 class ModuleWaitPongFactory : public ModuleFactory
150 ModuleWaitPongFactory()
154 ~ModuleWaitPongFactory()
158 virtual Module * CreateModule(Server* Me)
160 return new ModuleWaitPong(Me);
165 extern "C" void * init_module( void )
167 return new ModuleWaitPongFactory;