]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_conn_waitpong.cpp
Replace copyright headers with headers granting specific authors copyright
[user/henk/code/inspircd.git] / src / modules / m_conn_waitpong.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2008 Pippijn van Steenhoven <pip88nl@gmail.com>
6  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
7  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
8  *   Copyright (C) 2006-2007 Oliver Lupton <oliverlupton@gmail.com>
9  *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
10  *
11  * This file is part of InspIRCd.  InspIRCd is free software: you can
12  * redistribute it and/or modify it under the terms of the GNU General Public
13  * License as published by the Free Software Foundation, version 2.
14  *
15  * This program is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  */
23
24
25 #include "inspircd.h"
26
27 /* $ModDesc: Forces connecting clients to send a PONG message back to the server before they can complete their connection */
28
29 class ModuleWaitPong : public Module
30 {
31         bool sendsnotice;
32         bool killonbadreply;
33         LocalStringExt ext;
34
35  public:
36         ModuleWaitPong()
37          : ext("waitpong_pingstr", this)
38         {
39                 ServerInstance->Modules->AddService(ext);
40                 OnRehash(NULL);
41                 Implementation eventlist[] = { I_OnUserRegister, I_OnCheckReady, I_OnPreCommand, I_OnRehash };
42                 ServerInstance->Modules->Attach(eventlist, this, 4);
43         }
44
45         void OnRehash(User* user)
46         {
47                 ConfigReader Conf;
48
49                 sendsnotice = Conf.ReadFlag("waitpong", "sendsnotice", 0);
50
51                 if(Conf.GetError() == CONF_VALUE_NOT_FOUND)
52                         sendsnotice = true;
53
54                 killonbadreply = Conf.ReadFlag("waitpong", "killonbadreply", 0);
55
56                 if(Conf.GetError() == CONF_VALUE_NOT_FOUND)
57                         killonbadreply = true;
58         }
59
60         ModResult OnUserRegister(LocalUser* user)
61         {
62                 std::string pingrpl = ServerInstance->GenRandomStr(10);
63
64                 user->Write("PING :%s", pingrpl.c_str());
65
66                 if(sendsnotice)
67                         user->WriteServ("NOTICE %s :*** If you are having problems connecting due to ping timeouts, please type /quote PONG %s or /raw PONG %s now.", user->nick.c_str(), pingrpl.c_str(), pingrpl.c_str());
68
69                 ext.set(user, pingrpl);
70                 return MOD_RES_PASSTHRU;
71         }
72
73         ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser* user, bool validated, const std::string &original_line)
74         {
75                 if (command == "PONG")
76                 {
77                         std::string* pingrpl = ext.get(user);
78
79                         if (pingrpl)
80                         {
81                                 if (!parameters.empty() && *pingrpl == parameters[0])
82                                 {
83                                         ext.unset(user);
84                                         return MOD_RES_DENY;
85                                 }
86                                 else
87                                 {
88                                         if(killonbadreply)
89                                                 ServerInstance->Users->QuitUser(user, "Incorrect ping reply for registration");
90                                         return MOD_RES_DENY;
91                                 }
92                         }
93                 }
94                 return MOD_RES_PASSTHRU;
95         }
96
97         ModResult OnCheckReady(LocalUser* user)
98         {
99                 return ext.get(user) ? MOD_RES_DENY : MOD_RES_PASSTHRU;
100         }
101
102         ~ModuleWaitPong()
103         {
104         }
105
106         Version GetVersion()
107         {
108                 return Version("Require pong prior to registration", VF_VENDOR);
109         }
110
111 };
112
113 MODULE_INIT(ModuleWaitPong)