2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2006-2008 Robin Burchell <robin+git@viroteck.net>
6 * Copyright (C) 2005-2007 Craig Edwards <craigedwards@brainbox.cc>
7 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
8 * Copyright (C) 2006 Craig McLure <craig@chatspike.net>
10 * This file is part of InspIRCd. InspIRCd is free software: you can
11 * redistribute it and/or modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation, version 2.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include "socketengine.h"
29 #include "command_parse.h"
31 void FloodQuitUserHandler::Call(User* current)
33 ServerInstance->Logs->Log("USERS",DEFAULT,"Excess flood from: %s@%s", current->ident.c_str(), current->host.c_str());
34 ServerInstance->SNO->WriteToSnoMask('f',"Excess flood from: %s%s%s@%s",
35 current->registered == REG_ALL ? current->nick.c_str() : "",
36 current->registered == REG_ALL ? "!" : "", current->ident.c_str(), current->host.c_str());
37 ServerInstance->Users->QuitUser(current, "Excess flood");
39 if (current->registered != REG_ALL)
41 ZLine* zl = new ZLine(ServerInstance->Time(), 0, ServerInstance->Config->ServerName, "Flood from unregistered connection", current->GetIPString());
42 if (ServerInstance->XLines->AddLine(zl,NULL))
43 ServerInstance->XLines->ApplyLines();
50 * This function is called once a second from the mainloop.
51 * It is intended to do background checking on all the user structs, e.g.
52 * stuff like ping checks, registration timeouts, etc.
54 void InspIRCd::DoBackgroundUserStuff()
57 * loop over all local users..
59 LocalUserList::reverse_iterator count2 = this->Users->local_users.rbegin();
60 while (count2 != this->Users->local_users.rend())
62 LocalUser *curr = *count2;
68 if (curr->CommandFloodPenalty || curr->eh.getSendQSize())
70 unsigned int rate = curr->MyClass->GetCommandRate();
71 if (curr->CommandFloodPenalty > rate)
72 curr->CommandFloodPenalty -= rate;
74 curr->CommandFloodPenalty = 0;
75 curr->eh.OnDataReady();
78 switch (curr->registered)
81 if (Time() > curr->nping)
83 // This user didn't answer the last ping, remove them
86 time_t time = this->Time() - (curr->nping - curr->MyClass->GetPingTime());
88 snprintf(message, MAXBUF, "Ping timeout: %ld second%s", (long)time, time > 1 ? "s" : "");
90 curr->nping = Time() + curr->MyClass->GetPingTime();
91 this->Users->QuitUser(curr, message);
95 curr->Write("PING :%s",this->Config->ServerName.c_str());
97 curr->nping = Time() +curr->MyClass->GetPingTime();
101 if (AllModulesReportReady(curr) && curr->dns_done)
103 /* User has sent NICK/USER, modules are okay, DNS finished. */
110 if (curr->registered != REG_ALL && (Time() > (curr->age + curr->MyClass->GetRegTimeout())))
113 * registration timeout -- didnt send USER/NICK/HOST
114 * in the time specified in their connection class.
116 this->Users->QuitUser(curr, "Registration timeout");