1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/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(User* user, Channel* chan, std::string &word)
32 if ((word.length() > 35) || (word.empty()))
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"));
41 virtual bool TellListTooLong(User* user, Channel* chan, std::string &word)
43 user->WriteNumeric(939, "%s %s %s :Channel spamfilter list is full", user->nick.c_str(), chan->name.c_str(), word.c_str());
47 virtual void TellAlreadyOnList(User* user, Channel* chan, std::string &word)
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());
52 virtual void TellNotSet(User* user, Channel* chan, std::string &word)
54 user->WriteNumeric(938, "%s %s :No such spamfilter word is set",user->nick.c_str(), chan->name.c_str());
58 class ModuleChanFilter : public Module
66 ModuleChanFilter(InspIRCd* Me)
69 cf = new ChanFilter(ServerInstance);
70 if (!ServerInstance->Modes->AddMode(cf))
71 throw ModuleException("Could not add new modes!");
73 cf->DoImplements(this);
74 Implementation eventlist[] = { I_OnCleanup, I_OnChannelDelete, I_OnRehash, I_OnUserPreMessage, I_OnUserPreNotice, I_OnSyncChannel };
75 ServerInstance->Modules->Attach(eventlist, this, 6);
78 ServerInstance->Modules->PublishInterface("ChannelBanList", this);
81 virtual void OnChannelDelete(Channel* chan)
83 cf->DoChannelDelete(chan);
86 virtual void OnRehash(User* user)
88 ConfigReader Conf(ServerInstance);
89 hidemask = Conf.ReadFlag("chanfilter", "hidemask", 0);
93 virtual int ProcessMessages(User* user,Channel* chan,std::string &text)
95 if (!IS_LOCAL(user) || (CHANOPS_EXEMPT(ServerInstance, 'g') && chan->GetStatus(user) == STATUS_OP))
99 chan->GetExt(cf->GetInfoKey(), list);
103 for (modelist::iterator i = list->begin(); i != list->end(); i++)
105 if (InspIRCd::Match(text, i->mask))
108 user->WriteNumeric(404, "%s %s :Cannot send to channel (your message contained a censored word)",user->nick.c_str(), chan->name.c_str());
110 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());
119 virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
121 if (target_type == TYPE_CHANNEL)
123 return ProcessMessages(user,(Channel*)dest,text);
128 virtual void OnCleanup(int target_type, void* item)
130 cf->DoCleanup(target_type, item);
133 virtual const char* OnRequest(Request* request)
135 return cf->DoOnRequest(request);
138 virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
140 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
143 virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
145 cf->DoSyncChannel(chan, proto, opaque);
148 virtual Version GetVersion()
150 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
153 virtual ~ModuleChanFilter()
155 ServerInstance->Modes->DelMode(cf);
157 ServerInstance->Modules->UnpublishInterface("ChannelBanList", this);
161 MODULE_INIT(ModuleChanFilter)