1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
21 #include "u_listmode.h"
24 /* $ModDesc: Provides channel-specific censor lists (like mode +G but varies from channel to channel) */
25 /* $ModDep: ../../include/u_listmode.h */
27 /** Handles channel mode +g
29 class ChanFilter : public ListModeBase
32 ChanFilter(InspIRCd* Instance) : ListModeBase(Instance, 'g', "End of channel spamfilter list", "941", "940", false, "chanfilter") { }
34 virtual bool ValidateParam(userrec* user, chanrec* chan, std::string &word)
36 if ((word.length() > 35) || (word.empty()))
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"));
45 virtual bool TellListTooLong(userrec* user, chanrec* chan, std::string &word)
47 user->WriteServ("939 %s %s %s :Channel spamfilter list is full",user->nick, chan->name, word.c_str());
51 virtual void TellAlreadyOnList(userrec* user, chanrec* chan, std::string &word)
53 user->WriteServ("937 %s %s :The word %s is already on the spamfilter list",user->nick, chan->name,word.c_str());
56 virtual void TellNotSet(userrec* user, chanrec* chan, std::string &word)
58 user->WriteServ("938 %s %s :No such spamfilter word is set",user->nick, chan->name);
62 class ModuleChanFilter : public Module
69 ModuleChanFilter(InspIRCd* Me)
72 cf = new ChanFilter(ServerInstance);
73 ServerInstance->AddMode(cf, 'g');
76 void Implements(char* List)
78 cf->DoImplements(List);
79 List[I_OnCleanup] = List[I_OnChannelDelete] = List[I_OnRehash] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnSyncChannel] = 1;
82 virtual void OnChannelDelete(chanrec* chan)
84 cf->DoChannelDelete(chan);
87 virtual void OnRehash(const std::string ¶meter)
92 virtual int ProcessMessages(userrec* user,chanrec* chan,std::string &text)
94 // Create a copy of the string in irc::string
95 irc::string line = text.c_str();
98 chan->GetExt(cf->GetInfoKey(), list);
102 for (modelist::iterator i = list->begin(); i != list->end(); i++)
104 if (line.find(i->mask.c_str()) != std::string::npos)
106 user->WriteServ("936 %s %s %s :Your message contained a censored word, and was blocked",user->nick, chan->name, i->mask.c_str());
114 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
116 if (target_type == TYPE_CHANNEL)
118 return ProcessMessages(user,(chanrec*)dest,text);
123 virtual void OnCleanup(int target_type, void* item)
125 cf->DoCleanup(target_type, item);
128 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
130 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
133 virtual void OnSyncChannel(chanrec* chan, Module* proto, void* opaque)
135 cf->DoSyncChannel(chan, proto, opaque);
138 virtual Version GetVersion()
140 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
143 virtual ~ModuleChanFilter()
145 ServerInstance->Modes->DelMode(cf);
151 class ModuleChanFilterFactory : public ModuleFactory
154 ModuleChanFilterFactory()
158 ~ModuleChanFilterFactory()
162 virtual Module * CreateModule(InspIRCd* Me)
164 return new ModuleChanFilter(Me);
170 extern "C" void * init_module( void )
172 return new ModuleChanFilterFactory;