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"
32 * This function is called once a second from the mainloop.
33 * It is intended to do background checking on all the user structs, e.g.
34 * stuff like ping checks, registration timeouts, etc.
36 void InspIRCd::DoBackgroundUserStuff()
39 * loop over all local users..
41 LocalUserList::reverse_iterator count2 = this->Users->local_users.rbegin();
42 while (count2 != this->Users->local_users.rend())
44 LocalUser *curr = *count2;
50 if (curr->CommandFloodPenalty || curr->eh.getSendQSize())
52 unsigned int rate = curr->MyClass->GetCommandRate();
53 if (curr->CommandFloodPenalty > rate)
54 curr->CommandFloodPenalty -= rate;
56 curr->CommandFloodPenalty = 0;
57 curr->eh.OnDataReady();
60 switch (curr->registered)
63 if (Time() > curr->nping)
65 // This user didn't answer the last ping, remove them
68 time_t time = this->Time() - (curr->nping - curr->MyClass->GetPingTime());
70 snprintf(message, MAXBUF, "Ping timeout: %ld second%s", (long)time, time > 1 ? "s" : "");
72 curr->nping = Time() + curr->MyClass->GetPingTime();
73 this->Users->QuitUser(curr, message);
77 curr->Write("PING :%s",this->Config->ServerName.c_str());
79 curr->nping = Time() +curr->MyClass->GetPingTime();
83 if (AllModulesReportReady(curr))
85 /* User has sent NICK/USER, modules are okay, DNS finished. */
92 if (curr->registered != REG_ALL && (Time() > (curr->age + curr->MyClass->GetRegTimeout())))
95 * registration timeout -- didnt send USER/NICK/HOST
96 * in the time specified in their connection class.
98 this->Users->QuitUser(curr, "Registration timeout");