]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_joinflood.cpp
Header update: 2007 -> 2008
[user/henk/code/inspircd.git] / src / modules / m_joinflood.cpp
index 3d342b636357f3efd72bb29ed750fff8de765c81..ee38cf0074456de1cc3a8ebb6f4769e1a44181f9 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 +j (join flood protection) */
 
@@ -93,7 +90,7 @@ class JoinFlood : public ModeHandler
  public:
        JoinFlood(InspIRCd* Instance) : ModeHandler(Instance, 'j', 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)
        {
                joinfloodsettings* x;
                if (channel->GetExt("joinflood",x))
@@ -102,13 +99,13 @@ class JoinFlood : 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)
        {
                joinfloodsettings* dummy;
 
@@ -197,7 +194,7 @@ class JoinFlood : public ModeHandler
                        {
                                joinfloodsettings *f;
                                channel->GetExt("joinflood", f);
-                               DELETE(f);
+                               delete f;
                                channel->Shrink("joinflood");
                                channel->SetMode('j', false);
                                return MODEACTION_ALLOW;
@@ -219,11 +216,13 @@ class ModuleJoinFlood : public Module
        {
                
                jf = new JoinFlood(ServerInstance);
-               if (!ServerInstance->AddMode(jf, 'j'))
+               if (!ServerInstance->AddMode(jf))
                        throw ModuleException("Could not add new modes!");
+               Implementation eventlist[] = { I_OnChannelDelete, I_OnUserPreJoin, I_OnUserJoin };
+               ServerInstance->Modules->Attach(eventlist, this, 3);
        }
        
-       virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname, std::string &privs)
+       virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs)
        {
                if (chan)
                {
@@ -240,9 +239,15 @@ class ModuleJoinFlood : public Module
                return 0;
        }
 
-       virtual void OnUserJoin(userrec* user, chanrec* channel, bool &silent)
+       virtual void OnUserJoin(User* user, Channel* channel, bool sync, bool &silent)
        {
                joinfloodsettings *f;
+
+               /* We arent interested in JOIN events caused by a network burst */
+               if (sync)
+                       return;
+
+               /* But all others are OK */
                if (channel->GetExt("joinflood",f))
                {
                        f->addjoin();
@@ -255,25 +260,21 @@ class ModuleJoinFlood : public Module
                }
        }
 
-       void OnChannelDelete(chanrec* chan)
+       void OnChannelDelete(Channel* chan)
        {
                joinfloodsettings *f;
                if (chan->GetExt("joinflood",f))
                {
-                       DELETE(f);
+                       delete f;
                        chan->Shrink("joinflood");
                }
        }
 
-       void Implements(char* List)
-       {
-               List[I_OnChannelDelete] = List[I_OnUserPreJoin] = List[I_OnUserJoin] = 1;
-       }
 
        virtual ~ModuleJoinFlood()
        {
                ServerInstance->Modes->DelMode(jf);
-               DELETE(jf);
+               delete jf;
        }
        
        virtual Version GetVersion()