| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
| 3 |
* m_userhost.c: Shows a user's host. |
| 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 "client.h" |
| 27 |
#include "ircd.h" |
| 28 |
#include "numeric.h" |
| 29 |
#include "s_serv.h" |
| 30 |
#include "send.h" |
| 31 |
#include "irc_string.h" |
| 32 |
#include "parse.h" |
| 33 |
#include "modules.h" |
| 34 |
|
| 35 |
|
| 36 |
/* |
| 37 |
* m_userhost added by Darren Reed 13/8/91 to aid clients and reduce |
| 38 |
* the need for complicated requests like WHOIS. It returns user/host |
| 39 |
* information only (no spurious AWAY labels or channels). |
| 40 |
*/ |
| 41 |
static void |
| 42 |
m_userhost(struct Client *client_p, struct Client *source_p, |
| 43 |
int parc, char *parv[]) |
| 44 |
{ |
| 45 |
struct Client *target_p; |
| 46 |
char buf[IRCD_BUFSIZE]; |
| 47 |
char response[NICKLEN*2+USERLEN+HOSTLEN+30]; |
| 48 |
char *t = NULL, *p = NULL, *nick = NULL; |
| 49 |
int i = 0; /* loop counter */ |
| 50 |
int cur_len; |
| 51 |
int rl; |
| 52 |
|
| 53 |
cur_len = snprintf(buf, sizeof(buf), form_str(RPL_USERHOST), me.name, source_p->name, ""); |
| 54 |
t = buf + cur_len; |
| 55 |
|
| 56 |
for (nick = strtoken(&p, parv[1], " "); nick && i++ < 5; |
| 57 |
nick = strtoken(&p, NULL, " ")) |
| 58 |
{ |
| 59 |
if ((target_p = find_person(client_p, nick)) != NULL) |
| 60 |
{ |
| 61 |
/* |
| 62 |
* Show real IP for USERHOST on yourself. |
| 63 |
* This is needed for things like mIRC, which do a server-based |
| 64 |
* lookup (USERHOST) to figure out what the clients' local IP |
| 65 |
* is. Useful for things like NAT, and dynamic dial-up users. |
| 66 |
*/ |
| 67 |
if (MyClient(target_p) && (target_p == source_p)) |
| 68 |
{ |
| 69 |
rl = sprintf(response, "%s%s=%c%s@%s ", |
| 70 |
target_p->name, |
| 71 |
HasUMode(target_p, UMODE_OPER) ? "*" : "", |
| 72 |
(target_p->away[0]) ? '-' : '+', |
| 73 |
target_p->username, |
| 74 |
target_p->sockhost); |
| 75 |
} |
| 76 |
else |
| 77 |
{ |
| 78 |
rl = sprintf(response, "%s%s=%c%s@%s ", |
| 79 |
target_p->name, (HasUMode(target_p, UMODE_OPER) && |
| 80 |
(!HasUMode(target_p, UMODE_HIDDEN) || |
| 81 |
HasUMode(source_p, UMODE_OPER))) ? "*" : "", |
| 82 |
(target_p->away[0]) ? '-' : '+', |
| 83 |
target_p->username, |
| 84 |
target_p->host); |
| 85 |
} |
| 86 |
|
| 87 |
if ((rl + cur_len) < (IRCD_BUFSIZE - 10)) |
| 88 |
{ |
| 89 |
sprintf(t, "%s", response); |
| 90 |
t += rl; |
| 91 |
cur_len += rl; |
| 92 |
} |
| 93 |
else |
| 94 |
break; |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
sendto_one(source_p, "%s", buf); |
| 99 |
} |
| 100 |
|
| 101 |
static struct Message userhost_msgtab = { |
| 102 |
"USERHOST", 0, 0, 2, 1, MFLG_SLOW, 0, |
| 103 |
{m_unregistered, m_userhost, m_userhost, m_ignore, m_userhost, m_ignore} |
| 104 |
}; |
| 105 |
|
| 106 |
static void |
| 107 |
module_init(void) |
| 108 |
{ |
| 109 |
mod_add_cmd(&userhost_msgtab); |
| 110 |
} |
| 111 |
|
| 112 |
static void |
| 113 |
module_exit(void) |
| 114 |
{ |
| 115 |
mod_del_cmd(&userhost_msgtab); |
| 116 |
} |
| 117 |
|
| 118 |
struct module module_entry = { |
| 119 |
.node = { NULL, NULL, NULL }, |
| 120 |
.name = NULL, |
| 121 |
.version = "$Revision$", |
| 122 |
.handle = NULL, |
| 123 |
.modinit = module_init, |
| 124 |
.modexit = module_exit, |
| 125 |
.flags = 0 |
| 126 |
}; |