]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_filter.h
b2c3816a8f3faa0d2ddb1561c5c5f9d4f5add74d
[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 #include "xline.h"
18
19 class FilterResult : public classbase
20 {
21  public:
22         std::string reason;
23         std::string action;
24         long gline_time;
25
26         FilterResult(const std::string &rea, const std::string &act, long gt) : reason(rea), action(act), gline_time(gt)
27         {
28         }
29
30         FilterResult()
31         {
32         }
33
34         virtual ~FilterResult()
35         {
36         }
37 };
38
39 class FilterBase : public Module
40
41  public:
42         FilterBase(InspIRCd* Me)
43                 : Module::Module(Me)
44         {
45         }
46         
47         virtual ~FilterBase()
48         {
49         }
50
51         virtual void Implements(char* List)
52         {
53                 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnRehash] = 1;
54         }
55
56         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
57         {
58                 return OnUserPreNotice(user,dest,target_type,text,status);
59         }
60
61         /* This must be implemented by the module which uses the header */
62         virtual FilterResult* FilterMatch(const std::string &text) = 0;
63
64         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
65         {
66                 FilterResult* f = this->FilterMatch(text);
67                 if (f)
68                 {
69                         std::string target = "";
70                         if (target_type == TYPE_USER)
71                         {
72                                 userrec* t = (userrec*)dest;
73                                 target = std::string(t->nick);
74                         }
75                         else if (target_type == TYPE_CHANNEL)
76                         {
77                                 chanrec* t = (chanrec*)dest;
78                                 target = std::string(t->name);
79                         }
80                         if (f->action == "block")
81                         {       
82                                 ServerInstance->WriteOpers(std::string("FILTER: ")+user->nick+" had their notice filtered, target was "+target+": "+f->reason);
83                                 user->WriteServ("NOTICE "+std::string(user->nick)+" :Your notice has been filtered and opers notified: "+f->reason);
84                         }
85                         ServerInstance->Log(DEFAULT,"FILTER: "+std::string(user->nick)+std::string(" had their notice filtered, target was ")+target+": "+f->reason+" Action: "+f->action);
86
87                         if (f->action == "kill")
88                         {
89                                 userrec::QuitUser(ServerInstance,user,f->reason);
90                         }
91
92                         if (f->action == "gline")
93                         {
94                                 if (ServerInstance->XLines->add_gline(f->gline_time, ServerInstance->Config->ServerName, f->reason.c_str(), user->MakeHostIP()))
95                                 {
96                                         ServerInstance->XLines->apply_lines(APPLY_GLINES);
97                                         FOREACH_MOD(I_OnAddGLine,OnAddGLine(f->gline_time, NULL, f->reason, user->MakeHostIP()));
98                                 }
99                         }
100                         return 1;
101                 }
102                 return 0;
103         }
104
105         virtual void OnRehash(const std::string &parameter)
106         {
107         }
108         
109         virtual Version GetVersion()
110         {
111                 // This is version 2 because version 1.x is the unreleased unrealircd module
112                 return Version(1,1,0,2,VF_VENDOR,API_VERSION);
113         }
114 };