]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_kicknorejoin.cpp
Remove "servermode" parameter, replace with IS_FAKE() which is more reliable
[user/henk/code/inspircd.git] / src / modules / m_kicknorejoin.cpp
index 790e8f680e186d01db6617c883c2e2a1b874aae4..5327c0592e67e821036aa49388e5330e3c498ede 100644 (file)
@@ -2,8 +2,8 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
- * See: http://www.inspircd.org/wiki/index.php/Credits
+ *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ * See: http://wiki.inspircd.org/Credits
  *
  * This program is free but copyrighted software; see
  *            the file COPYING for details.
  */
 
 #include "inspircd.h"
-#include <sstream>
-#include "users.h"
-#include "channels.h"
-#include "modules.h"
 
 /* $ModDesc: Provides channel mode +J (delay rejoin after kick) */
 
@@ -27,49 +23,43 @@ inline int strtoint(const std::string &str)
        return result;
 }
 
-typedef std::map<userrec*, time_t> delaylist;
+typedef std::map<User*, time_t> delaylist;
 
 /** Handles channel mode +J
  */
 class KickRejoin : public ModeHandler
 {
  public:
-       KickRejoin(InspIRCd* Instance) : ModeHandler(Instance, 'J', 1, 0, false, MODETYPE_CHANNEL, false) { }
+       KickRejoin(InspIRCd* Instance, Module* Creator) : ModeHandler(Instance, Creator, 'J', 1, 0, false, MODETYPE_CHANNEL, false) { }
 
-       ModePair ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter)
+       ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string &parameter)
        {
                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)
-       {
-               /* When TS is equal, the alphabetically later one wins */
-               return (their_param < our_param);
        }
-       
-       ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
+
+       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
        {
                if (!adding)
                {
                        // Taking the mode off, we need to clean up.
                        delaylist* dl;
-                       
+
                        if (channel->GetExt("norejoinusers", dl))
                        {
-                               DELETE(dl);
+                               delete dl;
                                channel->Shrink("norejoinusers");
                        }
-                       
+
                        if (!channel->IsModeSet('J'))
                        {
                                return MODEACTION_DENY;
                        }
                        else
                        {
-                               channel->SetMode('J', false);
+                               channel->SetModeParam('J', "");
                                return MODEACTION_ALLOW;
                        }
                }
@@ -78,8 +68,7 @@ class KickRejoin : public ModeHandler
                        if (!channel->IsModeSet('J'))
                        {
                                parameter = ConvToStr(atoi(parameter.c_str()));
-                               channel->SetModeParam('J', parameter.c_str(), adding);
-                               channel->SetMode('J', adding);
+                               channel->SetModeParam('J', parameter);
                                return MODEACTION_ALLOW;
                        }
                        else
@@ -94,11 +83,9 @@ class KickRejoin : public ModeHandler
                                {
                                        // new mode param, replace old with new
                                        parameter = ConvToStr(atoi(parameter.c_str()));
-                                       cur_param = ConvToStr(atoi(cur_param.c_str()));
                                        if (parameter != "0")
                                        {
-                                               channel->SetModeParam('J', cur_param.c_str(), false);
-                                               channel->SetModeParam('J', parameter.c_str(), adding);
+                                               channel->SetModeParam('J', parameter);
                                                return MODEACTION_ALLOW;
                                        }
                                        else
@@ -118,36 +105,36 @@ class KickRejoin : public ModeHandler
 
 class ModuleKickNoRejoin : public Module
 {
-       
-       KickRejoin* kr;
-       
+
+       KickRejoin kr;
+
 public:
+
        ModuleKickNoRejoin(InspIRCd* Me)
-               : Module(Me)
+               : Module(Me), kr(Me, this)
        {
-               
-               kr = new KickRejoin(ServerInstance);
-               if (!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))
                        {
-                               std::vector<userrec*> itemstoremove;
-                       
+                               std::vector<User*> itemstoremove;
+
                                for (delaylist::iterator iter = dl->begin(); iter != dl->end(); iter++)
                                {
-                                       if (iter->second > time(NULL))
+                                       if (iter->second > ServerInstance->Time())
                                        {
-                                               if (iter->first == user)                                        
+                                               if (iter->first == 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;
                                                }
                                        }
@@ -157,22 +144,22 @@ public:
                                                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, bool &silent)
+
+       virtual void OnUserKick(User* source, User* user, Channel* chan, const std::string &reason, bool &silent)
        {
                if (chan->IsModeSet('J') && (source != user))
                {
@@ -182,43 +169,38 @@ public:
                                dl = new delaylist;
                                chan->Extend("norejoinusers", dl);
                        }
-                       (*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);
+               ServerInstance->Modes->DelMode(&kr);
        }
-       
+
        virtual Version GetVersion()
        {
-               return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
+               return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
        }
 };
 
 
-MODULE_INIT(ModuleKickNoRejoin);
+MODULE_INIT(ModuleKickNoRejoin)