]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/userprocess.cpp
b150f2828ebb4951b809ee0189a84bb572831ba7
[user/henk/code/inspircd.git] / src / userprocess.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 /* $Core */
15
16 #include "inspircd.h"
17 #include "xline.h"
18 #include "socketengine.h"
19 #include "command_parse.h"
20
21 void FloodQuitUserHandler::Call(User* current)
22 {
23         Server->Logs->Log("USERS",DEFAULT,"Excess flood from: %s@%s", current->ident.c_str(), current->host.c_str());
24         Server->SNO->WriteToSnoMask('f',"Excess flood from: %s%s%s@%s",
25                         current->registered == REG_ALL ? current->nick.c_str() : "",
26                         current->registered == REG_ALL ? "!" : "", current->ident.c_str(), current->host.c_str());
27         Server->Users->QuitUser(current, "Excess flood");
28
29         if (current->registered != REG_ALL)
30         {
31                 ZLine* zl = new ZLine(Server, Server->Time(), 0, Server->Config->ServerName, "Flood from unregistered connection", current->GetIPString());
32                 if (Server->XLines->AddLine(zl,NULL))
33                         Server->XLines->ApplyLines();
34                 else
35                         delete zl;
36         }
37 }
38
39 /**
40  * This function is called once a second from the mainloop.
41  * It is intended to do background checking on all the user structs, e.g.
42  * stuff like ping checks, registration timeouts, etc.
43  */
44 void InspIRCd::DoBackgroundUserStuff()
45 {
46         /*
47          * loop over all local users..
48          */
49         std::vector<User*>::reverse_iterator count2 = this->Users->local_users.rbegin();
50         while (count2 != this->Users->local_users.rend())
51         {
52                 User *curr = *count2;
53                 count2++;
54
55                 if (curr->quitting)
56                         continue;
57
58                 if (curr->Penalty)
59                 {
60                         curr->Penalty--;
61                         curr->OnDataReady();
62                 }
63
64                 if (curr->getSendQSize() == 0)
65                 {
66                         FOREACH_MOD(I_OnBufferFlushed,OnBufferFlushed(curr));
67                 }
68
69                 switch (curr->registered)
70                 {
71                         case REG_ALL:
72                                 if (TIME > curr->nping)
73                                 {
74                                         // This user didn't answer the last ping, remove them
75                                         if (!curr->lastping)
76                                         {
77                                                 time_t time = this->Time() - (curr->nping - curr->MyClass->GetPingTime());
78                                                 char message[MAXBUF];
79                                                 snprintf(message, MAXBUF, "Ping timeout: %ld second%s", (long)time, time > 1 ? "s" : "");
80                                                 curr->lastping = 1;
81                                                 curr->nping = TIME + curr->MyClass->GetPingTime();
82                                                 this->Users->QuitUser(curr, message);
83                                                 continue;
84                                         }
85
86                                         curr->Write("PING :%s",this->Config->ServerName);
87                                         curr->lastping = 0;
88                                         curr->nping = TIME  +curr->MyClass->GetPingTime();
89                                 }
90                                 break;
91                         case REG_NICKUSER:
92                                 if (AllModulesReportReady(curr) && curr->dns_done)
93                                 {
94                                         /* User has sent NICK/USER, modules are okay, DNS finished. */
95                                         curr->FullConnect();
96                                         continue;
97                                 }
98                                 break;
99                 }
100
101                 if (curr->registered != REG_ALL && (TIME > (curr->age + curr->MyClass->GetRegTimeout())))
102                 {
103                         /*
104                          * registration timeout -- didnt send USER/NICK/HOST
105                          * in the time specified in their connection class.
106                          */
107                         this->Users->QuitUser(curr, "Registration timeout");
108                         continue;
109                 }
110         }
111 }
112