]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_filter.cpp
More exception throwing in constructors
[user/henk/code/inspircd.git] / src / modules / m_filter.cpp
index 37a13f96875195785b1c1c8d8881accea7895845..c8d5633ffbfc02758557b6df5a90fd32f860343d 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
  *                       E-mail:
  *                <brain@chatspike.net>
  *               <Craig@chatspike.net>
@@ -29,6 +29,15 @@ using namespace std;
 
 /* $ModDesc: An enhanced version of the unreal m_filter.so used by chatspike.net */
 
+class FilterException : public ModuleException
+{
+ public:
+       virtual char* GetReason()
+       {
+               return "Could not find <filter file=\"\"> definition in your config file!";
+       }
+};
+
 class ModuleFilter : public Module
 {
  Server *Srv;
@@ -49,9 +58,8 @@ class ModuleFilter : public Module
                MyConf = new ConfigReader(filterfile);
                if ((filterfile == "") || (!MyConf->Verify()))
                {
-                       printf("Error, could not find <filter file=\"\"> definition in your config file!\n");
-                       log(DEFAULT,"Error, could not find <filter file=\"\"> definition in your config file!");
-                       return;
+                       FilterException e;
+                       throw(e);
                }
                Srv->Log(DEFAULT,std::string("m_filter: read configuration from ")+filterfile);
        }
@@ -69,56 +77,12 @@ class ModuleFilter : public Module
        
        // format of a config entry is <keyword pattern="*glob*" reason="Some reason here" action="kill/block">
        
-       virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
+       virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
        {
-               std::string text2 = text+" ";
-               for (int index = 0; index < MyConf->Enumerate("keyword"); index++)
-               {
-                       std::string pattern = MyConf->ReadValue("keyword","pattern",index);
-                       if ((Srv->MatchText(text2,pattern)) || (Srv->MatchText(text,pattern)))
-                       {
-                               std::string target = "";
-                               std::string reason = MyConf->ReadValue("keyword","reason",index);
-                               std::string do_action = MyConf->ReadValue("keyword","action",index);
-
-                               if (do_action == "")
-                                       do_action = "none";
-
-                               if (target_type == TYPE_USER)
-                               {
-                                       userrec* t = (userrec*)dest;
-                                       target = std::string(t->nick);
-                               }
-                               else if (target_type == TYPE_CHANNEL)
-                               {
-                                       chanrec* t = (chanrec*)dest;
-                                       target = std::string(t->name);
-                               }
-                               if (do_action == "block")
-                               {       
-                                       Srv->SendOpers(std::string("FILTER: ")+std::string(user->nick)+
-                                                       std::string(" had their message filtered, target was ")+
-                                                       target+": "+reason);
-                                       // this form of SendTo (with the source as NuLL) sends a server notice
-                                       Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+
-                                                       " :Your message has been filtered and opers notified: "+reason);
-                               }
-
-                               Srv->Log(DEFAULT,std::string("FILTER: ")+std::string(user->nick)+
-                                               std::string(" had their message filtered, target was ")+
-                                               target+": "+reason+" Action: "+do_action);
-
-                               if (do_action == "kill")
-                               {
-                                       Srv->QuitUser(user,reason);
-                               }
-                               return 1;
-                       }
-               }
-               return 0;
+               return OnUserPreNotice(user,dest,target_type,text,status);
        }
        
-       virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
+       virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
        {
                std::string text2 = text+" ";
                for (int index = 0; index < MyConf->Enumerate("keyword"); index++)
@@ -178,9 +142,8 @@ class ModuleFilter : public Module
                if ((filterfile == "") || (!MyConf->Verify()))
                {
                        // bail if the user forgot to create a config file
-                       printf("Error, could not find <filter file=\"\"> definition in your config file!");
-                       log(DEFAULT,"Error, could not find <filter file=\"\"> definition in your config file!");
-                       return;
+                       FilterException e;
+                       throw(e);
                }
                Srv->Log(DEFAULT,std::string("m_filter: read configuration from ")+filterfile);
        }