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 * ---------------------------------------------------
18 #include "socketengine.h"
19 #include "command_parse.h"
21 void FloodQuitUserHandler::Call(User* current)
23 Server->Logs->Log("USERS",DEFAULT,"Excess flood from: %s@%s", current->ident.c_str(), current->host.c_str());
24 Server->SNO->WriteToSnoMask('f',"Excess flood from: %s%s%s@%s",
25 current->registered == REG_ALL ? current->nick.c_str() : "",
26 current->registered == REG_ALL ? "!" : "", current->ident.c_str(), current->host.c_str());
27 Server->Users->QuitUser(current, "Excess flood");
29 if (current->registered != REG_ALL)
31 ZLine* zl = new ZLine(Server, Server->Time(), 0, Server->Config->ServerName, "Flood from unregistered connection", current->GetIPString());
32 if (Server->XLines->AddLine(zl,NULL))
33 Server->XLines->ApplyLines();
39 void ProcessUserHandler::Call(User* cu)
43 if (cu->GetFd() == FD_MAGIC_NUMBER)
46 char* ReadBuffer = Server->GetReadBuffer();
55 MOD_RESULT = cu->io->OnRawSocketRead(cu->GetFd(), ReadBuffer, Server->Config->NetBufferSize, result2);
57 catch (CoreException& modexcept)
59 Server->Logs->Log("USERS",DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
73 result = cu->ReadData(ReadBuffer, Server->Config->NetBufferSize);
76 if ((result) && (result != -EAGAIN))
81 Server->stats->statsRecv += result;
83 * perform a check on the raw buffer as an array (not a string!) to remove
84 * character 0 which is illegal in the RFC - replace them with spaces.
87 for (int checker = 0; checker < result; checker++)
89 if (ReadBuffer[checker] == 0)
90 ReadBuffer[checker] = ' ';
94 ReadBuffer[result] = '\0';
97 currfd = current->GetFd();
99 // add the data to the users buffer
102 if (!current->AddBuffer(ReadBuffer))
104 // AddBuffer returned false, theres too much data in the user's buffer and theyre up to no good.
105 if (current->registered == REG_ALL)
107 if (current->MyClass)
109 // Make sure they arn't flooding long lines.
110 if (Server->Time() > current->reset_due)
112 current->reset_due = Server->Time() + current->MyClass->GetThreshold();
113 current->lines_in = 0;
118 if (current->MyClass->GetFlood() && current->lines_in > current->MyClass->GetFlood())
119 Server->FloodQuitUser(current);
122 current->WriteServ("NOTICE %s :Your previous line was too long and was not delivered (Over %d chars) Please shorten it.", current->nick.c_str(), MAXBUF-2);
123 current->recvq.clear();
128 Server->FloodQuitUser(current);
133 /* If user is over penalty, dont process here, just build up */
134 if (!current->OverPenalty)
135 Server->Parser->DoLines(current);
140 if ((result == -1) && (errno != EAGAIN) && (errno != EINTR))
142 Server->Users->QuitUser(cu, errno ? strerror(errno) : "EOF from client");
147 // result EAGAIN means nothing read
148 else if ((result == EAGAIN) || (result == -EAGAIN))
152 else if (result == 0)
154 Server->Users->QuitUser(cu, "Connection closed");
160 * This function is called once a second from the mainloop.
161 * It is intended to do background checking on all the user structs, e.g.
162 * stuff like ping checks, registration timeouts, etc.
164 void InspIRCd::DoBackgroundUserStuff()
167 * loop over all local users..
169 for (std::vector<User*>::iterator count2 = this->Users->local_users.begin(); count2 != this->Users->local_users.end(); count2++)
171 User *curr = *count2;
179 if (curr->Penalty < 10)
180 Parser->DoLines(curr, true);
183 if (curr->OverPenalty)
185 if (curr->sendq.empty())
186 curr->OverPenalty = false;
189 switch (curr->registered)
192 if (TIME > curr->nping)
194 // This user didn't answer the last ping, remove them
197 time_t time = this->Time() - (curr->nping - curr->MyClass->GetPingTime());
198 char message[MAXBUF];
199 snprintf(message, MAXBUF, "Ping timeout: %ld second%s", (long)time, time > 1 ? "s" : "");
201 curr->nping = TIME + curr->MyClass->GetPingTime();
202 this->Users->QuitUser(curr, message);
206 curr->Write("PING :%s",this->Config->ServerName);
208 curr->nping = TIME +curr->MyClass->GetPingTime();
212 if (AllModulesReportReady(curr) && curr->dns_done)
214 /* User has sent NICK/USER, modules are okay, DNS finished. */
221 if (curr->registered != REG_ALL && (TIME > (curr->age + curr->MyClass->GetRegTimeout())))
224 * registration timeout -- didnt send USER/NICK/HOST
225 * in the time specified in their connection class.
227 this->Users->QuitUser(curr, "Registration timeout");