1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
17 #include "socketengine.h"
18 #include "command_parse.h"
20 void FloodQuitUserHandler::Call(User* current)
22 Server->Log(DEFAULT,"Excess flood from: %s@%s", current->ident, current->host);
23 Server->SNO->WriteToSnoMask('f',"Excess flood from: %s%s%s@%s",
24 current->registered == REG_ALL ? current->nick : "",
25 current->registered == REG_ALL ? "!" : "", current->ident, current->host);
26 User::QuitUser(Server, current, "Excess flood");
27 if (current->registered != REG_ALL)
29 Server->XLines->add_zline(120, Server->Config->ServerName, "Flood from unregistered connection", current->GetIPString());
30 Server->XLines->apply_lines(APPLY_ZLINES);
34 void ProcessUserHandler::Call(User* cu)
38 if (cu->GetFd() == FD_MAGIC_NUMBER)
41 char* ReadBuffer = Server->GetReadBuffer();
43 if (Server->Config->GetIOHook(cu->GetPort()))
50 MOD_RESULT = Server->Config->GetIOHook(cu->GetPort())->OnRawSocketRead(cu->GetFd(),ReadBuffer,sizeof(ReadBuffer),result2);
52 catch (CoreException& modexcept)
54 Server->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
68 result = cu->ReadData(ReadBuffer, sizeof(ReadBuffer));
71 if ((result) && (result != -EAGAIN))
76 Server->stats->statsRecv += result;
78 * perform a check on the raw buffer as an array (not a string!) to remove
79 * character 0 which is illegal in the RFC - replace them with spaces.
82 for (int checker = 0; checker < result; checker++)
84 if (ReadBuffer[checker] == 0)
85 ReadBuffer[checker] = ' ';
89 ReadBuffer[result] = '\0';
92 currfd = current->GetFd();
94 // add the data to the users buffer
97 if (!current->AddBuffer(ReadBuffer))
99 // AddBuffer returned false, theres too much data in the user's buffer and theyre up to no good.
100 if (current->registered == REG_ALL)
102 // Make sure they arn't flooding long lines.
103 if (Server->Time() > current->reset_due)
105 current->reset_due = Server->Time() + current->threshold;
106 current->lines_in = 0;
111 if (current->flood && current->lines_in > current->flood)
112 Server->FloodQuitUser(current);
115 current->WriteServ("NOTICE %s :Your previous line was too long and was not delivered (Over %d chars) Please shorten it.", current->nick, MAXBUF-2);
116 current->recvq.clear();
120 Server->FloodQuitUser(current);
125 /* If user is over penalty, dont process here, just build up */
126 if (!current->OverPenalty)
127 Server->Parser->DoLines(current);
132 if ((result == -1) && (errno != EAGAIN) && (errno != EINTR))
134 User::QuitUser(Server, cu, errno ? strerror(errno) : "EOF from client");
139 // result EAGAIN means nothing read
140 else if ((result == EAGAIN) || (result == -EAGAIN))
144 else if (result == 0)
146 User::QuitUser(Server, cu, "Connection closed");
152 * This function is called once a second from the mainloop.
153 * It is intended to do background checking on all the user structs, e.g.
154 * stuff like ping checks, registration timeouts, etc.
156 void InspIRCd::DoBackgroundUserStuff()
159 * loop over all local users..
161 for (std::vector<User*>::iterator count2 = local_users.begin(); count2 != local_users.end(); count2++)
163 User *curr = *count2;
168 if (curr->OverPenalty)
170 if (curr->sendq.empty())
171 curr->OverPenalty = false;
173 if (curr->Penalty < 10)
174 Parser->DoLines(curr, true);
177 if ((curr->registered != REG_ALL) && (TIME > curr->timeout))
180 * registration timeout -- didnt send USER/NICK/HOST
181 * in the time specified in their connection class.
184 User::QuitUser(this, curr, "Registration timeout");
189 * `ready` means that the user has provided NICK/USER(/PASS), and all modules agree
190 * that the user is okay to proceed. The one thing we are then waiting for is DNS, which we do here...
192 bool ready = ((curr->registered == REG_NICKUSER) && AllModulesReportReady(curr));
199 * DNS isn't done yet?
200 * Cool. Check for timeout.
202 if (TIME > curr->signon)
204 /* FZZZZZZZZT, timeout! */
205 curr->WriteServ("NOTICE Auth :*** Could not resolve your hostname: Request timed out; using your IP address (%s) instead.", curr->GetIPString());
206 curr->dns_done = true;
207 this->stats->statsDnsBad++;
214 /* DNS passed, connect the user */
220 // It's time to PING this user. Send them a ping.
221 if ((TIME > curr->nping) && (curr->registered == REG_ALL))
223 // This user didn't answer the last ping, remove them
226 time_t time = this->Time(false) - (curr->nping - curr->pingmax);
227 char message[MAXBUF];
228 snprintf(message, MAXBUF, "Ping timeout: %ld second%s", (long)time, time > 1 ? "s" : "");
231 curr->nping = TIME+curr->pingmax;
232 User::QuitUser(this, curr, message);
235 curr->Write("PING :%s",this->Config->ServerName);
237 curr->nping = TIME+curr->pingmax;