- }
- else
- {
- WriteOpers("*** Excess flood from %s",current->ip);
- log(DEFAULT,"Excess flood from: %s",current->ip);
- add_zline(120,Config->ServerName,"Flood from unregistered connection",current->ip);
- apply_lines(APPLY_ZLINES);
- }
- return;
- }
- if (current->recvq.length() > (unsigned)Config->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,Config->ServerName,"Flood from unregistered connection",current->ip);
- apply_lines(APPLY_ZLINES);
- }
- return;
- }
- // while there are complete lines to process...
- while (current->BufferIsReady())
- {
- floodlines++;
- if (TIME > current->reset_due)
- {
- current->reset_due = TIME + current->threshold;
- 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");
- return;
- }
- 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,Config->ServerName,"Flood from unregistered connection",current->ip);
- apply_lines(APPLY_ZLINES);
- }
- return;
- }
- char sanitized[MAXBUF];
- // use GetBuffer to copy single lines into the sanitized string
- std::string single_line = current->GetBuffer();
- current->bytes_in += single_line.length();
- current->cmds_in++;
- if (single_line.length()>512)
- {
- 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");
- return;
- }
- strlcpy(sanitized,single_line.c_str(),MAXBUF);
- if (*sanitized)
- {
- userrec* old_comp = fd_ref_table[currfd];
- // we're gonna re-scan to check if the nick is gone, after every
- // command - if it has, we're gonna bail
- ServerInstance->Parser->ProcessBuffer(sanitized,current);
- // look for the user's record in case it's changed... if theyve quit,
- // we cant do anything more with their buffer, so bail.
- // there used to be an ugly, slow loop here. Now we have a reference
- // table, life is much easier (and FASTER)
- userrec* new_comp = fd_ref_table[currfd];
- if ((currfd < 0) || (!fd_ref_table[currfd]) || (old_comp != new_comp))
- {
- return;
- }
- else
- {
- /* The user is still here, flush their buffer */
- current->FlushWriteBuf();
- }
- }
- }
- return;
- }
- if ((result == -1) && (errno != EAGAIN) && (errno != EINTR))
- {
- log(DEBUG,"killing: %s",cu->nick);
- kill_link(cu,strerror(errno));
- return;
- }
- }
- // result EAGAIN means nothing read
- else if ((result == EAGAIN) || (result == -EAGAIN))
- {
- }
- else if (result == 0)
- {
- log(DEBUG,"InspIRCd: Exited: %s",cu->nick);
- kill_link(cu,"Client exited");
- log(DEBUG,"Bailing from client exit");
- return;
- }
+ }
+ else
+ {
+ this->WriteOpers("*** Excess flood from %s",current->GetIPString());
+ log(DEFAULT,"Excess flood from: %s",current->GetIPString());
+ add_zline(120,this->Config->ServerName,"Flood from unregistered connection",current->GetIPString());
+ apply_lines(APPLY_ZLINES);
+ }
+
+ return;
+ }
+
+ if (current->recvq.length() > (unsigned)this->Config->NetBufferSize)
+ {
+ if (current->registered == REG_ALL)
+ {
+ userrec::QuitUser(this, current,"RecvQ exceeded");
+ }
+ else
+ {
+ this->WriteOpers("*** Excess flood from %s",current->GetIPString());
+ log(DEFAULT,"Excess flood from: %s",current->GetIPString());
+ add_zline(120,this->Config->ServerName,"Flood from unregistered connection",current->GetIPString());
+ apply_lines(APPLY_ZLINES);
+ }
+
+ return;
+ }
+
+ // while there are complete lines to process...
+ while (current->BufferIsReady())
+ {
+ if (TIME > current->reset_due)
+ {
+ current->reset_due = TIME + current->threshold;
+ current->lines_in = 0;
+ }
+
+ 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);
+ userrec::QuitUser(this, current,"Excess flood");
+ return;
+ }
+
+ if ((++floodlines > current->flood) && (current->flood != 0))
+ {
+ if (current->registered == REG_ALL)
+ {
+ 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);
+ userrec::QuitUser(this, current,"Excess flood");
+ }
+ else
+ {
+ add_zline(120,this->Config->ServerName,"Flood from unregistered connection",current->GetIPString());
+ apply_lines(APPLY_ZLINES);
+ }
+
+ return;
+ }
+
+ // use GetBuffer to copy single lines into the sanitized string
+ std::string single_line = current->GetBuffer();
+ current->bytes_in += single_line.length();
+ current->cmds_in++;
+ if (single_line.length() > 512)
+ single_line.resize(512);
+
+ userrec* old_comp = this->fd_ref_table[currfd];
+
+ this->Parser->ProcessBuffer(single_line,current);
+ /*
+ * look for the user's record in case it's changed... if theyve quit,
+ * we cant do anything more with their buffer, so bail.
+ * there used to be an ugly, slow loop here. Now we have a reference
+ * table, life is much easier (and FASTER)
+ */
+ userrec* new_comp = this->fd_ref_table[currfd];
+ if ((currfd < 0) || (!this->fd_ref_table[currfd]) || (old_comp != new_comp))
+ {
+ return;
+ }
+ else
+ {
+ /* The user is still here, flush their buffer */
+ current->FlushWriteBuf();
+ }
+ }
+
+ return;
+ }
+
+ if ((result == -1) && (errno != EAGAIN) && (errno != EINTR))
+ {
+ log(DEBUG,"killing: %s",cu->nick);
+ userrec::QuitUser(this,cu,strerror(errno));
+ return;
+ }
+ }
+
+ // result EAGAIN means nothing read
+ else if ((result == EAGAIN) || (result == -EAGAIN))
+ {
+ /* do nothing */
+ }
+ else if (result == 0)
+ {
+ log(DEBUG,"InspIRCd: Exited: %s",cu->nick);
+ userrec::QuitUser(this,cu,"Client exited");
+ log(DEBUG,"Bailing from client exit");
+ return;
+ }
+}
+
+void InspIRCd::DoSocketTimeouts(time_t TIME)
+{
+ unsigned int numsockets = this->module_sockets.size();
+ SocketEngine* SE = this->SE;
+
+ for (std::vector<InspSocket*>::iterator a = this->module_sockets.begin(); a < this->module_sockets.end(); a++)
+ {
+ InspSocket* s = (InspSocket*)*a;
+ if ((s) && (s->GetFd() >= 0) && (s->GetFd() < MAX_DESCRIPTORS) && (this->socket_ref[s->GetFd()] != NULL) && (s->Timeout(TIME)))
+ {
+ log(DEBUG,"userprocess.cpp: Socket poll returned false, close and bail");
+ this->socket_ref[s->GetFd()] = NULL;
+ SE->DelFd(s->GetFd());
+ this->module_sockets.erase(a);
+ s->Close();
+ DELETE(s);
+ break;
+ }
+
+ if (this->module_sockets.size() != numsockets)
+ break;
+ }