2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: A slightly useful ircd.
|
|
|
|
* m_pong.c: The reply to a ping message.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
|
|
|
* Copyright (C) 1996-2002 Hybrid Development Team
|
|
|
|
* Copyright (C) 2002-2005 ircd-ratbox development team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*/
|
|
|
|
|
2016-08-13 05:05:54 +02:00
|
|
|
using namespace ircd;
|
|
|
|
|
2016-03-09 08:29:41 +01:00
|
|
|
static const char pong_desc[] = "Provides the PONG command to respond to a PING message";
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
static void mr_pong(struct MsgBuf *, client::client &, client::client &, int, const char **);
|
|
|
|
static void ms_pong(struct MsgBuf *, client::client &, client::client &, int, const char **);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
struct Message pong_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"PONG", 0, 0, 0, 0,
|
2007-01-25 07:40:21 +01:00
|
|
|
{{mr_pong, 0}, mg_ignore, mg_ignore, {ms_pong, 2}, mg_ignore, mg_ignore}
|
|
|
|
};
|
|
|
|
|
|
|
|
mapi_clist_av1 pong_clist[] = { &pong_msgtab, NULL };
|
2016-03-09 08:29:41 +01:00
|
|
|
|
2016-03-07 08:47:40 +01:00
|
|
|
DECLARE_MODULE_AV2(pong, NULL, NULL, pong_clist, NULL, NULL, NULL, NULL, pong_desc);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-08-23 02:37:07 +02:00
|
|
|
ms_pong(struct MsgBuf *msgbuf_p, client::client &client, client::client &source, int parc, const char *parv[])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-22 03:57:43 +02:00
|
|
|
client::client *target_p;
|
2007-01-25 07:40:21 +01:00
|
|
|
const char *destination;
|
|
|
|
|
|
|
|
destination = parv[2];
|
2016-08-23 04:33:36 +02:00
|
|
|
source.flags &= ~client::flags::PINGSENT;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/* Now attempt to route the PONG, comstud pointed out routable PING
|
|
|
|
* is used for SPING. routable PING should also probably be left in
|
|
|
|
* -Dianora
|
|
|
|
* That being the case, we will route, but only for registered clients (a
|
|
|
|
* case can be made to allow them only from servers). -Shadowfax
|
|
|
|
*/
|
|
|
|
if(!EmptyString(destination) && !match(destination, me.name) &&
|
|
|
|
irccmp(destination, me.id))
|
|
|
|
{
|
2007-02-01 01:49:07 +01:00
|
|
|
if((target_p = find_client(destination)))
|
2014-03-03 05:25:47 +01:00
|
|
|
sendto_one(target_p, ":%s PONG %s %s",
|
2016-08-23 02:37:07 +02:00
|
|
|
get_id(&source, target_p), parv[1],
|
2007-01-25 07:40:21 +01:00
|
|
|
get_id(target_p, target_p));
|
|
|
|
else
|
|
|
|
{
|
2016-08-16 11:12:01 +02:00
|
|
|
if(!rfc1459::is_digit(*destination))
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_numeric(&source, ERR_NOSUCHSERVER,
|
2007-01-25 07:40:21 +01:00
|
|
|
form_str(ERR_NOSUCHSERVER), destination);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* destination is us, emulate EOB */
|
2016-08-23 04:33:36 +02:00
|
|
|
if(is_server(source) && !has_sent_eob(source))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 04:33:36 +02:00
|
|
|
if(my_connect(source))
|
2016-08-26 13:50:12 +02:00
|
|
|
sendto_realops_snomask(sno::GENERAL, L_ALL,
|
2007-01-25 07:40:21 +01:00
|
|
|
"End of burst (emulated) from %s (%d seconds)",
|
2016-08-23 02:37:07 +02:00
|
|
|
source.name,
|
|
|
|
(signed int) (rb_current_time() - source.localClient->firsttime));
|
2016-08-23 04:33:36 +02:00
|
|
|
set_eob(source);
|
2007-01-25 07:40:21 +01:00
|
|
|
eob_count++;
|
2016-08-23 02:37:07 +02:00
|
|
|
call_hook(h_server_eob, &source);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-08-23 02:37:07 +02:00
|
|
|
mr_pong(struct MsgBuf *msgbuf_p, client::client &client, client::client &source, int parc, const char *parv[])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
if(parc == 2 && !EmptyString(parv[1]))
|
|
|
|
{
|
2016-08-23 04:33:36 +02:00
|
|
|
if(ConfigFileEntry.ping_cookie && source.flags & client::flags::SENTUSER && source.name[0])
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-05-02 22:14:16 +02:00
|
|
|
uint32_t incoming_ping = strtoul(parv[1], NULL, 16);
|
2007-01-25 07:40:21 +01:00
|
|
|
if(incoming_ping)
|
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
if(source.localClient->random_ping == incoming_ping)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 04:33:36 +02:00
|
|
|
source.flags |= client::flags::PING_COOKIE;
|
2016-08-23 02:37:07 +02:00
|
|
|
register_local_user(&client, &source);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(ERR_WRONGPONG),
|
|
|
|
me.name, source.name,
|
|
|
|
source.localClient->random_ping);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(ERR_NOORIGIN), me.name, source.name);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
source.flags &= ~client::flags::PINGSENT;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|