]>
Commit | Line | Data |
---|---|---|
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 | #include "stdinc.h" | |
26 | #include "whowas.h" | |
27 | #include "client.h" | |
28 | #include "hash.h" | |
29 | #include "match.h" | |
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" | |
40 | ||
41 | static const char whowas_desc[] = | |
42 | "Provides the WHOWAS command to display information on a disconnected user"; | |
43 | ||
44 | static void m_whowas(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
45 | ||
46 | struct Message whowas_msgtab = { | |
47 | "WHOWAS", 0, 0, 0, 0, | |
48 | {mg_unreg, {m_whowas, 2}, {m_whowas, 4}, mg_ignore, mg_ignore, {m_whowas, 2}} | |
49 | }; | |
50 | ||
51 | mapi_clist_av1 whowas_clist[] = { &whowas_msgtab, NULL }; | |
52 | ||
53 | DECLARE_MODULE_AV2(whowas, NULL, NULL, whowas_clist, NULL, NULL, NULL, NULL, whowas_desc); | |
54 | ||
55 | /* | |
56 | ** m_whowas | |
57 | ** parv[1] = nickname queried | |
58 | */ | |
59 | static void | |
60 | m_whowas(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
61 | { | |
62 | rb_dlink_list *whowas_list; | |
63 | rb_dlink_node *ptr; | |
64 | int cur = 0; | |
65 | int max = -1; | |
66 | char *p; | |
67 | const char *nick; | |
68 | char tbuf[26]; | |
69 | long sendq_limit; | |
70 | ||
71 | static time_t last_used = 0L; | |
72 | ||
73 | if(MyClient(source_p) && !IsOper(source_p)) | |
74 | { | |
75 | if(last_used + (parc > 3 ? ConfigFileEntry.pace_wait : | |
76 | ConfigFileEntry.pace_wait_simple | |
77 | ) > rb_current_time()) | |
78 | { | |
79 | sendto_one(source_p, form_str(RPL_LOAD2HI), | |
80 | me.name, source_p->name, "WHOWAS"); | |
81 | sendto_one_numeric(source_p, RPL_ENDOFWHOWAS, form_str(RPL_ENDOFWHOWAS), | |
82 | parv[1]); | |
83 | return; | |
84 | } | |
85 | else | |
86 | last_used = rb_current_time(); | |
87 | } | |
88 | ||
89 | ||
90 | if(parc > 2) | |
91 | max = atoi(parv[2]); | |
92 | ||
93 | if(parc > 3) | |
94 | if(hunt_server(client_p, source_p, ":%s WHOWAS %s %s :%s", 3, parc, parv)) | |
95 | return; | |
96 | ||
97 | if(!MyClient(source_p) && (max <= 0 || max > 20)) | |
98 | max = 20; | |
99 | ||
100 | if((p = strchr(parv[1], ','))) | |
101 | *p = '\0'; | |
102 | ||
103 | nick = parv[1]; | |
104 | ||
105 | sendq_limit = get_sendq(client_p) * 9 / 10; | |
106 | whowas_list = whowas_get_list(nick); | |
107 | ||
108 | if(whowas_list == NULL) | |
109 | { | |
110 | sendto_one_numeric(source_p, ERR_WASNOSUCHNICK, form_str(ERR_WASNOSUCHNICK), nick); | |
111 | sendto_one_numeric(source_p, RPL_ENDOFWHOWAS, form_str(RPL_ENDOFWHOWAS), parv[1]); | |
112 | return; | |
113 | } | |
114 | ||
115 | RB_DLINK_FOREACH(ptr, whowas_list->head) | |
116 | { | |
117 | struct Whowas *temp = ptr->data; | |
118 | if(cur > 0 && rb_linebuf_len(&client_p->localClient->buf_sendq) > sendq_limit) | |
119 | { | |
120 | sendto_one(source_p, form_str(ERR_TOOMANYMATCHES), | |
121 | me.name, source_p->name, "WHOWAS"); | |
122 | break; | |
123 | } | |
124 | ||
125 | sendto_one(source_p, form_str(RPL_WHOWASUSER), | |
126 | me.name, source_p->name, temp->name, | |
127 | temp->username, temp->hostname, temp->realname); | |
128 | if (!EmptyString(temp->sockhost) && | |
129 | strcmp(temp->sockhost, "0") && | |
130 | show_ip_whowas(temp, source_p)) | |
131 | sendto_one_numeric(source_p, RPL_WHOISACTUALLY, | |
132 | form_str(RPL_WHOISACTUALLY), | |
133 | temp->name, temp->sockhost); | |
134 | ||
135 | if (!EmptyString(temp->suser)) | |
136 | sendto_one_numeric(source_p, RPL_WHOISLOGGEDIN, | |
137 | "%s %s :was logged in as", | |
138 | temp->name, temp->suser); | |
139 | ||
140 | sendto_one_numeric(source_p, RPL_WHOISSERVER, | |
141 | form_str(RPL_WHOISSERVER), | |
142 | temp->name, temp->servername, | |
143 | rb_ctime(temp->logoff, tbuf, sizeof(tbuf))); | |
144 | ||
145 | cur++; | |
146 | if(max > 0 && cur >= max) | |
147 | break; | |
148 | } | |
149 | ||
150 | sendto_one_numeric(source_p, RPL_ENDOFWHOWAS, form_str(RPL_ENDOFWHOWAS), parv[1]); | |
151 | } |