]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_conn_waitpong.cpp
Send RPL_SAVENICK from irc2 when renaming a user to their UUID.
[user/henk/code/inspircd.git] / src / modules / m_conn_waitpong.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2013, 2018-2019 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2012-2013, 2015, 2018 Attila Molnar <attilamolnar@hush.com>
6  *   Copyright (C) 2012 Robby <robby@chatbelgie.be>
7  *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
8  *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
9  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
10  *   Copyright (C) 2006, 2010 Craig Edwards <brain@inspircd.org>
11  *
12  * This file is part of InspIRCd.  InspIRCd is free software: you can
13  * redistribute it and/or modify it under the terms of the GNU General Public
14  * License as published by the Free Software Foundation, version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
19  * details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24
25
26 #include "inspircd.h"
27
28 class ModuleWaitPong : public Module
29 {
30         bool sendsnotice;
31         bool killonbadreply;
32         LocalStringExt ext;
33
34  public:
35         ModuleWaitPong()
36                 : ext("waitpong_pingstr", ExtensionItem::EXT_USER, this)
37         {
38         }
39
40         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
41         {
42                 ConfigTag* tag = ServerInstance->Config->ConfValue("waitpong");
43                 sendsnotice = tag->getBool("sendsnotice", false);
44                 killonbadreply = tag->getBool("killonbadreply", true);
45         }
46
47         ModResult OnUserRegister(LocalUser* user) CXX11_OVERRIDE
48         {
49                 std::string pingrpl = ServerInstance->GenRandomStr(10);
50                 {
51                         ClientProtocol::Messages::Ping pingmsg(pingrpl);
52                         user->Send(ServerInstance->GetRFCEvents().ping, pingmsg);
53                 }
54
55                 if(sendsnotice)
56                         user->WriteNotice("*** If you are having problems connecting due to registration timeouts type /quote PONG " + pingrpl + " or /raw PONG " + pingrpl + " now.");
57
58                 ext.set(user, pingrpl);
59                 return MOD_RES_PASSTHRU;
60         }
61
62         ModResult OnPreCommand(std::string& command, CommandBase::Params& parameters, LocalUser* user, bool validated) CXX11_OVERRIDE
63         {
64                 if (command == "PONG")
65                 {
66                         std::string* pingrpl = ext.get(user);
67
68                         if (pingrpl)
69                         {
70                                 if (!parameters.empty() && *pingrpl == parameters[0])
71                                 {
72                                         ext.unset(user);
73                                         return MOD_RES_DENY;
74                                 }
75                                 else
76                                 {
77                                         if(killonbadreply)
78                                                 ServerInstance->Users->QuitUser(user, "Incorrect ping reply for registration");
79                                         return MOD_RES_DENY;
80                                 }
81                         }
82                 }
83                 return MOD_RES_PASSTHRU;
84         }
85
86         ModResult OnCheckReady(LocalUser* user) CXX11_OVERRIDE
87         {
88                 return ext.get(user) ? MOD_RES_DENY : MOD_RES_PASSTHRU;
89         }
90
91         Version GetVersion() CXX11_OVERRIDE
92         {
93                 return Version("Requires all clients to respond to a PING request before they can fully connect.", VF_VENDOR);
94         }
95 };
96
97 MODULE_INIT(ModuleWaitPong)