]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
m_kicknorejoin Limit time to 30m by default
authorattilamolnar <attilamolnar@hush.com>
Mon, 18 Feb 2013 18:56:05 +0000 (19:56 +0100)
committerattilamolnar <attilamolnar@hush.com>
Tue, 16 Apr 2013 11:18:40 +0000 (13:18 +0200)
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)

docs/conf/modules.conf.example
src/modules/m_kicknorejoin.cpp

index 0e7b3a29bf838ec4cc7d57f1c2834fb339a5ce74..7a6c478f133759a542a912626ae3f648b9a44c3a 100644 (file)
 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
 # Anti-Auto-Rejoin: Adds support for prevention of auto-rejoin (+J)
 #<module name="m_kicknorejoin.so">
+# Set the maximum time that is accepted as a parameter for +J here.
+#<kicknorejoin maxtime="1m">
 
 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
 # Knock module: adds the /KNOCK command and +K channel mode
index 6d2d10c84c43989803ccfca34db192c0420d1d6b..9614b84f20c13571ec25356f797b920385d7d8a6 100644 (file)
@@ -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 &parameter, bool adding)
+       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::stringparameter, 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)