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");
30 if (current->registered != REG_ALL)
32 Server->XLines->AddZLine(120, Server->Config->ServerName, "Flood from unregistered connection", current->GetIPString());
33 Server->XLines->ApplyLines();
37 void ProcessUserHandler::Call(User* cu)
41 if (cu->GetFd() == FD_MAGIC_NUMBER)
44 char* ReadBuffer = Server->GetReadBuffer();
46 if (Server->Config->GetIOHook(cu->GetPort()))
53 MOD_RESULT = Server->Config->GetIOHook(cu->GetPort())->OnRawSocketRead(cu->GetFd(),ReadBuffer,Server->Config->NetBufferSize,result2);
55 catch (CoreException& modexcept)
57 Server->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
71 result = cu->ReadData(ReadBuffer, sizeof(ReadBuffer));
74 if ((result) && (result != -EAGAIN))
79 Server->stats->statsRecv += result;
81 * perform a check on the raw buffer as an array (not a string!) to remove
82 * character 0 which is illegal in the RFC - replace them with spaces.
85 for (int checker = 0; checker < result; checker++)
87 if (ReadBuffer[checker] == 0)
88 ReadBuffer[checker] = ' ';
92 ReadBuffer[result] = '\0';
95 currfd = current->GetFd();
97 // add the data to the users buffer
100 if (!current->AddBuffer(ReadBuffer))
102 // AddBuffer returned false, theres too much data in the user's buffer and theyre up to no good.
103 if (current->registered == REG_ALL)
105 if (current->MyClass)
107 // Make sure they arn't flooding long lines.
108 if (Server->Time() > current->reset_due)
110 current->reset_due = Server->Time() + current->MyClass->GetThreshold();
111 current->lines_in = 0;
116 if (current->MyClass->GetFlood() && current->lines_in > current->MyClass->GetFlood())
117 Server->FloodQuitUser(current);
120 current->WriteServ("NOTICE %s :Your previous line was too long and was not delivered (Over %d chars) Please shorten it.", current->nick, MAXBUF-2);
121 current->recvq.clear();
126 Server->FloodQuitUser(current);
131 /* If user is over penalty, dont process here, just build up */
132 if (!current->OverPenalty)
133 Server->Parser->DoLines(current);
138 if ((result == -1) && (errno != EAGAIN) && (errno != EINTR))
140 User::QuitUser(Server, cu, errno ? strerror(errno) : "EOF from client");
145 // result EAGAIN means nothing read
146 else if ((result == EAGAIN) || (result == -EAGAIN))
150 else if (result == 0)
152 User::QuitUser(Server, cu, "Connection closed");
158 * This function is called once a second from the mainloop.
159 * It is intended to do background checking on all the user structs, e.g.
160 * stuff like ping checks, registration timeouts, etc.
162 void InspIRCd::DoBackgroundUserStuff()
165 * loop over all local users..
167 for (std::vector<User*>::iterator count2 = local_users.begin(); count2 != local_users.end(); count2++)
169 User *curr = *count2;
174 if (curr->Penalty < 10)
175 Parser->DoLines(curr, true);
178 if (curr->OverPenalty)
180 if (curr->sendq.empty())
181 curr->OverPenalty = false;
184 if ((curr->registered != REG_ALL) && (TIME > curr->timeout))
187 * registration timeout -- didnt send USER/NICK/HOST
188 * in the time specified in their connection class.
191 User::QuitUser(this, curr, "Registration timeout");
196 * `ready` means that the user has provided NICK/USER(/PASS), and all modules agree
197 * that the user is okay to proceed. The one thing we are then waiting for now is DNS...
199 bool ready = ((curr->registered == REG_NICKUSER) && AllModulesReportReady(curr));
205 /* DNS passed, connect the user */
211 // It's time to PING this user. Send them a ping.
212 if ((TIME > curr->nping) && (curr->registered == REG_ALL))
214 // This user didn't answer the last ping, remove them
217 time_t time = this->Time(false) - (curr->nping - curr->MyClass->GetPingTime());
218 char message[MAXBUF];
219 snprintf(message, MAXBUF, "Ping timeout: %ld second%s", (long)time, time > 1 ? "s" : "");
222 curr->nping = TIME + curr->MyClass->GetPingTime();
223 User::QuitUser(this, curr, message);
226 curr->Write("PING :%s",this->Config->ServerName);
228 curr->nping = TIME +curr->MyClass->GetPingTime();