]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_nickflood.cpp
Merge pull request #1238 from SaberUK/master+openssl
[user/henk/code/inspircd.git] / src / modules / m_nickflood.cpp
index f74a1842206f9772817292e7554aaf4ca26185f2..abb3cdfafa4a1f4889cf103c3970a4d5802318f7 100644 (file)
@@ -20,6 +20,9 @@
 
 #include "inspircd.h"
 
+// The number of seconds nickname changing will be blocked for.
+static unsigned int duration;
+
 /** Holds settings and state associated with channel mode +F
  */
 class nickfloodsettings
@@ -72,7 +75,7 @@ class nickfloodsettings
 
        void lock()
        {
-               unlocktime = ServerInstance->Time() + 60;
+               unlocktime = ServerInstance->Time() + duration;
        }
 };
 
@@ -91,7 +94,7 @@ class NickFlood : public ParamMode<NickFlood, SimpleExtItem<nickfloodsettings> >
                std::string::size_type colon = parameter.find(':');
                if ((colon == std::string::npos) || (parameter.find('-') != std::string::npos))
                {
-                       source->WriteNumeric(608, "%s :Invalid flood parameter",channel->name.c_str());
+                       source->WriteNumeric(608, channel->name, "Invalid flood parameter");
                        return MODEACTION_DENY;
                }
 
@@ -101,7 +104,7 @@ class NickFlood : public ParamMode<NickFlood, SimpleExtItem<nickfloodsettings> >
 
                if ((nnicks<1) || (nsecs<1))
                {
-                       source->WriteNumeric(608, "%s :Invalid flood parameter",channel->name.c_str());
+                       source->WriteNumeric(608, channel->name, "Invalid flood parameter");
                        return MODEACTION_DENY;
                }
 
@@ -126,9 +129,15 @@ class ModuleNickFlood : public Module
        {
        }
 
-       ModResult OnUserPreNick(User* user, const std::string &newnick) CXX11_OVERRIDE
+       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
        {
-               for (UCListIter i = user->chans.begin(); i != user->chans.end(); i++)
+               for (User::ChanList::iterator i = user->chans.begin(); i != user->chans.end(); i++)
                {
                        Channel* channel = (*i)->chan;
                        ModResult res;
@@ -142,7 +151,7 @@ class ModuleNickFlood : public Module
 
                                if (f->islocked())
                                {
-                                       user->WriteNumeric(ERR_CANTCHANGENICK, ":%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 +159,7 @@ class ModuleNickFlood : public Module
                                {
                                        f->clear();
                                        f->lock();
-                                       channel->WriteChannelWithServ((char*)ServerInstance->Config->ServerName.c_str(), "NOTICE %s :No nick changes are allowed for 60 seconds because there have been more than %u nick changes in %u seconds.", channel->name.c_str(), 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;
                                }
                        }
@@ -167,7 +176,7 @@ class ModuleNickFlood : public Module
                if (isdigit(user->nick[0])) /* allow switches to UID */
                        return;
 
-               for (UCListIter i = user->chans.begin(); i != user->chans.end(); ++i)
+               for (User::ChanList::iterator i = user->chans.begin(); i != user->chans.end(); ++i)
                {
                        Channel* channel = (*i)->chan;
                        ModResult res;