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