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