]> jfr.im git - solanum.git/blame - modules/m_userhost.c
m_oper: receive ircd-seven-style opernames
[solanum.git] / modules / m_userhost.c
CommitLineData
212380e3
AC
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
212380e3
AC
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"
4562c604 31#include "match.h"
212380e3
AC
32#include "msg.h"
33#include "parse.h"
34#include "modules.h"
35#include "s_conf.h"
1123eefc 36#include "s_newconf.h"
212380e3 37
eeabf33a
EM
38static const char userhost_desc[] =
39 "Provides the USERHOST command to show a user's host";
40
212380e3
AC
41static char buf[BUFSIZE];
42
3c7d6fcc 43static void m_userhost(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
212380e3
AC
44
45struct Message userhost_msgtab = {
7baa37a9 46 "USERHOST", 0, 0, 0, 0,
212380e3
AC
47 {mg_unreg, {m_userhost, 2}, mg_ignore, mg_ignore, mg_ignore, {m_userhost, 2}}
48};
49
50mapi_clist_av1 userhost_clist[] = { &userhost_msgtab, NULL };
eeabf33a 51
4855e957 52DECLARE_MODULE_AV2(userhost, NULL, NULL, userhost_clist, NULL, NULL, NULL, NULL, userhost_desc);
212380e3
AC
53
54/*
55 * m_userhost added by Darren Reed 13/8/91 to aid clients and reduce
56 * the need for complicated requests like WHOIS. It returns user/host
57 * information only (no spurious AWAY labels or channels).
58 */
3c7d6fcc 59static void
428ca87b 60m_userhost(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
61{
62 struct Client *target_p;
63 char response[NICKLEN * 2 + USERLEN + HOSTLEN + 30];
64 char *t;
65 int i; /* loop counter */
66 int cur_len;
67 int rl;
68
5203cba5 69 cur_len = sprintf(buf, form_str(RPL_USERHOST), me.name, source_p->name, "");
212380e3
AC
70 t = buf + cur_len;
71
72 for (i = 1; i <= 5; i++)
73 {
74 if(parc < i + 1)
75 break;
76
77 if((target_p = find_person(parv[i])) != NULL)
78 {
79 /*
80 * Show real IP for USERHOST on yourself.
81 * This is needed for things like mIRC, which do a server-based
82 * lookup (USERHOST) to figure out what the clients' local IP
83 * is. Useful for things like NAT, and dynamic dial-up users.
84 */
85 if(MyClient(target_p) && (target_p == source_p))
86 {
5203cba5 87 rl = sprintf(response, "%s%s=%c%s@%s ",
212380e3 88 target_p->name,
1123eefc 89 SeesOper(target_p, source_p) ? "*" : "",
c127b45b 90 (target_p->user->away) ? '-' : '+',
212380e3
AC
91 target_p->username,
92 target_p->sockhost);
93 }
94 else
95 {
5203cba5 96 rl = sprintf(response, "%s%s=%c%s@%s ",
212380e3 97 target_p->name,
1123eefc 98 SeesOper(target_p, source_p) ? "*" : "",
c127b45b 99 (target_p->user->away) ? '-' : '+',
212380e3
AC
100 target_p->username, target_p->host);
101 }
102
103 if((rl + cur_len) < (BUFSIZE - 10))
104 {
5203cba5 105 sprintf(t, "%s", response);
212380e3
AC
106 t += rl;
107 cur_len += rl;
108 }
109 else
110 break;
111 }
112 }
113
114 sendto_one(source_p, "%s", buf);
212380e3 115}