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 // Make sure they arn't flooding long lines.
105 if (Server->Time() > current->reset_due)
107 current->reset_due = Server->Time() + current->MyClass->GetThreshold();
108 current->lines_in = 0;
113 if (current->MyClass->GetFlood() && current->lines_in > current->MyClass->GetFlood())
114 Server->FloodQuitUser(current);
117 current->WriteServ("NOTICE %s :Your previous line was too long and was not delivered (Over %d chars) Please shorten it.", current->nick, MAXBUF-2);
118 current->recvq.clear();
122 Server->FloodQuitUser(current);
127 /* If user is over penalty, dont process here, just build up */
128 if (!current->OverPenalty)
129 Server->Parser->DoLines(current);
134 if ((result == -1) && (errno != EAGAIN) && (errno != EINTR))
136 User::QuitUser(Server, cu, errno ? strerror(errno) : "EOF from client");
141 // result EAGAIN means nothing read
142 else if ((result == EAGAIN) || (result == -EAGAIN))
146 else if (result == 0)
148 User::QuitUser(Server, cu, "Connection closed");
154 * This function is called once a second from the mainloop.
155 * It is intended to do background checking on all the user structs, e.g.
156 * stuff like ping checks, registration timeouts, etc.
158 void InspIRCd::DoBackgroundUserStuff()
161 * loop over all local users..
163 for (std::vector<User*>::iterator count2 = local_users.begin(); count2 != local_users.end(); count2++)
165 User *curr = *count2;
170 if (curr->Penalty < 10)
171 Parser->DoLines(curr, true);
174 if (curr->OverPenalty)
176 if (curr->sendq.empty())
177 curr->OverPenalty = false;
180 if ((curr->registered != REG_ALL) && (TIME > curr->timeout))
183 * registration timeout -- didnt send USER/NICK/HOST
184 * in the time specified in their connection class.
187 User::QuitUser(this, curr, "Registration timeout");
192 * `ready` means that the user has provided NICK/USER(/PASS), and all modules agree
193 * that the user is okay to proceed. The one thing we are then waiting for now is DNS...
195 bool ready = ((curr->registered == REG_NICKUSER) && AllModulesReportReady(curr));
201 /* DNS passed, connect the user */
207 // It's time to PING this user. Send them a ping.
208 if ((TIME > curr->nping) && (curr->registered == REG_ALL))
210 // This user didn't answer the last ping, remove them
213 time_t time = this->Time(false) - (curr->nping - curr->MyClass->GetPingTime());
214 char message[MAXBUF];
215 snprintf(message, MAXBUF, "Ping timeout: %ld second%s", (long)time, time > 1 ? "s" : "");
218 curr->nping = TIME + curr->MyClass->GetPingTime();
219 User::QuitUser(this, curr, message);
222 curr->Write("PING :%s",this->Config->ServerName);
224 curr->nping = TIME +curr->MyClass->GetPingTime();