| 1 |
adx |
30 |
/* |
| 2 |
michael |
2820 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
adx |
30 |
* |
| 4 |
michael |
2820 |
* Copyright (c) 1997-2014 ircd-hybrid development team |
| 5 |
adx |
30 |
* |
| 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 |
michael |
4565 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 19 |
adx |
30 |
* USA |
| 20 |
|
|
*/ |
| 21 |
|
|
|
| 22 |
michael |
2820 |
/*! \file m_whowas.c |
| 23 |
|
|
* \brief Includes required functions for processing the WHOWAS command. |
| 24 |
|
|
* \version $Id$ |
| 25 |
|
|
*/ |
| 26 |
|
|
|
| 27 |
adx |
30 |
#include "stdinc.h" |
| 28 |
michael |
1358 |
#include "list.h" |
| 29 |
adx |
30 |
#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 |
michael |
3347 |
#include "misc.h" |
| 37 |
|
|
#include "server.h" |
| 38 |
adx |
30 |
#include "send.h" |
| 39 |
michael |
1309 |
#include "conf.h" |
| 40 |
adx |
30 |
#include "parse.h" |
| 41 |
|
|
#include "modules.h" |
| 42 |
|
|
|
| 43 |
|
|
|
| 44 |
|
|
static void |
| 45 |
michael |
3338 |
do_whowas(struct Client *source_p, const int parc, char *parv[]) |
| 46 |
adx |
30 |
{ |
| 47 |
|
|
int cur = 0; |
| 48 |
|
|
int max = -1; |
| 49 |
michael |
1358 |
const dlink_node *ptr = NULL; |
| 50 |
adx |
30 |
|
| 51 |
michael |
2076 |
if (parc > 2 && !EmptyString(parv[2])) |
| 52 |
|
|
if ((max = atoi(parv[2])) > 20 && !MyConnect(source_p)) |
| 53 |
|
|
max = 20; |
| 54 |
adx |
30 |
|
| 55 |
michael |
2076 |
DLINK_FOREACH(ptr, WHOWASHASH[strhash(parv[1])].head) |
| 56 |
michael |
1358 |
{ |
| 57 |
|
|
const struct Whowas *temp = ptr->data; |
| 58 |
adx |
30 |
|
| 59 |
michael |
2076 |
if (!irccmp(parv[1], temp->name)) |
| 60 |
adx |
30 |
{ |
| 61 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_WHOWASUSER, temp->name, |
| 62 |
|
|
temp->username, temp->hostname, |
| 63 |
|
|
temp->realname); |
| 64 |
adx |
30 |
|
| 65 |
michael |
2748 |
if ((temp->shide || ConfigServerHide.hide_servers) && !HasUMode(source_p, UMODE_OPER)) |
| 66 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_WHOISSERVER, temp->name, |
| 67 |
michael |
4340 |
ConfigServerInfo.network_name, myctime(temp->logoff)); |
| 68 |
adx |
30 |
else |
| 69 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_WHOISSERVER, temp->name, |
| 70 |
|
|
temp->servername, myctime(temp->logoff)); |
| 71 |
michael |
1358 |
++cur; |
| 72 |
adx |
30 |
} |
| 73 |
|
|
|
| 74 |
|
|
if (max > 0 && cur >= max) |
| 75 |
|
|
break; |
| 76 |
|
|
} |
| 77 |
|
|
|
| 78 |
|
|
if (!cur) |
| 79 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_WASNOSUCHNICK, parv[1]); |
| 80 |
adx |
30 |
|
| 81 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_ENDOFWHOWAS, parv[1]); |
| 82 |
adx |
30 |
} |
| 83 |
michael |
1230 |
|
| 84 |
michael |
3295 |
/*! \brief WHOWAS command handler |
| 85 |
|
|
* |
| 86 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
| 87 |
|
|
* originally comes from. This can be a local or remote client. |
| 88 |
|
|
* \param parc Integer holding the number of supplied arguments. |
| 89 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 90 |
|
|
* pointers. |
| 91 |
|
|
* \note Valid arguments for this command are: |
| 92 |
|
|
* - parv[0] = command |
| 93 |
|
|
* - parv[1] = nickname |
| 94 |
|
|
* - parv[2] = count |
| 95 |
|
|
* - parv[3] = nickname/servername |
| 96 |
|
|
*/ |
| 97 |
michael |
2820 |
static int |
| 98 |
michael |
3156 |
m_whowas(struct Client *source_p, int parc, char *parv[]) |
| 99 |
michael |
1230 |
{ |
| 100 |
|
|
static time_t last_used = 0; |
| 101 |
|
|
|
| 102 |
|
|
if (parc < 2 || EmptyString(parv[1])) |
| 103 |
|
|
{ |
| 104 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NONICKNAMEGIVEN); |
| 105 |
michael |
2820 |
return 0; |
| 106 |
michael |
1230 |
} |
| 107 |
|
|
|
| 108 |
michael |
4340 |
if ((last_used + ConfigGeneral.pace_wait) > CurrentTime) |
| 109 |
michael |
1230 |
{ |
| 110 |
michael |
4759 |
sendto_one_numeric(source_p, &me, RPL_LOAD2HI, "WHOWAS"); |
| 111 |
michael |
2820 |
return 0; |
| 112 |
michael |
1230 |
} |
| 113 |
|
|
|
| 114 |
|
|
last_used = CurrentTime; |
| 115 |
|
|
|
| 116 |
michael |
4720 |
if (!ConfigServerHide.disable_remote_commands) |
| 117 |
|
|
if (hunt_server(source_p, ":%s WHOWAS %s %s :%s", 3, parc, parv) != HUNTED_ISME) |
| 118 |
michael |
2986 |
return 0; |
| 119 |
|
|
|
| 120 |
michael |
3338 |
do_whowas(source_p, parc, parv); |
| 121 |
michael |
2820 |
return 0; |
| 122 |
michael |
1230 |
} |
| 123 |
|
|
|
| 124 |
michael |
3295 |
/*! \brief WHOWAS command handler |
| 125 |
|
|
* |
| 126 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
| 127 |
|
|
* originally comes from. This can be a local or remote client. |
| 128 |
|
|
* \param parc Integer holding the number of supplied arguments. |
| 129 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 130 |
|
|
* pointers. |
| 131 |
|
|
* \note Valid arguments for this command are: |
| 132 |
|
|
* - parv[0] = command |
| 133 |
|
|
* - parv[1] = nickname |
| 134 |
|
|
* - parv[2] = count |
| 135 |
|
|
* - parv[3] = nickname/servername |
| 136 |
|
|
*/ |
| 137 |
michael |
2820 |
static int |
| 138 |
michael |
3346 |
ms_whowas(struct Client *source_p, int parc, char *parv[]) |
| 139 |
michael |
1230 |
{ |
| 140 |
|
|
if (parc < 2 || EmptyString(parv[1])) |
| 141 |
|
|
{ |
| 142 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NONICKNAMEGIVEN); |
| 143 |
michael |
2820 |
return 0; |
| 144 |
michael |
1230 |
} |
| 145 |
|
|
|
| 146 |
michael |
4720 |
if (hunt_server(source_p, ":%s WHOWAS %s %s :%s", 3, parc, parv) != HUNTED_ISME) |
| 147 |
|
|
return 0; |
| 148 |
michael |
2986 |
|
| 149 |
michael |
3338 |
do_whowas(source_p, parc, parv); |
| 150 |
michael |
2820 |
return 0; |
| 151 |
michael |
1230 |
} |
| 152 |
|
|
|
| 153 |
michael |
2820 |
static struct Message whowas_msgtab = |
| 154 |
|
|
{ |
| 155 |
michael |
4545 |
"WHOWAS", NULL, 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
| 156 |
michael |
3346 |
{ m_unregistered, m_whowas, ms_whowas, m_ignore, ms_whowas, m_ignore } |
| 157 |
michael |
1230 |
}; |
| 158 |
|
|
|
| 159 |
|
|
static void |
| 160 |
|
|
module_init(void) |
| 161 |
|
|
{ |
| 162 |
|
|
mod_add_cmd(&whowas_msgtab); |
| 163 |
|
|
} |
| 164 |
|
|
|
| 165 |
|
|
static void |
| 166 |
|
|
module_exit(void) |
| 167 |
|
|
{ |
| 168 |
|
|
mod_del_cmd(&whowas_msgtab); |
| 169 |
|
|
} |
| 170 |
|
|
|
| 171 |
michael |
2820 |
struct module module_entry = |
| 172 |
|
|
{ |
| 173 |
michael |
1230 |
.node = { NULL, NULL, NULL }, |
| 174 |
|
|
.name = NULL, |
| 175 |
|
|
.version = "$Revision$", |
| 176 |
|
|
.handle = NULL, |
| 177 |
|
|
.modinit = module_init, |
| 178 |
|
|
.modexit = module_exit, |
| 179 |
|
|
.flags = 0 |
| 180 |
|
|
}; |