]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_antibottler.cpp
(Probably) major speed improvements, nuked a hell of a lot of strlen()s. Added a...
[user/henk/code/inspircd.git] / src / modules / m_antibottler.cpp
index 78db8f67c743f7c4070b71a82e3b9bb8f781a4a3..fd91183dce820484fab40acd2fd43b0606b06952 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,7 @@ class ModuleAntiBottler : public Module
                return Version(1,0,0,1,VF_VENDOR);
        }
 
-
+       /* XXX - OnServerRaw? Wouldn't it be easier to use an OnUserConnect, or something? --w00t */
        virtual void OnServerRaw(std::string &raw, bool inbound, userrec* user)
        {
                if (inbound)
@@ -51,28 +52,36 @@ class ModuleAntiBottler : public Module
                        bool not_bottler = false;
                        if (!strncmp(data,"user ",5))
                        {
-                               for (int j = 0; j < strlen(data); j++)
+                               for (unsigned int j = 0; j < strlen(data); j++)
                                {
-                                       if (data[j] = ':')
+                                       if (data[j] == ':')
                                                break;
                                                
-                                       if (data[j] = '"')
+                                       if (data[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 (unsigned int j = 0; j < strlen(remote); j++)
                                {
                                        if (((remote[j] < '0') || (remote[j] > '9')) && (remote[j] != '.'))
                                        {
@@ -101,9 +110,9 @@ class ModuleAntiBottlerFactory : public ModuleFactory
        {
        }
        
-       virtual Module * CreateModule()
+       virtual Module * CreateModule(Server* Me)
        {
-               return new ModuleAntiBottler;
+               return new ModuleAntiBottler(Me);
        }
        
 };