]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_dccallow.cpp
Make classbase and refcountbase uncopyable; expand comments on their indended uses
[user/henk/code/inspircd.git] / src / modules / m_dccallow.cpp
index cd43a4539f112b22f8cfc801898afb5852a1caf7..d4be35cebb62d9f30685e98bdf2c6cd12ad7beb6 100644 (file)
 
 static ConfigReader *Conf;
 
-class BannedFileList : public classbase
+class BannedFileList
 {
  public:
        std::string filemask;
        std::string action;
 };
 
-class DCCAllow : public classbase
+class DCCAllow
 {
  public:
        std::string nickname;
@@ -43,11 +43,12 @@ 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, Module* parent) : Command(Me, parent, "DCCALLOW", 0, 0)
+       CommandDccallow(Module* parent) : Command(parent, "DCCALLOW", 0)
        {
                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 */
@@ -97,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)
                                                {
@@ -110,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 == '+')
                                {
@@ -135,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);
                                        }
@@ -199,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());
@@ -228,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)
                        {
@@ -246,10 +239,12 @@ class ModuleDCCAllow : public Module
        CommandDccallow cmd;
  public:
 
-       ModuleDCCAllow(InspIRCd* Me)
-               : Module(Me), cmd(Me, this)
+       ModuleDCCAllow()
+               : cmd(this)
        {
-               Conf = new ConfigReader(ServerInstance);
+               Conf = new ConfigReader;
+               ext = new SimpleExtItem<dccallowlist>("dccallow", this);
+               ServerInstance->Extensions.Register(ext);
                ServerInstance->AddCommand(&cmd);
                ReadFileConf();
                Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_OnUserQuit, I_OnUserPreNick, I_OnRehash };
@@ -260,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);
                }
 
@@ -281,7 +274,6 @@ class ModuleDCCAllow : public Module
                RemoveNick(user);
        }
 
-
        virtual ModResult OnUserPreNick(User* user, const std::string &newnick)
        {
                RemoveNick(user);
@@ -315,7 +307,8 @@ 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))
@@ -382,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())
                                {
@@ -414,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())
                                {
@@ -470,12 +465,13 @@ 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);
        }
 };