]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_timedbans.cpp
Merge insp20
[user/henk/code/inspircd.git] / src / modules / m_timedbans.cpp
index e10a622e90aa4187f357dfe17eea72953997c0a7..e3a93833686355ad265ea950049e964d6e50b0f4 100644 (file)
@@ -20,8 +20,6 @@
  */
 
 
-/* $ModDesc: Adds timed bans */
-
 #include "inspircd.h"
 
 /** Holds a timed ban
@@ -45,7 +43,6 @@ class CommandTban : public Command
        CommandTban(Module* Creator) : Command(Creator,"TBAN", 3)
        {
                syntax = "<channel> <duration> <banmask>";
-               TRANSLATE4(TR_TEXT, TR_TEXT, TR_TEXT, TR_END);
        }
 
        CmdResult Handle (const std::vector<std::string> &parameters, User *user)
@@ -53,14 +50,14 @@ class CommandTban : public Command
                Channel* channel = ServerInstance->FindChan(parameters[0]);
                if (!channel)
                {
-                       user->WriteNumeric(401, "%s %s :No such channel",user->nick.c_str(), parameters[0].c_str());
+                       user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such channel", parameters[0].c_str());
                        return CMD_FAILURE;
                }
                int cm = channel->GetPrefixValue(user);
                if (cm < HALFOP_VALUE)
                {
-                       user->WriteNumeric(482, "%s %s :You do not have permission to set bans on this channel",
-                               user->nick.c_str(), channel->name.c_str());
+                       user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s :You do not have permission to set bans on this channel",
+                               channel->name.c_str());
                        return CMD_FAILURE;
                }
 
@@ -70,7 +67,7 @@ class CommandTban : public Command
                unsigned long expire = duration + ServerInstance->Time();
                if (duration < 1)
                {
-                       user->WriteServ("NOTICE "+user->nick+" :Invalid ban time");
+                       user->WriteNotice("Invalid ban time");
                        return CMD_FAILURE;
                }
                std::string mask = parameters[2];
@@ -78,22 +75,19 @@ class CommandTban : public Command
                setban.push_back(parameters[0]);
                setban.push_back("+b");
                bool isextban = ((mask.size() > 2) && (mask[1] == ':'));
-               if (!isextban && !ServerInstance->IsValidMask(mask))
+               if (!isextban && !InspIRCd::IsValidMask(mask))
                        mask.append("!*@*");
-               if ((mask.length() > 250) || (!ServerInstance->IsValidMask(mask) && !isextban))
+
+               setban.push_back(mask);
+               // Pass the user (instead of ServerInstance->FakeClient) to ModeHandler::Process() to
+               // make it so that the user sets the mode themselves
+               ServerInstance->Modes->Process(setban, user);
+               if (ServerInstance->Modes->GetLastParse().empty())
                {
-                       user->WriteServ("NOTICE "+user->nick+" :Invalid ban mask");
+                       user->WriteNotice("Invalid ban mask");
                        return CMD_FAILURE;
                }
-               setban.push_back(mask);
-               // use CallHandler to make it so that the user sets the mode
-               // themselves
-               ServerInstance->Parser->CallHandler("MODE",setban,user);
-               for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
-                       if (!strcasecmp(i->data.c_str(), mask.c_str()))
-                               goto found;
-               return CMD_FAILURE;
-found:
+
                CUList tmp;
                T.channel = channelname;
                T.mask = mask;
@@ -114,27 +108,22 @@ found:
        }
 };
 
-class ModuleTimedBans : public Module
+class BanWatcher : public ModeWatcher
 {
-       CommandTban cmd;
  public:
-       ModuleTimedBans()
-               : cmd(this)
+       BanWatcher(Module* parent)
+               : ModeWatcher(parent, "ban", MODETYPE_CHANNEL)
        {
        }
 
-       void init()
+       void AfterMode(User* source, User* dest, Channel* chan, const std::string& banmask, bool adding)
        {
-               ServerInstance->Modules->AddService(cmd);
-               Implementation eventlist[] = { I_OnDelBan, I_OnBackgroundTimer };
-               ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
-       }
+               if (adding)
+                       return;
 
-       virtual ModResult OnDelBan(User* source, Channel* chan, const std::string &banmask)
-       {
                irc::string listitem = banmask.c_str();
                irc::string thischan = chan->name.c_str();
-               for (timedbans::iterator i = TimedBanList.begin(); i != TimedBanList.end(); i++)
+               for (timedbans::iterator i = TimedBanList.begin(); i != TimedBanList.end(); ++i)
                {
                        irc::string target = i->mask.c_str();
                        irc::string tchan = i->channel.c_str();
@@ -144,10 +133,22 @@ class ModuleTimedBans : public Module
                                break;
                        }
                }
-               return MOD_RES_PASSTHRU;
+       }
+};
+
+class ModuleTimedBans : public Module
+{
+       CommandTban cmd;
+       BanWatcher banwatcher;
+
+ public:
+       ModuleTimedBans()
+               : cmd(this)
+               , banwatcher(this)
+       {
        }
 
-       virtual void OnBackgroundTimer(time_t curtime)
+       void OnBackgroundTimer(time_t curtime) CXX11_OVERRIDE
        {
                timedbans expired;
                for (timedbans::iterator i = TimedBanList.begin(); i != TimedBanList.end();)
@@ -178,12 +179,12 @@ class ModuleTimedBans : public Module
                                cr->WriteAllExcept(ServerInstance->FakeClient, true, '@', empty, "NOTICE %s :%s", cr->name.c_str(), expiry.c_str());
                                ServerInstance->PI->SendChannelNotice(cr, '@', expiry);
 
-                               ServerInstance->SendGlobalMode(setban, ServerInstance->FakeClient);
+                               ServerInstance->Modes->Process(setban, ServerInstance->FakeClient);
                        }
                }
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Adds timed bans", VF_COMMON | VF_VENDOR);
        }