X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_conn_waitpong.cpp;h=7ab1dc77aabffd8f86969ff2a69bed00b54857d6;hb=45805210f8c9bbce6222c50863a1671f562ccfbb;hp=5d4a9e94c797abde445697f9204bd003014164b6;hpb=ea4a9c57ed61b7d012023a9d7da75463f1f5ed94;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_conn_waitpong.cpp b/src/modules/m_conn_waitpong.cpp index 5d4a9e94c..7ab1dc77a 100644 --- a/src/modules/m_conn_waitpong.cpp +++ b/src/modules/m_conn_waitpong.cpp @@ -1,139 +1,143 @@ -#include -#include -#include "aes.h" -#include "users.h" -#include "channels.h" -#include "modules.h" -#include "helperfuncs.h" +/* +------------------------------------+ + * | Inspire Internet Relay Chat Daemon | + * +------------------------------------+ + * + * InspIRCd: (C) 2002-2008 InspIRCd Development Team + * See: http://www.inspircd.org/wiki/index.php/Credits + * + * This program is free but copyrighted software; see + * the file COPYING for details. + * + * --------------------------------------------------- + */ -/* $ModDesc: Forces connecting clients to send a PONG message back to the server before they can complete their connection */ +#include "inspircd.h" -static std::string RandString(unsigned int length) -{ - unsigned char* tmp = new unsigned char[(length/4)*3]; - - for(unsigned int i = 0; i < (length/4)*3; i++) - tmp[i] = (unsigned char)rand(); - - unsigned char* out = new unsigned char[length]; - - to64frombits(out, tmp, (length/4)*3); - - std::string ret((char*)out); - - delete out; - delete tmp; - - return ret; -} +/* $ModDesc: Forces connecting clients to send a PONG message back to the server before they can complete their connection */ class ModuleWaitPong : public Module { - Server* Srv; - ConfigReader* Conf; - bool sendsnotice; bool killonbadreply; + const char* extenstr; public: - ModuleWaitPong(Server* Me) - : Module::Module(Me) + ModuleWaitPong(InspIRCd* Me) + : Module(Me), extenstr("waitpong_pingstr") { - Srv = Me; - OnRehash(""); + OnRehash(NULL,""); + Implementation eventlist[] = { I_OnUserRegister, I_OnCheckReady, I_OnPreCommand, I_OnRehash, I_OnUserDisconnect, I_OnCleanup }; + ServerInstance->Modules->Attach(eventlist, this, 6); } - - virtual void OnRehash(std::string param) + + virtual void OnRehash(User* user, const std::string ¶m) { - Conf = new ConfigReader; - - sendsnotice = Conf->ReadFlag("waitpong", "sendsnotice", 0); - - if(Conf->GetError() == CONF_VALUE_NOT_FOUND) + ConfigReader Conf(ServerInstance); + + sendsnotice = Conf.ReadFlag("waitpong", "sendsnotice", 0); + + if(Conf.GetError() == CONF_VALUE_NOT_FOUND) sendsnotice = true; - - killonbadreply = Conf->ReadFlag("waitpong", "killonbadreply", 0); - if(Conf->GetError() == CONF_VALUE_NOT_FOUND) + killonbadreply = Conf.ReadFlag("waitpong", "killonbadreply", 0); + + if(Conf.GetError() == CONF_VALUE_NOT_FOUND) killonbadreply = true; - - delete Conf; } - void Implements(char* List) + + char* RandString(unsigned int length) { - List[I_OnUserRegister] = List[I_OnCheckReady] = List[I_OnUserDisconnect] = List[I_OnPreCommand] = List[I_OnRehash] = 1; + unsigned char* out = new unsigned char[length+1]; + for(unsigned int i = 0; i < length; i++) + out[i] = ((rand() % 26) + 65); + out[length] = '\0'; + + return (char*)out; } - virtual void OnUserRegister(userrec* user) + virtual int OnUserRegister(User* user) { - std::string* pingrpl = new std::string; - *pingrpl = RandString(10); - - Srv->Send(user->fd, "PING :" + *pingrpl); - + char* pingrpl = RandString(10); + + user->Write("PING :%s", pingrpl); + if(sendsnotice) - 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->c_str(), pingrpl->c_str()); - - user->Extend("waitpong_pingstr", (char*)pingrpl); + 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.c_str(), pingrpl, pingrpl); + + user->Extend(extenstr, pingrpl); + return 0; } - - virtual int OnPreCommand(std::string command, char** parameters, int pcnt, userrec* user, bool validated) + + virtual int OnPreCommand(std::string &command, std::vector ¶meters, User* user, bool validated, const std::string &original_line) { - if(command == "PONG") + if (command == "PONG") { - std::string* pingrpl = (std::string*)user->GetExt("waitpong_pingstr"); - - if(pingrpl && (*pingrpl == parameters[0])) - { - delete pingrpl; - user->Shrink("waitpong_pingstr"); - return 1; - } - else if(killonbadreply) + char* pingrpl; + user->GetExt(extenstr, pingrpl); + + if (pingrpl) { - Srv->QuitUser(user, "Incorrect ping reply for registration"); + if (strcmp(pingrpl, parameters[0].c_str()) == 0) + { + delete[] pingrpl; + user->Shrink(extenstr); + return 1; + } + else + { + if(killonbadreply) + ServerInstance->Users->QuitUser(user, "Incorrect ping reply for registration"); + return 1; + } } } - return 0; } - virtual bool OnCheckReady(userrec* user) - { - return (!user->GetExt("waitpong_pingstr")); - } - - virtual ~ModuleWaitPong() + virtual bool OnCheckReady(User* user) { + char* pingrpl; + return (!user->GetExt(extenstr, pingrpl)); } - - virtual Version GetVersion() + + virtual void OnUserDisconnect(User* user) { - return Version(1, 0, 0, 0, VF_VENDOR); + char* pingrpl; + user->GetExt(extenstr, pingrpl); + + if (pingrpl) + { + delete[] pingrpl; + user->Shrink(extenstr); + } } - -}; -class ModuleWaitPongFactory : public ModuleFactory -{ - public: - ModuleWaitPongFactory() + virtual void OnCleanup(int target_type, void* item) { + if (target_type == TYPE_USER) + { + User* user = (User*)item; + char* pingrpl; + user->GetExt(extenstr, pingrpl); + + if (pingrpl) + { + delete[] pingrpl; + user->Shrink(extenstr); + } + } } - - ~ModuleWaitPongFactory() + + virtual ~ModuleWaitPong() { } - - virtual Module * CreateModule(Server* Me) + + virtual Version GetVersion() { - return new ModuleWaitPong(Me); + return Version("$Id$", VF_VENDOR, API_VERSION); } -}; +}; -extern "C" void * init_module( void ) -{ - return new ModuleWaitPongFactory; -} +MODULE_INIT(ModuleWaitPong)