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