diff options
author | attilamolnar <attilamolnar@hush.com> | 2013-02-18 19:56:05 +0100 |
---|---|---|
committer | attilamolnar <attilamolnar@hush.com> | 2013-04-16 13:18:40 +0200 |
commit | 4b81b4004d086555885d5e4a2541b0a92eb4a9ae (patch) | |
tree | f92372154ba4bd4def60efad28f0c12bcd8db4cb /src | |
parent | e3939559e4496c520ec29ad16a5cab99efe7257e (diff) |
m_kicknorejoin Limit time to 30m by default
In the current implementation we only expire entries when someone joins, without a limit it was possible to make us practically never remove entries and consume (a tiny amount of) memory for each entry until the mode was removed/parameter was changed
The default limit of 30m is chosen to not surprise people when they upgrade. If you need to prevent rejoins for more than a minute then you should set a (timed)ban instead
Config option is available to change the limit (2.0 only)
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/m_kicknorejoin.cpp | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/src/modules/m_kicknorejoin.cpp b/src/modules/m_kicknorejoin.cpp index 6d2d10c84..9614b84f2 100644 --- a/src/modules/m_kicknorejoin.cpp +++ b/src/modules/m_kicknorejoin.cpp @@ -31,27 +31,42 @@ typedef std::map<User*, time_t> delaylist; /** Handles channel mode +J */ -class KickRejoin : public ParamChannelModeHandler +class KickRejoin : public ModeHandler { public: + unsigned int max; SimpleExtItem<delaylist> ext; - KickRejoin(Module* Creator) : ParamChannelModeHandler(Creator, "kicknorejoin", 'J'), ext("norejoinusers", Creator) { } - - bool ParamValidate(std::string& parameter) + KickRejoin(Module* Creator) + : ModeHandler(Creator, "kicknorejoin", 'J', PARAM_SETONLY, MODETYPE_CHANNEL) + , ext("norejoinusers", Creator) { - int v = atoi(parameter.c_str()); - if (v <= 0) - return false; - parameter = ConvToStr(v); - return true; } - ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding) + ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) { - ModeAction rv = ParamChannelModeHandler::OnModeChange(source, dest, channel, parameter, adding); - if (rv == MODEACTION_ALLOW && !adding) + if (adding) + { + int v = ConvToInt(parameter); + if (v <= 0) + return MODEACTION_DENY; + if (parameter == channel->GetModeParameter(this)) + return MODEACTION_DENY; + + if ((IS_LOCAL(source) && ((unsigned int)v > max))) + v = max; + + parameter = ConvToStr(v); + channel->SetModeParam(this, parameter); + } + else + { + if (!channel->IsModeSet(this)) + return MODEACTION_DENY; + ext.unset(channel); - return rv; + channel->SetModeParam(this, ""); + } + return MODEACTION_ALLOW; } }; @@ -70,8 +85,16 @@ public: { ServerInstance->Modules->AddService(kr); ServerInstance->Modules->AddService(kr.ext); - Implementation eventlist[] = { I_OnUserPreJoin, I_OnUserKick }; + Implementation eventlist[] = { I_OnUserPreJoin, I_OnUserKick, I_OnRehash }; ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation)); + OnRehash(NULL); + } + + void OnRehash(User* user) + { + kr.max = ServerInstance->Duration(ServerInstance->Config->ConfValue("kicknorejoin")->getString("maxtime")); + if (!kr.max) + kr.max = 30*60; } ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven) |