2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: A slightly useful ircd.
|
|
|
|
* m_whois.c: Shows who a user was.
|
|
|
|
*
|
|
|
|
* 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-07 09:53:27 +01:00
|
|
|
static const char whowas_desc[] =
|
|
|
|
"Provides the WHOWAS command to display information on a disconnected user";
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
static void m_whowas(struct MsgBuf *, client::client &, client::client &, int, const char **);
|
2016-03-09 08:29:41 +01:00
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
struct Message whowas_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"WHOWAS", 0, 0, 0, 0,
|
2013-09-13 22:29:26 +02:00
|
|
|
{mg_unreg, {m_whowas, 2}, {m_whowas, 4}, mg_ignore, mg_ignore, {m_whowas, 2}}
|
2007-01-25 07:40:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
mapi_clist_av1 whowas_clist[] = { &whowas_msgtab, NULL };
|
2016-03-09 08:29:41 +01:00
|
|
|
|
2016-03-07 09:53:27 +01:00
|
|
|
DECLARE_MODULE_AV2(whowas, NULL, NULL, whowas_clist, NULL, NULL, NULL, NULL, whowas_desc);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
** m_whowas
|
|
|
|
** parv[1] = nickname queried
|
|
|
|
*/
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-08-23 02:37:07 +02:00
|
|
|
m_whowas(struct MsgBuf *msgbuf_p, client::client &client, client::client &source, int parc, const char *parv[])
|
2014-03-03 05:25:47 +01:00
|
|
|
{
|
2016-01-23 17:16:34 +01:00
|
|
|
rb_dlink_list *whowas_list;
|
|
|
|
rb_dlink_node *ptr;
|
2007-01-25 07:40:21 +01:00
|
|
|
int cur = 0;
|
2016-01-23 17:16:34 +01:00
|
|
|
int max = -1;
|
2007-01-25 07:40:21 +01:00
|
|
|
char *p;
|
|
|
|
const char *nick;
|
2008-04-20 07:03:39 +02:00
|
|
|
char tbuf[26];
|
2013-02-02 00:50:03 +01:00
|
|
|
long sendq_limit;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
|
|
|
static time_t last_used = 0L;
|
|
|
|
|
2016-08-24 00:25:09 +02:00
|
|
|
if(my(source) && !is(source, umode::OPER))
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2013-09-13 22:29:26 +02:00
|
|
|
if(last_used + (parc > 3 ? ConfigFileEntry.pace_wait :
|
|
|
|
ConfigFileEntry.pace_wait_simple
|
|
|
|
) > rb_current_time())
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(RPL_LOAD2HI),
|
|
|
|
me.name, source.name, "WHOWAS");
|
|
|
|
sendto_one_numeric(&source, RPL_ENDOFWHOWAS, form_str(RPL_ENDOFWHOWAS),
|
2016-01-23 17:16:34 +01:00
|
|
|
parv[1]);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
else
|
2008-04-02 01:53:20 +02:00
|
|
|
last_used = rb_current_time();
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(parc > 2)
|
|
|
|
max = atoi(parv[2]);
|
|
|
|
|
|
|
|
if(parc > 3)
|
2016-08-23 02:37:07 +02:00
|
|
|
if(hunt_server(&client, &source, ":%s WHOWAS %s %s :%s", 3, parc, parv))
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2013-09-13 22:29:26 +02:00
|
|
|
|
2016-08-23 04:33:36 +02:00
|
|
|
if(!my(source) && (max <= 0 || max > 20))
|
2013-09-13 22:29:26 +02:00
|
|
|
max = 20;
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-07-13 07:17:21 +02:00
|
|
|
if((p = (char *)strchr(parv[1], ',')))
|
2007-01-25 07:40:21 +01:00
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
nick = parv[1];
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
sendq_limit = get_sendq(&client) * 9 / 10;
|
2016-08-25 04:52:37 +02:00
|
|
|
const auto history(whowas::history(nick));
|
|
|
|
if(history.empty())
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_numeric(&source, ERR_WASNOSUCHNICK, form_str(ERR_WASNOSUCHNICK), nick);
|
|
|
|
sendto_one_numeric(&source, RPL_ENDOFWHOWAS, form_str(RPL_ENDOFWHOWAS), parv[1]);
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2016-01-23 17:16:34 +01:00
|
|
|
}
|
|
|
|
|
2016-08-25 04:52:37 +02:00
|
|
|
for(const auto &ww : history)
|
2016-01-23 17:16:34 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
if(cur > 0 && rb_linebuf_len(&client.localClient->buf_sendq) > sendq_limit)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(ERR_TOOMANYMATCHES),
|
2016-08-25 04:52:37 +02:00
|
|
|
me.name,
|
|
|
|
source.name,
|
|
|
|
"WHOWAS");
|
2016-01-23 17:16:34 +01:00
|
|
|
break;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
2016-01-23 17:16:34 +01:00
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one(&source, form_str(RPL_WHOWASUSER),
|
2016-08-25 04:52:37 +02:00
|
|
|
me.name,
|
|
|
|
source.name,
|
|
|
|
ww->name,
|
|
|
|
ww->username,
|
|
|
|
ww->hostname,
|
|
|
|
ww->realname);
|
|
|
|
|
|
|
|
if(!EmptyString(ww->sockhost) && strcmp(ww->sockhost, "0") && show_ip_whowas(*ww, source))
|
|
|
|
sendto_one_numeric(&source, RPL_WHOISACTUALLY, form_str(RPL_WHOISACTUALLY),
|
|
|
|
ww->name,
|
|
|
|
ww->sockhost);
|
|
|
|
|
|
|
|
if(!EmptyString(ww->suser))
|
|
|
|
sendto_one_numeric(&source, RPL_WHOISLOGGEDIN, "%s %s :was logged in as",
|
|
|
|
ww->name,
|
|
|
|
ww->suser);
|
2016-01-23 17:16:34 +01:00
|
|
|
|
2016-08-24 12:11:01 +02:00
|
|
|
sendto_one_numeric(&source, RPL_WHOISSERVER, form_str(RPL_WHOISSERVER),
|
2016-08-25 04:52:37 +02:00
|
|
|
ww->name,
|
|
|
|
ww->scache? name(*ww->scache).c_str() : "*",
|
|
|
|
rb_ctime(ww->logoff, tbuf, sizeof(tbuf)));
|
2016-01-23 17:16:34 +01:00
|
|
|
|
|
|
|
cur++;
|
2007-01-25 07:40:21 +01:00
|
|
|
if(max > 0 && cur >= max)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-08-23 02:37:07 +02:00
|
|
|
sendto_one_numeric(&source, RPL_ENDOFWHOWAS, form_str(RPL_ENDOFWHOWAS), parv[1]);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|