1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
25 #include "helperfuncs.h"
27 #include "u_listmode.h"
29 /* $ModDesc: Provides channel-specific censor lists (like mode +G but varies from channel to channel) */
31 class ChanFilter : public ListModeBase
34 ChanFilter(Server* serv) : ListModeBase(serv, 'g', "End of channel spamfilter list", "941", "940", "chanfilter") { }
36 virtual bool ValidateParam(userrec* user, chanrec* chan, std::string &word)
38 if (word.length() > 35)
40 WriteServ(user->fd, "935 %s %s %s :word is too long for censor list",user->nick, chan->name,word.c_str());
47 virtual bool TellListTooLong(userrec* user, chanrec* chan, std::string &word)
49 WriteServ(user->fd,"939 %s %s %s :Channel spamfilter list is full",user->nick, chan->name, word.c_str());
53 virtual void TellAlreadyOnList(userrec* user, chanrec* chan, std::string &word)
55 WriteServ(user->fd,"937 %s %s :The word %s is already on the spamfilter list",user->nick, chan->name,word.c_str());
58 virtual void TellNotSet(userrec* user, chanrec* chan, std::string &word)
60 WriteServ(user->fd,"938 %s %s :No such spamfilter word is set",user->nick, chan->name);
64 class ModuleChanFilter : public Module
71 ModuleChanFilter(Server* Me)
72 : Module::Module(Me), Srv(Me)
74 cf = new ChanFilter(Srv);
75 Srv->AddMode(cf, 'g');
78 void Implements(char* List)
80 cf->DoImplements(List);
81 List[I_OnCleanup] = List[I_On005Numeric] = List[I_OnChannelDelete] = List[I_OnRehash] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnSyncChannel] = 1;
84 virtual void On005Numeric(std::string &output)
86 InsertMode(output,"g",1);
89 virtual void OnChannelDelete(chanrec* chan)
91 cf->DoChannelDelete(chan);
94 virtual void OnRehash(const std::string ¶meter)
99 virtual int ProcessMessages(userrec* user,chanrec* chan,std::string &text)
101 // Create a copy of the string in irc::string
102 irc::string line = text.c_str();
104 modelist* list = (modelist*)chan->GetExt(cf->GetInfoKey());
108 for (modelist::iterator i = list->begin(); i != list->end(); i++)
110 if (line.find(i->mask.c_str()) != std::string::npos)
112 WriteServ(user->fd,"936 %s %s %s :Your message contained a censored word, and was blocked",user->nick, chan->name, i->mask.c_str());
120 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
122 if (target_type == TYPE_CHANNEL)
124 return ProcessMessages(user,(chanrec*)dest,text);
129 virtual void OnCleanup(int target_type, void* item)
131 cf->DoCleanup(target_type, item);
134 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
136 return OnUserPreMessage(user,dest,target_type,text,status);
139 virtual void OnSyncChannel(chanrec* chan, Module* proto, void* opaque)
141 cf->DoSyncChannel(chan, proto, opaque);
144 virtual Version GetVersion()
146 return Version(1,0,0,1,VF_STATIC|VF_VENDOR);
149 virtual ~ModuleChanFilter()
155 class ModuleChanFilterFactory : public ModuleFactory
158 ModuleChanFilterFactory()
162 ~ModuleChanFilterFactory()
166 virtual Module * CreateModule(Server* Me)
168 return new ModuleChanFilter(Me);
174 extern "C" void * init_module( void )
176 return new ModuleChanFilterFactory;