]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_messageflood.cpp
delete operator tracking in debug mode (using a macro -- live with it.)
[user/henk/code/inspircd.git] / src / modules / m_messageflood.cpp
index bd1aa438d478e61d518878476e027ce98a5907b0..c5df268ea896ad5953ee90b09cd46d60350d5ce9 100644 (file)
@@ -35,7 +35,11 @@ class floodsettings
        std::map<userrec*,int> counters;
 
        floodsettings() : ban(0), secs(0), lines(0) {};
-       floodsettings(bool a, int b, int c) : ban(a), secs(b), lines(c) { reset = time(NULL) + secs; };
+       floodsettings(bool a, int b, int c) : ban(a), secs(b), lines(c)
+       {
+               reset = time(NULL) + secs;
+               log(DEBUG,"Create new floodsettings: %lu %lu",time(NULL),reset);
+       };
 
        void addmessage(userrec* who)
        {
@@ -45,8 +49,14 @@ class floodsettings
                        iter->second++;
                        log(DEBUG,"Count for %s is now %d",who->nick,iter->second);
                }
-               if (reset > time(NULL))
+               else
+               {
+                       counters[who] = 1;
+                       log(DEBUG,"Count for %s is now *1*",who->nick);
+               }
+               if (time(NULL) > reset)
                {
+                       log(DEBUG,"floodsettings timer Resetting.");
                        counters.clear();
                        reset = time(NULL) + secs;
                }
@@ -57,6 +67,7 @@ class floodsettings
                std::map<userrec*,int>::iterator iter = counters.find(who);
                if (iter != counters.end())
                {
+                       log(DEBUG,"should kick? %d, %d",iter->second,this->lines);
                        return (iter->second >= this->lines);
                }
                else return false;
@@ -133,7 +144,7 @@ class ModuleMsgFlood : public Module
                                        {
                                                if (!c->GetExt("flood"))
                                                {
-                                                       floodsettings *f = new floodsettings(ban,nlines,nsecs);
+                                                       floodsettings *f = new floodsettings(ban,nsecs,nlines);
                                                        c->Extend("flood",(char*)f);
                                                }
                                        }
@@ -152,7 +163,7 @@ class ModuleMsgFlood : public Module
                                if (c->GetExt("flood"))
                                {
                                        floodsettings *f = (floodsettings*)c->GetExt("flood");
-                                       delete f;
+                                       DELETE(f);
                                        c->Shrink("flood");
                                }
                        }
@@ -161,39 +172,46 @@ class ModuleMsgFlood : public Module
                return 0;
        }
 
-       int ProcessMessages(userrec* user,chanrec* dest,std::string &text)
+       void ProcessMessages(userrec* user,chanrec* dest, const std::string &text)
        {
-               floodsettings *f = (floodsettings*)dest->GetExt("flood");
-               if (f)
+               if (IS_LOCAL(user))
                {
-                       f->addmessage(user);
-                       if (f->shouldkick(user))
+                       floodsettings *f = (floodsettings*)dest->GetExt("flood");
+                       if (f)
                        {
-                               /* Youre outttta here! */
-                               f->clear(user);
-                               Srv->KickUser(NULL, user, dest, "Channel flood triggered (mode +f)");
-                               return 1;
+                               f->addmessage(user);
+                               if (f->shouldkick(user))
+                               {
+                                       /* Youre outttta here! */
+                                       f->clear(user);
+                                       if (f->ban)
+                                       {
+                                               char* parameters[3];
+                                               parameters[0] = dest->name;
+                                               parameters[1] = "+b";
+                                               parameters[2] = user->MakeWildHost();
+                                               Srv->SendMode(parameters,3,user);
+                                       }
+                                       Srv->KickUser(NULL, user, dest, "Channel flood triggered (mode +f)");
+                               }
                        }
                }
-               return 0;
        }
 
-        virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
-        {
-                if (target_type == TYPE_CHANNEL)
-                {
-                        return ProcessMessages(user,(chanrec*)dest,text);
-                }
-                else return 0;
+       virtual void OnUserMessage(userrec* user, void* dest, int target_type, const std::string &text, char status)
+       {
+               if (target_type == TYPE_CHANNEL)
+               {
+                       ProcessMessages(user,(chanrec*)dest,text);
+               }
        }
 
-       virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
+       virtual void OnUserNotice(userrec* user, void* dest, int target_type, const std::string &text, char status)
        {
                if (target_type == TYPE_CHANNEL)
                {
-                       return ProcessMessages(user,(chanrec*)dest,text);
+                       ProcessMessages(user,(chanrec*)dest,text);
                }
-               else return 0;
        }
 
        void OnChannelDelete(chanrec* chan)
@@ -201,35 +219,20 @@ class ModuleMsgFlood : public Module
                if (chan->GetExt("flood"))
                {
                        floodsettings *f = (floodsettings*)chan->GetExt("flood");
-                       delete f;
+                       DELETE(f);
                        chan->Shrink("flood");
                }
        }
 
        void Implements(char* List)
        {
-               List[I_On005Numeric] = List[I_OnExtendedMode] = List[I_OnChannelDelete] = List[I_OnUserPreNotice] = List[I_OnUserPreMessage] = 1;
+               List[I_On005Numeric] = List[I_OnExtendedMode] = List[I_OnChannelDelete] = List[I_OnUserNotice] = List[I_OnUserMessage] = 1;
        }
 
-        virtual void On005Numeric(std::string &output)
-        {
-                std::stringstream line(output);
-                std::string temp1, temp2;
-                while (!line.eof())
-                {
-                        line >> temp1;
-                        if (temp1.substr(0,10) == "CHANMODES=")
-                        {
-                               // By doing this we're *assuming* no other module has fucked up the CHANMODES=
-                               // section of the 005 numeric. If they have, we're going DOWN in a blaze of glory,
-                               // with a honking great EXCEPTION :)
-                               temp1.insert(temp1.find(",")+1,"f");
-                        }
-                        temp2 = temp2 + temp1 + " ";
-                }
-               if (temp2.length())
-                       output = temp2.substr(0,temp2.length()-1);
-        }
+       virtual void On005Numeric(std::string &output)
+       {
+               InsertMode(output, "f", 3);
+       }
 
        virtual ~ModuleMsgFlood()
        {