]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_userhost.c
ShadowIRCd 6.2.0-beta1
[irc/rqf/shadowircd.git] / modules / m_userhost.c
CommitLineData
212380e3 1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_userhost.c: Shows a user's host.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 *
212380e3 24 */
25
26#include "stdinc.h"
27#include "client.h"
28#include "ircd.h"
29#include "numeric.h"
30#include "s_serv.h"
31#include "send.h"
13ae2f4b 32#include "match.h"
212380e3 33#include "msg.h"
34#include "parse.h"
35#include "modules.h"
36#include "s_conf.h"
37
38static char buf[BUFSIZE];
39
40static int m_userhost(struct Client *, struct Client *, int, const char **);
41
42struct Message userhost_msgtab = {
43 "USERHOST", 0, 0, 0, MFLG_SLOW,
44 {mg_unreg, {m_userhost, 2}, mg_ignore, mg_ignore, mg_ignore, {m_userhost, 2}}
45};
46
47mapi_clist_av1 userhost_clist[] = { &userhost_msgtab, NULL };
48DECLARE_MODULE_AV1(userhost, NULL, NULL, userhost_clist, NULL, NULL, "$Revision: 254 $");
49
50/*
51 * m_userhost added by Darren Reed 13/8/91 to aid clients and reduce
52 * the need for complicated requests like WHOIS. It returns user/host
53 * information only (no spurious AWAY labels or channels).
54 */
55static int
56m_userhost(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
57{
58 struct Client *target_p;
59 char response[NICKLEN * 2 + USERLEN + HOSTLEN + 30];
60 char *t;
61 int i; /* loop counter */
62 int cur_len;
63 int rl;
64
8e425f41 65 cur_len = rb_sprintf(buf, form_str(RPL_USERHOST), me.name, source_p->name, "");
212380e3 66 t = buf + cur_len;
67
68 for (i = 1; i <= 5; i++)
69 {
70 if(parc < i + 1)
71 break;
72
73 if((target_p = find_person(parv[i])) != NULL)
74 {
75 /*
76 * Show real IP for USERHOST on yourself.
77 * This is needed for things like mIRC, which do a server-based
78 * lookup (USERHOST) to figure out what the clients' local IP
79 * is. Useful for things like NAT, and dynamic dial-up users.
80 */
81 if(MyClient(target_p) && (target_p == source_p))
82 {
581fa5c4 83 rl = rb_sprintf(response, "%s%s=%c%s@%s ",
212380e3 84 target_p->name,
85 IsOper(target_p) ? "*" : "",
c387fc41 86 (target_p->user->away) ? '-' : '+',
212380e3 87 target_p->username,
88 target_p->sockhost);
89 }
90 else
91 {
581fa5c4 92 rl = rb_sprintf(response, "%s%s=%c%s@%s ",
212380e3 93 target_p->name,
94 IsOper(target_p) ? "*" : "",
c387fc41 95 (target_p->user->away) ? '-' : '+',
212380e3 96 target_p->username, target_p->host);
97 }
98
99 if((rl + cur_len) < (BUFSIZE - 10))
100 {
581fa5c4 101 rb_sprintf(t, "%s", response);
212380e3 102 t += rl;
103 cur_len += rl;
104 }
105 else
106 break;
107 }
108 }
109
110 sendto_one(source_p, "%s", buf);
111
112 return 0;
113}