]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/userprocess.cpp
Allow for skipping clone checking before DNS is complete.
[user/henk/code/inspircd.git] / src / userprocess.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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>
9  *
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.
13  *
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
17  * details.
18  *
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/>.
21  */
22
23
24 /* $Core */
25
26 #include "inspircd.h"
27 #include "xline.h"
28 #include "socketengine.h"
29 #include "command_parse.h"
30
31 /**
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.
35  */
36 void UserManager::DoBackgroundUserStuff()
37 {
38         /*
39          * loop over all local users..
40          */
41         for (LocalUserList::iterator i = local_users.begin(); i != local_users.end(); ++i)
42         {
43                 LocalUser* curr = *i;
44
45                 if (curr->quitting)
46                         continue;
47
48                 if (curr->CommandFloodPenalty || curr->eh.getSendQSize())
49                 {
50                         unsigned int rate = curr->MyClass->GetCommandRate();
51                         if (curr->CommandFloodPenalty > rate)
52                                 curr->CommandFloodPenalty -= rate;
53                         else
54                                 curr->CommandFloodPenalty = 0;
55                         curr->eh.OnDataReady();
56                 }
57
58                 switch (curr->registered)
59                 {
60                         case REG_ALL:
61                                 if (ServerInstance->Time() > curr->nping)
62                                 {
63                                         // This user didn't answer the last ping, remove them
64                                         if (!curr->lastping)
65                                         {
66                                                 time_t time = ServerInstance->Time() - (curr->nping - curr->MyClass->GetPingTime());
67                                                 const std::string message = "Ping timeout: " + ConvToStr(time) + (time == 1 ? " seconds" : " second");
68                                                 this->QuitUser(curr, message);
69                                                 continue;
70                                         }
71
72                                         curr->Write("PING :" + ServerInstance->Config->ServerName);
73                                         curr->lastping = 0;
74                                         curr->nping = ServerInstance->Time() + curr->MyClass->GetPingTime();
75                                 }
76                                 break;
77                         case REG_NICKUSER:
78                                 if (AllModulesReportReady(curr))
79                                 {
80                                         /* User has sent NICK/USER, modules are okay, DNS finished. */
81                                         curr->FullConnect();
82                                         continue;
83                                 }
84                                 break;
85                 }
86
87                 if (curr->registered != REG_ALL && (ServerInstance->Time() > (curr->age + curr->MyClass->GetRegTimeout())))
88                 {
89                         /*
90                          * registration timeout -- didnt send USER/NICK/HOST
91                          * in the time specified in their connection class.
92                          */
93                         this->QuitUser(curr, "Registration timeout");
94                         continue;
95                 }
96         }
97 }