]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_antibottler.cpp
Review and optimize
[user/henk/code/inspircd.git] / src / modules / m_antibottler.cpp
index 78db8f67c743f7c4070b71a82e3b9bb8f781a4a3..8d588cf5c8a1d863194e35ba69a66e6a2711af30 100644 (file)
@@ -13,6 +13,7 @@
  *
  * ---------------------------------------------------
  */
+using namespace std;
 
 #include "users.h"
 #include "channels.h"
@@ -26,14 +27,14 @@ class ModuleAntiBottler : public Module
         
         Server *Srv;
  public:
-       ModuleAntiBottler()
+       ModuleAntiBottler(Server* Me)
+               : Module::Module(Me)
        {
-               Srv = new Server;
+               Srv = Me;
        }
        
        virtual ~ModuleAntiBottler()
        {
-               delete Srv;
        }
        
        virtual Version GetVersion()
@@ -41,7 +42,6 @@ class ModuleAntiBottler : public Module
                return Version(1,0,0,1,VF_VENDOR);
        }
 
-
        virtual void OnServerRaw(std::string &raw, bool inbound, userrec* user)
        {
                if (inbound)
@@ -51,30 +51,38 @@ class ModuleAntiBottler : public Module
                        bool not_bottler = false;
                        if (!strncmp(data,"user ",5))
                        {
-                               for (int j = 0; j < strlen(data); j++)
+                               for (char* j = data; *j; j++)
                                {
-                                       if (data[j] = ':')
+                                       if (*j == ':')
                                                break;
                                                
-                                       if (data[j] = '"')
+                                       if (*j == '"')
                                        {
                                                not_bottler = true;
                                        }
                                }
                                // Bug Fix (#14) -- FCS
-                               if (!strlen(data)) return;                              
-                               char *user = strtok(data," ");
-                               if (!strlen(data)) return;
+
+                               if (!(data) || !(*data))
+                                       return;
+
+                               /*
+                                * slight efficiency fix: strtok() just returns NULL if it has no more
+                                * tokens to return. Plus strlen's here really could have been replaced
+                                * with above pointer voodoo :-). --w00t
+                                */
+                               strtok(data," ");
                                char *ident = strtok(NULL," ");
-                               if (!strlen(data)) return;
                                char *local = strtok(NULL," ");
-                               if (!strlen(data)) return;
                                char *remote = strtok(NULL," :");
-                               if (!strlen(data)) return;
                                char *gecos = strtok(NULL,"\r\n");
-                               for (int j = 0; j < strlen(remote); j++)
+
+                               if (!ident || !local || !remote || !gecos)
+                                       return;
+
+                               for (char* j = remote; *j; j++)
                                {
-                                       if (((remote[j] < '0') || (remote[j] > '9')) && (remote[j] != '.'))
+                                       if (((*j < '0') || (*j > '9')) && (*j != '.'))
                                        {
                                                not_bottler = true;
                                        }
@@ -101,9 +109,9 @@ class ModuleAntiBottlerFactory : public ModuleFactory
        {
        }
        
-       virtual Module * CreateModule()
+       virtual Module * CreateModule(Server* Me)
        {
-               return new ModuleAntiBottler;
+               return new ModuleAntiBottler(Me);
        }
        
 };