]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_filter.cpp
Auto loading of commands as shared objects via dlsym (very lightweight interface...
[user/henk/code/inspircd.git] / src / modules / m_filter.cpp
index 3b687166f9a0c5e0f181d894ac1d410947f71dea..775130f356e32eb4ea819ebe8e44ff1cece844de 100644 (file)
@@ -25,12 +25,16 @@ using namespace std;
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
-#include "helperfuncs.h"
+
+#include "inspircd.h"
 
 /* $ModDesc: An enhanced version of the unreal m_filter.so used by chatspike.net */
 
-class Filter
+
+
+class Filter : public classbase
 {
+ public:
        std::string reason;
        std::string action;
 };
@@ -40,7 +44,7 @@ typedef std::map<std::string,Filter*> filter_t;
 class FilterException : public ModuleException
 {
  public:
-       virtual char* GetReason()
+       virtual const char* GetReason()
        {
                return "Could not find <filter file=\"\"> definition in your config file!";
        }
@@ -48,12 +52,11 @@ class FilterException : public ModuleException
 
 class ModuleFilter : public Module
 {
- Server *Srv;
- ConfigReader *Conf, *MyConf;
  filter_t filters;
  
  public:
-       ModuleFilter(Server* Me)
+       ModuleFilter(InspIRCd* Me)
                : Module::Module(Me)
        {
                // read the configuration file on startup.
@@ -61,14 +64,12 @@ class ModuleFilter : public Module
                // main config file, then append your <keyword> tags to the bottom
                // of the main config... but rather messy. That's why the capability
                // of using a seperate config file is provided.
-               Srv = Me;
+               
                OnRehash("");
        }
        
        virtual ~ModuleFilter()
        {
-               delete MyConf;
-               delete Conf;
        }
 
        void Implements(char* List)
@@ -88,9 +89,9 @@ class ModuleFilter : public Module
                std::string text2 = text+" ";
                for (filter_t::iterator index = filters.begin(); index != filters.end(); index++)
                {
-                       if ((Srv->MatchText(text2,index->first)) || (Srv->MatchText(text,index->first)))
+                       if ((ServerInstance->MatchText(text2,index->first)) || (ServerInstance->MatchText(text,index->first)))
                        {
-                               Filter* f = (Filter*)*x->second;
+                               Filter* f = (Filter*)index->second;
                                std::string target = "";
 
                                if (target_type == TYPE_USER)
@@ -106,19 +107,14 @@ class ModuleFilter : public Module
 
                                if (f->action == "block")
                                {       
-                                       Srv->SendOpers(std::string("FILTER: ")+std::string(user->nick)+
-                                                       std::string(" had their notice filtered, target was ")+
-                                                       target+": "+f->reason);
-                                       Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+
-                                                       " :Your notice has been filtered and opers notified: "+f->reason);
+                                       ServerInstance->WriteOpers(std::string("FILTER: ")+user->nick+" had their notice filtered, target was "+target+": "+f->reason);
+                                       user->WriteServ("NOTICE "+std::string(user->nick)+" :Your notice has been filtered and opers notified: "+f->reason);
                                }
-                               Srv->Log(DEFAULT,std::string("FILTER: ")+std::string(user->nick)+
-                                               std::string(" had their notice filtered, target was ")+
-                                               target+": "+f->reason+" Action: "+f->action);
+                               ServerInstance->Log(DEFAULT,"FILTER: "+std::string(user->nick)+std::string(" had their notice filtered, target was ")+target+": "+f->reason+" Action: "+f->action);
 
                                if (f->action == "kill")
                                {
-                                       Srv->QuitUser(user,f->reason);
+                                       userrec::QuitUser(ServerInstance,user,f->reason);
                                }
                                return 1;
                        }
@@ -126,14 +122,14 @@ class ModuleFilter : public Module
                return 0;
        }
        
-       virtual void OnRehash(std::string parameter)
+       virtual void OnRehash(const std::string &parameter)
        {
                // reload our config file on rehash - we must destroy and re-allocate the classes
                // to call the constructor again and re-read our data.
-               Conf = new ConfigReader;
+               ConfigReader* Conf = new ConfigReader(ServerInstance);
                std::string filterfile = Conf->ReadValue("filter","file",0);
                // this automatically re-reads the configuration file into the class
-               MyConf = new ConfigReader(filterfile);
+               ConfigReader* MyConf = new ConfigReader(ServerInstance, filterfile);
                if ((filterfile == "") || (!MyConf->Verify()))
                {
                        // bail if the user forgot to create a config file
@@ -142,7 +138,7 @@ class ModuleFilter : public Module
                }
                for (filter_t::iterator n = filters.begin(); n != filters.end(); n++)
                {
-                       delete n->second;
+                       DELETE(n->second);
                }
                filters.clear();
                for (int index = 0; index < MyConf->Enumerate("keyword"); index++)
@@ -157,9 +153,9 @@ class ModuleFilter : public Module
                        x->action = do_action;
                        filters[pattern] = x;
                }
-               Srv->Log(DEFAULT,std::string("m_filter: read configuration from ")+filterfile);
-               delete Conf;
-               delete MyConf;
+               ServerInstance->Log(DEFAULT,"m_filter: read configuration from "+filterfile);
+               DELETE(Conf);
+               DELETE(MyConf);
        }
        
        virtual Version GetVersion()
@@ -183,7 +179,7 @@ class ModuleFilterFactory : public ModuleFactory
        {
        }
        
-       virtual Module * CreateModule(Server* Me)
+       virtual Module * CreateModule(InspIRCd* Me)
        {
                return new ModuleFilter(Me);
        }