]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_dccallow.cpp
Remove the -Dssize_t declaration now its typedeffed.
[user/henk/code/inspircd.git] / src / modules / m_dccallow.cpp
index 56345932c56c0d3e92bd43b91a4cb3b0ad2a3815..10a8d9310f822d366fbd06a10f1a90a8eaab4884 100644 (file)
@@ -43,13 +43,13 @@ typedef std::vector<DCCAllow> dccallowlist;
 dccallowlist* dl;
 typedef std::vector<BannedFileList> bannedfilelist;
 bannedfilelist bfl;
+SimpleExtItem<dccallowlist>* ext;
 
 class CommandDccallow : public Command
 {
  public:
-       CommandDccallow(InspIRCd* Me) : Command(Me, "DCCALLOW", 0, 0)
+       CommandDccallow(Module* parent) : Command(parent, "DCCALLOW", 0)
        {
-               this->source = "m_dccallow.so";
                syntax = "{[+|-]<nick> <time>|HELP|LIST}";
                /* XXX we need to fix this so it can work with translation stuff (i.e. move +- into a seperate param */
        }
@@ -98,7 +98,8 @@ class CommandDccallow : public Command
                                if (action == '-')
                                {
                                        // check if it contains any entries
-                                       if (user->GetExt("dccallow_list", dl))
+                                       dl = ext->get(user);
+                                       if (dl)
                                        {
                                                for (dccallowlist::iterator i = dl->begin(); i != dl->end(); ++i)
                                                {
@@ -111,22 +112,6 @@ class CommandDccallow : public Command
                                                        }
                                                }
                                        }
-                                       else
-                                       {
-                                               delete  dl;
-                                               user->Shrink("dccallow_list");
-
-                                               // remove from userlist
-                                               for (userlist::iterator j = ul.begin(); j != ul.end(); ++j)
-                                               {
-                                                       User* u = (User*)(*j);
-                                                       if (u == user)
-                                                       {
-                                                               ul.erase(j);
-                                                               break;
-                                                       }
-                                               }
-                                       }
                                }
                                else if (action == '+')
                                {
@@ -136,10 +121,11 @@ class CommandDccallow : public Command
                                                return CMD_FAILURE;
                                        }
 
-                                       if (!user->GetExt("dccallow_list", dl))
+                                       dl = ext->get(user);
+                                       if (!dl)
                                        {
                                                dl = new dccallowlist;
-                                               user->Extend("dccallow_list", dl);
+                                               ext->set(user, dl);
                                                // add this user to the userlist
                                                ul.push_back(user);
                                        }
@@ -200,6 +186,11 @@ class CommandDccallow : public Command
                return CMD_FAILURE;
        }
 
