]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_nickflood.cpp
m_swhois Switch to OnPostOper hook instead of using OnPostCommand
[user/henk/code/inspircd.git] / src / modules / m_nickflood.cpp
index 898c7358dec9f86cf9c1d646a7bbc8df73e9f3cd..3db6f5e641ad84b87d4a7b42b202a7df250c0347 100644 (file)
@@ -1,26 +1,31 @@
-/*       +------------------------------------+
- *       | Inspire Internet Relay Chat Daemon |
- *       +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
  *
- *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
- * See: http://wiki.inspircd.org/Credits
+ *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2007, 2009 Robin Burchell <robin+git@viroteck.net>
  *
- * This program is free but copyrighted software; see
- *            the file COPYING for details.
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
  *
- * ---------------------------------------------------
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+
 #include "inspircd.h"
 
 /* $ModDesc: Provides channel mode +F (nick flood protection) */
 
 /** Holds settings and state associated with channel mode +F
  */
-class nickfloodsettings : public classbase
+class nickfloodsettings
 {
- private:
-       InspIRCd* ServerInstance;
  public:
        int secs;
        int nicks;
@@ -29,9 +34,9 @@ class nickfloodsettings : public classbase
        int counter;
        bool locked;
 
-       nickfloodsettings(InspIRCd *Instance, int b, int c) : ServerInstance(Instance), secs(b), nicks(c)
+       nickfloodsettings(int b, int c) : secs(b), nicks(c)
        {
-               reset = Instance->Time() + secs;
+               reset = ServerInstance->Time() + secs;
                counter = 0;
                locked = false;
        };
@@ -91,18 +96,9 @@ class NickFlood : public ModeHandler
 {
  public:
        SimpleExtItem<nickfloodsettings> ext;
-       NickFlood(InspIRCd* Instance, Module* Creator) : ModeHandler(Instance, Creator, 'F', 1, 0, false, MODETYPE_CHANNEL, false),
+       NickFlood(Module* Creator) : ModeHandler(Creator, "nickflood", 'F', PARAM_SETONLY, MODETYPE_CHANNEL),
                ext("nickflood", Creator) { }
 
-       ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string &parameter)
-       {
-               nickfloodsettings* x = ext.get(channel);
-               if (x)
-                       return std::make_pair(true, ConvToStr(x->nicks)+":"+ConvToStr(x->secs));
-               else
-                       return std::make_pair(false, parameter);
-       }
-
        ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
        {
                nickfloodsettings *f = ext.get(channel);
@@ -140,7 +136,7 @@ class NickFlood : public ModeHandler
                                        if (!f)
                                        {
                                                parameter = ConvToStr(nnicks) + ":" +ConvToStr(nsecs);
-                                               f = new nickfloodsettings(ServerInstance, nsecs, nnicks);
+                                               f = new nickfloodsettings(nsecs, nnicks);
                                                ext.set(channel, f);
                                                channel->SetModeParam('F', parameter);
                                                return MODEACTION_ALLOW;
@@ -159,7 +155,7 @@ class NickFlood : public ModeHandler
                                                        // new mode param, replace old with new
                                                        if ((nsecs > 0) && (nnicks > 0))
                                                        {
-                                                               f = new nickfloodsettings(ServerInstance, nsecs, nnicks);
+                                                               f = new nickfloodsettings(nsecs, nnicks);
                                                                ext.set(channel, f);
                                                                channel->SetModeParam('F', parameter);
                                                                return MODEACTION_ALLOW;
@@ -197,29 +193,31 @@ class ModuleNickFlood : public Module
 
  public:
 
-       ModuleNickFlood(InspIRCd* Me)
-               : Module(Me), nf(Me, this)
+       ModuleNickFlood()
+               : nf(this)
        {
                if (!ServerInstance->Modes->AddMode(&nf))
                        throw ModuleException("Could not add new modes!");
-               Extensible::Register(&nf.ext);
+               ServerInstance->Extensions.Register(&nf.ext);
                Implementation eventlist[] = { I_OnUserPreNick, I_OnUserPostNick };
                ServerInstance->Modules->Attach(eventlist, this, 2);
        }
 
        ModResult OnUserPreNick(User* user, const std::string &newnick)
        {
-               if (isdigit(newnick[0])) /* allow switches to UID */
+               if (ServerInstance->NICKForced.get(user)) /* Allow forced nick changes */
                        return MOD_RES_PASSTHRU;
 
                for (UCListIter i = user->chans.begin(); i != user->chans.end(); i++)
                {
-                       Channel *channel = i->first;
+                       Channel *channel = *i;
+                       ModResult res;
 
                        nickfloodsettings *f = nf.ext.get(channel);
                        if (f)
                        {
-                               if (CHANOPS_EXEMPT(ServerInstance, 'F') && channel->GetStatus(user) == STATUS_OP)
+                               res = ServerInstance->OnCheckExemption(user,channel,"nickflood");
+                               if (res == MOD_RES_ALLOW)
                                        continue;
 
                                if (f->islocked())
@@ -232,7 +230,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.c_str(), f->nicks, f->secs);
+                                       channel->WriteChannelWithServ((char*)ServerInstance->Config->ServerName.c_str(), "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 MOD_RES_DENY;
                                }
                        }
@@ -251,12 +249,14 @@ class ModuleNickFlood : public Module
 
                for (UCListIter i = user->chans.begin(); i != user->chans.end(); ++i)
                {
-                       Channel *channel = i->first;
+                       Channel *channel = *i;
+                       ModResult res;
 
                        nickfloodsettings *f = nf.ext.get(channel);
                        if (f)
                        {
-                               if (CHANOPS_EXEMPT(ServerInstance, 'F') && channel->GetStatus(user) == STATUS_OP)
+                               res = ServerInstance->OnCheckExemption(user,channel,"nickflood");
+                               if (res == MOD_RES_ALLOW)
                                        return;
                                
                                /* moved this here to avoid incrementing the counter for nick
@@ -271,12 +271,11 @@ class ModuleNickFlood : public Module
 
        ~ModuleNickFlood()
        {
-               ServerInstance->Modes->DelMode(&nf);
        }
 
        Version GetVersion()
        {
-               return Version("Channel mode F - nick flood protection", VF_COMMON | VF_VENDOR);
+               return Version("Channel mode F - nick flood protection", VF_VENDOR);
        }
 };