]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_conn_waitpong.cpp
Enable the LINK snomask from m_spanningtree, remove unused FLOOD snomask
[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 class ModuleWaitPong : public Module
28 {
29         bool sendsnotice;
30         bool killonbadreply;
31         LocalStringExt ext;
32
33  public:
34         ModuleWaitPong()
35          : ext("waitpong_pingstr", this)
36         {
37         }
38
39         void init() CXX11_OVERRIDE
40         {
41                 ServerInstance->Modules->AddService(ext);
42                 OnRehash(NULL);
43                 Implementation eventlist[] = { I_OnUserRegister, I_OnCheckReady, I_OnPreCommand, I_OnRehash };
44                 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
45         }
46
47         void OnRehash(User* user) CXX11_OVERRIDE
48         {
49                 ConfigTag* tag = ServerInstance->Config->ConfValue("waitpong");
50                 sendsnotice = tag->getBool("sendsnotice", true);
51                 killonbadreply = tag->getBool("killonbadreply", true);
52         }
53
54         ModResult OnUserRegister(LocalUser* user) CXX11_OVERRIDE
55         {
56                 std::string pingrpl = ServerInstance->GenRandomStr(10);
57
58                 user->Write("PING :%s", pingrpl.c_str());
59
60                 if(sendsnotice)
61                         user->WriteNotice("*** If you are having problems connecting due to ping timeouts, please type /quote PONG " + pingrpl + " or /raw PONG " + pingrpl + " now.");
62
63                 ext.set(user, pingrpl);
64                 return MOD_RES_PASSTHRU;
65         }
66
67         ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser* user, bool validated, const std::string &original_line) CXX11_OVERRIDE
68         {
69                 if (command == "PONG")
70                 {
71                         std::string* pingrpl = ext.get(user);
72
73                         if (pingrpl)
74                         {
75                                 if (!parameters.empty() && *pingrpl == parameters[0])
76                                 {
77                                         ext.unset(user);
78                                         return MOD_RES_DENY;
79                                 }
80                                 else
81                                 {
82                                         if(killonbadreply)
83                                                 ServerInstance->Users->QuitUser(user, "Incorrect ping reply for registration");
84                                         return MOD_RES_DENY;
85                                 }
86                         }
87                 }
88                 return MOD_RES_PASSTHRU;
89         }
90
91         ModResult OnCheckReady(LocalUser* user) CXX11_OVERRIDE
92         {
93                 return ext.get(user) ? MOD_RES_DENY : MOD_RES_PASSTHRU;
94         }
95
96         Version GetVersion() CXX11_OVERRIDE
97         {
98                 return Version("Require pong prior to registration", VF_VENDOR);
99         }
100 };
101
102 MODULE_INIT(ModuleWaitPong)