]> jfr.im git - solanum.git/blame - modules/m_ping.c
client: refactor del_all_accepts to allow skipping own accept list
[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
d5d35409
AW
38static const char ping_desc[] =
39 "Provides the PING command to ensure a client or server is still alive";
212380e3 40
3c7d6fcc
EM
41static void m_ping(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
42static void ms_ping(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
eeabf33a 43
212380e3 44struct Message ping_msgtab = {
7baa37a9 45 "PING", 0, 0, 0, 0,
212380e3
AC
46 {mg_unreg, {m_ping, 2}, {ms_ping, 2}, {ms_ping, 2}, mg_ignore, {m_ping, 2}}
47};
48
49mapi_clist_av1 ping_clist[] = { &ping_msgtab, NULL };
eeabf33a 50
d5d35409 51DECLARE_MODULE_AV2(ping, NULL, NULL, ping_clist, NULL, NULL, NULL, NULL, ping_desc);
212380e3
AC
52
53/*
54** m_ping
212380e3
AC
55** parv[1] = origin
56** parv[2] = destination
57*/
3c7d6fcc 58static void
428ca87b 59m_ping(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
60{
61 struct Client *target_p;
62 const char *destination;
63
64 destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */
65
66 if(!EmptyString(destination) && !match(destination, me.name))
67 {
68 if((target_p = find_server(source_p, destination)))
69 {
70 sendto_one(target_p, ":%s PING %s :%s",
71 get_id(source_p, target_p),
72 source_p->name, get_id(target_p, target_p));
73 }
74 else
75 {
76 sendto_one_numeric(source_p, ERR_NOSUCHSERVER,
77 form_str(ERR_NOSUCHSERVER),
78 destination);
3c7d6fcc 79 return;
212380e3
AC
80 }
81 }
82 else
83 sendto_one(source_p, ":%s PONG %s :%s", me.name,
84 (destination) ? destination : me.name, parv[1]);
212380e3
AC
85}
86
3c7d6fcc 87static void
428ca87b 88ms_ping(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
89{
90 struct Client *target_p;
91 const char *destination;
92
93 destination = parv[2]; /* Will get NULL or pointer (parc >= 2!!) */
94
95 if(!EmptyString(destination) && irccmp(destination, me.name) &&
96 irccmp(destination, me.id))
97 {
98 if((target_p = find_client(destination)) && IsServer(target_p))
55abcbb2 99 sendto_one(target_p, ":%s PING %s :%s",
212380e3
AC
100 get_id(source_p, target_p), source_p->name,
101 get_id(target_p, target_p));
102 /* not directed at an id.. */
103 else if(!IsDigit(*destination))
104 sendto_one_numeric(source_p, ERR_NOSUCHSERVER,
105 form_str(ERR_NOSUCHSERVER),
106 destination);
107 }
108 else
55abcbb2
KB
109 sendto_one(source_p, ":%s PONG %s :%s",
110 get_id(&me, source_p), me.name,
212380e3 111 get_id(source_p, source_p));
212380e3 112}