]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/userprocess.cpp
Show a better warning when certtool/openssl are missing.
[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 void FloodQuitUserHandler::Call(User* current)
32 {
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");
38
39         if (current->registered != REG_ALL)
40         {
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();
44                 else
45                         delete zl;
46         }
47 }
48
49 /**
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.
53  */
54 void InspIRCd::DoBackgroundUserStuff()
55 {
56         /*
57          * loop over all local users..
58          */
59         LocalUserList::reverse_iterator count2 = this->Users->local_users.rbegin();
60         while (count2 != this->Users->local_users.rend())
61         {
62                 LocalUser *curr = *count2;
63                 count2++;
64
65                 if (curr->quitting)
66                         continue;
67
68                 if (curr->CommandFloodPenalty || curr->eh.getSendQSize())
69                 {
70                         unsigned int rate = curr->MyClass->GetCommandRate();
71                         if (curr->CommandFloodPenalty > rate)
72                                 curr->CommandFloodPenalty -= rate;
73                         else
74                                 curr->CommandFloodPenalty = 0;
75                         curr->eh.OnDataReady();
76                 }
77
78                 switch (curr->registered)
79                 {
80                         case REG_ALL:
81                                 if (Time() > curr->nping)
82                                 {
83                                         // This user didn't answer the last ping, remove them
84                                         if (!curr->lastping)
85                                         {
86                                                 time_t time = this->Time() - (curr->nping - curr->MyClass->GetPingTime());
87                                                 char message[MAXBUF];
88                                                 snprintf(message, MAXBUF, "Ping timeout: %ld second%s", (long)time, time > 1 ? "s" : "");
89                                                 curr->lastping = 1;
90                                                 curr->nping = Time() + curr->MyClass->GetPingTime();
91                                                 this->Users->QuitUser(curr, message);
92                                                 continue;
93                                         }
94
95                                         curr->Write("PING :%s",this->Config->ServerName.c_str());
96                                         curr->lastping = 0;
97                                         curr->nping = Time()  +curr->MyClass->GetPingTime();
98                                 }
99                                 break;
100                         case REG_NICKUSER:
101                                 if (AllModulesReportReady(curr) && curr->dns_done)
102                                 {
103                                         /* User has sent NICK/USER, modules are okay, DNS finished. */
104                                         curr->FullConnect();
105                                         continue;
106                                 }
107
108                                 // If the user has been quit in OnCheckReady then we shouldn't
109                                 // quit them again for having a registration timeout.
110                                 if (curr->quitting)
111                                         continue;
112                                 break;
113                 }
114
115                 if (curr->registered != REG_ALL && curr->MyClass && (Time() > (curr->signon + curr->MyClass->GetRegTimeout())))
116                 {
117                         /*
118                          * registration timeout -- didnt send USER/NICK/HOST
119                          * in the time specified in their connection class.
120                          */
121                         this->Users->QuitUser(curr, "Registration timeout");
122                         continue;
123                 }
124         }
125 }
126