X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_kicknorejoin.cpp;h=80e1fb8d0ecd1f58f3e533f92c43f216fd03cb20;hb=1484a054870bdfe94346057053d5c8e48a708232;hp=2387abb3efd281b068efd06d604fa6492f5945c9;hpb=64b3ed7211734e17c75f999e63fea739a99268da;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_kicknorejoin.cpp b/src/modules/m_kicknorejoin.cpp index 2387abb3e..80e1fb8d0 100644 --- a/src/modules/m_kicknorejoin.cpp +++ b/src/modules/m_kicknorejoin.cpp @@ -6,6 +6,7 @@ #include "channels.h" #include "modules.h" #include "helperfuncs.h" +#include "inspircd.h" /* $ModDesc: Provides channel mode +J (delay rejoin after kick) */ @@ -19,9 +20,42 @@ inline int strtoint(const std::string &str) typedef std::map delaylist; +class KickRejoin : public ModeHandler +{ + public: + KickRejoin() : ModeHandler('J', 1, 0, false, MODETYPE_CHANNEL, false) { } + + ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding) + { + if (!adding) + { + // Taking the mode off, we need to clean up. + delaylist* dl; + + if (channel->GetExt("norejoinusers", dl)) + { + DELETE(dl); + channel->Shrink("norejoinusers"); + } + } + if ((!adding) || (atoi(parameter.c_str()) > 0)) + { + parameter = ConvToStr(atoi(parameter.c_str())); + channel->SetModeParam('J', parameter.c_str(), adding); + channel->SetMode('J', adding); + return MODEACTION_ALLOW; + } + else + { + return MODEACTION_DENY; + } + } +}; + class ModuleKickNoRejoin : public Module { Server *Srv; + KickRejoin* kr; public: @@ -29,41 +63,16 @@ public: : Module::Module(Me) { Srv = Me; - - Srv->AddExtendedMode('J', MT_CHANNEL, false, 1, 0); - } - - virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms) - { - if ((modechar == 'J') && (type == MT_CHANNEL)) - { - if (!mode_on) - { - // Taking the mode off, we need to clean up. - chanrec* c = (chanrec*)target; - - delaylist* dl = (delaylist*)c->GetExt("norejoinusers"); - - if (dl) - { - delete dl; - c->Shrink("norejoinusers"); - } - } - /* Don't allow negative or 0 +J value */ - return ((!mode_on) || (atoi(params[0].c_str()) > 0)); - } - return 0; + kr = new KickRejoin(); + Srv->AddMode(kr, 'J'); } virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname) { if (chan) { - delaylist* dl = (delaylist*)chan->GetExt("norejoinusers"); - log(DEBUG, "m_kicknorejoin.so: tried to grab delay list"); - - if (dl) + delaylist* dl; + if (chan->GetExt("norejoinusers", dl)) { log(DEBUG, "m_kicknorejoin.so: got delay list, iterating over it"); std::vector itemstoremove; @@ -95,24 +104,23 @@ public: if (!dl->size()) { // Now it's empty.. - delete dl; - chan->Shrink("norejoinusers"); + DELETE(dl); + chan->Shrink("norejoinusers"); } } } return 0; } - - virtual void OnUserKick(userrec* source, userrec* user, chanrec* chan, std::string reason) + + virtual void OnUserKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason) { - if (chan->IsCustomModeSet('J') && (source != user)) + if (chan->IsModeSet('J') && (source != user)) { - delaylist* dl = (delaylist*)chan->GetExt("norejoinusers"); - - if (!dl) + delaylist* dl; + if (!chan->GetExt("norejoinusers", dl)) { dl = new delaylist; - chan->Extend("norejoinusers", (char*)dl); + chan->Extend("norejoinusers", dl); } log(DEBUG, "m_kicknorejoin.so: setting record for %s, %d second delay", user->nick, strtoint(chan->GetModeParameter('J'))); @@ -122,11 +130,11 @@ public: virtual void OnChannelDelete(chanrec* chan) { - delaylist* dl = (delaylist*)chan->GetExt("norejoinusers"); - - if (dl) + delaylist* dl; + + if (chan->GetExt("norejoinusers", dl)) { - delete dl; + DELETE(dl); chan->Shrink("norejoinusers"); } } @@ -139,7 +147,7 @@ public: virtual void Implements(char* List) { - List[I_OnCleanup] = List[I_On005Numeric] = List[I_OnExtendedMode] = List[I_OnChannelDelete] = List[I_OnUserPreJoin] = List[I_OnUserKick] = 1; + List[I_OnCleanup] = List[I_On005Numeric] = List[I_OnChannelDelete] = List[I_OnUserPreJoin] = List[I_OnUserKick] = 1; } virtual void On005Numeric(std::string &output) @@ -149,6 +157,7 @@ public: virtual ~ModuleKickNoRejoin() { + DELETE(kr); } virtual Version GetVersion()