10 /* $ModDesc: Forces connecting clients to send a PONG message back to the server before they can complete their connection */
14 char* RandString(unsigned int length)
16 unsigned char* tmp = new unsigned char[(length/4)*3];
18 for(unsigned int i = 0; i < (length/4)*3; i++)
19 tmp[i] = (unsigned char)rand();
21 unsigned char* out = new unsigned char[length+1];
23 to64frombits(out, tmp, (length/4)*3);
32 class ModuleWaitPong : public Module
41 ModuleWaitPong(InspIRCd* Me)
48 virtual void OnRehash(const std::string ¶m)
50 Conf = new ConfigReader(ServerInstance);
52 sendsnotice = Conf->ReadFlag("waitpong", "sendsnotice", 0);
54 if(Conf->GetError() == CONF_VALUE_NOT_FOUND)
57 killonbadreply = Conf->ReadFlag("waitpong", "killonbadreply", 0);
59 if(Conf->GetError() == CONF_VALUE_NOT_FOUND)
60 killonbadreply = true;
65 void Implements(char* List)
67 List[I_OnUserRegister] = List[I_OnCheckReady] = List[I_OnPreCommand] = List[I_OnRehash] = List[I_OnUserDisconnect] = List[I_OnCleanup] = 1;
70 virtual void OnUserRegister(userrec* user)
72 char* pingrpl = RandString(10);
74 user->Write("PING :%s", pingrpl);
77 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);
79 user->Extend("waitpong_pingstr", pingrpl);
82 virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec* user, bool validated)
87 user->GetExt("waitpong_pingstr", pingrpl);
91 if(strcmp(pingrpl, parameters[0]) == 0)
94 user->Shrink("waitpong_pingstr");
100 userrec::QuitUser(ServerInstance, user, "Incorrect ping reply for registration");
109 virtual bool OnCheckReady(userrec* user)
112 return (!user->GetExt("waitpong_pingstr", pingrpl));
115 virtual void OnUserDisconnect(userrec* user)
118 user->GetExt("waitpong_pingstr", pingrpl);
123 user->Shrink("waitpong_pingstr");
127 virtual void OnCleanup(int target_type, void* item)
129 if(target_type == TYPE_USER)
131 userrec* user = (userrec*)item;
133 user->GetExt("waitpong_pingstr", pingrpl);
138 user->Shrink("waitpong_pingstr");
143 virtual ~ModuleWaitPong()
147 virtual Version GetVersion()
149 return Version(1, 0, 0, 1, VF_VENDOR);
154 class ModuleWaitPongFactory : public ModuleFactory
157 ModuleWaitPongFactory()
161 ~ModuleWaitPongFactory()
165 virtual Module * CreateModule(InspIRCd* Me)
167 return new ModuleWaitPong(Me);
172 extern "C" void * init_module( void )
174 return new ModuleWaitPongFactory;