1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 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");
30 if (current->registered != REG_ALL)
32 ZLine* zl = new ZLine(Server, Server->Time(), 0, Server->Config->ServerName, "Flood from unregistered connection", current->GetIPString());
33 if (Server->XLines->AddLine(zl,NULL))
34 Server->XLines->ApplyLines();
40 void ProcessUserHandler::Call(User* cu)
44 if (cu->GetFd() == FD_MAGIC_NUMBER)
47 char* ReadBuffer = Server->GetReadBuffer();
49 if (Server->Config->GetIOHook(cu->GetPort()))
56 MOD_RESULT = Server->Config->GetIOHook(cu->GetPort())->OnRawSocketRead(cu->GetFd(),ReadBuffer,Server->Config->NetBufferSize,result2);
58 catch (CoreException& modexcept)
60 Server->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
74 result = cu->ReadData(ReadBuffer, sizeof(ReadBuffer));
77 if ((result) && (result != -EAGAIN))
82 Server->stats->statsRecv += result;
84 * perform a check on the raw buffer as an array (not a string!) to remove
85 * character 0 which is illegal in the RFC - replace them with spaces.
88 for (int checker = 0; checker < result; checker++)
90 if (ReadBuffer[checker] == 0)
91 ReadBuffer[checker] = ' ';
95 ReadBuffer[result] = '\0';
98 currfd = current->GetFd();
100 // add the data to the users buffer
103 if (!current->AddBuffer(ReadBuffer))
105 // AddBuffer returned false, theres too much data in the user's buffer and theyre up to no good.
106 if (current->registered == REG_ALL)
108 if (current->MyClass)
110 // Make sure they arn't flooding long lines.
111 if (Server->Time() > current->reset_due)
113 current->reset_due = Server->Time() + current->MyClass->GetThreshold();
114 current->lines_in = 0;
119 if (current->MyClass->GetFlood() && current->lines_in > current->MyClass->GetFlood())
120 Server->FloodQuitUser(current);
123 current->WriteServ("NOTICE %s :Your previous line was too long and was not delivered (Over %d chars) Please shorten it.", current->nick, MAXBUF-2);
124 current->recvq.clear();
129 Server->FloodQuitUser(current);
134 /* If user is over penalty, dont process here, just build up */
135 if (!current->OverPenalty)
136 Server->Parser->DoLines(current);
141 if ((result == -1) && (errno != EAGAIN) && (errno != EINTR))
143 User::QuitUser(Server, cu, errno ? strerror(errno) : "EOF from client");
148 // result EAGAIN means nothing read
149 else if ((result == EAGAIN) || (result == -EAGAIN))
153 else if (result == 0)
155 User::QuitUser(Server, cu, "Connection closed");
161 * This function is called once a second from the mainloop.
162 * It is intended to do background checking on all the user structs, e.g.
163 * stuff like ping checks, registration timeouts, etc.
165 void InspIRCd::DoBackgroundUserStuff()
168 * loop over all local users..
170 for (std::vector<User*>::iterator count2 = this->Users->local_users.begin(); count2 != this->Users->local_users.end(); count2++)
172 User *curr = *count2;
177 if (curr->Penalty < 10)
178 Parser->DoLines(curr, true);
181 if (curr->OverPenalty)
183 if (curr->sendq.empty())
184 curr->OverPenalty = false;
187 if ((curr->registered != REG_ALL) && (TIME > curr->timeout))
190 * registration timeout -- didnt send USER/NICK/HOST
191 * in the time specified in their connection class.
193 User::QuitUser(this, curr, "Registration timeout");
198 * `ready` means that the user has provided NICK/USER(/PASS), and all modules agree
199 * that the user is okay to proceed. The one thing we are then waiting for now is DNS...
201 bool ready = ((curr->registered == REG_NICKUSER) && AllModulesReportReady(curr));
207 /* DNS passed, connect the user */
213 // It's time to PING this user. Send them a ping.
214 if ((TIME > curr->nping) && (curr->registered == REG_ALL))
216 // This user didn't answer the last ping, remove them
219 time_t time = this->Time(false) - (curr->nping - curr->MyClass->GetPingTime());
220 char message[MAXBUF];
221 snprintf(message, MAXBUF, "Ping timeout: %ld second%s", (long)time, time > 1 ? "s" : "");
223 curr->nping = TIME + curr->MyClass->GetPingTime();
224 User::QuitUser(this, curr, message);
227 curr->Write("PING :%s",this->Config->ServerName);
229 curr->nping = TIME +curr->MyClass->GetPingTime();