]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_messageflood.cpp
Works with the m_testclient test program/suite!
[user/henk/code/inspircd.git] / src / modules / m_messageflood.cpp
index 2cbecfdac409e3b32160029972d481a078bdbf8c..52fed00f0b47822dd9014b0ebebafcb57d46b1cb 100644 (file)
@@ -25,7 +25,7 @@ using namespace std;
 
 /* $ModDesc: Provides channel mode +f (message flood protection) */
 
-class floodsettings
+class floodsettings : public classbase
 {
  public:
        bool ban;
@@ -90,6 +90,8 @@ class MsgFlood : public ModeHandler
 
        ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
        {
+               floodsettings *f;
+
                if (adding)
                {
                        char ndata[MAXBUF];
@@ -131,10 +133,13 @@ class MsgFlood : public ModeHandler
                                }
                                else
                                {
-                                       if (!channel->GetExt("flood"))
+                                       if (!channel->GetExt("flood", f))
                                        {
+                                               parameter = ConvToStr(nlines) + ":" +ConvToStr(nsecs);
                                                floodsettings *f = new floodsettings(ban,nsecs,nlines);
-                                               channel->Extend("flood",(char*)f);
+                                               channel->Extend("flood",f);
+                                               channel->SetMode('f', true);
+                                               channel->SetModeParam('f', parameter.c_str(), true);
                                                return MODEACTION_ALLOW;
                                        }
                                }
@@ -148,11 +153,11 @@ class MsgFlood : public ModeHandler
                }
                else
                {
-                       if (channel->GetExt("flood"))
+                       if (channel->GetExt("flood", f))
                        {
-                               floodsettings *f = (floodsettings*)channel->GetExt("flood");
                                DELETE(f);
                                channel->Shrink("flood");
+                               channel->SetMode('f', false);
                                return MODEACTION_ALLOW;
                        }
                }
@@ -180,8 +185,8 @@ class ModuleMsgFlood : public Module
        {
                if (IS_LOCAL(user))
                {
-                       floodsettings *f = (floodsettings*)dest->GetExt("flood");
-                       if (f)
+                       floodsettings *f;
+                       if (dest->GetExt("flood", f))
                        {
                                f->addmessage(user);
                                if (f->shouldkick(user))
@@ -190,11 +195,23 @@ class ModuleMsgFlood : public Module
                                        f->clear(user);
                                        if (f->ban)
                                        {
-                                               char* parameters[3];
+                                               const char* parameters[3];
                                                parameters[0] = dest->name;
                                                parameters[1] = "+b";
                                                parameters[2] = user->MakeWildHost();
                                                Srv->SendMode(parameters,3,user);
+                                               std::deque<std::string> n;
+                                               /* Propogate the ban to other servers.
+                                                * We dont know what protocol we may be using,
+                                                * so this event is picked up by our protocol
+                                                * module and formed into a ban command that
+                                                * suits the protocol in use.
+                                                */
+                                               n.push_back(dest->name);
+                                               n.push_back("+b");
+                                               n.push_back(user->MakeWildHost());
+                                               Event rmode((char *)&n, NULL, "send_mode");
+                                               rmode.Send();
                                        }
                                        Srv->KickUser(NULL, user, dest, "Channel flood triggered (mode +f)");
                                }
@@ -220,9 +237,9 @@ class ModuleMsgFlood : public Module
 
        void OnChannelDelete(chanrec* chan)
        {
-               if (chan->GetExt("flood"))
+               floodsettings* f;
+               if (chan->GetExt("flood", f))
                {
-                       floodsettings *f = (floodsettings*)chan->GetExt("flood");
                        DELETE(f);
                        chan->Shrink("flood");
                }