]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/userprocess.cpp
Modularize DNS
[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 InspIRCd::DoBackgroundUserStuff()
37 {
38         /*
39          * loop over all local users..
40          */
41         LocalUserList::reverse_iterator count2 = this->Users->local_users.rbegin();
42         while (count2 != this->Users->local_users.rend())
43         {
44                 LocalUser *curr = *count2;
45                 count2++;
46
47                 if (curr->quitting)
48                         continue;
49
50                 if (curr->CommandFloodPenalty || curr->eh.getSendQSize())
51                 {
52                         unsigned int rate = curr->MyClass->GetCommandRate();
53                         if (curr->CommandFloodPenalty > rate)
54                                 curr->CommandFloodPenalty -= rate;
55                         else
56                                 curr->CommandFloodPenalty = 0;
57                         curr->eh.OnDataReady();
58                 }
59
60                 switch (curr->registered)
61                 {
62                         case REG_ALL:
63                                 if (Time() > curr->nping)
64                                 {
65                                         // This user didn't answer the last ping, remove them
66                                         if (!curr->lastping)
67                                         {
68                                                 time_t time = this->Time() - (curr->nping - curr->MyClass->GetPingTime());
69                                                 char message[MAXBUF];
70                                                 snprintf(message, MAXBUF, "Ping timeout: %ld second%s", (long)time, time > 1 ? "s" : "");
71                                                 curr->lastping = 1;
72                                                 curr->nping = Time() + curr->MyClass->GetPingTime();
73                                                 this->Users->QuitUser(curr, message);
74                                                 continue;
75                                         }
76
77                                         curr->Write("PING :%s",this->Config->ServerName.c_str());
78                                         curr->lastping = 0;
79                                         curr->nping = Time()  +curr->MyClass->GetPingTime();
80                                 }
81                                 break;
82                         case REG_NICKUSER:
83                                 if (AllModulesReportReady(curr))
84                                 {
85                                         /* User has sent NICK/USER, modules are okay, DNS finished. */
86                                         curr->FullConnect();
87                                         continue;
88                                 }
89                                 break;
90                 }
91
92                 if (curr->registered != REG_ALL && (Time() > (curr->age + curr->MyClass->GetRegTimeout())))
93                 {
94                         /*
95                          * registration timeout -- didnt send USER/NICK/HOST
96                          * in the time specified in their connection class.
97                          */
98                         this->Users->QuitUser(curr, "Registration timeout");
99                         continue;
100                 }
101         }
102 }
103