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 if (time(NULL) > reset)
54 reset = time(NULL) + secs;
60 return (counter >= this->joins);
72 if (time(NULL) > unlocktime)
88 unlocktime = time(NULL) + 60;
94 class ModuleJoinFlood : public Module
100 ModuleJoinFlood(Server* Me)
104 Srv->AddExtendedMode('j',MT_CHANNEL,false,1,0);
107 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
109 if ((modechar == 'j') && (type == MT_CHANNEL))
113 std::string FloodParams = params[0];
114 chanrec* c = (chanrec*)target;
117 strlcpy(ndata,FloodParams.c_str(),MAXBUF);
133 /* Set up the flood parameters for this channel */
134 int njoins = atoi(joins);
135 int nsecs = atoi(secs);
136 if ((njoins<1) || (nsecs<1))
138 WriteServ(user->fd,"608 %s %s :Invalid flood parameter",user->nick,c->name);
143 if (!c->GetExt("joinflood"))
145 joinfloodsettings *f = new joinfloodsettings(njoins,nsecs);
146 c->Extend("joinflood",(char*)f);
153 WriteServ(user->fd,"608 %s %s :Invalid flood parameter",user->nick,c->name);
160 chanrec* c = (chanrec*)target;
161 if (c->GetExt("joinflood"))
163 joinfloodsettings *f = (joinfloodsettings*)c->GetExt("joinflood");
165 c->Shrink("joinflood");
173 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
177 joinfloodsettings *f = (joinfloodsettings*)chan->GetExt("joinflood");
182 WriteServ(user->fd,"609 %s %s :This channel is temporarily unavailable (+j). Please try again later.",user->nick,chan->name);
190 virtual void OnUserJoin(userrec* user, chanrec* channel)
192 joinfloodsettings *f = (joinfloodsettings*)channel->GetExt("joinflood");
200 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);
205 void OnChannelDelete(chanrec* chan)
207 if (chan->GetExt("joinflood"))
209 joinfloodsettings *f = (joinfloodsettings*)chan->GetExt("joinflood");
211 chan->Shrink("joinflood");
215 void Implements(char* List)
217 List[I_On005Numeric] = List[I_OnExtendedMode] = List[I_OnChannelDelete] = List[I_OnUserPreJoin] = List[I_OnUserJoin] = 1;
220 virtual void On005Numeric(std::string &output)
222 std::stringstream line(output);
223 std::string temp1, temp2;
227 if (temp1.substr(0,10) == "CHANMODES=")
229 // By doing this we're *assuming* no other module has fucked up the CHANMODES=
230 // section of the 005 numeric. If they have, we're going DOWN in a blaze of glory,
231 // with a honking great EXCEPTION :)
232 temp1.insert(temp1.find(",")+1,"j");
234 temp2 = temp2 + temp1 + " ";
237 output = temp2.substr(0,temp2.length()-1);
240 virtual ~ModuleJoinFlood()
244 virtual Version GetVersion()
246 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
251 class ModuleJoinFloodFactory : public ModuleFactory
254 ModuleJoinFloodFactory()
258 ~ModuleJoinFloodFactory()
262 virtual Module * CreateModule(Server* Me)
264 return new ModuleJoinFlood(Me);
270 extern "C" void * init_module( void )
272 return new ModuleJoinFloodFactory;