]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_nickflood.cpp
Apply CAP ACK/NAK stuff from nenolod, thanks :)
[user/henk/code/inspircd.git] / src / modules / m_nickflood.cpp
index 4799bd4efaf758ec9b63130c1869607508b3d97a..21f1438d970f3d7a954ee4473fe494fced9e3249 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
  * See: http://www.inspircd.org/wiki/index.php/Credits
  *
  * This program is free but copyrighted software; see
@@ -12,9 +12,6 @@
  */
 
 #include "inspircd.h"
-#include "users.h"
-#include "channels.h"
-#include "modules.h"
 
 /* $ModDesc: Provides channel mode +F (nick flood protection) */
 
@@ -93,7 +90,7 @@ 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 &parameter)
+       ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string &parameter)
        {
                nickfloodsettings* x;
                if (channel->GetExt("nickflood",x))
@@ -102,13 +99,13 @@ class NickFlood : public ModeHandler
                        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 &parameter, bool adding)
+       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding, bool)
        {
                nickfloodsettings* dummy;
 
@@ -197,7 +194,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;
@@ -218,15 +215,20 @@ class ModuleNickFlood : public Module
        {
                
                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))
@@ -254,25 +256,21 @@ 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()