X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_joinflood.cpp;h=ed67a880a8d6e915fecca2e07ae9958106536f18;hb=7f00015727fab50e37de46aa90d218b31c852c87;hp=34d39c8b603b1bb6b5d50b82a2687e6a0417f7a4;hpb=fd6ee21f2f55875984884a8413d61012e066029f;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_joinflood.cpp b/src/modules/m_joinflood.cpp index 34d39c8b6..ed67a880a 100644 --- a/src/modules/m_joinflood.cpp +++ b/src/modules/m_joinflood.cpp @@ -2,33 +2,27 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev. - * E-mail: - * - * - * - * Written by Craig Edwards, Craig McLure, and others. + * InspIRCd: (C) 2002-2007 InspIRCd Development Team + * See: http://www.inspircd.org/wiki/index.php/Credits + * * This program is free but copyrighted software; see * the file COPYING for details. * * --------------------------------------------------- */ -using namespace std; - #include #include #include "users.h" #include "channels.h" #include "modules.h" -#include "helperfuncs.h" #include "configreader.h" #include "inspircd.h" /* $ModDesc: Provides channel mode +j (join flood protection) */ - - +/** Holds settings and state associated with channel mode +j + */ class joinfloodsettings : public classbase { public: @@ -39,23 +33,22 @@ class joinfloodsettings : public classbase time_t unlocktime; int counter; bool locked; - + InspIRCd* ServerInstance; + joinfloodsettings() : secs(0), joins(0) {}; + joinfloodsettings(int b, int c) : secs(b), joins(c) { reset = time(NULL) + secs; counter = 0; locked = false; - log(DEBUG,"Create new joinfloodsettings: %lu %lu",time(NULL),reset); }; void addjoin() { counter++; - log(DEBUG,"joinflood counter is %d",counter); if (time(NULL) > reset) { - log(DEBUG,"joinflood counter reset"); counter = 0; reset = time(NULL) + secs; } @@ -68,7 +61,6 @@ class joinfloodsettings : public classbase void clear() { - log(DEBUG,"joinflood counter clear"); counter = 0; } @@ -91,13 +83,14 @@ class joinfloodsettings : public classbase void lock() { - log(DEBUG,"joinflood lock"); locked = true; unlocktime = time(NULL) + 60; } }; +/** Handles channel mode +j + */ class JoinFlood : public ModeHandler { public: @@ -141,6 +134,7 @@ class JoinFlood : public ModeHandler else data++; } if (secs) + { /* Set up the flood parameters for this channel */ int njoins = atoi(joins); @@ -162,6 +156,36 @@ class JoinFlood : public ModeHandler channel->SetModeParam('j', parameter.c_str(), true); return MODEACTION_ALLOW; } + else + { + std::string cur_param = channel->GetModeParameter('j'); + parameter = ConvToStr(njoins) + ":" +ConvToStr(nsecs); + if (cur_param == parameter) + { + // mode params match + return MODEACTION_DENY; + } + else + { + // new mode param, replace old with new + if ((nsecs > 0) && (njoins > 0)) + { + joinfloodsettings* f; + channel->GetExt("joinflood", f); + delete f; + f = new joinfloodsettings(nsecs,njoins); + channel->Shrink("joinflood"); + channel->Extend("joinflood", f); + channel->SetModeParam('j', cur_param.c_str(), false); + channel->SetModeParam('j', parameter.c_str(), true); + return MODEACTION_ALLOW; + } + else + { + return MODEACTION_DENY; + } + } + } } } else @@ -198,10 +222,11 @@ class ModuleJoinFlood : public Module { jf = new JoinFlood(ServerInstance); - ServerInstance->AddMode(jf, 'j'); + if (!ServerInstance->AddMode(jf, 'j')) + throw ModuleException("Could not add new modes!"); } - virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname) + virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname, std::string &privs) { if (chan) { @@ -245,22 +270,18 @@ class ModuleJoinFlood : public Module void Implements(char* List) { - List[I_On005Numeric] = List[I_OnChannelDelete] = List[I_OnUserPreJoin] = List[I_OnUserJoin] = 1; - } - - virtual void On005Numeric(std::string &output) - { - ServerInstance->ModeGrok->InsertMode(output, "j", 3); + List[I_OnChannelDelete] = List[I_OnUserPreJoin] = List[I_OnUserJoin] = 1; } virtual ~ModuleJoinFlood() { + ServerInstance->Modes->DelMode(jf); DELETE(jf); } virtual Version GetVersion() { - return Version(1,0,0,0,VF_STATIC|VF_VENDOR); + return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION); } };