]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_dccallow.cpp
Only valid targets for encap are now server ids
[user/henk/code/inspircd.git] / src / modules / m_dccallow.cpp
index 2b67654cc737585b3d1a2e057836108cd55c6805..572188b7c0065db75104ea7e2262ec659e656756 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
  * See: http://www.inspircd.org/wiki/index.php/Credits
  *
  * This program is free but copyrighted software; see
@@ -54,7 +54,7 @@ class CommandDccallow : public Command
                /* XXX we need to fix this so it can work with translation stuff (i.e. move +- into a seperate param */
        }
 
-       CmdResult Handle(const char **parameters, int pcnt, User *user)
+       CmdResult Handle(const char* const* parameters, int pcnt, User *user)
        {
                /* syntax: DCCALLOW [+|-]<nick> (<time>) */
                if (!pcnt)
@@ -92,21 +92,17 @@ class CommandDccallow : public Command
                                
                                if (action == '-')
                                {
-                                       user->GetExt("dccallow_list", dl);
                                        // check if it contains any entries
-                                       if (dl)
+                                       if (user->GetExt("dccallow_list", dl))
                                        {
-                                               if (dl->size())
+                                               for (dccallowlist::iterator i = dl->begin(); i != dl->end(); ++i)
                                                {
-                                                       for (dccallowlist::iterator i = dl->begin(); i != dl->end(); ++i)
+                                                       // search through list
+                                                       if (i->nickname == target->nick)
                                                        {
-                                                               // search through list
-                                                               if (i->nickname == target->nick)
-                                                               {
-                                                                       dl->erase(i);
-                                                                       user->WriteServ("995 %s %s :Removed %s from your DCCALLOW list", user->nick, user->nick, target->nick);
-                                                                       break;
-                                                               }
+                                                               dl->erase(i);
+                                                               user->WriteServ("995 %s %s :Removed %s from your DCCALLOW list", user->nick, user->nick, target->nick);
+                                                               break;
                                                        }
                                                }
                                        }
@@ -129,10 +125,7 @@ class CommandDccallow : public Command
                                }
                                else if (action == '+')
                                {
-                                       // fetch current DCCALLOW list
-                                       user->GetExt("dccallow_list", dl);
-                                       // they don't have one, create it
-                                       if (!dl)
+                                       if (!user->GetExt("dccallow_list", dl))
                                        {
                                                dl = new dccallowlist;
                                                user->Extend("dccallow_list", dl);
@@ -228,9 +221,8 @@ class CommandDccallow : public Command
        {
                 // display current DCCALLOW list
                user->WriteServ("990 %s :Users on your DCCALLOW list:", user->nick);
-               user->GetExt("dccallow_list", dl);
-               
-               if (dl)
+       
+               if (user->GetExt("dccallow_list", dl))
                {
                        for (dccallowlist::const_iterator c = dl->begin(); c != dl->end(); ++c)
                        {
@@ -255,12 +247,10 @@ class ModuleDCCAllow : public Module
                mycommand = new CommandDccallow(ServerInstance);
                ServerInstance->AddCommand(mycommand);
                ReadFileConf();
+               Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_OnUserQuit, I_OnUserPreNick, I_OnRehash };
+               ServerInstance->Modules->Attach(eventlist, this, 5);
        }
 
-       void Implements(char* List)
-       {
-               List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnUserQuit] = List[I_OnUserPreNick] = List[I_OnRehash] = 1;
-       }
 
        virtual void OnRehash(User* user, const std::string &parameter)
        {
@@ -270,13 +260,12 @@ class ModuleDCCAllow : public Module
 
        virtual void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message)
        {
-               dccallowlist* dl;
+               dccallowlist* udl;
        
                // remove their DCCALLOW list if they have one
-               user->GetExt("dccallow_list", dl);
-               if (dl)
+               if (user->GetExt("dccallow_list", udl))
                {
-                       delete dl;
+                       delete udl;
                        user->Shrink("dccallow_list");
                        RemoveFromUserlist(user);
                }
@@ -319,10 +308,8 @@ class ModuleDCCAllow : public Module
                                // :jamie!jamie@test-D4457903BA652E0F.silverdream.org PRIVMSG eimaj :VERSION
                                        
                                if (strncmp(text.c_str(), "\1DCC ", 5) == 0)
-                               {
-                                       u->GetExt("dccallow_list", dl);
-               
-                                       if (dl && dl->size())
+                               {       
+                                       if (u->GetExt("dccallow_list", dl) && dl->size())
                                        {
                                                for (dccallowlist::const_iterator iter = dl->begin(); iter != dl->end(); ++iter)
                                                        if (ServerInstance->MatchText(user->GetFullHost(), iter->hostmask))
@@ -385,23 +372,21 @@ class ModuleDCCAllow : public Module
                for (userlist::iterator iter = ul.begin(); iter != ul.end(); ++iter)
                {
                        User* u = (User*)(*iter);
-                       u->GetExt("dccallow_list", dl);
-       
-                       if (dl)
+                       if (u->GetExt("dccallow_list", dl))
                        {
                                if (dl->size())
                                {
-                                       dccallowlist::iterator iter = dl->begin();
-                                       while (iter != dl->end())
+                                       dccallowlist::iterator iter2 = dl->begin();
+                                       while (iter2 != dl->end())
                                        {
-                                               if ((iter->set_on + iter->length) <= ServerInstance->Time())
+                                               if ((iter2->set_on + iter2->length) <= ServerInstance->Time())
                                                {
-                                                       u->WriteServ("997 %s %s :DCCALLOW entry for %s has expired", u->nick, u->nick, iter->nickname.c_str());
-                                                       iter = dl->erase(iter);
+                                                       u->WriteServ("997 %s %s :DCCALLOW entry for %s has expired", u->nick, u->nick, iter2->nickname.c_str());
+                                                       iter2 = dl->erase(iter2);
                                                }
                                                else
                                                {
-                                                       ++iter;
+                                                       ++iter2;
                                                }
                                        }
                                }
@@ -419,9 +404,7 @@ class ModuleDCCAllow : public Module
                for (userlist::iterator iter = ul.begin(); iter != ul.end(); ++iter)
                {
                        User *u = (User*)(*iter);
-                       u->GetExt("dccallow_list", dl);
-       
-                       if (dl)
+                       if (u->GetExt("dccallow_list", dl))
                        {
                                if (dl->size())
                                {
@@ -485,3 +468,4 @@ class ModuleDCCAllow : public Module
 };
 
 MODULE_INIT(ModuleDCCAllow)
+