X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_kicknorejoin.cpp;h=bf5e10595c38b2c2925c8f71520f1adf81d9d800;hb=65627cc9d9f3227ea6dc091dd62a71fbce41a5e2;hp=56322507cf563b19cc328496b2d9eec40caabd99;hpb=f07a2aa0866a8f953b41ba21592919f05d3a315e;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_kicknorejoin.cpp b/src/modules/m_kicknorejoin.cpp index 56322507c..bf5e10595 100644 --- a/src/modules/m_kicknorejoin.cpp +++ b/src/modules/m_kicknorejoin.cpp @@ -1,16 +1,20 @@ -#include -#include -#include -#include -#include "users.h" -#include "channels.h" -#include "modules.h" +/* +------------------------------------+ + * | Inspire Internet Relay Chat Daemon | + * +------------------------------------+ + * + * InspIRCd: (C) 2002-2008 InspIRCd Development Team + * See: http://www.inspircd.org/wiki/index.php/Credits + * + * This program is free but copyrighted software; see + * the file COPYING for details. + * + * --------------------------------------------------- + */ + #include "inspircd.h" /* $ModDesc: Provides channel mode +J (delay rejoin after kick) */ - - inline int strtoint(const std::string &str) { std::istringstream ss(str); @@ -19,7 +23,7 @@ inline int strtoint(const std::string &str) return result; } -typedef std::map delaylist; +typedef std::map delaylist; /** Handles channel mode +J */ @@ -28,21 +32,21 @@ class KickRejoin : public ModeHandler public: KickRejoin(InspIRCd* Instance) : ModeHandler(Instance, 'J', 1, 0, false, MODETYPE_CHANNEL, false) { } - ModePair ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter) - { - if (channel->IsModeSet('J')) - return std::make_pair(true, channel->GetModeParameter('J')); - else - return std::make_pair(false, parameter); - } + ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter) + { + if (channel->IsModeSet('J')) + return std::make_pair(true, channel->GetModeParameter('J')); + else + return std::make_pair(false, parameter); + } - bool CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, chanrec* channel) + bool CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, Channel* channel) { /* When TS is equal, the alphabetically later one wins */ return (their_param < our_param); } - - ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding) + + ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool) { if (!adding) { @@ -51,14 +55,22 @@ class KickRejoin : public ModeHandler if (channel->GetExt("norejoinusers", dl)) { - DELETE(dl); + delete dl; channel->Shrink("norejoinusers"); } + + if (!channel->IsModeSet('J')) + { + return MODEACTION_DENY; + } + else + { + channel->SetMode('J', false); + return MODEACTION_ALLOW; + } } - if ((!adding) || (atoi(parameter.c_str()) > 0)) + else if (atoi(parameter.c_str()) > 0) { - ServerInstance->Log(DEBUG,"Got parameter: '%s'",parameter.c_str()); - if (!channel->IsModeSet('J')) { parameter = ConvToStr(atoi(parameter.c_str())); @@ -68,12 +80,6 @@ class KickRejoin : public ModeHandler } else { - if (!adding) - { - channel->SetModeParam('J', parameter.c_str(), adding); - return MODEACTION_ALLOW; - } - std::string cur_param = channel->GetModeParameter('J'); if (cur_param == parameter) { @@ -108,65 +114,63 @@ class KickRejoin : public ModeHandler class ModuleKickNoRejoin : public Module { - + KickRejoin* kr; - + public: - + ModuleKickNoRejoin(InspIRCd* Me) - : Module::Module(Me) + : Module(Me) { - + kr = new KickRejoin(ServerInstance); - ServerInstance->AddMode(kr, 'J'); + 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); } - virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname, std::string &privs) + virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven) { if (chan) { delaylist* dl; if (chan->GetExt("norejoinusers", dl)) { - ServerInstance->Log(DEBUG, "m_kicknorejoin.so: got delay list, iterating over it"); - std::vector itemstoremove; - + std::vector itemstoremove; + for (delaylist::iterator iter = dl->begin(); iter != dl->end(); iter++) { - ServerInstance->Log(DEBUG, "m_kicknorejoin.so:\t[%s] => %d", iter->first->nick, iter->second); - if (iter->second > time(NULL)) + if (iter->second > ServerInstance->Time()) { - ServerInstance->Log(DEBUG, "m_kicknorejoin.so: still inside time slot"); - if (iter->first == user) + if (iter->first == user) { - ServerInstance->Log(DEBUG, "m_kicknorejoin.so: and we have the right user"); - user->WriteServ( "495 %s %s :You cannot rejoin this channel yet after being kicked (+J)", user->nick, chan->name); + 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; } } else { // Expired record, remove. - ServerInstance->Log(DEBUG, "m_kicknorejoin.so: record expired"); itemstoremove.push_back(iter->first); } } - + for (unsigned int i = 0; i < itemstoremove.size(); i++) dl->erase(itemstoremove[i]); - + if (!dl->size()) { // Now it's empty.. - DELETE(dl); + delete dl; chan->Shrink("norejoinusers"); } } } return 0; } - - virtual void OnUserKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason) + + virtual void OnUserKick(User* source, User* user, Channel* chan, const std::string &reason, bool &silent) { if (chan->IsModeSet('J') && (source != user)) { @@ -176,68 +180,39 @@ public: dl = new delaylist; chan->Extend("norejoinusers", dl); } - - ServerInstance->Log(DEBUG, "m_kicknorejoin.so: setting record for %s, %d second delay", user->nick, strtoint(chan->GetModeParameter('J'))); - (*dl)[user] = time(NULL) + strtoint(chan->GetModeParameter('J')); + (*dl)[user] = ServerInstance->Time() + strtoint(chan->GetModeParameter('J')); } } - - virtual void OnChannelDelete(chanrec* chan) + + virtual void OnChannelDelete(Channel* chan) { delaylist* dl; - + if (chan->GetExt("norejoinusers", dl)) { - DELETE(dl); + delete dl; chan->Shrink("norejoinusers"); } } - + virtual void OnCleanup(int target_type, void* item) { if(target_type == TYPE_CHANNEL) - OnChannelDelete((chanrec*)item); + OnChannelDelete((Channel*)item); } - virtual void Implements(char* List) - { - List[I_OnCleanup] = List[I_OnChannelDelete] = List[I_OnUserPreJoin] = List[I_OnUserKick] = 1; - } virtual ~ModuleKickNoRejoin() { ServerInstance->Modes->DelMode(kr); - DELETE(kr); - } - - virtual Version GetVersion() - { - return Version(1, 0, 0, 0, VF_COMMON | VF_VENDOR); + delete kr; } -}; - -class ModuleKickNoRejoinFactory : public ModuleFactory -{ - public: - ModuleKickNoRejoinFactory() - { - } - - ~ModuleKickNoRejoinFactory() - { - } - - virtual Module * CreateModule(InspIRCd* Me) + virtual Version GetVersion() { - return new ModuleKickNoRejoin(Me); + return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION); } - }; -extern "C" void * init_module( void ) -{ - return new ModuleKickNoRejoinFactory; -} - +MODULE_INIT(ModuleKickNoRejoin)