]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_conn_waitpong.cpp
Add support for blocking tag messages with the deaf mode.
[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  *   Copyright (C) 2006 Oliver Lupton <om@inspircd.org>
12  *
13  * This file is part of InspIRCd.  InspIRCd is free software: you can
14  * redistribute it and/or modify it under the terms of the GNU General Public
15  * License as published by the Free Software Foundation, version 2.
16  *
17  * This program is distributed in the hope that it will be useful, but WITHOUT
18  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
20  * details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24  */
25
26
27 #include "inspircd.h"
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", ExtensionItem::EXT_USER, this)
38         {
39         }
40
41         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
42         {
43                 ConfigTag* tag = ServerInstance->Config->ConfValue("waitpong");
44                 sendsnotice = tag->getBool("sendsnotice", false);
45                 killonbadreply = tag->getBool("killonbadreply", true);
46         }
47
48         ModResult OnUserRegister(LocalUser* user) CXX11_OVERRIDE
49         {
50                 std::string pingrpl = ServerInstance->GenRandomStr(10);
51                 {
52                         ClientProtocol::Messages::Ping pingmsg(pingrpl);
53                         user->Send(ServerInstance->GetRFCEvents().ping, pingmsg);
54                 }
55
56                 if(sendsnotice)
57                         user->WriteNotice("*** If you are having problems connecting due to registration timeouts type /quote PONG " + pingrpl + " or /raw PONG " + pingrpl + " now.");
58
59                 ext.set(user, pingrpl);
60                 return MOD_RES_PASSTHRU;
61         }
62
63         ModResult OnPreCommand(std::string& command, CommandBase::Params& parameters, LocalUser* user, bool validated) CXX11_OVERRIDE
64         {
65                 if (command == "PONG")
66                 {
67                         std::string* pingrpl = ext.get(user);
68
69                         if (pingrpl)
70                         {
71                                 if (!parameters.empty() && *pingrpl == parameters[0])
72                                 {
73                                         ext.unset(user);
74                                         return MOD_RES_DENY;
75                                 }
76                                 else
77                                 {
78                                         if(killonbadreply)
79                                                 ServerInstance->Users->QuitUser(user, "Incorrect ping reply for registration");
80                                         return MOD_RES_DENY;
81                                 }
82                         }
83                 }
84                 return MOD_RES_PASSTHRU;
85         }
86
87         ModResult OnCheckReady(LocalUser* user) CXX11_OVERRIDE
88         {
89                 return ext.get(user) ? MOD_RES_DENY : MOD_RES_PASSTHRU;
90         }
91
92         Version GetVersion() CXX11_OVERRIDE
93         {
94                 return Version("Requires all clients to respond to a PING request before they can fully connect.", VF_VENDOR);
95         }
96 };
97
98 MODULE_INIT(ModuleWaitPong)