]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chanfilter.cpp
Someone is getting slapped for this; the new hidesplits/hidebans behavior doesn't...
[user/henk/code/inspircd.git] / src / modules / m_chanfilter.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include <stdio.h>
15 #include <string>
16 #include <vector>
17 #include "users.h"
18 #include "channels.h"
19 #include "modules.h"
20 #include "hashcomp.h"
21 #include "u_listmode.h"
22 #include "inspircd.h"
23
24 /* $ModDesc: Provides channel-specific censor lists (like mode +G but varies from channel to channel) */
25 /* $ModDep: ../../include/u_listmode.h */
26
27 /** Handles channel mode +g
28  */
29 class ChanFilter : public ListModeBase
30 {
31  public:
32         ChanFilter(InspIRCd* Instance) : ListModeBase(Instance, 'g', "End of channel spamfilter list", "941", "940", false, "chanfilter") { }
33         
34         virtual bool ValidateParam(userrec* user, chanrec* chan, std::string &word)
35         {
36                 if ((word.length() > 35) || (word.empty()))
37                 {
38                         user->WriteServ("935 %s %s %s :word is too %s for censor list",user->nick, chan->name,word.c_str(), (word.empty() ? "short" : "long"));
39                         return false;
40                 }
41                 
42                 return true;
43         }
44         
45         virtual bool TellListTooLong(userrec* user, chanrec* chan, std::string &word)
46         {
47                 user->WriteServ("939 %s %s %s :Channel spamfilter list is full",user->nick, chan->name, word.c_str());
48                 return true;
49         }
50         
51         virtual void TellAlreadyOnList(userrec* user, chanrec* chan, std::string &word)
52         {
53                 user->WriteServ("937 %s %s :The word %s is already on the spamfilter list",user->nick, chan->name,word.c_str());
54         }
55         
56         virtual void TellNotSet(userrec* user, chanrec* chan, std::string &word)
57         {
58                 user->WriteServ("938 %s %s :No such spamfilter word is set",user->nick, chan->name);
59         }
60 };
61
62 class ModuleChanFilter : public Module
63 {
64         
65         ChanFilter* cf;
66         
67  public:
68  
69         ModuleChanFilter(InspIRCd* Me)
70                 : Module::Module(Me)
71         {
72                 cf = new ChanFilter(ServerInstance);
73                 if (!ServerInstance->AddMode(cf, 'g'))
74                         throw ModuleException("Could not add new modes!");
75         }
76
77         void Implements(char* List) 
78         { 
79                 cf->DoImplements(List);
80                 List[I_OnCleanup] = List[I_OnChannelDelete] = List[I_OnRehash] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnSyncChannel] = 1;
81         }
82
83         virtual void OnChannelDelete(chanrec* chan)
84         {
85                 cf->DoChannelDelete(chan);
86         }
87
88         virtual void OnRehash(userrec* user, const std::string &parameter)
89         {
90                 cf->DoRehash();
91         }
92
93         virtual int ProcessMessages(userrec* user,chanrec* chan,std::string &text)
94         {
95                 if (!IS_LOCAL(user))
96                         return 0;
97
98                 // Create a copy of the string in irc::string
99                 irc::string line = text.c_str();
100
101                 modelist* list;
102                 chan->GetExt(cf->GetInfoKey(), list);
103
104                 if (list)
105                 {
106                         for (modelist::iterator i = list->begin(); i != list->end(); i++)
107                         {
108                                 if (line.find(i->mask.c_str()) != std::string::npos)
109                                 {
110                                         user->WriteServ("936 %s %s %s :Your message contained a censored word, and was blocked",user->nick, chan->name, i->mask.c_str());
111                                         return 1;
112                                 }
113                         }
114                 }
115                 return 0;
116         }
117
118         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
119         {
120                 if (target_type == TYPE_CHANNEL)
121                 {
122                         return ProcessMessages(user,(chanrec*)dest,text);
123                 }
124                 else return 0;
125         }
126
127         virtual void OnCleanup(int target_type, void* item)
128         {
129                 cf->DoCleanup(target_type, item);
130         }
131         
132         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
133         {
134                 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
135         }
136         
137         virtual void OnSyncChannel(chanrec* chan, Module* proto, void* opaque)
138         {
139                 cf->DoSyncChannel(chan, proto, opaque);
140         }
141
142         virtual Version GetVersion()
143         {
144                 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
145         }
146         
147         virtual ~ModuleChanFilter()
148         {
149                 ServerInstance->Modes->DelMode(cf);
150                 DELETE(cf);
151         }
152 };
153
154
155 class ModuleChanFilterFactory : public ModuleFactory
156 {
157  public:
158         ModuleChanFilterFactory()
159         {
160         }
161         
162         ~ModuleChanFilterFactory()
163         {
164         }
165         
166         virtual Module * CreateModule(InspIRCd* Me)
167         {
168                 return new ModuleChanFilter(Me);
169         }
170         
171 };
172
173
174 extern "C" void * init_module( void )
175 {
176         return new ModuleChanFilterFactory;
177 }