]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_filter.h
Inherit m_filter.cpp and m_filter_pcre.cpp from a base set of classes, so that change...
[user/henk/code/inspircd.git] / src / modules / m_filter.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 class FilterResult : public classbase
18 {
19  public:
20         std::string reason;
21         std::string action;
22
23         FilterResult(const std::string &rea, const std::string &act) : reason(rea), action(act)
24         {
25         }
26
27         FilterResult()
28         {
29         }
30
31         virtual ~FilterResult()
32         {
33         }
34 };
35
36 class FilterBase : public Module
37
38  public:
39         FilterBase(InspIRCd* Me)
40                 : Module::Module(Me)
41         {
42         }
43         
44         virtual ~FilterBase()
45         {
46         }
47
48         virtual void Implements(char* List)
49         {
50                 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnRehash] = 1;
51         }
52
53         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
54         {
55                 return OnUserPreNotice(user,dest,target_type,text,status);
56         }
57
58         /* This must be implemented by the module which uses the header */
59         virtual FilterResult* FilterMatch(const std::string &text) = 0;
60
61         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
62         {
63                 FilterResult* f = this->FilterMatch(text);
64                 if (f)
65                 {
66                         std::string target = "";
67                         if (target_type == TYPE_USER)
68                         {
69                                 userrec* t = (userrec*)dest;
70                                 target = std::string(t->nick);
71                         }
72                         else if (target_type == TYPE_CHANNEL)
73                         {
74                                 chanrec* t = (chanrec*)dest;
75                                 target = std::string(t->name);
76                         }
77                         if (f->action == "block")
78                         {       
79                                 ServerInstance->WriteOpers(std::string("FILTER: ")+user->nick+" had their notice filtered, target was "+target+": "+f->reason);
80                                 user->WriteServ("NOTICE "+std::string(user->nick)+" :Your notice has been filtered and opers notified: "+f->reason);
81                         }
82                         ServerInstance->Log(DEFAULT,"FILTER: "+std::string(user->nick)+std::string(" had their notice filtered, target was ")+target+": "+f->reason+" Action: "+f->action);
83
84                         if (f->action == "kill")
85                         {
86                                 userrec::QuitUser(ServerInstance,user,f->reason);
87                         }
88                         return 1;
89                 }
90                 return 0;
91         }
92
93         virtual void OnRehash(const std::string &parameter)
94         {
95         }
96         
97         virtual Version GetVersion()
98         {
99                 // This is version 2 because version 1.x is the unreleased unrealircd module
100                 return Version(1,1,0,2,VF_VENDOR,API_VERSION);
101         }
102 };