]> jfr.im git - solanum.git/blame - modules/m_whowas.c
extensions/umode_hide_idle_time: mask times for hidden sources (#373)
[solanum.git] / modules / m_whowas.c
CommitLineData
212380e3
AC
1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_whois.c: Shows who a user was.
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 "whowas.h"
27#include "client.h"
212380e3 28#include "hash.h"
4562c604 29#include "match.h"
212380e3
AC
30#include "ircd.h"
31#include "ircd_defs.h"
32#include "numeric.h"
33#include "s_serv.h"
34#include "s_user.h"
35#include "send.h"
36#include "s_conf.h"
37#include "msg.h"
38#include "parse.h"
39#include "modules.h"
d4f7eb4c 40#include "s_newconf.h"
212380e3 41
3bf449fe
AW
42static const char whowas_desc[] =
43 "Provides the WHOWAS command to display information on a disconnected user";
212380e3 44
3c7d6fcc 45static void m_whowas(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
eeabf33a 46
212380e3 47struct Message whowas_msgtab = {
7baa37a9 48 "WHOWAS", 0, 0, 0, 0,
7a9a9000 49 {mg_unreg, {m_whowas, 2}, {m_whowas, 4}, mg_ignore, mg_ignore, {m_whowas, 2}}
212380e3
AC
50};
51
52mapi_clist_av1 whowas_clist[] = { &whowas_msgtab, NULL };
eeabf33a 53
3bf449fe 54DECLARE_MODULE_AV2(whowas, NULL, NULL, whowas_clist, NULL, NULL, NULL, NULL, whowas_desc);
212380e3
AC
55
56/*
57** m_whowas
212380e3
AC
58** parv[1] = nickname queried
59*/
3c7d6fcc 60static void
428ca87b 61m_whowas(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
55abcbb2 62{
b47f8a4f
AC
63 rb_dlink_list *whowas_list;
64 rb_dlink_node *ptr;
212380e3 65 int cur = 0;
b47f8a4f 66 int max = -1;
212380e3
AC
67 char *p;
68 const char *nick;
08d75d97 69 char tbuf[26];
df2516e6 70 long sendq_limit;
212380e3
AC
71
72 static time_t last_used = 0L;
73
d4f7eb4c 74 if(MyClient(source_p) && !IsOperGeneral(source_p))
212380e3 75 {
7a9a9000
JT
76 if(last_used + (parc > 3 ? ConfigFileEntry.pace_wait :
77 ConfigFileEntry.pace_wait_simple
78 ) > rb_current_time())
212380e3
AC
79 {
80 sendto_one(source_p, form_str(RPL_LOAD2HI),
81 me.name, source_p->name, "WHOWAS");
b47f8a4f
AC
82 sendto_one_numeric(source_p, RPL_ENDOFWHOWAS, form_str(RPL_ENDOFWHOWAS),
83 parv[1]);
3c7d6fcc 84 return;
212380e3
AC
85 }
86 else
e3354945 87 last_used = rb_current_time();
212380e3
AC
88 }
89
90
91 if(parc > 2)
92 max = atoi(parv[2]);
93
212380e3
AC
94 if(parc > 3)
95 if(hunt_server(client_p, source_p, ":%s WHOWAS %s %s :%s", 3, parc, parv))
3c7d6fcc 96 return;
7a9a9000
JT
97
98 if(!MyClient(source_p) && (max <= 0 || max > 20))
99 max = 20;
212380e3
AC
100
101 if((p = strchr(parv[1], ',')))
102 *p = '\0';
103
104 nick = parv[1];
105
df2516e6 106 sendq_limit = get_sendq(client_p) * 9 / 10;
b47f8a4f 107 whowas_list = whowas_get_list(nick);
df2516e6 108
b47f8a4f 109 if(whowas_list == NULL)
212380e3 110 {
b47f8a4f
AC
111 sendto_one_numeric(source_p, ERR_WASNOSUCHNICK, form_str(ERR_WASNOSUCHNICK), nick);
112 sendto_one_numeric(source_p, RPL_ENDOFWHOWAS, form_str(RPL_ENDOFWHOWAS), parv[1]);
3c7d6fcc 113 return;
b47f8a4f
AC
114 }
115
116 RB_DLINK_FOREACH(ptr, whowas_list->head)
117 {
118 struct Whowas *temp = ptr->data;
119 if(cur > 0 && rb_linebuf_len(&client_p->localClient->buf_sendq) > sendq_limit)
212380e3 120 {
b47f8a4f
AC
121 sendto_one(source_p, form_str(ERR_TOOMANYMATCHES),
122 me.name, source_p->name, "WHOWAS");
123 break;
212380e3 124 }
b47f8a4f
AC
125
126 sendto_one(source_p, form_str(RPL_WHOWASUSER),
127 me.name, source_p->name, temp->name,
128 temp->username, temp->hostname, temp->realname);
129 if (!EmptyString(temp->sockhost) &&
130 strcmp(temp->sockhost, "0") &&
131 show_ip_whowas(temp, source_p))
132 sendto_one_numeric(source_p, RPL_WHOISACTUALLY,
133 form_str(RPL_WHOISACTUALLY),
134 temp->name, temp->sockhost);
135
136 if (!EmptyString(temp->suser))
137 sendto_one_numeric(source_p, RPL_WHOISLOGGEDIN,
138 "%s %s :was logged in as",
139 temp->name, temp->suser);
140
141 sendto_one_numeric(source_p, RPL_WHOISSERVER,
142 form_str(RPL_WHOISSERVER),
143 temp->name, temp->servername,
144 rb_ctime(temp->logoff, tbuf, sizeof(tbuf)));
145
146 cur++;
212380e3
AC
147 if(max > 0 && cur >= max)
148 break;
149 }
150
b47f8a4f 151 sendto_one_numeric(source_p, RPL_ENDOFWHOWAS, form_str(RPL_ENDOFWHOWAS), parv[1]);
212380e3 152}