]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_conn_waitpong.cpp
461a3754a0fb2c205858aea6e93b5ea417119377
[user/henk/code/inspircd.git] / src / modules / m_conn_waitpong.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 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 #include "inspircd.h"
15
16 /* $ModDesc: Forces connecting clients to send a PONG message back to the server before they can complete their connection */
17
18 class ModuleWaitPong : public Module
19 {
20         bool sendsnotice;
21         bool killonbadreply;
22         LocalStringExt ext;
23
24  public:
25         ModuleWaitPong()
26          : ext("waitpong_pingstr", this)
27         {
28                 ServerInstance->Modules->AddService(ext);
29                 OnRehash(NULL);
30                 Implementation eventlist[] = { I_OnUserRegister, I_OnCheckReady, I_OnPreCommand, I_OnRehash };
31                 ServerInstance->Modules->Attach(eventlist, this, 4);
32         }
33
34         void OnRehash(User* user)
35         {
36                 ConfigReader Conf;
37
38                 sendsnotice = Conf.ReadFlag("waitpong", "sendsnotice", 0);
39
40                 if(Conf.GetError() == CONF_VALUE_NOT_FOUND)
41                         sendsnotice = true;
42
43                 killonbadreply = Conf.ReadFlag("waitpong", "killonbadreply", 0);
44
45                 if(Conf.GetError() == CONF_VALUE_NOT_FOUND)
46                         killonbadreply = true;
47         }
48
49         ModResult OnUserRegister(LocalUser* user)
50         {
51                 std::string pingrpl = ServerInstance->GenRandomStr(10);
52
53                 user->Write("PING :%s", pingrpl.c_str());
54
55                 if(sendsnotice)
56                         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());
57
58                 ext.set(user, pingrpl);
59                 return MOD_RES_PASSTHRU;
60         }
61
62         ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser* user, bool validated, const std::string &original_line)
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)
87         {
88                 return ext.get(user) ? MOD_RES_DENY : MOD_RES_PASSTHRU;
89         }
90
91         ~ModuleWaitPong()
92         {
93         }
94
95         Version GetVersion()
96         {
97                 return Version("Require pong prior to registration", VF_VENDOR);
98         }
99
100 };
101
102 MODULE_INIT(ModuleWaitPong)