X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_nickflood.cpp;h=50e2b3d9366a3ed0c456c275acafbaa14d602fab;hb=de4e4860091fe5a9a530acdb25f9a17e22323acf;hp=39e097daa5b7aee1a566d1f6fbd22db99f50f6ee;hpb=cee5a82d95fc3f5d3670ef483998bfc2d4a5a82e;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_nickflood.cpp b/src/modules/m_nickflood.cpp index 39e097daa..50e2b3d93 100644 --- a/src/modules/m_nickflood.cpp +++ b/src/modules/m_nickflood.cpp @@ -19,6 +19,10 @@ #include "inspircd.h" +#include "modules/exemption.h" + +// The number of seconds nickname changing will be blocked for. +static unsigned int duration; /** Holds settings and state associated with channel mode +F */ @@ -72,7 +76,7 @@ class nickfloodsettings void lock() { - unlocktime = ServerInstance->Time() + 60; + unlocktime = ServerInstance->Time() + duration; } }; @@ -86,12 +90,12 @@ class NickFlood : public ParamMode > { } - ModeAction OnSet(User* source, Channel* channel, std::string& parameter) + ModeAction OnSet(User* source, Channel* channel, std::string& parameter) CXX11_OVERRIDE { std::string::size_type colon = parameter.find(':'); if ((colon == std::string::npos) || (parameter.find('-') != std::string::npos)) { - source->WriteNumeric(608, channel->name, "Invalid flood parameter"); + source->WriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter)); return MODEACTION_DENY; } @@ -101,7 +105,7 @@ class NickFlood : public ParamMode > if ((nnicks<1) || (nsecs<1)) { - source->WriteNumeric(608, channel->name, "Invalid flood parameter"); + source->WriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter)); return MODEACTION_DENY; } @@ -118,12 +122,20 @@ class NickFlood : public ParamMode > class ModuleNickFlood : public Module { + CheckExemption::EventProvider exemptionprov; NickFlood nf; public: ModuleNickFlood() - : nf(this) + : exemptionprov(this) + , nf(this) + { + } + + void ReadConfig(ConfigStatus&) CXX11_OVERRIDE { + ConfigTag* tag = ServerInstance->Config->ConfValue("nickflood"); + duration = tag->getDuration("duration", 60, 10, 600); } ModResult OnUserPreNick(LocalUser* user, const std::string& newnick) CXX11_OVERRIDE @@ -136,13 +148,13 @@ class ModuleNickFlood : public Module nickfloodsettings *f = nf.ext.get(channel); if (f) { - res = ServerInstance->OnCheckExemption(user,channel,"nickflood"); + res = CheckExemption::Call(exemptionprov, user, channel, "nickflood"); if (res == MOD_RES_ALLOW) continue; if (f->islocked()) { - user->WriteNumeric(ERR_CANTCHANGENICK, InspIRCd::Format("%s has been locked for nickchanges for 60 seconds because there have been more than %u nick changes in %u seconds", channel->name.c_str(), f->nicks, f->secs)); + user->WriteNumeric(ERR_CANTCHANGENICK, InspIRCd::Format("%s has been locked for nickchanges for %u seconds because there have been more than %u nick changes in %u seconds", channel->name.c_str(), duration, f->nicks, f->secs)); return MOD_RES_DENY; } @@ -150,7 +162,7 @@ class ModuleNickFlood : public Module { f->clear(); f->lock(); - channel->WriteNotice(InspIRCd::Format("No nick changes are allowed for 60 seconds because there have been more than %u nick changes in %u seconds.", f->nicks, f->secs)); + channel->WriteNotice(InspIRCd::Format("No nick changes are allowed for %u seconds because there have been more than %u nick changes in %u seconds.", duration, f->nicks, f->secs)); return MOD_RES_DENY; } } @@ -175,7 +187,7 @@ class ModuleNickFlood : public Module nickfloodsettings *f = nf.ext.get(channel); if (f) { - res = ServerInstance->OnCheckExemption(user,channel,"nickflood"); + res = CheckExemption::Call(exemptionprov, user, channel, "nickflood"); if (res == MOD_RES_ALLOW) return;