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 * ---------------------------------------------------
14 /* $Core: libIRCDuserprocess */
19 #include "socketengine.h"
20 #include "command_parse.h"
22 void FloodQuitUserHandler::Call(User* current)
24 Server->Log(DEFAULT,"Excess flood from: %s@%s", current->ident, current->host);
25 Server->SNO->WriteToSnoMask('f',"Excess flood from: %s%s%s@%s",
26 current->registered == REG_ALL ? current->nick : "",
27 current->registered == REG_ALL ? "!" : "", current->ident, current->host);
28 User::QuitUser(Server, current, "Excess flood");
29 if (current->registered != REG_ALL)
31 Server->XLines->add_zline(120, Server->Config->ServerName, "Flood from unregistered connection", current->GetIPString());
32 Server->XLines->apply_lines(APPLY_ZLINES);
36 void ProcessUserHandler::Call(User* cu)
40 if (cu->GetFd() == FD_MAGIC_NUMBER)
43 char* ReadBuffer = Server->GetReadBuffer();
45 if (Server->Config->GetIOHook(cu->GetPort()))
52 MOD_RESULT = Server->Config->GetIOHook(cu->GetPort())->OnRawSocketRead(cu->GetFd(),ReadBuffer,Server->Config->NetBufferSize,result2);
54 catch (CoreException& modexcept)
56 Server->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
70 result = cu->ReadData(ReadBuffer, sizeof(ReadBuffer));
73 if ((result) && (result != -EAGAIN))
78 Server->stats->statsRecv += result;
80 * perform a check on the raw buffer as an array (not a string!) to remove
81 * character 0 which is illegal in the RFC - replace them with spaces.
84 for (int checker = 0; checker < result; checker++)
86 if (ReadBuffer[checker] == 0)
87 ReadBuffer[checker] = ' ';
91 ReadBuffer[result] = '\0';
94 currfd = current->GetFd();
96 // add the data to the users buffer
99 if (!current->AddBuffer(ReadBuffer))
101 // AddBuffer returned false, theres too much data in the user's buffer and theyre up to no good.
102 if (current->registered == REG_ALL)
104 if (current->MyClass)
106 // Make sure they arn't flooding long lines.
107 if (Server->Time() > current->reset_due)
109 current->reset_due = Server->Time() + current->MyClass->GetThreshold();
110 current->lines_in = 0;
115 if (current->MyClass->GetFlood() && current->lines_in > current->MyClass->GetFlood())
116 Server->FloodQuitUser(current);
119 current->WriteServ("NOTICE %s :Your previous line was too long and was not delivered (Over %d chars) Please shorten it.", current->nick, MAXBUF-2);
120 current->recvq.clear();
125 Server->FloodQuitUser(current);
130 /* If user is over penalty, dont process here, just build up */
131 if (!current->OverPenalty)
132 Server->Parser->DoLines(current);
137 if ((result == -1) && (errno != EAGAIN) && (errno != EINTR))
139 User::QuitUser(Server, cu, errno ? strerror(errno) : "EOF from client");
144 // result EAGAIN means nothing read
145 else if ((result == EAGAIN) || (result == -EAGAIN))
149 else if (result == 0)
151 User::QuitUser(Server, cu, "Connection closed");
157 * This function is called once a second from the mainloop.
158 * It is intended to do background checking on all the user structs, e.g.
159 * stuff like ping checks, registration timeouts, etc.
161 void InspIRCd::DoBackgroundUserStuff()
164 * loop over all local users..
166 for (std::vector<User*>::iterator count2 = local_users.begin(); count2 != local_users.end(); count2++)
168 User *curr = *count2;
173 if (curr->Penalty < 10)
174 Parser->DoLines(curr, true);
177 if (curr->OverPenalty)
179 if (curr->sendq.empty())
180 curr->OverPenalty = false;
183 if ((curr->registered != REG_ALL) && (TIME > curr->timeout))
186 * registration timeout -- didnt send USER/NICK/HOST
187 * in the time specified in their connection class.
190 User::QuitUser(this, curr, "Registration timeout");
195 * `ready` means that the user has provided NICK/USER(/PASS), and all modules agree
196 * that the user is okay to proceed. The one thing we are then waiting for now is DNS...
198 bool ready = ((curr->registered == REG_NICKUSER) && AllModulesReportReady(curr));
204 /* DNS passed, connect the user */
210 // It's time to PING this user. Send them a ping.
211 if ((TIME > curr->nping) && (curr->registered == REG_ALL))
213 // This user didn't answer the last ping, remove them
216 time_t time = this->Time(false) - (curr->nping - curr->MyClass->GetPingTime());
217 char message[MAXBUF];
218 snprintf(message, MAXBUF, "Ping timeout: %ld second%s", (long)time, time > 1 ? "s" : "");
221 curr->nping = TIME + curr->MyClass->GetPingTime();
222 User::QuitUser(this, curr, message);
225 curr->Write("PING :%s",this->Config->ServerName);
227 curr->nping = TIME +curr->MyClass->GetPingTime();