1 |
adx |
30 |
/* |
2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
|
|
* m_ping.c: Requests that a PONG message be sent back. |
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 |
knight |
31 |
* $Id$ |
23 |
adx |
30 |
*/ |
24 |
|
|
|
25 |
|
|
#include "stdinc.h" |
26 |
|
|
#include "handlers.h" |
27 |
|
|
#include "client.h" |
28 |
|
|
#include "ircd.h" |
29 |
|
|
#include "numeric.h" |
30 |
|
|
#include "send.h" |
31 |
|
|
#include "irc_string.h" |
32 |
|
|
#include "msg.h" |
33 |
|
|
#include "parse.h" |
34 |
|
|
#include "modules.h" |
35 |
|
|
#include "hash.h" |
36 |
|
|
#include "s_conf.h" |
37 |
|
|
#include "s_serv.h" |
38 |
|
|
|
39 |
michael |
1121 |
static void m_ping(struct Client *, struct Client *, int, char *[]); |
40 |
|
|
static void ms_ping(struct Client *, struct Client *, int, char *[]); |
41 |
adx |
30 |
|
42 |
|
|
struct Message ping_msgtab = { |
43 |
|
|
"PING", 0, 0, 1, 0, MFLG_SLOW, 0, |
44 |
|
|
{m_unregistered, m_ping, ms_ping, m_ignore, m_ping, m_ping} |
45 |
|
|
}; |
46 |
|
|
|
47 |
|
|
void |
48 |
|
|
_modinit(void) |
49 |
|
|
{ |
50 |
|
|
mod_add_cmd(&ping_msgtab); |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
void |
54 |
|
|
_moddeinit(void) |
55 |
|
|
{ |
56 |
|
|
mod_del_cmd(&ping_msgtab); |
57 |
|
|
} |
58 |
|
|
|
59 |
knight |
31 |
const char *_version = "$Revision$"; |
60 |
adx |
30 |
|
61 |
|
|
/* |
62 |
|
|
** m_ping |
63 |
|
|
** parv[0] = sender prefix |
64 |
|
|
** parv[1] = origin |
65 |
|
|
** parv[2] = destination |
66 |
|
|
*/ |
67 |
|
|
static void |
68 |
|
|
m_ping(struct Client *client_p, struct Client *source_p, |
69 |
|
|
int parc, char *parv[]) |
70 |
|
|
{ |
71 |
|
|
struct Client *target_p; |
72 |
|
|
char *origin, *destination; |
73 |
|
|
|
74 |
michael |
1121 |
if (parc < 2 || EmptyString(parv[1])) |
75 |
adx |
30 |
{ |
76 |
|
|
sendto_one(source_p, form_str(ERR_NOORIGIN), me.name, parv[0]); |
77 |
|
|
return; |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
origin = parv[1]; |
81 |
|
|
destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */ |
82 |
|
|
|
83 |
|
|
if (ConfigFileEntry.disable_remote && !IsOper(source_p)) |
84 |
|
|
{ |
85 |
|
|
sendto_one(source_p,":%s PONG %s :%s", me.name, |
86 |
|
|
(destination) ? destination : me.name, origin); |
87 |
|
|
return; |
88 |
|
|
} |
89 |
|
|
|
90 |
|
|
if (!EmptyString(destination) && irccmp(destination, me.name) != 0) |
91 |
|
|
{ |
92 |
|
|
/* We're sending it across servers.. origin == client_p->name --fl_ */ |
93 |
|
|
origin = client_p->name; |
94 |
|
|
|
95 |
michael |
1169 |
if ((target_p = hash_find_server(destination)) != NULL) |
96 |
adx |
30 |
{ |
97 |
|
|
sendto_one(target_p,":%s PING %s :%s", parv[0], |
98 |
|
|
origin, destination); |
99 |
|
|
} |
100 |
|
|
else |
101 |
|
|
{ |
102 |
|
|
sendto_one(source_p, form_str(ERR_NOSUCHSERVER), |
103 |
|
|
me.name, parv[0], destination); |
104 |
|
|
return; |
105 |
|
|
} |
106 |
|
|
} |
107 |
|
|
else |
108 |
|
|
sendto_one(source_p,":%s PONG %s :%s", me.name, |
109 |
|
|
(destination) ? destination : me.name, origin); |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
static void |
113 |
|
|
ms_ping(struct Client *client_p, struct Client *source_p, |
114 |
|
|
int parc, char *parv[]) |
115 |
|
|
{ |
116 |
|
|
struct Client *target_p; |
117 |
|
|
const char *origin, *destination; |
118 |
|
|
|
119 |
michael |
1121 |
if (parc < 2 || EmptyString(parv[1])) |
120 |
adx |
30 |
{ |
121 |
|
|
sendto_one(source_p, form_str(ERR_NOORIGIN), me.name, parv[0]); |
122 |
|
|
return; |
123 |
|
|
} |
124 |
|
|
|
125 |
|
|
origin = source_p->name; |
126 |
|
|
destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */ |
127 |
|
|
|
128 |
|
|
if (!EmptyString(destination) && irccmp(destination, me.name) != 0 && irccmp(destination, me.id) != 0) |
129 |
|
|
{ |
130 |
michael |
1169 |
if ((target_p = hash_find_server(destination))) |
131 |
adx |
30 |
sendto_one(target_p,":%s PING %s :%s", parv[0], |
132 |
|
|
origin, destination); |
133 |
|
|
else |
134 |
|
|
{ |
135 |
|
|
sendto_one(source_p, form_str(ERR_NOSUCHSERVER), |
136 |
|
|
ID_or_name(&me, client_p), parv[0], destination); |
137 |
|
|
return; |
138 |
|
|
} |
139 |
|
|
} |
140 |
|
|
else |
141 |
|
|
sendto_one(source_p,":%s PONG %s :%s", |
142 |
|
|
ID_or_name(&me, client_p), (destination) ? destination : me.name, origin); |
143 |
|
|
} |