X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmodules%2Fm_nickflood.cpp;h=1ed30f767d1f69fe9e54d7a36639f3c48be7171b;hb=2630a87bb13b089e6d0fdcff4bcd0f3a9612e52f;hp=0a8e9a31d2ecd9cb21640f5e7cc263422e77db61;hpb=2dfc384cde46ba63ed7c2f4420712596096123ca;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_nickflood.cpp b/src/modules/m_nickflood.cpp index 0a8e9a31d..1ed30f767 100644 --- a/src/modules/m_nickflood.cpp +++ b/src/modules/m_nickflood.cpp @@ -48,7 +48,11 @@ class nickfloodsettings : public classbase bool shouldlock() { - return (counter >= this->nicks); + /* XXX HACK: using counter + 1 here now to allow the counter to only be incremented + * on successful nick changes; this will be checked before the counter is + * incremented. + */ + return (counter + 1 >= this->nicks); } void clear() @@ -144,7 +148,7 @@ class NickFlood : public ModeHandler parameter = ConvToStr(nnicks) + ":" +ConvToStr(nsecs); nickfloodsettings *f = new nickfloodsettings(ServerInstance, nsecs, nnicks); channel->Extend("nickflood", f); - channel->SetMode('F', parameter); + channel->SetModeParam('F', parameter); return MODEACTION_ALLOW; } else @@ -167,7 +171,7 @@ class NickFlood : public ModeHandler f = new nickfloodsettings(ServerInstance, nsecs, nnicks); channel->Shrink("nickflood"); channel->Extend("nickflood", f); - channel->SetMode('F', parameter); + channel->SetModeParam('F', parameter); return MODEACTION_ALLOW; } else @@ -192,7 +196,7 @@ class NickFlood : public ModeHandler channel->GetExt("nickflood", f); delete f; channel->Shrink("nickflood"); - channel->SetMode('F', ""); + channel->SetModeParam('F', ""); return MODEACTION_ALLOW; } } @@ -202,19 +206,17 @@ class NickFlood : public ModeHandler class ModuleNickFlood : public Module { - NickFlood* jf; + NickFlood jf; public: ModuleNickFlood(InspIRCd* Me) - : Module(Me) + : Module(Me), jf(Me) { - - jf = new NickFlood(ServerInstance); - if (!ServerInstance->Modes->AddMode(jf)) + if (!ServerInstance->Modes->AddMode(&jf)) throw ModuleException("Could not add new modes!"); - Implementation eventlist[] = { I_OnChannelDelete, I_OnUserPreNick }; - ServerInstance->Modules->Attach(eventlist, this, 2); + Implementation eventlist[] = { I_OnChannelDelete, I_OnUserPreNick, I_OnUserPostNick }; + ServerInstance->Modules->Attach(eventlist, this, 3); } virtual int OnUserPreNick(User* user, const std::string &newnick) @@ -238,7 +240,6 @@ class ModuleNickFlood : public Module return 1; } - f->addnick(); if (f->shouldlock()) { f->clear(); @@ -252,6 +253,34 @@ class ModuleNickFlood : public Module return 0; } + /* + * XXX: HACK: We do the increment on the *POST* event here (instead of all together) because we have no way of knowing whether other modules would block a nickchange. + */ + virtual void OnUserPostNick(User* user, const std::string &oldnick) + { + if (isdigit(user->nick[0])) /* allow switches to UID */ + return; + + for (UCListIter i = user->chans.begin(); i != user->chans.end(); ++i) + { + Channel *channel = i->first; + + nickfloodsettings *f; + if (channel->GetExt("nickflood", f)) + { + if (CHANOPS_EXEMPT(ServerInstance, 'F') && channel->GetStatus(user) == STATUS_OP) + return; + + /* moved this here to avoid incrementing the counter for nick + * changes that are denied for some other reason (bans, +N, etc.) + * per bug #874. + */ + f->addnick(); + } + } + return; + } + void OnChannelDelete(Channel* chan) { nickfloodsettings *f; @@ -265,8 +294,7 @@ class ModuleNickFlood : public Module virtual ~ModuleNickFlood() { - ServerInstance->Modes->DelMode(jf); - delete jf; + ServerInstance->Modes->DelMode(&jf); } virtual Version GetVersion()