+       RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
+       {
+               return ROUTE_BROADCAST;
+       }
+
        void DisplayHelp(User* user)
        {
                user->WriteNumeric(998, "%s :DCCALLOW [<+|->nick [time]] [list] [help]", user->nick.c_str());
@@ -229,7 +220,8 @@ class CommandDccallow : public Command
                 // display current DCCALLOW list
                user->WriteNumeric(990, "%s :Users on your DCCALLOW list:", user->nick.c_str());
 
-               if (user->GetExt("dccallow_list", dl))
+               dl = ext->get(user);
+               if (dl)
                {
                        for (dccallowlist::const_iterator c = dl->begin(); c != dl->end(); ++c)
                        {
@@ -244,15 +236,16 @@ class CommandDccallow : public Command
 
 class ModuleDCCAllow : public Module
 {
-       CommandDccallow* mycommand;
+       CommandDccallow cmd;
  public:
 
-       ModuleDCCAllow(InspIRCd* Me)
-               : Module(Me)
+       ModuleDCCAllow()
+               : cmd(this)
        {
-               Conf = new ConfigReader(ServerInstance);
-               mycommand = new CommandDccallow(ServerInstance);
-               ServerInstance->AddCommand(mycommand);
+               Conf = new ConfigReader;
+               ext = new SimpleExtItem<dccallowlist>("dccallow", this);
+               Extensible::Register(ext);
+               ServerInstance->AddCommand(&cmd);
                ReadFileConf();
                Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_OnUserQuit, I_OnUserPreNick, I_OnRehash };
                ServerInstance->Modules->Attach(eventlist, this, 5);
@@ -262,19 +255,17 @@ class ModuleDCCAllow : public Module
        virtual void OnRehash(User* user)
        {
                delete Conf;
-               Conf = new ConfigReader(ServerInstance);
+               Conf = new ConfigReader;
                ReadFileConf();
        }
 
        virtual void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message)
        {
-               dccallowlist* udl;
+               dccallowlist* udl = ext->get(user);
 
                // remove their DCCALLOW list if they have one
-               if (user->GetExt("dccallow_list", udl))
+               if (udl)
                {
-                       delete udl;
-                       user->Shrink("dccallow_list");
                        RemoveFromUserlist(user);
                }
 
@@ -283,22 +274,21 @@ class ModuleDCCAllow : public Module
                RemoveNick(user);
        }
 
-
-       virtual int OnUserPreNick(User* user, const std::string &newnick)
+       virtual ModResult OnUserPreNick(User* user, const std::string &newnick)
        {
                RemoveNick(user);
-               return 0;
+               return MOD_RES_PASSTHRU;
        }
 
-       virtual int OnUserPreMessage(User* user, void* dest, int target_type, std::string &text, char status, CUList &exempt_list)
+       virtual ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string &text, char status, CUList &exempt_list)
        {
                return OnUserPreNotice(user, dest, target_type, text, status, exempt_list);
        }
 
-       virtual int OnUserPreNotice(User* user, void* dest, int target_type, std::string &text, char status, CUList &exempt_list)
+       virtual ModResult OnUserPreNotice(User* user, void* dest, int target_type, std::string &text, char status, CUList &exempt_list)
        {
                if (!IS_LOCAL(user))
-                       return 0;
+                       return MOD_RES_PASSTHRU;
 
                if (target_type == TYPE_USER)
                {
@@ -306,7 +296,7 @@ class ModuleDCCAllow : public Module
 
                        /* Always allow a user to dcc themselves (although... why?) */
                        if (user == u)
-                               return 0;
+                               return MOD_RES_PASSTHRU;
 
                        if ((text.length()) && (text[0] == '\1'))
                        {
@@ -317,11 +307,12 @@ class ModuleDCCAllow : public Module
 
                                if (strncmp(text.c_str(), "\1DCC ", 5) == 0)
                                {
-                                       if (u->GetExt("dccallow_list", dl) && dl->size())
+                                       dl = ext->get(u);
+                                       if (dl && dl->size())
                                        {
                                                for (dccallowlist::const_iterator iter = dl->begin(); iter != dl->end(); ++iter)
                                                        if (InspIRCd::Match(user->GetFullHost(), iter->hostmask))
-                                                               return 0;
+                                                               return MOD_RES_PASSTHRU;
                                        }
 
                                        // tokenize
@@ -348,7 +339,7 @@ class ModuleDCCAllow : public Module
                                                        {
                                                                /* We have a matching badfile entry, override whatever the default action is */
                                                                if (bfl[i].action == "allow")
-                                                                       return 0;
+                                                                       return MOD_RES_PASSTHRU;
                                                                else
                                                                {
                                                                        found = true;
@@ -359,24 +350,24 @@ class ModuleDCCAllow : public Module
 
                                                /* only follow the default action if no badfile matches were found above */
                                                if ((!found) && (defaultaction == "allow"))
-                                                       return 0;
+                                                       return MOD_RES_PASSTHRU;
 
                                                user->WriteServ("NOTICE %s :The user %s is not accepting DCC SENDs from you. Your file %s was not sent.", user->nick.c_str(), u->nick.c_str(), filename.c_str());
                                                u->WriteServ("NOTICE %s :%s (%s@%s) attempted to send you a file named %s, which was blocked.", u->nick.c_str(), user->nick.c_str(), user->ident.c_str(), user->dhost.c_str(), filename.c_str());
                                                u->WriteServ("NOTICE %s :If you trust %s and were expecting this, you can type /DCCALLOW HELP for information on the DCCALLOW system.", u->nick.c_str(), user->nick.c_str());
-                                               return 1;
+                                               return MOD_RES_DENY;
                                        }
                                        else if ((type == "CHAT") && (blockchat))
                                        {
                                                user->WriteServ("NOTICE %s :The user %s is not accepting DCC CHAT requests from you.", user->nick.c_str(), u->nick.c_str());
                                                u->WriteServ("NOTICE %s :%s (%s@%s) attempted to initiate a DCC CHAT session, which was blocked.", u->nick.c_str(), user->nick.c_str(), user->ident.c_str(), user->dhost.c_str());
                                                u->WriteServ("NOTICE %s :If you trust %s and were expecting this, you can type /DCCALLOW HELP for information on the DCCALLOW system.", u->nick.c_str(), user->nick.c_str());
-                                               return 1;
+                                               return MOD_RES_DENY;
                                        }
                                }
                        }
                }
-               return 0;
+               return MOD_RES_PASSTHRU;
        }
 
        void Expire()
@@ -384,7 +375,8 @@ class ModuleDCCAllow : public Module
                for (userlist::iterator iter = ul.begin(); iter != ul.end(); ++iter)
                {
                        User* u = (User*)(*iter);
-                       if (u->GetExt("dccallow_list", dl))
+                       dl = ext->get(u);
+                       if (dl)
                        {
                                if (dl->size())
                                {
@@ -416,7 +408,8 @@ class ModuleDCCAllow : public Module
                for (userlist::iterator iter = ul.begin(); iter != ul.end(); ++iter)
                {
                        User *u = (User*)(*iter);
-                       if (u->GetExt("dccallow_list", dl))
+                       dl = ext->get(u);
+                       if (dl)
                        {
                                if (dl->size())
                                {
@@ -471,11 +464,14 @@ class ModuleDCCAllow : public Module
 
        virtual ~ModuleDCCAllow()
        {
+               delete Conf;
+               delete ext;
+               Conf = NULL;
        }
 
        virtual Version GetVersion()
        {
-               return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
+               return Version("Povides support for the /DCCALLOW command", VF_COMMON | VF_VENDOR, API_VERSION);
        }
 };