]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * m_ping.c: Requests that a PONG message be sent back. | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
22 | * USA | |
23 | * | |
24 | * $Id: m_ping.c 254 2005-09-21 23:35:12Z nenolod $ | |
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 "msg.h" | |
34 | #include "parse.h" | |
35 | #include "modules.h" | |
36 | #include "hash.h" | |
37 | #include "s_conf.h" | |
38 | #include "s_serv.h" | |
39 | ||
40 | static int m_ping(struct Client *, struct Client *, int, const char **); | |
41 | static int ms_ping(struct Client *, struct Client *, int, const char **); | |
42 | ||
43 | struct Message ping_msgtab = { | |
44 | "PING", 0, 0, 0, MFLG_SLOW, | |
45 | {mg_unreg, {m_ping, 2}, {ms_ping, 2}, {ms_ping, 2}, mg_ignore, {m_ping, 2}} | |
46 | }; | |
47 | ||
48 | mapi_clist_av1 ping_clist[] = { &ping_msgtab, NULL }; | |
49 | DECLARE_MODULE_AV1(ping, NULL, NULL, ping_clist, NULL, NULL, "$Revision: 254 $"); | |
50 | ||
51 | /* | |
52 | ** m_ping | |
53 | ** parv[0] = sender prefix | |
54 | ** parv[1] = origin | |
55 | ** parv[2] = destination | |
56 | */ | |
57 | static int | |
58 | m_ping(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
59 | { | |
60 | struct Client *target_p; | |
61 | const char *destination; | |
62 | ||
63 | destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */ | |
64 | ||
65 | if(!EmptyString(destination) && !match(destination, me.name)) | |
66 | { | |
67 | if((target_p = find_server(source_p, destination))) | |
68 | { | |
69 | sendto_one(target_p, ":%s PING %s :%s", | |
70 | get_id(source_p, target_p), | |
71 | source_p->name, get_id(target_p, target_p)); | |
72 | } | |
73 | else | |
74 | { | |
75 | sendto_one_numeric(source_p, ERR_NOSUCHSERVER, | |
76 | form_str(ERR_NOSUCHSERVER), | |
77 | destination); | |
78 | return 0; | |
79 | } | |
80 | } | |
81 | else | |
82 | sendto_one(source_p, ":%s PONG %s :%s", me.name, | |
83 | (destination) ? destination : me.name, parv[1]); | |
84 | ||
85 | return 0; | |
86 | } | |
87 | ||
88 | static int | |
89 | ms_ping(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
90 | { | |
91 | struct Client *target_p; | |
92 | const char *destination; | |
93 | ||
94 | destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */ | |
95 | ||
96 | if(!EmptyString(destination) && irccmp(destination, me.name) && | |
97 | irccmp(destination, me.id)) | |
98 | { | |
99 | if((target_p = find_client(destination)) && IsServer(target_p)) | |
100 | sendto_one(target_p, ":%s PING %s :%s", | |
101 | get_id(source_p, target_p), source_p->name, | |
102 | get_id(target_p, target_p)); | |
103 | /* not directed at an id.. */ | |
104 | else if(!IsDigit(*destination)) | |
105 | sendto_one_numeric(source_p, ERR_NOSUCHSERVER, | |
106 | form_str(ERR_NOSUCHSERVER), | |
107 | destination); | |
108 | } | |
109 | else | |
110 | sendto_one(source_p, ":%s PONG %s :%s", | |
111 | get_id(&me, source_p), me.name, | |
112 | get_id(source_p, source_p)); | |
113 | ||
114 | return 0; | |
115 | } |