1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
19 // Message and notice filtering using glob patterns
20 // a module based on the original work done by Craig Edwards in 2003
21 // for the chatspike network.
30 /* $ModDesc: An enhanced version of the unreal m_filter.so used by chatspike.net */
34 /** Holds a filter pattern and reason
36 class Filter : public classbase
43 typedef std::map<std::string,Filter*> filter_t;
45 class ModuleFilter : public Module
51 ModuleFilter(InspIRCd* Me)
54 // read the configuration file on startup.
55 // it is perfectly valid to set <filter file> to the value of the
56 // main config file, then append your <keyword> tags to the bottom
57 // of the main config... but rather messy. That's why the capability
58 // of using a seperate config file is provided.
63 virtual ~ModuleFilter()
67 void Implements(char* List)
69 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnRehash] = 1;
72 // format of a config entry is <keyword pattern="*glob*" reason="Some reason here" action="kill/block">
74 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
76 return OnUserPreNotice(user,dest,target_type,text,status);
79 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
81 std::string text2 = text+" ";
82 for (filter_t::iterator index = filters.begin(); index != filters.end(); index++)
84 if ((ServerInstance->MatchText(text2,index->first)) || (ServerInstance->MatchText(text,index->first)))
86 Filter* f = (Filter*)index->second;
87 std::string target = "";
89 if (target_type == TYPE_USER)
91 userrec* t = (userrec*)dest;
92 target = std::string(t->nick);
94 else if (target_type == TYPE_CHANNEL)
96 chanrec* t = (chanrec*)dest;
97 target = std::string(t->name);
100 if (f->action == "block")
102 ServerInstance->WriteOpers(std::string("FILTER: ")+user->nick+" had their notice filtered, target was "+target+": "+f->reason);
103 user->WriteServ("NOTICE "+std::string(user->nick)+" :Your notice has been filtered and opers notified: "+f->reason);
105 ServerInstance->Log(DEFAULT,"FILTER: "+std::string(user->nick)+std::string(" had their notice filtered, target was ")+target+": "+f->reason+" Action: "+f->action);
107 if (f->action == "kill")
109 userrec::QuitUser(ServerInstance,user,f->reason);
117 virtual void OnRehash(const std::string ¶meter)
119 // this automatically re-reads the configuration file into the class
120 ConfigReader* MyConf = new ConfigReader(ServerInstance);
121 for (filter_t::iterator n = filters.begin(); n != filters.end(); n++)
126 for (int index = 0; index < MyConf->Enumerate("keyword"); index++)
128 std::string pattern = MyConf->ReadValue("keyword","pattern",index);
129 std::string reason = MyConf->ReadValue("keyword","reason",index);
130 std::string do_action = MyConf->ReadValue("keyword","action",index);
133 Filter* x = new Filter;
135 x->action = do_action;
136 filters[pattern] = x;
141 virtual Version GetVersion()
143 // This is version 2 because version 1.x is the unreleased unrealircd module
144 return Version(2,1,0,2,VF_VENDOR,API_VERSION);
149 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
151 class ModuleFilterFactory : public ModuleFactory
154 ModuleFilterFactory()
158 ~ModuleFilterFactory()
162 virtual Module * CreateModule(InspIRCd* Me)
164 return new ModuleFilter(Me);
170 extern "C" void * init_module( void )
172 return new ModuleFilterFactory;