1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 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 /* $ModDesc: Provides channel-specific censor lists (like mode +G but varies from channel to channel) */
29 typedef std::vector<std::string> SpamList;
31 class ModuleChanFilter : public Module
42 Conf = new ConfigReader;
43 Srv->AddExtendedListMode('g');
44 MaxEntries = Conf->ReadInteger("chanfilter","maxsize",0,true);
49 virtual void On005Numeric(std::string &output)
51 std::stringstream line(output);
52 std::string temp1, temp2;
56 if (temp1.substr(0,10) == "CHANMODES=")
58 // append the chanmode to the end
59 temp1 = temp1.substr(10,temp1.length());
60 temp1 = "CHANMODES=g" + temp1;
62 temp2 = temp2 + temp1 + " ";
65 output = temp2.substr(0,temp2.length()-1);
68 virtual void OnUserPart(userrec* user, chanrec* channel)
70 // when the last user parts, delete the list
71 if (Srv->CountUsers(channel) == 1)
73 SpamList* spamlist = (SpamList*)channel->GetExt("spam_list");
76 channel->Shrink("spam_list");
82 virtual void OnRehash(std::string parameter)
85 Conf = new ConfigReader;
86 // re-read our config options on a rehash
87 MaxEntries = Conf->ReadInteger("chanfilter","maxsize",0,true);
90 virtual int ProcessMessages(userrec* user,chanrec* chan,std::string &text)
93 strlcpy(buffer,text.c_str(),MAXBUF);
94 for (unsigned int j = 0; j < strlen(buffer); j++)
95 buffer[j] = tolower(buffer[j]);
96 SpamList* spamlist = (SpamList*)chan->GetExt("spam_list");
99 for (SpamList::iterator i = spamlist->begin(); i != spamlist->end(); i++)
101 if (strstr(text.c_str(),i->c_str()))
103 WriteServ(user->fd,"936 %s %s :Your message contained a censored word, and was blocked",user->nick, chan->name);
111 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
113 if (target_type == TYPE_CHANNEL)
115 return ProcessMessages(user,(chanrec*)dest,text);
120 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
122 if (target_type == TYPE_CHANNEL)
124 return ProcessMessages(user,(chanrec*)dest,text);
129 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
131 if ((modechar == 'g') && (type == MT_CHANNEL))
133 chanrec* chan = (chanrec*)target;
135 for (unsigned int j = 0; j < params[0].length(); j++)
136 params[0][j] = tolower(params[0][j]);
138 std::string param = params[0];
142 SpamList* spamlist = (SpamList*)chan->GetExt("spam_list");
145 spamlist = new SpamList;
146 chan->Extend("spam_list",(char*)spamlist);
148 if (spamlist->size() < (unsigned)MaxEntries)
150 for (SpamList::iterator i = spamlist->begin(); i != spamlist->end(); i++)
154 WriteServ(user->fd,"937 %s %s :The word %s is already on the spamfilter list",user->nick, chan->name,params[0].c_str());
158 spamlist->push_back(params[0]);
161 WriteServ(user->fd,"939 %s %s :Channel spamfilter list is full",user->nick, chan->name);
166 SpamList* spamlist = (SpamList*)chan->GetExt("spam_list");
169 for (SpamList::iterator i = spamlist->begin(); i != spamlist->end(); i++)
178 WriteServ(user->fd,"938 %s %s :No such spamfilter word is set",user->nick, chan->name);
186 virtual void OnSendList(userrec* user, chanrec* channel, char mode)
190 SpamList* spamlist = (SpamList*)channel->GetExt("spam_list");
193 for (SpamList::iterator i = spamlist->begin(); i != spamlist->end(); i++)
195 WriteServ(user->fd,"941 %s %s %s",user->nick, channel->name,i->c_str());
198 WriteServ(user->fd,"940 %s %s :End of channel spamfilter list",user->nick, channel->name);
202 virtual ~ModuleChanFilter()
208 virtual Version GetVersion()
210 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
213 virtual void OnSyncChannel(chanrec* chan, Module* proto, void* opaque)
215 SpamList* spamlist = (SpamList*)chan->GetExt("spam_list");
216 string_list commands;
219 for (SpamList::iterator i = spamlist->begin(); i != spamlist->end(); i++)
221 proto->ProtoSendMode(opaque,TYPE_CHANNEL,chan,"+g "+*i);
229 class ModuleChanFilterFactory : public ModuleFactory
232 ModuleChanFilterFactory()
236 ~ModuleChanFilterFactory()
240 virtual Module * CreateModule()
242 return new ModuleChanFilter;
248 extern "C" void * init_module( void )
250 return new ModuleChanFilterFactory;