]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_dccallow.cpp
Fix some numerics
[user/henk/code/inspircd.git] / src / modules / m_dccallow.cpp
index 487e4a7ed23fca65038e1d6a473ebe9de56f18ba..0e57896f3b78c78d7317536b745660e202277b72 100644 (file)
@@ -58,11 +58,12 @@ class CommandDccallow : public Command
        DCCAllowExt& ext;
 
  public:
+       unsigned int maxentries;
        CommandDccallow(Module* parent, DCCAllowExt& Ext)
                : Command(parent, "DCCALLOW", 0)
                , ext(Ext)
        {
-               syntax = "{[+|-]<nick> <time>|HELP|LIST}";
+               syntax = "[(+|-)<nick> [<time>]]|[LIST|HELP]";
                /* XXX we need to fix this so it can work with translation stuff (i.e. move +- into a seperate param */
        }
 
@@ -101,10 +102,10 @@ class CommandDccallow : public Command
                                }
                        }
 
-                       std::string nick = parameters[0].substr(1);
+                       std::string nick(parameters[0], 1);
                        User *target = ServerInstance->FindNickOnly(nick);
 
-                       if ((target) && (!IS_SERVER(target)) && (!target->quitting) && (target->registered == REG_ALL))
+                       if ((target) && (!target->quitting) && (target->registered == REG_ALL))
                        {
 
                                if (action == '-')
@@ -142,6 +143,12 @@ class CommandDccallow : public Command
                                                ul.push_back(user);
                                        }
 
+                                       if (dl->size() >= maxentries)
+                                       {
+                                               user->WriteNumeric(996, "%s :Too many nicks on DCCALLOW list", user->nick.c_str());
+                                               return CMD_FAILURE;
+                                       }
+
                                        for (dccallowlist::const_iterator k = dl->begin(); k != dl->end(); ++k)
                                        {
                                                if (k->nickname == target->nick)
@@ -205,7 +212,7 @@ class CommandDccallow : public Command
 
        void DisplayHelp(User* user)
        {
-               user->WriteNumeric(998, ":DCCALLOW [<+|->nick [time]] [list] [help]");
+               user->WriteNumeric(998, ":DCCALLOW [(+|-)<nick> [<time>]]|[LIST|HELP]");
                user->WriteNumeric(998, ":You may allow DCCs from specific users by specifying a");
                user->WriteNumeric(998, ":DCC allow for the user you want to receive DCCs from.");
                user->WriteNumeric(998, ":For example, to allow the user Brain to send you inspircd.exe");
@@ -225,6 +232,10 @@ class CommandDccallow : public Command
                user->WriteNumeric(998, ":  they will be removed from your DCCALLOW list.");
                user->WriteNumeric(998, ":  your DCCALLOW list will be deleted when you leave IRC.");
                user->WriteNumeric(999, ":End of DCCALLOW HELP");
+
+               LocalUser* localuser = IS_LOCAL(user);
+               if (localuser)
+                       localuser->CommandFloodPenalty += 4000;
        }
 
        void DisplayDCCAllowList(User* user)
@@ -253,7 +264,7 @@ class ModuleDCCAllow : public Module
 
  public:
        ModuleDCCAllow()
-               : ext("dccallow", this)
+               : ext("dccallow", ExtensionItem::EXT_USER, this)
                , cmd(this, ext)
        {
        }
@@ -264,11 +275,7 @@ class ModuleDCCAllow : public Module
 
                // remove their DCCALLOW list if they have one
                if (udl)
-               {
-                       userlist::iterator it = std::find(ul.begin(), ul.end(), user);
-                       if (it != ul.end())
-                               ul.erase(it);
-               }
+                       stdalgo::erase(ul, user);
 
                // remove them from any DCCALLOW lists
                // they are currently on
@@ -318,6 +325,9 @@ class ModuleDCCAllow : public Module
                                        while (ss >> buf)
                                                tokens.push_back(buf);
 
+                                       if (tokens.size() < 2)
+                                               return MOD_RES_PASSTHRU;
+
                                        irc::string type = tokens[1].c_str();
 
                                        ConfigTag* conftag = ServerInstance->Config->ConfValue("dccallow");
@@ -325,6 +335,9 @@ class ModuleDCCAllow : public Module
 
                                        if (type == "SEND")
                                        {
+                                               if (tokens.size() < 3)
+                                                       return MOD_RES_PASSTHRU;
+
                                                std::string defaultaction = conftag->getString("action");
                                                std::string filename = tokens[2];
 
@@ -447,6 +460,9 @@ class ModuleDCCAllow : public Module
 
        void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
        {
+               ConfigTag* tag = ServerInstance->Config->ConfValue("dccallow");
+               cmd.maxentries = tag->getInt("maxentries", 20);
+
                bfl.clear();
                ConfigTagList tags = ServerInstance->Config->ConfTags("banfile");
                for (ConfigIter i = tags.first; i != tags.second; ++i)