]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
A few anti-flood features
[user/henk/code/inspircd.git] / src / inspircd.cpp
index cb702245cbaf92e29f755966eadaf0329d19e61a..2558f3efc57a6c40d828adcb7a087318b0c5969e 100644 (file)
@@ -4068,8 +4068,6 @@ int InspIRCd(void)
                                        result = read(count2a->second->fd, data, 65535);
                                        if (result)
                                        {
-                                               if (result > 0)
-                                                       data[result] = '\0';
                                                // perform a check on the raw buffer as an array (not a string!) to remove
                                                // characters 0 and 7 which are illegal in the RFC - replace them with spaces.
                                                // hopefully this should stop even more people whining about "Unknown command: *"
@@ -4078,35 +4076,67 @@ int InspIRCd(void)
                                                        if ((data[checker] == 0) || (data[checker] == 7))
                                                                data[checker] = ' ';
                                                }
+                                               if (result > 0)
+                                                       data[result] = '\0';
                                                userrec* current = count2a->second;
                                                int currfd = current->fd;
-                                               //char* l = strtok(data,"\n");
                                                int floodlines = 0;
                                                current->AddBuffer(data);
+                                               if (current->recvq.length() > NetBufferSize)
+                                               {
+                                                       if (current->registered == 7)
+                                                       {
+                                                               kill_link(current,"RecvQ exceeded");
+                                                       }
+                                                       else
+                                                       {
+                                                               WriteOpers("*** Excess flood from %s",current->ip);
+                                                               log(DEFAULT,"Excess flood from: %s",current->ip);
+                                                               add_zline(120,ServerName,"Flood from unregistered connection",current->ip);
+                                                               apply_lines();
+                                                       }
+                                                       goto label;
+                                               }
                                                // while there are complete lines to process...
                                                while (current->BufferIsReady())
                                                {
                                                        floodlines++;
-                                                       if ((floodlines > current->flood) && (current->flood != 0))
+                                                       if (TIME > current->reset_due)
                                                        {
-                                                               log(DEFAULT,"Excess flood from: %s!%s@%s",current->nick,current->ident,current->host);
-                                                               WriteOpers("*** Excess flood from: %s!%s@%s",current->nick,current->ident,current->host);
+                                                               current->reset_due = TIME+3;
+                                                               current->lines_in = 0;
+                                                       }
+                                                       current->lines_in++;
+                                                       if (current->lines_in > current->flood)
+                                                       {
+                                                               log(DEFAULT,"Excess flood from: %s!%s@%s",current->nick,current->ident,current->host);
+                                                               WriteOpers("*** Excess flood from: %s!%s@%s",current->nick,current->ident,current->host);
                                                                kill_link(current,"Excess flood");
+                                                       }
+                                                       if ((floodlines > current->flood) && (current->flood != 0))
+                                                       {
+                                                               if (current->registered == 7)
+                                                               {
+                                                                       log(DEFAULT,"Excess flood from: %s!%s@%s",current->nick,current->ident,current->host);
+                                                                       WriteOpers("*** Excess flood from: %s!%s@%s",current->nick,current->ident,current->host);
+                                                                       kill_link(current,"Excess flood");
+                                                               }
+                                                               else
+                                                               {
+                                                                       add_zline(120,ServerName,"Flood from unregistered connection",current->ip);
+                                                                       apply_lines();
+                                                               }
                                                                goto label;
                                                        }
-                                                       char sanitized[NetBufferSize];
-                                                       memset(sanitized, 0, NetBufferSize);
+                                                       char sanitized[MAXBUF];
                                                        // use GetBuffer to copy single lines into the sanitized string
                                                        strlcpy(sanitized,current->GetBuffer().c_str(),MAXBUF);
                                                        if (*sanitized)
                                                        {
-
-
                                                                // we're gonna re-scan to check if the nick is gone, after every
                                                                // command - if it has, we're gonna bail
                                                                bool find_again = false;
                                                                process_buffer(sanitized,current);
-       
                                                                // look for the user's record in case it's changed
                                                                for (user_hash::iterator c2 = clientlist.begin(); c2 != clientlist.end(); c2++)
                                                                {
@@ -4122,7 +4152,6 @@ int InspIRCd(void)
                                                                        goto label;
 
                                                        }
-                                                       //l = strtok(NULL,"\n");
                                                }
                                                goto label;
                                        }