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