]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_messageflood.cpp
WriteChannel* functions and ChanExceptSender* functions are now methods of chanrec...
[user/henk/code/inspircd.git] / src / modules / m_messageflood.cpp
index 04f9766d55f8d2a2016bf62221d0837ddbfe7be2..6079eb47b733c27b9ebdf421836ae57ddbf77163 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;
@@ -88,8 +88,25 @@ class MsgFlood : public ModeHandler
  public:
        MsgFlood() : ModeHandler('f', 1, 0, false, MODETYPE_CHANNEL, false) { }
 
+        ModePair ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter)
+        {
+               floodsettings* x;
+               if (channel->GetExt("flood",x))
+                       return std::make_pair(true, (x->ban ? "*" : "")+ConvToStr(x->lines)+":"+ConvToStr(x->secs));
+                else
+                        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)
+       {
+               /* 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)
        {
+               floodsettings *f;
+
                if (adding)
                {
                        char ndata[MAXBUF];
@@ -131,11 +148,11 @@ 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;
@@ -151,9 +168,8 @@ 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);
@@ -184,8 +200,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))
@@ -194,12 +210,12 @@ 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;
+                                               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
@@ -212,7 +228,7 @@ class ModuleMsgFlood : public Module
                                                Event rmode((char *)&n, NULL, "send_mode");
                                                rmode.Send();
                                        }
-                                       Srv->KickUser(NULL, user, dest, "Channel flood triggered (mode +f)");
+                                       dest->ServerKickUser(user, "Channel flood triggered (mode +f)", true);
                                }
                        }
                }
@@ -236,9 +252,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");
                }