]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chanfilter.cpp
6280280e3bb3d6602c6ae3765bfde700fab59276
[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 #define _CRT_SECURE_NO_DEPRECATE
15 #define _SCL_SECURE_NO_DEPRECATE
16
17 #include "inspircd.h"
18 #include "u_listmode.h"
19
20 /* $ModDesc: Provides channel-specific censor lists (like mode +G but varies from channel to channel) */
21 /* $ModDep: ../../include/u_listmode.h */
22
23 /** Handles channel mode +g
24  */
25 class ChanFilter : public ListModeBase
26 {
27  public:
28         ChanFilter(InspIRCd* Instance) : ListModeBase(Instance, 'g', "End of channel spamfilter list", "941", "940", false, "chanfilter") { }
29         
30         virtual bool ValidateParam(User* user, Channel* chan, std::string &word)
31         {
32                 if ((word.length() > 35) || (word.empty()))
33                 {
34                         user->WriteServ("935 %s %s %s :word is too %s for censor list",user->nick, chan->name,word.c_str(), (word.empty() ? "short" : "long"));
35                         return false;
36                 }
37                 
38                 return true;
39         }
40         
41         virtual bool TellListTooLong(User* user, Channel* chan, std::string &word)
42         {
43                 user->WriteServ("939 %s %s %s :Channel spamfilter list is full",user->nick, chan->name, word.c_str());
44                 return true;
45         }
46         
47         virtual void TellAlreadyOnList(User* user, Channel* chan, std::string &word)
48         {
49                 user->WriteServ("937 %s %s :The word %s is already on the spamfilter list",user->nick, chan->name,word.c_str());
50         }
51         
52         virtual void TellNotSet(User* user, Channel* chan, std::string &word)
53         {
54                 user->WriteServ("938 %s %s :No such spamfilter word is set",user->nick, chan->name);
55         }
56 };
57
58 class ModuleChanFilter : public Module
59 {
60         
61         ChanFilter* cf;
62         
63  public:
64  
65         ModuleChanFilter(InspIRCd* Me)
66                 : Module(Me)
67         {
68                 cf = new ChanFilter(ServerInstance);
69                 if (!ServerInstance->AddMode(cf))
70                         throw ModuleException("Could not add new modes!");
71         }
72
73         void Implements(char* List) 
74         { 
75                 cf->DoImplements(List);
76                 List[I_OnCleanup] = List[I_OnChannelDelete] = List[I_OnRehash] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnSyncChannel] = 1;
77         }
78
79         virtual void OnChannelDelete(Channel* chan)
80         {
81                 cf->DoChannelDelete(chan);
82         }
83
84         virtual void OnRehash(User* user, const std::string &parameter)
85         {
86                 cf->DoRehash();
87         }
88
89         virtual int ProcessMessages(User* user,Channel* chan,std::string &text)
90         {
91                 if (!IS_LOCAL(user) || CHANOPS_EXEMPT(ServerInstance, 'g') && chan->GetStatus(user) == STATUS_OP)
92                         return 0;
93
94                 // Create a copy of the string in irc::string
95                 irc::string line = text.c_str();
96
97                 modelist* list;
98                 chan->GetExt(cf->GetInfoKey(), list);
99
100                 if (list)
101                 {
102                         for (modelist::iterator i = list->begin(); i != list->end(); i++)
103                         {
104                                 if (line.find(i->mask.c_str()) != std::string::npos)
105                                 {
106                                         user->WriteServ("936 %s %s %s :Your message contained a censored word, and was blocked",user->nick, chan->name, i->mask.c_str());
107                                         return 1;
108                                 }
109                         }
110                 }
111
112                 return 0;
113         }
114
115         virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
116         {
117                 if (target_type == TYPE_CHANNEL)
118                 {
119                         return ProcessMessages(user,(Channel*)dest,text);
120                 }
121                 else return 0;
122         }
123
124         virtual void OnCleanup(int target_type, void* item)
125         {
126                 cf->DoCleanup(target_type, item);
127         }
128         
129         virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
130         {
131                 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
132         }
133         
134         virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
135         {
136                 cf->DoSyncChannel(chan, proto, opaque);
137         }
138
139         virtual Version GetVersion()
140         {
141                 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
142         }
143         
144         virtual ~ModuleChanFilter()
145         {
146                 ServerInstance->Modes->DelMode(cf);
147                 DELETE(cf);
148         }
149 };
150
151 MODULE_INIT(ModuleChanFilter)