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);
47 virtual void On005Numeric(std::string &output)
49 std::stringstream line(output);
50 std::string temp1, temp2;
54 if (temp1.substr(0,10) == "CHANMODES=")
56 // append the chanmode to the end
57 temp1 = temp1.substr(10,temp1.length());
58 temp1 = "CHANMODES=g" + temp1;
60 temp2 = temp2 + temp1 + " ";
63 output = temp2.substr(0,temp2.length()-1);
66 virtual void OnUserPart(userrec* user, chanrec* channel)
68 // when the last user parts, delete the list
69 if (Srv->CountUsers(channel) == 1)
71 SpamList* spamlist = (SpamList*)channel->GetExt("spam_list");
74 channel->Shrink("spam_list");
80 virtual void OnRehash(std::string parameter)
83 Conf = new ConfigReader;
84 // re-read our config options on a rehash
85 MaxEntries = Conf->ReadInteger("chanfilter","maxsize",0,true);
88 virtual int ProcessMessages(userrec* user,chanrec* chan,std::string &text)
91 strlcpy(buffer,text.c_str(),MAXBUF);
92 for (unsigned int j = 0; j < strlen(buffer); j++)
93 buffer[j] = tolower(buffer[j]);
94 SpamList* spamlist = (SpamList*)chan->GetExt("spam_list");
97 for (SpamList::iterator i = spamlist->begin(); i != spamlist->end(); i++)
99 if (strstr(text.c_str(),i->c_str()))
101 WriteServ(user->fd,"936 %s %s :Your message contained a censored word, and was blocked",user->nick, chan->name);
109 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
111 if (target_type == TYPE_CHANNEL)
113 return ProcessMessages(user,(chanrec*)dest,text);
118 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
120 if (target_type == TYPE_CHANNEL)
122 return ProcessMessages(user,(chanrec*)dest,text);
127 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
129 if ((modechar == 'g') && (type == MT_CHANNEL))
131 chanrec* chan = (chanrec*)target;
133 for (unsigned int j = 0; j < params[0].length(); j++)
134 params[0][j] = tolower(params[0][j]);
136 std::string param = params[0];
140 SpamList* spamlist = (SpamList*)chan->GetExt("spam_list");
143 spamlist = new SpamList;
144 chan->Extend("spam_list",(char*)spamlist);
146 if (spamlist->size() < (unsigned)MaxEntries)
148 for (SpamList::iterator i = spamlist->begin(); i != spamlist->end(); i++)
152 WriteServ(user->fd,"937 %s %s :The word %s is already on the spamfilter list",user->nick, chan->name,params[0].c_str());
156 spamlist->push_back(params[0]);
159 WriteServ(user->fd,"939 %s %s :Channel spamfilter list is full",user->nick, chan->name);
164 SpamList* spamlist = (SpamList*)chan->GetExt("spam_list");
167 for (SpamList::iterator i = spamlist->begin(); i != spamlist->end(); i++)
176 WriteServ(user->fd,"938 %s %s :No such spamfilter word is set",user->nick, chan->name);
184 virtual void OnSendList(userrec* user, chanrec* channel, char mode)
188 SpamList* spamlist = (SpamList*)channel->GetExt("spam_list");
191 for (SpamList::iterator i = spamlist->begin(); i != spamlist->end(); i++)
193 WriteServ(user->fd,"941 %s %s %s",user->nick, channel->name,i->c_str());
196 WriteServ(user->fd,"940 %s %s :End of channel spamfilter list",user->nick, channel->name);
200 virtual ~ModuleChanFilter()
206 virtual Version GetVersion()
208 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
211 virtual void OnSyncChannel(chanrec* chan, Module* proto, void* opaque)
213 SpamList* spamlist = (SpamList*)chan->GetExt("spam_list");
214 string_list commands;
217 for (SpamList::iterator i = spamlist->begin(); i != spamlist->end(); i++)
219 proto->ProtoSendMode(opaque,TYPE_CHANNEL,chan,"+g "+*i);
228 class ModuleChanFilterFactory : public ModuleFactory
231 ModuleChanFilterFactory()
235 ~ModuleChanFilterFactory()
239 virtual Module * CreateModule()
241 return new ModuleChanFilter;
247 extern "C" void * init_module( void )
249 return new ModuleChanFilterFactory;