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 "list.h" |
27 |
#include "ircd.h" |
28 |
#include "handlers.h" |
29 |
#include "s_user.h" |
30 |
#include "client.h" |
31 |
#include "hash.h" /* for find_client() */ |
32 |
#include "numeric.h" |
33 |
#include "s_conf.h" |
34 |
#include "send.h" |
35 |
#include "irc_string.h" |
36 |
#include "msg.h" |
37 |
#include "parse.h" |
38 |
#include "modules.h" |
39 |
|
40 |
static void mr_pong(struct Client *, struct Client *, int, char **); |
41 |
static void ms_pong(struct Client *, struct Client *, int, char **); |
42 |
|
43 |
struct Message pong_msgtab = { |
44 |
"PONG", 0, 0, 1, 0, MFLG_SLOW | MFLG_UNREG, 0, |
45 |
{mr_pong, m_ignore, ms_pong, m_ignore, m_ignore, m_ignore} |
46 |
}; |
47 |
|
48 |
#ifndef STATIC_MODULES |
49 |
void |
50 |
_modinit(void) |
51 |
{ |
52 |
mod_add_cmd(&pong_msgtab); |
53 |
} |
54 |
|
55 |
void |
56 |
_moddeinit(void) |
57 |
{ |
58 |
mod_del_cmd(&pong_msgtab); |
59 |
} |
60 |
|
61 |
const char *_version = "$Revision$"; |
62 |
#endif |
63 |
|
64 |
static void |
65 |
ms_pong(struct Client *client_p, struct Client *source_p, |
66 |
int parc, char *parv[]) |
67 |
{ |
68 |
struct Client *target_p; |
69 |
const char *origin, *destination; |
70 |
|
71 |
if (parc < 2 || *parv[1] == '\0') |
72 |
{ |
73 |
sendto_one(source_p, form_str(ERR_NOORIGIN), |
74 |
me.name, parv[0]); |
75 |
return; |
76 |
} |
77 |
|
78 |
origin = parv[1]; |
79 |
destination = parv[2]; |
80 |
|
81 |
/* Now attempt to route the PONG, comstud pointed out routable PING |
82 |
* is used for SPING. routable PING should also probably be left in |
83 |
* -Dianora |
84 |
* That being the case, we will route, but only for registered clients (a |
85 |
* case can be made to allow them only from servers). -Shadowfax |
86 |
*/ |
87 |
if (!EmptyString(destination) && !match(destination, me.name) && |
88 |
irccmp(destination, me.id)) |
89 |
{ |
90 |
if ((target_p = find_client(destination)) || |
91 |
(target_p = find_server(destination))) |
92 |
sendto_one(target_p,":%s PONG %s %s", |
93 |
parv[0], origin, destination); |
94 |
else |
95 |
{ |
96 |
sendto_one(source_p, form_str(ERR_NOSUCHSERVER), |
97 |
me.name, parv[0], destination); |
98 |
return; |
99 |
} |
100 |
} |
101 |
} |
102 |
|
103 |
static void |
104 |
mr_pong(struct Client *client_p, struct Client *source_p, |
105 |
int parc, char *parv[]) |
106 |
{ |
107 |
assert(source_p == client_p); |
108 |
|
109 |
if (parc == 2 && *parv[1] != '\0') |
110 |
{ |
111 |
if (ConfigFileEntry.ping_cookie && !source_p->localClient->registration) |
112 |
{ |
113 |
unsigned int incoming_ping = strtoul(parv[1], NULL, 10); |
114 |
|
115 |
if (incoming_ping) |
116 |
{ |
117 |
if (source_p->localClient->random_ping == incoming_ping) |
118 |
{ |
119 |
SetPingCookie(source_p); |
120 |
register_local_user(source_p); |
121 |
} |
122 |
else |
123 |
{ |
124 |
sendto_one(source_p, form_str(ERR_WRONGPONG), me.name, |
125 |
source_p->name, source_p->localClient->random_ping); |
126 |
return; |
127 |
} |
128 |
} |
129 |
} |
130 |
} |
131 |
else |
132 |
sendto_one(source_p, form_str(ERR_NOORIGIN), me.name, parv[0]); |
133 |
} |
134 |
|