1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 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 * ---------------------------------------------------
24 #include "helperfuncs.h"
26 /* $ModDesc: Provides channel mode +f (message flood protection) */
28 class joinfloodsettings
39 joinfloodsettings() : secs(0), joins(0) {};
40 joinfloodsettings(int b, int c) : secs(b), joins(c)
42 reset = time(NULL) + secs;
45 log(DEBUG,"Create new joinfloodsettings: %lu %lu",time(NULL),reset);
51 log(DEBUG,"joinflood counter is %d",counter);
52 if (time(NULL) > reset)
54 log(DEBUG,"joinflood counter reset");
56 reset = time(NULL) + secs;
62 return (counter >= this->joins);
67 log(DEBUG,"joinflood counter clear");
75 if (time(NULL) > unlocktime)
90 log(DEBUG,"joinflood lock");
92 unlocktime = time(NULL) + 60;
98 class ModuleJoinFlood : public Module
104 ModuleJoinFlood(Server* Me)
108 Srv->AddExtendedMode('j',MT_CHANNEL,false,1,0);
111 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
113 if ((modechar == 'j') && (type == MT_CHANNEL))
117 std::string FloodParams = params[0];
118 chanrec* c = (chanrec*)target;
121 strlcpy(ndata,FloodParams.c_str(),MAXBUF);
137 /* Set up the flood parameters for this channel */
138 int njoins = atoi(joins);
139 int nsecs = atoi(secs);
140 if ((njoins<1) || (nsecs<1))
142 WriteServ(user->fd,"608 %s %s :Invalid flood parameter",user->nick,c->name);
147 if (!c->GetExt("joinflood"))
149 joinfloodsettings *f = new joinfloodsettings(nsecs,njoins);
150 c->Extend("joinflood",(char*)f);
157 WriteServ(user->fd,"608 %s %s :Invalid flood parameter",user->nick,c->name);
164 chanrec* c = (chanrec*)target;
165 if (c->GetExt("joinflood"))
167 joinfloodsettings *f = (joinfloodsettings*)c->GetExt("joinflood");
169 c->Shrink("joinflood");
177 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
181 joinfloodsettings *f = (joinfloodsettings*)chan->GetExt("joinflood");
186 WriteServ(user->fd,"609 %s %s :This channel is temporarily unavailable (+j). Please try again later.",user->nick,chan->name);
194 virtual void OnUserJoin(userrec* user, chanrec* channel)
196 joinfloodsettings *f = (joinfloodsettings*)channel->GetExt("joinflood");
204 WriteChannelWithServ((char*)Srv->GetServerName().c_str(), channel, "NOTICE %s :This channel has been closed to new users for 60 seconds because there have been more than %d joins in %d seconds.",channel->name,f->joins,f->secs);
209 void OnChannelDelete(chanrec* chan)
211 if (chan->GetExt("joinflood"))
213 joinfloodsettings *f = (joinfloodsettings*)chan->GetExt("joinflood");
215 chan->Shrink("joinflood");
219 void Implements(char* List)
221 List[I_On005Numeric] = List[I_OnExtendedMode] = List[I_OnChannelDelete] = List[I_OnUserPreJoin] = List[I_OnUserJoin] = 1;
224 virtual void On005Numeric(std::string &output)
226 InsertMode(output, "j", 3);
229 virtual ~ModuleJoinFlood()
233 virtual Version GetVersion()
235 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
240 class ModuleJoinFloodFactory : public ModuleFactory
243 ModuleJoinFloodFactory()
247 ~ModuleJoinFloodFactory()
251 virtual Module * CreateModule(Server* Me)
253 return new ModuleJoinFlood(Me);
259 extern "C" void * init_module( void )
261 return new ModuleJoinFloodFactory;