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 * ---------------------------------------------------
14 #define _CRT_SECURE_NO_DEPRECATE
15 #define _SCL_SECURE_NO_DEPRECATE
18 #include "u_listmode.h"
20 /* $ModDesc: Provides channel-specific censor lists (like mode +G but varies from channel to channel) */
21 /* $ModDep: ../../include/u_listmode.h */
23 /** Handles channel mode +g
25 class ChanFilter : public ListModeBase
28 ChanFilter(InspIRCd* Instance) : ListModeBase(Instance, 'g', "End of channel spamfilter list", "941", "940", false, "chanfilter") { }
30 virtual bool ValidateParam(userrec* user, chanrec* chan, std::string &word)
32 if ((word.length() > 35) || (word.empty()))
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"));
41 virtual bool TellListTooLong(userrec* user, chanrec* chan, std::string &word)
43 user->WriteServ("939 %s %s %s :Channel spamfilter list is full",user->nick, chan->name, word.c_str());
47 virtual void TellAlreadyOnList(userrec* user, chanrec* chan, std::string &word)
49 user->WriteServ("937 %s %s :The word %s is already on the spamfilter list",user->nick, chan->name,word.c_str());
52 virtual void TellNotSet(userrec* user, chanrec* chan, std::string &word)
54 user->WriteServ("938 %s %s :No such spamfilter word is set",user->nick, chan->name);
58 class ModuleChanFilter : public Module
65 ModuleChanFilter(InspIRCd* Me)
68 cf = new ChanFilter(ServerInstance);
69 if (!ServerInstance->AddMode(cf, 'g'))
70 throw ModuleException("Could not add new modes!");
73 void Implements(char* List)
75 cf->DoImplements(List);
76 List[I_OnCleanup] = List[I_OnChannelDelete] = List[I_OnRehash] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnSyncChannel] = 1;
79 virtual void OnChannelDelete(chanrec* chan)
81 cf->DoChannelDelete(chan);
84 virtual void OnRehash(userrec* user, const std::string ¶meter)
89 virtual int ProcessMessages(userrec* user,chanrec* chan,std::string &text)
91 if (!IS_LOCAL(user) || CHANOPS_EXEMPT(ServerInstance, 'g') && chan->GetStatus(user) == STATUS_OP)
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());
115 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
117 if (target_type == TYPE_CHANNEL)
119 return ProcessMessages(user,(chanrec*)dest,text);
124 virtual void OnCleanup(int target_type, void* item)
126 cf->DoCleanup(target_type, item);
129 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
131 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
134 virtual void OnSyncChannel(chanrec* chan, Module* proto, void* opaque)
136 cf->DoSyncChannel(chan, proto, opaque);
139 virtual Version GetVersion()
141 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
144 virtual ~ModuleChanFilter()
146 ServerInstance->Modes->DelMode(cf);
151 MODULE_INIT(ModuleChanFilter)