]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_conn_waitpong.cpp
Remove InspIRCd* parameters and fields
[user/henk/code/inspircd.git] / src / modules / m_conn_waitpong.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 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                 OnRehash(NULL);
29                 Implementation eventlist[] = { I_OnUserRegister, I_OnCheckReady, I_OnPreCommand, I_OnRehash };
30                 ServerInstance->Modules->Attach(eventlist, this, 4);
31         }
32
33         void OnRehash(User* user)
34         {
35                 ConfigReader Conf;
36
37                 sendsnotice = Conf.ReadFlag("waitpong", "sendsnotice", 0);
38
39                 if(Conf.GetError() == CONF_VALUE_NOT_FOUND)
40                         sendsnotice = true;
41
42                 killonbadreply = Conf.ReadFlag("waitpong", "killonbadreply", 0);
43
44                 if(Conf.GetError() == CONF_VALUE_NOT_FOUND)
45                         killonbadreply = true;
46         }
47
48         std::string RandString()
49         {
50                 char out[11];
51                 for(unsigned int i = 0; i < 10; i++)
52                         out[i] = ((rand() % 26) + 65);
53                 out[10] = '\0';
54
55                 return out;
56         }
57
58         ModResult OnUserRegister(User* user)
59         {
60                 std::string pingrpl = RandString();
61
62                 user->Write("PING :%s", pingrpl.c_str());
63
64                 if(sendsnotice)
65                         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());
66
67                 ext.set(user, pingrpl);
68                 return MOD_RES_PASSTHRU;
69         }
70
71         ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, User* user, bool validated, const std::string &original_line)
72         {
73                 if (command == "PONG")
74                 {
75                         std::string* pingrpl = ext.get(user);
76
77                         if (pingrpl)
78                         {
79                                 if (!parameters.empty() && *pingrpl == parameters[0])
80                                 {
81                                         ext.unset(user);
82                                         return MOD_RES_DENY;
83                                 }
84                                 else
85                                 {
86                                         if(killonbadreply)
87                                                 ServerInstance->Users->QuitUser(user, "Incorrect ping reply for registration");
88                                         return MOD_RES_DENY;
89                                 }
90                         }
91                 }
92                 return MOD_RES_PASSTHRU;
93         }
94
95         ModResult OnCheckReady(User* user)
96         {
97                 return ext.get(user) ? MOD_RES_DENY : MOD_RES_PASSTHRU;
98         }
99
100         ~ModuleWaitPong()
101         {
102         }
103
104         Version GetVersion()
105         {
106                 return Version("Require pong prior to registration", VF_VENDOR);
107         }
108
109 };
110
111 MODULE_INIT(ModuleWaitPong)