]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_messageflood.cpp
and a little tweak to remote MOTD too.
[user/henk/code/inspircd.git] / src / modules / m_messageflood.cpp
index 9a9f684e5d75046e5892d061a396cadca647a5b0..e4510d15562c00d731cdf6315e0a5f011a6d2b36 100644 (file)
  * ---------------------------------------------------
  */
 
-#include <stdio.h>
-#include <map>
+#include "inspircd.h"
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
-#include "inspircd.h"
 
 /* $ModDesc: Provides channel mode +f (message flood protection) */
 
@@ -82,14 +80,14 @@ class MsgFlood : public ModeHandler
  public:
        MsgFlood(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(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter)
+       {
                floodsettings* x;
-               if (channel->GetExt("flood",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);
-        }
+               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)
        {
@@ -196,47 +194,52 @@ class ModuleMsgFlood : public Module
  public:
  
        ModuleMsgFlood(InspIRCd* Me)
-               : Module::Module(Me)
+               : Module(Me)
        {
                
                mf = new MsgFlood(ServerInstance);
-               ServerInstance->AddMode(mf, 'f');
+               if (!ServerInstance->AddMode(mf, 'f'))
+                       throw ModuleException("Could not add new modes!");
        }
        
        void ProcessMessages(userrec* user,chanrec* dest, const std::string &text)
        {
-               if (IS_LOCAL(user))
+               if (!IS_LOCAL(user) || CHANOPS_EXEMPT(ServerInstance, 'f') && dest->GetStatus(user) == STATUS_OP)
                {
-                       floodsettings *f;
-                       if (dest->GetExt("flood", f))
+                       return;
+               }
+
+               floodsettings *f;
+               if (dest->GetExt("flood", f))
+               {
+                       f->addmessage(user);
+                       if (f->shouldkick(user))
                        {
-                               f->addmessage(user);
-                               if (f->shouldkick(user))
+                               /* Youre outttta here! */
+                               f->clear(user);
+                               if (f->ban)
                                {
-                                       /* Youre outttta here! */
-                                       f->clear(user);
-                                       if (f->ban)
-                                       {
-                                               const char* parameters[3];
-                                               parameters[0] = dest->name;
-                                               parameters[1] = "+b";
-                                               parameters[2] = user->MakeWildHost();
-                                               ServerInstance->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(ServerInstance);
-                                       }
-                                       dest->ServerKickUser(user, "Channel flood triggered (mode +f)", true);
+                                       const char* parameters[3];
+                                       parameters[0] = dest->name;
+                                       parameters[1] = "+b";
+                                       parameters[2] = user->MakeWildHost();
+                                       ServerInstance->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(ServerInstance);
                                }
+                               char kickmessage[MAXBUF];
+                               snprintf(kickmessage, MAXBUF, "Channel flood triggered (limit is %d lines in %d secs)", f->lines, f->secs);
+                               dest->ServerKickUser(user, kickmessage, true);
                        }
                }
        }
@@ -304,7 +307,7 @@ class ModuleMsgFloodFactory : public ModuleFactory
 };
 
 
-extern "C" void * init_module( void )
+extern "C" DllExport void * init_module( void )
 {
        return new ModuleMsgFloodFactory;
 }