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 * ---------------------------------------------------
19 /* $ModDesc: Forces connecting clients to send a PONG message back to the server before they can complete their connection */
21 class ModuleWaitPong : public Module
29 ModuleWaitPong(InspIRCd* Me)
30 : Module(Me), Instance(Me), extenstr("waitpong_pingstr")
35 virtual void OnRehash(userrec* user, const std::string ¶m)
37 ConfigReader Conf(Instance);
39 sendsnotice = Conf.ReadFlag("waitpong", "sendsnotice", 0);
41 if(Conf.GetError() == CONF_VALUE_NOT_FOUND)
44 killonbadreply = Conf.ReadFlag("waitpong", "killonbadreply", 0);
46 if(Conf.GetError() == CONF_VALUE_NOT_FOUND)
47 killonbadreply = true;
50 void Implements(char* List)
52 List[I_OnUserRegister] = List[I_OnCheckReady] = List[I_OnPreCommand] = List[I_OnRehash] = List[I_OnUserDisconnect] = List[I_OnCleanup] = 1;
55 char* RandString(unsigned int length)
57 unsigned char* out = new unsigned char[length+1];
58 for(unsigned int i = 0; i < length; i++)
59 out[i] = ((rand() % 26) + 65);
65 virtual int OnUserRegister(userrec* user)
67 char* pingrpl = RandString(10);
69 user->Write("PING :%s", pingrpl);
72 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);
74 user->Extend(extenstr, pingrpl);
78 virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec* user, bool validated, const std::string &original_line)
83 user->GetExt(extenstr, pingrpl);
87 if(strcmp(pingrpl, parameters[0]) == 0)
90 user->Shrink(extenstr);
96 userrec::QuitUser(ServerInstance, user, "Incorrect ping reply for registration");
104 virtual bool OnCheckReady(userrec* user)
107 return (!user->GetExt(extenstr, pingrpl));
110 virtual void OnUserDisconnect(userrec* user)
113 user->GetExt(extenstr, pingrpl);
118 user->Shrink(extenstr);
122 virtual void OnCleanup(int target_type, void* item)
124 if(target_type == TYPE_USER)
126 userrec* user = (userrec*)item;
128 user->GetExt(extenstr, pingrpl);
133 user->Shrink(extenstr);
138 virtual ~ModuleWaitPong()
142 virtual Version GetVersion()
144 return Version(1, 1, 0, 1, VF_VENDOR, API_VERSION);
149 class ModuleWaitPongFactory : public ModuleFactory
152 ModuleWaitPongFactory()
156 ~ModuleWaitPongFactory()
160 virtual Module * CreateModule(InspIRCd* Me)
162 return new ModuleWaitPong(Me);
167 extern "C" DllExport void * init_module( void )
169 return new ModuleWaitPongFactory;