X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_kicknorejoin.cpp;h=9d5fe3b623434d831e456cebe20d87491bb21c7a;hb=e80a1296a096ff2c495b3cd2a3913d5e5f6ec450;hp=835f73443f7ed02dc20dbe833869f18f642de65d;hpb=fbe8169b82cb071dd57b66941093df654aa7b22c;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_kicknorejoin.cpp b/src/modules/m_kicknorejoin.cpp index 835f73443..9d5fe3b62 100644 --- a/src/modules/m_kicknorejoin.cpp +++ b/src/modules/m_kicknorejoin.cpp @@ -15,7 +15,7 @@ /* $ModDesc: Provides channel mode +J (delay rejoin after kick) */ -inline int strtoint(const std::string &str) +static inline int strtoint(const std::string &str) { std::istringstream ss(str); int result; @@ -30,7 +30,9 @@ typedef std::map delaylist; class KickRejoin : public ModeHandler { public: - KickRejoin(InspIRCd* Instance) : ModeHandler(Instance, 'J', 1, 0, false, MODETYPE_CHANNEL, false) { } + SimpleExtItem ext; + KickRejoin(Module* Creator) : ModeHandler(Creator, "kicknorejoin", 'J', PARAM_SETONLY, MODETYPE_CHANNEL), + ext("norejoinusers", Creator) { } ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter) { @@ -40,18 +42,11 @@ class KickRejoin : public ModeHandler return std::make_pair(false, parameter); } - ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool) + ModeAction OnModeChange(User* source, User* dest, Channel* 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"); - } + ext.unset(channel); if (!channel->IsModeSet('J')) { @@ -105,26 +100,26 @@ class KickRejoin : public ModeHandler class ModuleKickNoRejoin : public Module { - KickRejoin kr; public: - ModuleKickNoRejoin(InspIRCd* Me) - : Module(Me), kr(Me) + ModuleKickNoRejoin() + : kr(this) { if (!ServerInstance->Modes->AddMode(&kr)) throw ModuleException("Could not add new modes!"); - Implementation eventlist[] = { I_OnCleanup, I_OnChannelDelete, I_OnUserPreJoin, I_OnUserKick }; - ServerInstance->Modules->Attach(eventlist, this, 4); + ServerInstance->Extensions.Register(&kr.ext); + Implementation eventlist[] = { I_OnUserPreJoin, I_OnUserKick }; + ServerInstance->Modules->Attach(eventlist, this, 2); } - virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven) + ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven) { if (chan) { - delaylist* dl; - if (chan->GetExt("norejoinusers", dl)) + delaylist* dl = kr.ext.get(chan); + if (dl) { std::vector itemstoremove; @@ -135,7 +130,7 @@ public: if (iter->first == user) { user->WriteNumeric(ERR_DELAYREJOIN, "%s %s :You must wait %s seconds after being kicked to rejoin (+J)", user->nick.c_str(), chan->name.c_str(), chan->GetModeParameter('J').c_str()); - return 1; + return MOD_RES_DENY; } } else @@ -149,56 +144,33 @@ public: dl->erase(itemstoremove[i]); if (!dl->size()) - { - // Now it's empty.. - delete dl; - chan->Shrink("norejoinusers"); - } + kr.ext.unset(chan); } } - return 0; + return MOD_RES_PASSTHRU; } - virtual void OnUserKick(User* source, User* user, Channel* chan, const std::string &reason, bool &silent) + void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts) { - if (chan->IsModeSet('J') && (source != user)) + if (memb->chan->IsModeSet('J') && (source != memb->user)) { - delaylist* dl; - if (!chan->GetExt("norejoinusers", dl)) + delaylist* dl = kr.ext.get(memb->chan); + if (dl) { dl = new delaylist; - chan->Extend("norejoinusers", dl); + kr.ext.set(memb->chan, dl); } - (*dl)[user] = ServerInstance->Time() + strtoint(chan->GetModeParameter('J')); - } - } - - virtual void OnChannelDelete(Channel* chan) - { - delaylist* dl; - - if (chan->GetExt("norejoinusers", dl)) - { - delete dl; - chan->Shrink("norejoinusers"); + (*dl)[memb->user] = ServerInstance->Time() + strtoint(memb->chan->GetModeParameter('J')); } } - virtual void OnCleanup(int target_type, void* item) - { - if(target_type == TYPE_CHANNEL) - OnChannelDelete((Channel*)item); - } - - - virtual ~ModuleKickNoRejoin() + ~ModuleKickNoRejoin() { - ServerInstance->Modes->DelMode(&kr); } - virtual Version GetVersion() + Version GetVersion() { - return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION); + return Version("Channel mode J, kick-no-rejoin", VF_COMMON | VF_VENDOR); } };