]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_pong.c
Forgot version.c.SH for libratbox/.
[irc/rqf/shadowircd.git] / modules / m_pong.c
CommitLineData
212380e3 1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_pong.c: The reply to a ping message.
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 *
e26e2b19 24 * $Id: m_pong.c 3181 2007-02-01 00:49:07Z jilles $
212380e3 25 */
26
27#include "stdinc.h"
28#include "ircd.h"
29#include "s_user.h"
30#include "client.h"
31#include "hash.h" /* for find_client() */
32#include "hook.h"
33#include "numeric.h"
34#include "s_conf.h"
35#include "send.h"
36#include "channel.h"
13ae2f4b 37#include "match.h"
212380e3 38#include "msg.h"
39#include "parse.h"
40#include "hash.h"
41#include "modules.h"
42
43static int mr_pong(struct Client *, struct Client *, int, const char **);
44static int ms_pong(struct Client *, struct Client *, int, const char **);
45
46struct Message pong_msgtab = {
47 "PONG", 0, 0, 0, MFLG_SLOW | MFLG_UNREG,
48 {{mr_pong, 0}, mg_ignore, mg_ignore, {ms_pong, 2}, mg_ignore, mg_ignore}
49};
50
51mapi_clist_av1 pong_clist[] = { &pong_msgtab, NULL };
e26e2b19 52DECLARE_MODULE_AV1(pong, NULL, NULL, pong_clist, NULL, NULL, "$Revision: 3181 $");
212380e3 53
54static int
55ms_pong(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
56{
57 struct Client *target_p;
58 const char *destination;
59
60 destination = parv[2];
61 source_p->flags &= ~FLAGS_PINGSENT;
62
63 /* Now attempt to route the PONG, comstud pointed out routable PING
64 * is used for SPING. routable PING should also probably be left in
65 * -Dianora
66 * That being the case, we will route, but only for registered clients (a
67 * case can be made to allow them only from servers). -Shadowfax
68 */
69 if(!EmptyString(destination) && !match(destination, me.name) &&
70 irccmp(destination, me.id))
71 {
e26e2b19 72 if((target_p = find_client(destination)))
212380e3 73 sendto_one(target_p, ":%s PONG %s %s",
74 get_id(source_p, target_p), parv[1],
75 get_id(target_p, target_p));
76 else
77 {
78 if(!IsDigit(*destination))
79 sendto_one_numeric(source_p, ERR_NOSUCHSERVER,
80 form_str(ERR_NOSUCHSERVER), destination);
81 return 0;
82 }
83 }
84
85 /* destination is us, emulate EOB */
86 if(IsServer(source_p) && !HasSentEob(source_p))
87 {
88 if(MyConnect(source_p))
89 sendto_realops_snomask(SNO_GENERAL, L_ALL,
90 "End of burst (emulated) from %s (%d seconds)",
91 source_p->name,
9f6bbe3c 92 (signed int) (rb_current_time() - source_p->localClient->firsttime));
212380e3 93 SetEob(source_p);
94 eob_count++;
95 call_hook(h_server_eob, source_p);
96 }
97
98 return 0;
99}
100
101static int
102mr_pong(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
103{
104 if(parc == 2 && !EmptyString(parv[1]))
105 {
106 if(ConfigFileEntry.ping_cookie && source_p->user && source_p->name[0])
107 {
108 unsigned long incoming_ping = strtoul(parv[1], NULL, 16);
109 if(incoming_ping)
110 {
111 if(source_p->localClient->random_ping == incoming_ping)
112 {
113 char buf[USERLEN + 1];
907468c4 114 rb_strlcpy(buf, source_p->username, sizeof(buf));
2d2c402d 115 source_p->flags |= FLAGS_PING_COOKIE;
212380e3 116 register_local_user(client_p, source_p, buf);
117 }
118 else
119 {
120 sendto_one(source_p, form_str(ERR_WRONGPONG),
121 me.name, source_p->name,
122 source_p->localClient->random_ping);
123 return 0;
124 }
125 }
126 }
127
128 }
129 else
130 sendto_one(source_p, form_str(ERR_NOORIGIN), me.name, parv[0]);
131
132 source_p->flags &= ~FLAGS_PINGSENT;
133
134 return 0;
135}