1 |
/* |
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 |
* $Id$ |
23 |
*/ |
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 |
|
40 |
/* |
41 |
** m_ping |
42 |
** parv[0] = sender prefix |
43 |
** parv[1] = origin |
44 |
** parv[2] = destination |
45 |
*/ |
46 |
static void |
47 |
m_ping(struct Client *client_p, struct Client *source_p, |
48 |
int parc, char *parv[]) |
49 |
{ |
50 |
struct Client *target_p; |
51 |
char *origin, *destination; |
52 |
|
53 |
if (parc < 2 || EmptyString(parv[1])) |
54 |
{ |
55 |
sendto_one(source_p, form_str(ERR_NOORIGIN), |
56 |
me.name, source_p->name); |
57 |
return; |
58 |
} |
59 |
|
60 |
origin = parv[1]; |
61 |
destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */ |
62 |
|
63 |
if (ConfigFileEntry.disable_remote && !HasUMode(source_p, UMODE_OPER)) |
64 |
{ |
65 |
sendto_one(source_p, ":%s PONG %s :%s", me.name, |
66 |
(destination) ? destination : me.name, origin); |
67 |
return; |
68 |
} |
69 |
|
70 |
if (!EmptyString(destination) && irccmp(destination, me.name) != 0) |
71 |
{ |
72 |
/* We're sending it across servers.. origin == client_p->name --fl_ */ |
73 |
origin = client_p->name; |
74 |
|
75 |
if ((target_p = hash_find_server(destination)) != NULL) |
76 |
{ |
77 |
sendto_one(target_p, ":%s PING %s :%s", source_p->name, |
78 |
origin, destination); |
79 |
} |
80 |
else |
81 |
{ |
82 |
sendto_one(source_p, form_str(ERR_NOSUCHSERVER), |
83 |
me.name, source_p->name, destination); |
84 |
return; |
85 |
} |
86 |
} |
87 |
else |
88 |
sendto_one(source_p, ":%s PONG %s :%s", me.name, |
89 |
(destination) ? destination : me.name, origin); |
90 |
} |
91 |
|
92 |
static void |
93 |
ms_ping(struct Client *client_p, struct Client *source_p, |
94 |
int parc, char *parv[]) |
95 |
{ |
96 |
struct Client *target_p; |
97 |
const char *origin, *destination; |
98 |
|
99 |
if (parc < 2 || EmptyString(parv[1])) |
100 |
{ |
101 |
sendto_one(source_p, form_str(ERR_NOORIGIN), |
102 |
me.name, source_p->name); |
103 |
return; |
104 |
} |
105 |
|
106 |
origin = source_p->name; |
107 |
destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */ |
108 |
|
109 |
if (!EmptyString(destination) && irccmp(destination, me.name) != 0 && irccmp(destination, me.id) != 0) |
110 |
{ |
111 |
if ((target_p = hash_find_server(destination))) |
112 |
sendto_one(target_p, ":%s PING %s :%s", source_p->name, |
113 |
origin, destination); |
114 |
else |
115 |
{ |
116 |
sendto_one(source_p, form_str(ERR_NOSUCHSERVER), |
117 |
ID_or_name(&me, client_p), source_p->name, destination); |
118 |
return; |
119 |
} |
120 |
} |
121 |
else |
122 |
sendto_one(source_p, ":%s PONG %s :%s", |
123 |
ID_or_name(&me, client_p), (destination) ? destination : me.name, origin); |
124 |
} |
125 |
|
126 |
static struct Message ping_msgtab = { |
127 |
"PING", 0, 0, 1, MAXPARA, MFLG_SLOW, 0, |
128 |
{m_unregistered, m_ping, ms_ping, m_ignore, m_ping, m_ping} |
129 |
}; |
130 |
|
131 |
static void |
132 |
module_init(void) |
133 |
{ |
134 |
mod_add_cmd(&ping_msgtab); |
135 |
} |
136 |
|
137 |
static void |
138 |
module_exit(void) |
139 |
{ |
140 |
mod_del_cmd(&ping_msgtab); |
141 |
} |
142 |
|
143 |
struct module module_entry = { |
144 |
.node = { NULL, NULL, NULL }, |
145 |
.name = NULL, |
146 |
.version = "$Revision$", |
147 |
.handle = NULL, |
148 |
.modinit = module_init, |
149 |
.modexit = module_exit, |
150 |
.flags = 0 |
151 |
}; |