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 * ---------------------------------------------------
23 #include "helperfuncs.h"
25 /* $ModDesc: Provides channel mode +f (message flood protection) */
33 floodsettings() : ban(0), secs(0), lines(0) {};
34 floodsettings(bool a, int b, int c) : ban(a), secs(b), lines(c) {};
37 class ModuleMsgFlood : public Module
43 ModuleMsgFlood(Server* Me)
47 Srv->AddExtendedMode('f',MT_CHANNEL,false,1,0);
50 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
52 if ((modechar == 'f') && (type == MT_CHANNEL))
56 std::string FloodParams = params[0];
57 chanrec* c = (chanrec*)target;
59 strlcpy(data,FloodParams.c_str(),MAXBUF);
85 /* Set up the flood parameters for this channel */
86 int nlines = atoi(lines);
87 int nsecs = atoi(secs);
88 if ((nlines<1) || (nsecs<1))
90 WriteServ(user->fd,"608 %s %s :Invalid flood parameter",user->nick,c->name);
95 if (!c->GetExt("flood"))
97 floodsettings *f = new floodsettings(ban,nlines,nsecs);
98 c->Extend("flood",(char*)f);
105 WriteServ(user->fd,"608 %s %s :Invalid flood parameter",user->nick,c->name);
112 if (c->GetExt("flood"))
114 floodsettings *f = (floodsettings*)c->GetExt("flood");
124 void OnChannelDelete(chanrec* chan)
126 if (c->GetExt("flood"))
128 floodsettings *f = (floodsettings*)c->GetExt("flood");
134 void Implements(char* List)
136 List[I_On005Numeric] = List[I_OnExtendedMode] = List[I_OnChannelDelete] = 1;
139 virtual void On005Numeric(std::string &output)
141 std::stringstream line(output);
142 std::string temp1, temp2;
146 if (temp1.substr(0,10) == "CHANMODES=")
148 // By doing this we're *assuming* no other module has fucked up the CHANMODES=
149 // section of the 005 numeric. If they have, we're going DOWN in a blaze of glory,
150 // with a honking great EXCEPTION :)
151 temp1.insert(temp1.find(",")+1,"f");
153 temp2 = temp2 + temp1 + " ";
156 output = temp2.substr(0,temp2.length()-1);
159 virtual ~ModuleMsgFlood()
163 virtual Version GetVersion()
165 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
170 class ModuleMsgFloodFactory : public ModuleFactory
173 ModuleMsgFloodFactory()
177 ~ModuleMsgFloodFactory()
181 virtual Module * CreateModule(Server* Me)
183 return new ModuleMsgFlood(Me);
189 extern "C" void * init_module( void )
191 return new ModuleMsgFloodFactory;