]> jfr.im git - irc/rqf/shadowircd.git/blob - modules/m_whowas.c
ShadowIRCd 6.2.0-beta1
[irc/rqf/shadowircd.git] / modules / m_whowas.c
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
23 *
24 */
25
26 #include "stdinc.h"
27 #include "whowas.h"
28 #include "client.h"
29 #include "common.h"
30 #include "hash.h"
31 #include "match.h"
32 #include "ircd.h"
33 #include "ircd_defs.h"
34 #include "numeric.h"
35 #include "s_serv.h"
36 #include "s_user.h"
37 #include "send.h"
38 #include "s_conf.h"
39 #include "msg.h"
40 #include "parse.h"
41 #include "modules.h"
42
43 static int m_whowas(struct Client *, struct Client *, int, const char **);
44
45 struct Message whowas_msgtab = {
46 "WHOWAS", 0, 0, 0, MFLG_SLOW,
47 {mg_unreg, {m_whowas, 2}, mg_ignore, mg_ignore, mg_ignore, {m_whowas, 2}}
48 };
49
50 mapi_clist_av1 whowas_clist[] = { &whowas_msgtab, NULL };
51 DECLARE_MODULE_AV1(whowas, NULL, NULL, whowas_clist, NULL, NULL, "$Revision: 1717 $");
52
53 /*
54 ** m_whowas
55 ** parv[1] = nickname queried
56 */
57 static int
58 m_whowas(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
59 {
60 struct Whowas *temp;
61 int cur = 0;
62 int max = -1, found = 0;
63 char *p;
64 const char *nick;
65 char tbuf[26];
66
67 static time_t last_used = 0L;
68
69 if(!IsOper(source_p))
70 {
71 if((last_used + ConfigFileEntry.pace_wait_simple) > rb_current_time())
72 {
73 sendto_one(source_p, form_str(RPL_LOAD2HI),
74 me.name, source_p->name, "WHOWAS");
75 sendto_one(source_p, form_str(RPL_ENDOFWHOWAS),
76 me.name, source_p->name, parv[1]);
77 return 0;
78 }
79 else
80 last_used = rb_current_time();
81 }
82
83
84 if(parc > 2)
85 max = atoi(parv[2]);
86
87 #if 0
88 if(parc > 3)
89 if(hunt_server(client_p, source_p, ":%s WHOWAS %s %s :%s", 3, parc, parv))
90 return 0;
91 #endif
92
93 if((p = strchr(parv[1], ',')))
94 *p = '\0';
95
96 nick = parv[1];
97
98 temp = WHOWASHASH[hash_whowas_name(nick)];
99 found = 0;
100 for (; temp; temp = temp->next)
101 {
102 if(!irccmp(nick, temp->name))
103 {
104 sendto_one(source_p, form_str(RPL_WHOWASUSER),
105 me.name, source_p->name, temp->name,
106 temp->username, temp->hostname, temp->realname);
107 if (MyOper(source_p) && !EmptyString(temp->sockhost))
108 #if 0
109 sendto_one(source_p, form_str(RPL_WHOWASREAL),
110 me.name, source_p->name, temp->name,
111 "<untracked>", temp->sockhost);
112 #else
113 sendto_one_numeric(source_p, RPL_WHOISACTUALLY,
114 form_str(RPL_WHOISACTUALLY),
115 temp->name, temp->sockhost);
116 #endif
117 if (!EmptyString(temp->suser))
118 sendto_one_numeric(source_p, RPL_WHOISLOGGEDIN,
119 "%s %s :was logged in as",
120 temp->name, temp->suser);
121 sendto_one_numeric(source_p, RPL_WHOISSERVER,
122 form_str(RPL_WHOISSERVER),
123 temp->name, temp->servername,
124 rb_ctime(temp->logoff, tbuf, sizeof(tbuf)));
125 cur++;
126 found++;
127 }
128 if(max > 0 && cur >= max)
129 break;
130 }
131
132 if(!found)
133 sendto_one(source_p, form_str(ERR_WASNOSUCHNICK),
134 me.name, source_p->name, nick);
135
136 sendto_one(source_p, form_str(RPL_ENDOFWHOWAS),
137 me.name, source_p->name, parv[1]);
138 return 0;
139 }