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 * ---------------------------------------------------
26 #include "u_listmode.h"
29 /* $ModDesc: Provides channel-specific censor lists (like mode +G but varies from channel to channel) */
30 /* $ModDep: ../../include/u_listmode.h */
32 /** Handles channel mode +g
34 class ChanFilter : public ListModeBase
37 ChanFilter(InspIRCd* Instance) : ListModeBase(Instance, 'g', "End of channel spamfilter list", "941", "940", false, "chanfilter") { }
39 virtual bool ValidateParam(userrec* user, chanrec* chan, std::string &word)
41 if ((word.length() > 35) || (word.empty()))
43 user->WriteServ("935 %s %s %s :word is too %s for censor list",user->nick, chan->name,word.c_str(), (word.empty() ? "short" : "long"));
50 virtual bool TellListTooLong(userrec* user, chanrec* chan, std::string &word)
52 user->WriteServ("939 %s %s %s :Channel spamfilter list is full",user->nick, chan->name, word.c_str());
56 virtual void TellAlreadyOnList(userrec* user, chanrec* chan, std::string &word)
58 user->WriteServ("937 %s %s :The word %s is already on the spamfilter list",user->nick, chan->name,word.c_str());
61 virtual void TellNotSet(userrec* user, chanrec* chan, std::string &word)
63 user->WriteServ("938 %s %s :No such spamfilter word is set",user->nick, chan->name);
67 class ModuleChanFilter : public Module
74 ModuleChanFilter(InspIRCd* Me)
77 cf = new ChanFilter(ServerInstance);
78 ServerInstance->AddMode(cf, 'g');
81 void Implements(char* List)
83 cf->DoImplements(List);
84 List[I_OnCleanup] = List[I_OnChannelDelete] = List[I_OnRehash] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnSyncChannel] = 1;
87 virtual void OnChannelDelete(chanrec* chan)
89 cf->DoChannelDelete(chan);
92 virtual void OnRehash(const std::string ¶meter)
97 virtual int ProcessMessages(userrec* user,chanrec* chan,std::string &text)
99 // Create a copy of the string in irc::string
100 irc::string line = text.c_str();
103 chan->GetExt(cf->GetInfoKey(), list);
107 for (modelist::iterator i = list->begin(); i != list->end(); i++)
109 if (line.find(i->mask.c_str()) != std::string::npos)
111 user->WriteServ("936 %s %s %s :Your message contained a censored word, and was blocked",user->nick, chan->name, i->mask.c_str());
119 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
121 if (target_type == TYPE_CHANNEL)
123 return ProcessMessages(user,(chanrec*)dest,text);
128 virtual void OnCleanup(int target_type, void* item)
130 cf->DoCleanup(target_type, item);
133 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
135 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
138 virtual void OnSyncChannel(chanrec* chan, Module* proto, void* opaque)
140 cf->DoSyncChannel(chan, proto, opaque);
143 virtual Version GetVersion()
145 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
148 virtual ~ModuleChanFilter()
150 ServerInstance->Modes->DelMode(cf);
156 class ModuleChanFilterFactory : public ModuleFactory
159 ModuleChanFilterFactory()
163 ~ModuleChanFilterFactory()
167 virtual Module * CreateModule(InspIRCd* Me)
169 return new ModuleChanFilter(Me);
175 extern "C" void * init_module( void )
177 return new ModuleChanFilterFactory;