1 |
adx |
30 |
/* |
2 |
michael |
2820 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
7924 |
* Copyright (c) 1997-2017 ircd-hybrid development team |
5 |
adx |
30 |
* |
6 |
|
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program; if not, write to the Free Software |
18 |
michael |
4565 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
adx |
30 |
* USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
michael |
2820 |
/*! \file m_pong.c |
23 |
|
|
* \brief Includes required functions for processing the PONG command. |
24 |
|
|
* \version $Id$ |
25 |
|
|
*/ |
26 |
|
|
|
27 |
adx |
30 |
#include "stdinc.h" |
28 |
|
|
#include "ircd.h" |
29 |
michael |
3347 |
#include "user.h" |
30 |
adx |
30 |
#include "client.h" |
31 |
michael |
2820 |
#include "hash.h" |
32 |
adx |
30 |
#include "numeric.h" |
33 |
michael |
1309 |
#include "conf.h" |
34 |
adx |
30 |
#include "send.h" |
35 |
|
|
#include "irc_string.h" |
36 |
|
|
#include "parse.h" |
37 |
|
|
#include "modules.h" |
38 |
michael |
4712 |
#include "server.h" |
39 |
adx |
30 |
|
40 |
|
|
|
41 |
michael |
3346 |
/*! \brief PONG command handler |
42 |
|
|
* |
43 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
44 |
|
|
* originally comes from. This can be a local or remote client. |
45 |
|
|
* \param parc Integer holding the number of supplied arguments. |
46 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
47 |
|
|
* pointers. |
48 |
|
|
* \note Valid arguments for this command are: |
49 |
|
|
* - parv[0] = command |
50 |
|
|
* - parv[1] = origin |
51 |
|
|
* - parv[2] = destination |
52 |
|
|
*/ |
53 |
michael |
2820 |
static int |
54 |
michael |
3156 |
ms_pong(struct Client *source_p, int parc, char *parv[]) |
55 |
adx |
30 |
{ |
56 |
michael |
1121 |
if (parc < 2 || EmptyString(parv[1])) |
57 |
adx |
30 |
{ |
58 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOORIGIN); |
59 |
michael |
2820 |
return 0; |
60 |
adx |
30 |
} |
61 |
|
|
|
62 |
michael |
7894 |
const char *const destination = parv[2]; |
63 |
|
|
if (!EmptyString(destination)) |
64 |
adx |
30 |
{ |
65 |
michael |
7894 |
struct Client *target_p; |
66 |
michael |
1169 |
if ((target_p = hash_find_client(destination)) || |
67 |
michael |
4716 |
(target_p = hash_find_id(destination))) |
68 |
michael |
7892 |
{ |
69 |
michael |
7894 |
if (!IsMe(target_p) && target_p->from != source_p->from) |
70 |
michael |
7892 |
sendto_one(target_p, ":%s PONG %s %s", |
71 |
|
|
ID_or_name(source_p, target_p), parv[1], |
72 |
|
|
ID_or_name(target_p, target_p)); |
73 |
|
|
} |
74 |
michael |
4712 |
else if (!IsDigit(*destination)) |
75 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHSERVER, destination); |
76 |
adx |
30 |
} |
77 |
michael |
2820 |
|
78 |
|
|
return 0; |
79 |
adx |
30 |
} |
80 |
|
|
|
81 |
michael |
3346 |
/*! \brief PONG command handler |
82 |
|
|
* |
83 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
84 |
|
|
* originally comes from. This can be a local or remote client. |
85 |
|
|
* \param parc Integer holding the number of supplied arguments. |
86 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
87 |
|
|
* pointers. |
88 |
|
|
* \note Valid arguments for this command are: |
89 |
|
|
* - parv[0] = command |
90 |
|
|
* - parv[1] = origin/ping cookie |
91 |
|
|
*/ |
92 |
michael |
2820 |
static int |
93 |
michael |
3156 |
mr_pong(struct Client *source_p, int parc, char *parv[]) |
94 |
adx |
30 |
{ |
95 |
michael |
3156 |
assert(MyConnect(source_p)); |
96 |
michael |
503 |
|
97 |
michael |
3331 |
if (parc == 2 && !EmptyString(parv[1])) |
98 |
adx |
30 |
{ |
99 |
michael |
4886 |
if (ConfigGeneral.ping_cookie && source_p->connection->random_ping) |
100 |
adx |
30 |
{ |
101 |
michael |
982 |
unsigned int incoming_ping = strtoul(parv[1], NULL, 10); |
102 |
michael |
503 |
|
103 |
michael |
4886 |
if (source_p->connection->random_ping == incoming_ping) |
104 |
michael |
503 |
{ |
105 |
michael |
6313 |
AddFlag(source_p, FLAGS_PING_COOKIE); |
106 |
michael |
4886 |
|
107 |
|
|
if (!source_p->connection->registration) |
108 |
michael |
1080 |
register_local_user(source_p); |
109 |
adx |
30 |
} |
110 |
michael |
4886 |
else |
111 |
|
|
sendto_one_numeric(source_p, &me, ERR_WRONGPONG, |
112 |
|
|
source_p->connection->random_ping); |
113 |
adx |
30 |
} |
114 |
michael |
503 |
} |
115 |
adx |
30 |
else |
116 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOORIGIN); |
117 |
|
|
|
118 |
michael |
2820 |
return 0; |
119 |
adx |
30 |
} |
120 |
michael |
1230 |
|
121 |
michael |
2820 |
static struct Message pong_msgtab = |
122 |
|
|
{ |
123 |
michael |
5881 |
.cmd = "PONG", |
124 |
|
|
.args_max = MAXPARA, |
125 |
|
|
.handlers[UNREGISTERED_HANDLER] = mr_pong, |
126 |
|
|
.handlers[CLIENT_HANDLER] = m_ignore, |
127 |
|
|
.handlers[SERVER_HANDLER] = ms_pong, |
128 |
|
|
.handlers[ENCAP_HANDLER] = m_ignore, |
129 |
|
|
.handlers[OPER_HANDLER] = m_ignore |
130 |
michael |
1230 |
}; |
131 |
|
|
|
132 |
|
|
static void |
133 |
|
|
module_init(void) |
134 |
|
|
{ |
135 |
|
|
mod_add_cmd(&pong_msgtab); |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
static void |
139 |
|
|
module_exit(void) |
140 |
|
|
{ |
141 |
|
|
mod_del_cmd(&pong_msgtab); |
142 |
|
|
} |
143 |
|
|
|
144 |
michael |
2820 |
struct module module_entry = |
145 |
|
|
{ |
146 |
michael |
1230 |
.version = "$Revision$", |
147 |
|
|
.modinit = module_init, |
148 |
|
|
.modexit = module_exit, |
149 |
|
|
}; |