1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 1997-2014 ircd-hybrid development team |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 |
* USA |
20 |
*/ |
21 |
|
22 |
/*! \file m_ping.c |
23 |
* \brief Includes required functions for processing the PING command. |
24 |
* \version $Id$ |
25 |
*/ |
26 |
|
27 |
#include "stdinc.h" |
28 |
#include "client.h" |
29 |
#include "ircd.h" |
30 |
#include "numeric.h" |
31 |
#include "send.h" |
32 |
#include "irc_string.h" |
33 |
#include "parse.h" |
34 |
#include "modules.h" |
35 |
#include "hash.h" |
36 |
#include "conf.h" |
37 |
#include "s_serv.h" |
38 |
|
39 |
|
40 |
/* |
41 |
** m_ping |
42 |
** parv[0] = command |
43 |
** parv[1] = origin |
44 |
** parv[2] = destination |
45 |
*/ |
46 |
static int |
47 |
m_ping(struct Client *source_p, int parc, char *parv[]) |
48 |
{ |
49 |
struct Client *target_p; |
50 |
char *origin, *destination; |
51 |
|
52 |
if (parc < 2 || EmptyString(parv[1])) |
53 |
{ |
54 |
sendto_one_numeric(source_p, &me, ERR_NOORIGIN); |
55 |
return 0; |
56 |
} |
57 |
|
58 |
origin = parv[1]; |
59 |
destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */ |
60 |
|
61 |
if (ConfigServerHide.disable_remote_commands && !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 0; |
66 |
} |
67 |
|
68 |
if (!EmptyString(destination) && irccmp(destination, me.name) != 0) |
69 |
{ |
70 |
/* We're sending it across servers.. origin == source_p->name --fl_ */ |
71 |
origin = source_p->name; |
72 |
|
73 |
if ((target_p = hash_find_server(destination))) |
74 |
sendto_one(target_p, ":%s PING %s :%s", source_p->name, |
75 |
origin, destination); |
76 |
else |
77 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHSERVER, destination); |
78 |
} |
79 |
else |
80 |
sendto_one(source_p, ":%s PONG %s :%s", me.name, |
81 |
(destination) ? destination : me.name, origin); |
82 |
return 0; |
83 |
} |
84 |
|
85 |
static int |
86 |
ms_ping(struct Client *source_p, int parc, char *parv[]) |
87 |
{ |
88 |
struct Client *target_p; |
89 |
const char *origin, *destination; |
90 |
|
91 |
if (parc < 2 || EmptyString(parv[1])) |
92 |
{ |
93 |
sendto_one_numeric(source_p, &me, ERR_NOORIGIN); |
94 |
return 0; |
95 |
} |
96 |
|
97 |
origin = source_p->name; |
98 |
destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */ |
99 |
|
100 |
if (!EmptyString(destination) && irccmp(destination, me.name) != 0 && irccmp(destination, me.id) != 0) |
101 |
{ |
102 |
if ((target_p = hash_find_server(destination))) |
103 |
sendto_one(target_p, ":%s PING %s :%s", source_p->name, |
104 |
origin, destination); |
105 |
else |
106 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHSERVER, destination); |
107 |
} |
108 |
else |
109 |
sendto_one(source_p, ":%s PONG %s :%s", ID_or_name(&me, source_p), |
110 |
(destination) ? destination : me.name, origin); |
111 |
return 0; |
112 |
} |
113 |
|
114 |
static struct Message ping_msgtab = |
115 |
{ |
116 |
"PING", 0, 0, 1, MAXPARA, MFLG_SLOW, 0, |
117 |
{ m_unregistered, m_ping, ms_ping, m_ignore, m_ping, m_ping } |
118 |
}; |
119 |
|
120 |
static void |
121 |
module_init(void) |
122 |
{ |
123 |
mod_add_cmd(&ping_msgtab); |
124 |
} |
125 |
|
126 |
static void |
127 |
module_exit(void) |
128 |
{ |
129 |
mod_del_cmd(&ping_msgtab); |
130 |
} |
131 |
|
132 |
struct module module_entry = { |
133 |
.node = { NULL, NULL, NULL }, |
134 |
.name = NULL, |
135 |
.version = "$Revision$", |
136 |
.handle = NULL, |
137 |
.modinit = module_init, |
138 |
.modexit = module_exit, |
139 |
.flags = 0 |
140 |
}; |