]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_timedbans.cpp
Merge branch 'master+listmode'
[user/henk/code/inspircd.git] / src / modules / m_timedbans.cpp
index 8a4fbb4dcaecaca3c7ec1ea22c5c20d947822877..803156446a2e50d86e544a204f16f1097cc6dfdf 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;
                }
 
@@ -74,17 +71,15 @@ class CommandTban : public Command
                        return CMD_FAILURE;
                }
                std::string mask = parameters[2];
-               std::vector<std::string> setban;
-               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("!*@*");
 
-               setban.push_back(mask);
-               // use CallHandler to make it so that the user sets the mode
-               // themselves
-               ServerInstance->Parser->CallHandler("MODE",setban,user);
+               Modes::ChangeList setban;
+               setban.push_add(ServerInstance->Modes->FindMode('b', MODETYPE_CHANNEL), 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(user, channel, NULL, setban);
                if (ServerInstance->Modes->GetLastParse().empty())
                {
                        user->WriteNotice("Invalid ban mask");
@@ -115,11 +110,11 @@ class BanWatcher : public ModeWatcher
 {
  public:
        BanWatcher(Module* parent)
-               : ModeWatcher(parent, 'b', MODETYPE_CHANNEL)
+               : ModeWatcher(parent, "ban", MODETYPE_CHANNEL)
        {
        }
 
-       void AfterMode(User* source, User* dest, Channel* chan, const std::string& banmask, bool adding, ModeType type)
+       void AfterMode(User* source, User* dest, Channel* chan, const std::string& banmask, bool adding)
        {
                if (adding)
                        return;
@@ -151,19 +146,6 @@ class ModuleTimedBans : public Module
        {
        }
 
-       void init() CXX11_OVERRIDE
-       {
-               ServerInstance->Modules->AddService(cmd);
-               Implementation eventlist[] = { I_OnBackgroundTimer };
-               ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
-               ServerInstance->Modes->AddModeWatcher(&banwatcher);
-       }
-
-       ~ModuleTimedBans()
-       {
-               ServerInstance->Modes->DelModeWatcher(&banwatcher);
-       }
-
        void OnBackgroundTimer(time_t curtime) CXX11_OVERRIDE
        {
                timedbans expired;
@@ -185,17 +167,14 @@ class ModuleTimedBans : public Module
                        Channel* cr = ServerInstance->FindChan(chan);
                        if (cr)
                        {
-                               std::vector<std::string> setban;
-                               setban.push_back(chan);
-                               setban.push_back("-b");
-                               setban.push_back(mask);
-
                                CUList empty;
                                std::string expiry = "*** Timed ban on " + chan + " expired.";
                                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);
+                               Modes::ChangeList setban;
+                               setban.push_remove(ServerInstance->Modes->FindMode('b', MODETYPE_CHANNEL), mask);
+                               ServerInstance->Modes->Process(ServerInstance->FakeClient, cr, NULL, setban);
                        }
                }
        }