X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_nickflood.cpp;h=10ae40cb752c69859246f3e5d5aa6a69d939733a;hb=00fa6d592ed2640fcdf74444786de555c1c3da25;hp=c5ba4065b2b7645c4516c762253ab48a866875b0;hpb=4e7c9f5a9257723765f9994aff90440a0b6cf3c9;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_nickflood.cpp b/src/modules/m_nickflood.cpp index c5ba4065b..10ae40cb7 100644 --- a/src/modules/m_nickflood.cpp +++ b/src/modules/m_nickflood.cpp @@ -2,7 +2,7 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd: (C) 2002-2007 InspIRCd Development Team + * InspIRCd: (C) 2002-2009 InspIRCd Development Team * See: http://www.inspircd.org/wiki/index.php/Credits * * This program is free but copyrighted software; see @@ -19,21 +19,19 @@ */ class nickfloodsettings : public classbase { + private: + InspIRCd* ServerInstance; public: - int secs; int nicks; time_t reset; time_t unlocktime; int counter; bool locked; - InspIRCd* ServerInstance; - - nickfloodsettings() : secs(0), nicks(0) {}; - nickfloodsettings(int b, int c) : secs(b), nicks(c) + nickfloodsettings(InspIRCd *Instance, int b, int c) : ServerInstance(Instance), secs(b), nicks(c) { - reset = time(NULL) + secs; + reset = Instance->Time() + secs; counter = 0; locked = false; }; @@ -41,10 +39,10 @@ class nickfloodsettings : public classbase void addnick() { counter++; - if (time(NULL) > reset) + if (ServerInstance->Time() > reset) { counter = 0; - reset = time(NULL) + secs; + reset = ServerInstance->Time() + secs; } } @@ -62,7 +60,7 @@ class nickfloodsettings : public classbase { if (locked) { - if (time(NULL) > unlocktime) + if (ServerInstance->Time() > unlocktime) { locked = false; return false; @@ -78,7 +76,7 @@ class nickfloodsettings : public classbase void lock() { locked = true; - unlocktime = time(NULL) + 60; + unlocktime = ServerInstance->Time() + 60; } }; @@ -90,22 +88,22 @@ class NickFlood : public ModeHandler public: NickFlood(InspIRCd* Instance) : ModeHandler(Instance, 'F', 1, 0, false, MODETYPE_CHANNEL, false) { } - ModePair ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter) + ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter) { nickfloodsettings* x; if (channel->GetExt("nickflood",x)) return std::make_pair(true, ConvToStr(x->nicks)+":"+ConvToStr(x->secs)); else return std::make_pair(false, parameter); - } + } - bool CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, chanrec* channel) + bool CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, Channel* channel) { /* When TS is equal, the alphabetically later one wins */ return (their_param < our_param); } - ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding) + ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool) { nickfloodsettings* dummy; @@ -135,7 +133,7 @@ class NickFlood : public ModeHandler int nsecs = atoi(secs); if ((nnicks<1) || (nsecs<1)) { - source->WriteServ("608 %s %s :Invalid flood parameter",source->nick,channel->name); + source->WriteNumeric(608, "%s %s :Invalid flood parameter",source->nick.c_str(),channel->name.c_str()); parameter.clear(); return MODEACTION_DENY; } @@ -144,7 +142,7 @@ class NickFlood : public ModeHandler if (!channel->GetExt("nickflood", dummy)) { parameter = ConvToStr(nnicks) + ":" +ConvToStr(nsecs); - nickfloodsettings *f = new nickfloodsettings(nsecs,nnicks); + nickfloodsettings *f = new nickfloodsettings(ServerInstance, nsecs, nnicks); channel->Extend("nickflood", f); channel->SetMode('F', true); channel->SetModeParam('F', parameter.c_str(), true); @@ -167,7 +165,7 @@ class NickFlood : public ModeHandler nickfloodsettings* f; channel->GetExt("nickflood", f); delete f; - f = new nickfloodsettings(nsecs, nnicks); + f = new nickfloodsettings(ServerInstance, nsecs, nnicks); channel->Shrink("nickflood"); channel->Extend("nickflood", f); channel->SetModeParam('F', cur_param.c_str(), false); @@ -184,7 +182,7 @@ class NickFlood : public ModeHandler } else { - source->WriteServ("608 %s %s :Invalid flood parameter",source->nick,channel->name); + source->WriteNumeric(608, "%s %s :Invalid flood parameter",source->nick.c_str(),channel->name.c_str()); return MODEACTION_DENY; } } @@ -194,7 +192,7 @@ class NickFlood : public ModeHandler { nickfloodsettings *f; channel->GetExt("nickflood", f); - DELETE(f); + delete f; channel->Shrink("nickflood"); channel->SetMode('F', false); return MODEACTION_ALLOW; @@ -207,23 +205,28 @@ class NickFlood : public ModeHandler class ModuleNickFlood : public Module { NickFlood* jf; - + public: - + ModuleNickFlood(InspIRCd* Me) : Module(Me) { - + jf = new NickFlood(ServerInstance); - if (!ServerInstance->AddMode(jf, 'F')) + if (!ServerInstance->Modes->AddMode(jf)) throw ModuleException("Could not add new modes!"); + Implementation eventlist[] = { I_OnChannelDelete, I_OnUserPreNick }; + ServerInstance->Modules->Attach(eventlist, this, 2); } - virtual int OnUserPreNick(userrec* user, const std::string &newnick) + virtual int OnUserPreNick(User* user, const std::string &newnick) { + if (isdigit(newnick[0])) /* allow switches to UID */ + return 0; + for (UCListIter i = user->chans.begin(); i != user->chans.end(); i++) { - chanrec *channel = i->first; + Channel *channel = i->first; nickfloodsettings *f; if (channel->GetExt("nickflood", f)) @@ -233,7 +236,7 @@ class ModuleNickFlood : public Module if (f->islocked()) { - user->WriteServ("447 %s :%s has been locked for nickchanges for 60 seconds because there have been more than %d nick changes in %d seconds", user->nick, channel->name, f->nicks, f->secs); + user->WriteNumeric(447, "%s :%s has been locked for nickchanges for 60 seconds because there have been more than %d nick changes in %d seconds", user->nick.c_str(), channel->name.c_str(), f->nicks, f->secs); return 1; } @@ -242,7 +245,7 @@ class ModuleNickFlood : public Module { f->clear(); f->lock(); - channel->WriteChannelWithServ((char*)ServerInstance->Config->ServerName, "NOTICE %s :No nick changes are allowed for 60 seconds because there have been more than %d nick changes in %d seconds.", channel->name, f->nicks, f->secs); + channel->WriteChannelWithServ((char*)ServerInstance->Config->ServerName, "NOTICE %s :No nick changes are allowed for 60 seconds because there have been more than %d nick changes in %d seconds.", channel->name.c_str(), f->nicks, f->secs); return 1; } } @@ -250,31 +253,27 @@ class ModuleNickFlood : public Module return 0; } - - void OnChannelDelete(chanrec* chan) + + void OnChannelDelete(Channel* chan) { nickfloodsettings *f; if (chan->GetExt("nickflood",f)) { - DELETE(f); + delete f; chan->Shrink("nickflood"); } } - void Implements(char* List) - { - List[I_OnChannelDelete] = List[I_OnUserPreNick] = 1; - } virtual ~ModuleNickFlood() { ServerInstance->Modes->DelMode(jf); - DELETE(jf); + delete jf; } - + virtual Version GetVersion() { - return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION); + return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION); } };