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
39 ModuleChanFilter(Server* Me)
43 Conf = new ConfigReader;
44 Srv->AddExtendedListMode('g');
45 MaxEntries = Conf->ReadInteger("chanfilter","maxsize",0,true);
50 virtual void On005Numeric(std::string &output)
52 std::stringstream line(output);
53 std::string temp1, temp2;
57 if (temp1.substr(0,10) == "CHANMODES=")
59 // append the chanmode to the end
60 temp1 = temp1.substr(10,temp1.length());
61 temp1 = "CHANMODES=g" + temp1;
63 temp2 = temp2 + temp1 + " ";
66 output = temp2.substr(0,temp2.length()-1);
69 virtual void OnUserPart(userrec* user, chanrec* channel)
71 // when the last user parts, delete the list
72 if (Srv->CountUsers(channel) == 1)
74 SpamList* spamlist = (SpamList*)channel->GetExt("spam_list");
77 channel->Shrink("spam_list");
83 virtual void OnRehash(std::string parameter)
86 Conf = new ConfigReader;
87 // re-read our config options on a rehash
88 MaxEntries = Conf->ReadInteger("chanfilter","maxsize",0,true);
91 virtual int ProcessMessages(userrec* user,chanrec* chan,std::string &text)
94 strlcpy(buffer,text.c_str(),MAXBUF);
95 for (unsigned int j = 0; j < strlen(buffer); j++)
96 buffer[j] = tolower(buffer[j]);
97 SpamList* spamlist = (SpamList*)chan->GetExt("spam_list");
100 for (SpamList::iterator i = spamlist->begin(); i != spamlist->end(); i++)
102 if (strstr(buffer,i->c_str()))
104 WriteServ(user->fd,"936 %s %s :Your message contained a censored word, and was blocked",user->nick, chan->name);
112 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
114 if (target_type == TYPE_CHANNEL)
116 return ProcessMessages(user,(chanrec*)dest,text);
121 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
123 if (target_type == TYPE_CHANNEL)
125 return ProcessMessages(user,(chanrec*)dest,text);
130 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
132 if ((modechar == 'g') && (type == MT_CHANNEL))
134 chanrec* chan = (chanrec*)target;
136 for (unsigned int j = 0; j < params[0].length(); j++)
137 params[0][j] = tolower(params[0][j]);
139 std::string param = params[0];
143 SpamList* spamlist = (SpamList*)chan->GetExt("spam_list");
146 spamlist = new SpamList;
147 chan->Extend("spam_list",(char*)spamlist);
149 if (spamlist->size() < (unsigned)MaxEntries)
151 for (SpamList::iterator i = spamlist->begin(); i != spamlist->end(); i++)
155 WriteServ(user->fd,"937 %s %s :The word %s is already on the spamfilter list",user->nick, chan->name,params[0].c_str());
159 spamlist->push_back(params[0]);
162 WriteServ(user->fd,"939 %s %s :Channel spamfilter list is full",user->nick, chan->name);
167 SpamList* spamlist = (SpamList*)chan->GetExt("spam_list");
170 for (SpamList::iterator i = spamlist->begin(); i != spamlist->end(); i++)
179 WriteServ(user->fd,"938 %s %s :No such spamfilter word is set",user->nick, chan->name);
187 virtual void OnSendList(userrec* user, chanrec* channel, char mode)
191 SpamList* spamlist = (SpamList*)channel->GetExt("spam_list");
194 for (SpamList::iterator i = spamlist->begin(); i != spamlist->end(); i++)
196 WriteServ(user->fd,"941 %s %s %s",user->nick, channel->name,i->c_str());
199 WriteServ(user->fd,"940 %s %s :End of channel spamfilter list",user->nick, channel->name);
203 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(Server* Me)
242 return new ModuleChanFilter(Me);
248 extern "C" void * init_module( void )
250 return new ModuleChanFilterFactory;