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 +j (join 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;
97 class JoinFlood : public ModeHandler
100 JoinFlood() : ModeHandler('j', 1, 0, false, MODETYPE_CHANNEL, false) { }
102 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
108 strlcpy(ndata,parameter.c_str(),MAXBUF);
124 /* Set up the flood parameters for this channel */
125 int njoins = atoi(joins);
126 int nsecs = atoi(secs);
127 if ((njoins<1) || (nsecs<1))
129 WriteServ(source->fd,"608 %s %s :Invalid flood parameter",source->nick,channel->name);
131 return MODEACTION_DENY;
135 if (!channel->GetExt("joinflood"))
137 joinfloodsettings *f = new joinfloodsettings(nsecs,njoins);
138 channel->Extend("joinflood",(char*)f);
139 return MODEACTION_ALLOW;
145 WriteServ(source->fd,"608 %s %s :Invalid flood parameter",source->nick,channel->name);
146 return MODEACTION_DENY;
151 if (channel->GetExt("joinflood"))
153 joinfloodsettings *f = (joinfloodsettings*)channel->GetExt("joinflood");
155 channel->Shrink("joinflood");
156 return MODEACTION_ALLOW;
159 return MODEACTION_DENY;
163 class ModuleJoinFlood : public Module
170 ModuleJoinFlood(Server* Me)
174 jf = new JoinFlood();
175 Srv->AddMode(jf, 'j');
178 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
182 joinfloodsettings *f = (joinfloodsettings*)chan->GetExt("joinflood");
187 WriteServ(user->fd,"609 %s %s :This channel is temporarily unavailable (+j). Please try again later.",user->nick,chan->name);
195 virtual void OnUserJoin(userrec* user, chanrec* channel)
197 joinfloodsettings *f = (joinfloodsettings*)channel->GetExt("joinflood");
205 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);
210 void OnChannelDelete(chanrec* chan)
212 if (chan->GetExt("joinflood"))
214 joinfloodsettings *f = (joinfloodsettings*)chan->GetExt("joinflood");
216 chan->Shrink("joinflood");
220 void Implements(char* List)
222 List[I_On005Numeric] = List[I_OnChannelDelete] = List[I_OnUserPreJoin] = List[I_OnUserJoin] = 1;
225 virtual void On005Numeric(std::string &output)
227 InsertMode(output, "j", 3);
230 virtual ~ModuleJoinFlood()
235 virtual Version GetVersion()
237 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
242 class ModuleJoinFloodFactory : public ModuleFactory
245 ModuleJoinFloodFactory()
249 ~ModuleJoinFloodFactory()
253 virtual Module * CreateModule(Server* Me)
255 return new ModuleJoinFlood(Me);
261 extern "C" void * init_module( void )
263 return new ModuleJoinFloodFactory;