]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_chanfilter.cpp
7c28036b74bb0bd691775a47d6c2e269839afb6d
[user/henk/code/inspircd.git] / src / modules / m_chanfilter.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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, Module* Creator) : ListModeBase(Instance, Creator, '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->WriteNumeric(935, "%s %s %s :word is too %s for censor list",user->nick.c_str(), chan->name.c_str(), 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->WriteNumeric(939, "%s %s %s :Channel spamfilter list is full", user->nick.c_str(), chan->name.c_str(), word.c_str());
44                 return true;
45         }
46
47         virtual void TellAlreadyOnList(User* user, Channel* chan, std::string &word)
48         {
49                 user->WriteNumeric(937, "%s %s :The word %s is already on the spamfilter list",user->nick.c_str(), chan->name.c_str(), word.c_str());
50         }
51
52         virtual void TellNotSet(User* user, Channel* chan, std::string &word)
53         {
54                 user->WriteNumeric(938, "%s %s :No such spamfilter word is set",user->nick.c_str(), chan->name.c_str());
55         }
56 };
57
58 class ModuleChanFilter : public Module
59 {
60         ChanFilter cf;
61         bool hidemask;
62
63  public:
64
65         ModuleChanFilter(InspIRCd* Me)
66                 : Module(Me), cf(Me, this)
67         {
68                 if (!ServerInstance->Modes->AddMode(&cf))
69                         throw ModuleException("Could not add new modes!");
70
71                 cf.DoImplements(this);
72                 Implementation eventlist[] = { I_OnCleanup, I_OnChannelDelete, I_OnRehash, I_OnUserPreMessage, I_OnUserPreNotice, I_OnSyncChannel };
73                 ServerInstance->Modules->Attach(eventlist, this, 6);
74
75                 OnRehash(NULL);
76                 ServerInstance->Modules->PublishInterface("ChannelBanList", this);
77         }
78
79         virtual void OnRehash(User* user)
80         {
81                 ConfigReader Conf(ServerInstance);
82                 hidemask = Conf.ReadFlag("chanfilter", "hidemask", 0);
83                 cf.DoRehash();
84         }
85
86         virtual ModResult ProcessMessages(User* user,Channel* chan,std::string &text)
87         {
88                 if (!IS_LOCAL(user) || (CHANOPS_EXEMPT(ServerInstance, 'g') && chan->GetPrefixValue(user) == OP_VALUE))
89                         return MOD_RES_PASSTHRU;
90
91                 modelist* list = cf.extItem.get(chan);
92
93                 if (list)
94                 {
95                         for (modelist::iterator i = list->begin(); i != list->end(); i++)
96                         {
97                                 if (InspIRCd::Match(text, i->mask))
98                                 {
99                                         if (hidemask)
100                                                 user->WriteNumeric(404, "%s %s :Cannot send to channel (your message contained a censored word)",user->nick.c_str(), chan->name.c_str());
101                                         else
102                                                 user->WriteNumeric(404, "%s %s %s :Cannot send to channel (your message contained a censored word)",user->nick.c_str(), chan->name.c_str(), i->mask.c_str());
103                                         return MOD_RES_DENY;
104                                 }
105                         }
106                 }
107
108                 return MOD_RES_PASSTHRU;
109         }
110
111         virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
112         {
113                 if (target_type == TYPE_CHANNEL)
114                 {
115                         return ProcessMessages(user,(Channel*)dest,text);
116                 }
117                 return MOD_RES_PASSTHRU;
118         }
119
120         virtual void OnCleanup(int target_type, void* item)
121         {
122                 cf.DoCleanup(target_type, item);
123         }
124
125         virtual const char* OnRequest(Request* request)
126         {
127                 return cf.DoOnRequest(request);
128         }
129
130         virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
131         {
132                 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
133         }
134
135         virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
136         {
137                 cf.DoSyncChannel(chan, proto, opaque);
138         }
139
140         virtual Version GetVersion()
141         {
142                 return Version("Provides channel-specific censor lists (like mode +G but varies from channel to channel)", VF_COMMON | VF_VENDOR, API_VERSION);
143         }
144
145         virtual ~ModuleChanFilter()
146         {
147                 ServerInstance->Modes->DelMode(&cf);
148                 ServerInstance->Modules->UnpublishInterface("ChannelBanList", this);
149         }
150 };
151
152 MODULE_INIT(ModuleChanFilter)