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 "list.h" |
27 |
#include "whowas.h" |
28 |
#include "client.h" |
29 |
#include "hash.h" |
30 |
#include "irc_string.h" |
31 |
#include "ircd.h" |
32 |
#include "ircd_defs.h" |
33 |
#include "numeric.h" |
34 |
#include "s_serv.h" |
35 |
#include "s_user.h" |
36 |
#include "send.h" |
37 |
#include "conf.h" |
38 |
#include "parse.h" |
39 |
#include "modules.h" |
40 |
|
41 |
|
42 |
static void |
43 |
whowas_do(struct Client *client_p, struct Client *source_p, |
44 |
const int parc, char *parv[]) |
45 |
{ |
46 |
int cur = 0; |
47 |
int max = -1; |
48 |
const dlink_node *ptr = NULL; |
49 |
|
50 |
if (parc > 3) |
51 |
if (hunt_server(client_p, source_p, ":%s WHOWAS %s %s :%s", 3, |
52 |
parc, parv) != HUNTED_ISME) |
53 |
return; |
54 |
|
55 |
if (parc > 2 && !EmptyString(parv[2])) |
56 |
if ((max = atoi(parv[2])) > 20 && !MyConnect(source_p)) |
57 |
max = 20; |
58 |
|
59 |
DLINK_FOREACH(ptr, WHOWASHASH[strhash(parv[1])].head) |
60 |
{ |
61 |
const struct Whowas *temp = ptr->data; |
62 |
|
63 |
if (!irccmp(parv[1], temp->name)) |
64 |
{ |
65 |
sendto_one(source_p, form_str(RPL_WHOWASUSER), |
66 |
me.name, source_p->name, temp->name, |
67 |
temp->username, temp->hostname, |
68 |
temp->realname); |
69 |
|
70 |
if (ConfigServerHide.hide_servers && !HasUMode(source_p, UMODE_OPER)) |
71 |
sendto_one(source_p, form_str(RPL_WHOISSERVER), me.name, |
72 |
source_p->name, temp->name, |
73 |
ServerInfo.network_name, myctime(temp->logoff)); |
74 |
else |
75 |
sendto_one(source_p, form_str(RPL_WHOISSERVER), me.name, |
76 |
source_p->name, temp->name, |
77 |
temp->servername, myctime(temp->logoff)); |
78 |
++cur; |
79 |
} |
80 |
|
81 |
if (max > 0 && cur >= max) |
82 |
break; |
83 |
} |
84 |
|
85 |
if (!cur) |
86 |
sendto_one(source_p, form_str(ERR_WASNOSUCHNICK), |
87 |
me.name, source_p->name, parv[1]); |
88 |
|
89 |
sendto_one(source_p, form_str(RPL_ENDOFWHOWAS), |
90 |
me.name, source_p->name, parv[1]); |
91 |
} |
92 |
|
93 |
/* |
94 |
** m_whowas |
95 |
** parv[0] = sender prefix |
96 |
** parv[1] = nickname queried |
97 |
*/ |
98 |
static void |
99 |
m_whowas(struct Client *client_p, struct Client *source_p, |
100 |
int parc, char *parv[]) |
101 |
{ |
102 |
static time_t last_used = 0; |
103 |
|
104 |
if (parc < 2 || EmptyString(parv[1])) |
105 |
{ |
106 |
sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), |
107 |
me.name, source_p->name); |
108 |
return; |
109 |
} |
110 |
|
111 |
if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime) |
112 |
{ |
113 |
sendto_one(source_p,form_str(RPL_LOAD2HI), |
114 |
me.name, source_p->name); |
115 |
return; |
116 |
} |
117 |
|
118 |
last_used = CurrentTime; |
119 |
|
120 |
whowas_do(client_p, source_p, parc, parv); |
121 |
} |
122 |
|
123 |
static void |
124 |
mo_whowas(struct Client *client_p, struct Client *source_p, |
125 |
int parc, char *parv[]) |
126 |
{ |
127 |
if (parc < 2 || EmptyString(parv[1])) |
128 |
{ |
129 |
sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), |
130 |
me.name, source_p->name); |
131 |
return; |
132 |
} |
133 |
|
134 |
whowas_do(client_p, source_p, parc, parv); |
135 |
} |
136 |
|
137 |
static struct Message whowas_msgtab = { |
138 |
"WHOWAS", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
139 |
{ m_unregistered, m_whowas, mo_whowas, m_ignore, mo_whowas, m_ignore } |
140 |
}; |
141 |
|
142 |
static void |
143 |
module_init(void) |
144 |
{ |
145 |
mod_add_cmd(&whowas_msgtab); |
146 |
} |
147 |
|
148 |
static void |
149 |
module_exit(void) |
150 |
{ |
151 |
mod_del_cmd(&whowas_msgtab); |
152 |
} |
153 |
|
154 |
struct module module_entry = { |
155 |
.node = { NULL, NULL, NULL }, |
156 |
.name = NULL, |
157 |
.version = "$Revision$", |
158 |
.handle = NULL, |
159 |
.modinit = module_init, |
160 |
.modexit = module_exit, |
161 |
.flags = 0 |
162 |
}; |