1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* m_whois.c: Shows who a user was. |
4 |
* |
5 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
11 |
* |
12 |
* This program is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
21 |
* |
22 |
* $Id$ |
23 |
*/ |
24 |
|
25 |
#include "stdinc.h" |
26 |
#include "whowas.h" |
27 |
#include "handlers.h" |
28 |
#include "client.h" |
29 |
#include "common.h" |
30 |
#include "hash.h" |
31 |
#include "irc_string.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 |
|
44 |
static void m_whowas(struct Client *, struct Client *, int, char *[]); |
45 |
static void mo_whowas(struct Client *, struct Client *, int, char *[]); |
46 |
static void whowas_do(struct Client *, struct Client *, int, char *[]); |
47 |
|
48 |
struct Message whowas_msgtab = { |
49 |
"WHOWAS", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
50 |
{ m_unregistered, m_whowas, mo_whowas, m_ignore, mo_whowas, m_ignore } |
51 |
}; |
52 |
|
53 |
void |
54 |
_modinit(void) |
55 |
{ |
56 |
mod_add_cmd(&whowas_msgtab); |
57 |
} |
58 |
|
59 |
void |
60 |
_moddeinit(void) |
61 |
{ |
62 |
mod_del_cmd(&whowas_msgtab); |
63 |
} |
64 |
|
65 |
const char *_version = "$Revision$"; |
66 |
|
67 |
/* |
68 |
** m_whowas |
69 |
** parv[0] = sender prefix |
70 |
** parv[1] = nickname queried |
71 |
*/ |
72 |
static void |
73 |
m_whowas(struct Client *client_p, struct Client *source_p, |
74 |
int parc, char *parv[]) |
75 |
{ |
76 |
static time_t last_used = 0; |
77 |
|
78 |
if (parc < 2 || EmptyString(parv[1])) |
79 |
{ |
80 |
sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), |
81 |
me.name, source_p->name); |
82 |
return; |
83 |
} |
84 |
|
85 |
if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime) |
86 |
{ |
87 |
sendto_one(source_p,form_str(RPL_LOAD2HI), |
88 |
me.name, source_p->name); |
89 |
return; |
90 |
} |
91 |
|
92 |
last_used = CurrentTime; |
93 |
|
94 |
whowas_do(client_p, source_p, parc, parv); |
95 |
} |
96 |
|
97 |
static void |
98 |
mo_whowas(struct Client *client_p, struct Client *source_p, |
99 |
int parc, char *parv[]) |
100 |
{ |
101 |
if (parc < 2 || EmptyString(parv[1])) |
102 |
{ |
103 |
sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), |
104 |
me.name, source_p->name); |
105 |
return; |
106 |
} |
107 |
|
108 |
whowas_do(client_p, source_p, parc, parv); |
109 |
} |
110 |
|
111 |
static void |
112 |
whowas_do(struct Client *client_p, struct Client *source_p, |
113 |
int parc, char *parv[]) |
114 |
{ |
115 |
struct Whowas *temp = NULL; |
116 |
int cur = 0; |
117 |
int max = -1; |
118 |
char *p = NULL, *nick = NULL; |
119 |
|
120 |
if (parc > 2) |
121 |
{ |
122 |
max = atoi(parv[2]); |
123 |
|
124 |
if (!MyConnect(source_p) && max > 20) |
125 |
max = 20; |
126 |
} |
127 |
|
128 |
if (parc > 3) |
129 |
if (hunt_server(client_p, source_p, ":%s WHOWAS %s %s :%s", 3, |
130 |
parc, parv) != HUNTED_ISME) |
131 |
return; |
132 |
|
133 |
nick = parv[1]; |
134 |
while (*nick == ',') |
135 |
nick++; |
136 |
if ((p = strchr(nick,',')) != NULL) |
137 |
*p = '\0'; |
138 |
if (*nick == '\0') |
139 |
return; |
140 |
|
141 |
temp = WHOWASHASH[strhash(nick)]; |
142 |
|
143 |
for (; temp; temp = temp->next) |
144 |
{ |
145 |
if (!irccmp(nick, temp->name)) |
146 |
{ |
147 |
sendto_one(source_p, form_str(RPL_WHOWASUSER), |
148 |
me.name, source_p->name, temp->name, |
149 |
temp->username, temp->hostname, |
150 |
temp->realname); |
151 |
|
152 |
if (ConfigServerHide.hide_servers && !HasUMode(source_p, UMODE_OPER)) |
153 |
sendto_one(source_p, form_str(RPL_WHOISSERVER), |
154 |
me.name, source_p->name, temp->name, |
155 |
ServerInfo.network_name, myctime(temp->logoff)); |
156 |
else |
157 |
sendto_one(source_p, form_str(RPL_WHOISSERVER), |
158 |
me.name, source_p->name, temp->name, |
159 |
temp->servername, myctime(temp->logoff)); |
160 |
cur++; |
161 |
} |
162 |
|
163 |
if (max > 0 && cur >= max) |
164 |
break; |
165 |
} |
166 |
|
167 |
if (!cur) |
168 |
sendto_one(source_p, form_str(ERR_WASNOSUCHNICK), |
169 |
me.name, source_p->name, nick); |
170 |
|
171 |
sendto_one(source_p, form_str(RPL_ENDOFWHOWAS), |
172 |
me.name, source_p->name, parv[1]); |
173 |
} |