]> jfr.im git - solanum.git/blame - modules/m_ping.c
extensions: add AV2 description strings to a few modules
[solanum.git] / modules / m_ping.c
CommitLineData
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
212380e3
AC
23 */
24
25#include "stdinc.h"
26#include "client.h"
27#include "ircd.h"
28#include "numeric.h"
29#include "send.h"
4562c604 30#include "match.h"
212380e3
AC
31#include "msg.h"
32#include "parse.h"
33#include "modules.h"
34#include "hash.h"
35#include "s_conf.h"
36#include "s_serv.h"
37
428ca87b
AC
38static int m_ping(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
39static int ms_ping(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
212380e3
AC
40
41struct Message ping_msgtab = {
7baa37a9 42 "PING", 0, 0, 0, 0,
212380e3
AC
43 {mg_unreg, {m_ping, 2}, {ms_ping, 2}, {ms_ping, 2}, mg_ignore, {m_ping, 2}}
44};
45
46mapi_clist_av1 ping_clist[] = { &ping_msgtab, NULL };
105a4985 47DECLARE_MODULE_AV2(ping, NULL, NULL, ping_clist, NULL, NULL, NULL, NULL, NULL);
212380e3
AC
48
49/*
50** m_ping
212380e3
AC
51** parv[1] = origin
52** parv[2] = destination
53*/
54static int
428ca87b 55m_ping(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
56{
57 struct Client *target_p;
58 const char *destination;
59
60 destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */
61
62 if(!EmptyString(destination) && !match(destination, me.name))
63 {
64 if((target_p = find_server(source_p, destination)))
65 {
66 sendto_one(target_p, ":%s PING %s :%s",
67 get_id(source_p, target_p),
68 source_p->name, get_id(target_p, target_p));
69 }
70 else
71 {
72 sendto_one_numeric(source_p, ERR_NOSUCHSERVER,
73 form_str(ERR_NOSUCHSERVER),
74 destination);
75 return 0;
76 }
77 }
78 else
79 sendto_one(source_p, ":%s PONG %s :%s", me.name,
80 (destination) ? destination : me.name, parv[1]);
81
82 return 0;
83}
84
85static int
428ca87b 86ms_ping(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
87{
88 struct Client *target_p;
89 const char *destination;
90
91 destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */
92
93 if(!EmptyString(destination) && irccmp(destination, me.name) &&
94 irccmp(destination, me.id))
95 {
96 if((target_p = find_client(destination)) && IsServer(target_p))
55abcbb2 97 sendto_one(target_p, ":%s PING %s :%s",
212380e3
AC
98 get_id(source_p, target_p), source_p->name,
99 get_id(target_p, target_p));
100 /* not directed at an id.. */
101 else if(!IsDigit(*destination))
102 sendto_one_numeric(source_p, ERR_NOSUCHSERVER,
103 form_str(ERR_NOSUCHSERVER),
104 destination);
105 }
106 else
55abcbb2
KB
107 sendto_one(source_p, ":%s PONG %s :%s",
108 get_id(&me, source_p), me.name,
212380e3
AC
109 get_id(source_p, source_p));
110
111 return 0;
112}