1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* m_pong.c: The reply to a ping message. |
4 |
* |
5 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
11 |
* |
12 |
* This program is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
21 |
* |
22 |
* $Id$ |
23 |
*/ |
24 |
|
25 |
#include "stdinc.h" |
26 |
#include "ircd.h" |
27 |
#include "s_user.h" |
28 |
#include "client.h" |
29 |
#include "hash.h" /* for find_client() */ |
30 |
#include "numeric.h" |
31 |
#include "conf.h" |
32 |
#include "send.h" |
33 |
#include "irc_string.h" |
34 |
#include "parse.h" |
35 |
#include "modules.h" |
36 |
|
37 |
|
38 |
static void |
39 |
ms_pong(struct Client *client_p, struct Client *source_p, |
40 |
int parc, char *parv[]) |
41 |
{ |
42 |
struct Client *target_p; |
43 |
const char *origin, *destination; |
44 |
|
45 |
if (parc < 2 || EmptyString(parv[1])) |
46 |
{ |
47 |
sendto_one(source_p, form_str(ERR_NOORIGIN), |
48 |
me.name, source_p->name); |
49 |
return; |
50 |
} |
51 |
|
52 |
origin = parv[1]; |
53 |
destination = parv[2]; |
54 |
|
55 |
/* Now attempt to route the PONG, comstud pointed out routable PING |
56 |
* is used for SPING. routable PING should also probably be left in |
57 |
* -Dianora |
58 |
* That being the case, we will route, but only for registered clients (a |
59 |
* case can be made to allow them only from servers). -Shadowfax |
60 |
*/ |
61 |
if (!EmptyString(destination) && !match(destination, me.name) && |
62 |
irccmp(destination, me.id)) |
63 |
{ |
64 |
if ((target_p = hash_find_client(destination)) || |
65 |
(target_p = hash_find_server(destination))) |
66 |
sendto_one(target_p, ":%s PONG %s %s", |
67 |
source_p->name, origin, destination); |
68 |
else |
69 |
{ |
70 |
sendto_one(source_p, form_str(ERR_NOSUCHSERVER), |
71 |
me.name, source_p->name, destination); |
72 |
return; |
73 |
} |
74 |
} |
75 |
} |
76 |
|
77 |
static void |
78 |
mr_pong(struct Client *client_p, struct Client *source_p, |
79 |
int parc, char *parv[]) |
80 |
{ |
81 |
assert(source_p == client_p); |
82 |
|
83 |
if (parc == 2 && *parv[1] != '\0') |
84 |
{ |
85 |
if (ConfigFileEntry.ping_cookie && !source_p->localClient->registration) |
86 |
{ |
87 |
unsigned int incoming_ping = strtoul(parv[1], NULL, 10); |
88 |
|
89 |
if (incoming_ping) |
90 |
{ |
91 |
if (source_p->localClient->random_ping == incoming_ping) |
92 |
{ |
93 |
SetPingCookie(source_p); |
94 |
register_local_user(source_p); |
95 |
} |
96 |
else |
97 |
{ |
98 |
sendto_one(source_p, form_str(ERR_WRONGPONG), me.name, |
99 |
source_p->name, source_p->localClient->random_ping); |
100 |
return; |
101 |
} |
102 |
} |
103 |
} |
104 |
} |
105 |
else |
106 |
sendto_one(source_p, form_str(ERR_NOORIGIN), |
107 |
me.name, source_p->name); |
108 |
} |
109 |
|
110 |
static struct Message pong_msgtab = { |
111 |
"PONG", 0, 0, 1, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0, |
112 |
{mr_pong, m_ignore, ms_pong, m_ignore, m_ignore, m_ignore} |
113 |
}; |
114 |
|
115 |
static void |
116 |
module_init(void) |
117 |
{ |
118 |
mod_add_cmd(&pong_msgtab); |
119 |
} |
120 |
|
121 |
static void |
122 |
module_exit(void) |
123 |
{ |
124 |
mod_del_cmd(&pong_msgtab); |
125 |
} |
126 |
|
127 |
struct module module_entry = { |
128 |
.node = { NULL, NULL, NULL }, |
129 |
.name = NULL, |
130 |
.version = "$Revision$", |
131 |
.handle = NULL, |
132 |
.modinit = module_init, |
133 |
.modexit = module_exit, |
134 |
.flags = 0 |
135 |
}; |