]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_kicknorejoin.cpp
Switch <stdint.h> test to use a test file too.
[user/henk/code/inspircd.git] / src / modules / m_kicknorejoin.cpp
index 6d2d10c84c43989803ccfca34db192c0420d1d6b..a914f38693108b69d37a357d7131a92d72c6d43c 100644 (file)
 
 /* $ModDesc: Provides channel mode +J (delay rejoin after kick) */
 
-typedef std::map<User*, time_t> delaylist;
+typedef std::map<std::string, 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)
@@ -85,7 +108,7 @@ public:
                                {
                                        if (iter->second > ServerInstance->Time())
                                        {
-                                               if (iter->first == user)
+                                               if (iter->first == user->uuid)
                                                {
                                                        std::string modeparam = chan->GetModeParameter(&kr);
                                                        user->WriteNumeric(ERR_DELAYREJOIN, "%s %s :You must wait %s seconds after being kicked to rejoin (+J)",
@@ -101,7 +124,7 @@ public:
                                        }
                                }
 
-                               if (!dl->size())
+                               if (dl->empty())
                                        kr.ext.unset(chan);
                        }
                }
@@ -118,7 +141,7 @@ public:
                                dl = new delaylist;
                                kr.ext.set(memb->chan, dl);
                        }
-                       (*dl)[memb->user] = ServerInstance->Time() + ConvToInt(memb->chan->GetModeParameter(&kr));
+                       (*dl)[memb->user->uuid] = ServerInstance->Time() + ConvToInt(memb->chan->GetModeParameter(&kr));
                }
        }