]>
Commit | Line | Data |
---|---|---|
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 | |
23 | * | |
24 | * $Id: m_userhost.c 254 2005-09-21 23:35:12Z nenolod $ | |
25 | */ | |
26 | ||
27 | #include "stdinc.h" | |
28 | #include "client.h" | |
29 | #include "ircd.h" | |
30 | #include "numeric.h" | |
31 | #include "s_serv.h" | |
32 | #include "send.h" | |
4562c604 | 33 | #include "match.h" |
212380e3 AC |
34 | #include "msg.h" |
35 | #include "parse.h" | |
36 | #include "modules.h" | |
37 | #include "s_conf.h" | |
38 | ||
39 | static char buf[BUFSIZE]; | |
40 | ||
41 | static int m_userhost(struct Client *, struct Client *, int, const char **); | |
42 | ||
43 | struct Message userhost_msgtab = { | |
44 | "USERHOST", 0, 0, 0, MFLG_SLOW, | |
45 | {mg_unreg, {m_userhost, 2}, mg_ignore, mg_ignore, mg_ignore, {m_userhost, 2}} | |
46 | }; | |
47 | ||
48 | mapi_clist_av1 userhost_clist[] = { &userhost_msgtab, NULL }; | |
49 | DECLARE_MODULE_AV1(userhost, NULL, NULL, userhost_clist, NULL, NULL, "$Revision: 254 $"); | |
50 | ||
51 | /* | |
52 | * m_userhost added by Darren Reed 13/8/91 to aid clients and reduce | |
53 | * the need for complicated requests like WHOIS. It returns user/host | |
54 | * information only (no spurious AWAY labels or channels). | |
55 | */ | |
56 | static int | |
57 | m_userhost(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
58 | { | |
59 | struct Client *target_p; | |
60 | char response[NICKLEN * 2 + USERLEN + HOSTLEN + 30]; | |
61 | char *t; | |
62 | int i; /* loop counter */ | |
63 | int cur_len; | |
64 | int rl; | |
65 | ||
3dfaa671 | 66 | cur_len = rb_sprintf(buf, form_str(RPL_USERHOST), me.name, source_p->name, ""); |
212380e3 AC |
67 | t = buf + cur_len; |
68 | ||
69 | for (i = 1; i <= 5; i++) | |
70 | { | |
71 | if(parc < i + 1) | |
72 | break; | |
73 | ||
74 | if((target_p = find_person(parv[i])) != NULL) | |
75 | { | |
76 | /* | |
77 | * Show real IP for USERHOST on yourself. | |
78 | * This is needed for things like mIRC, which do a server-based | |
79 | * lookup (USERHOST) to figure out what the clients' local IP | |
80 | * is. Useful for things like NAT, and dynamic dial-up users. | |
81 | */ | |
82 | if(MyClient(target_p) && (target_p == source_p)) | |
83 | { | |
7cdb0a09 | 84 | rl = rb_sprintf(response, "%s%s=%c%s@%s ", |
212380e3 AC |
85 | target_p->name, |
86 | IsOper(target_p) ? "*" : "", | |
c127b45b | 87 | (target_p->user->away) ? '-' : '+', |
212380e3 AC |
88 | target_p->username, |
89 | target_p->sockhost); | |
90 | } | |
91 | else | |
92 | { | |
7cdb0a09 | 93 | rl = rb_sprintf(response, "%s%s=%c%s@%s ", |
212380e3 AC |
94 | target_p->name, |
95 | IsOper(target_p) ? "*" : "", | |
c127b45b | 96 | (target_p->user->away) ? '-' : '+', |
212380e3 AC |
97 | target_p->username, target_p->host); |
98 | } | |
99 | ||
100 | if((rl + cur_len) < (BUFSIZE - 10)) | |
101 | { | |
7cdb0a09 | 102 | rb_sprintf(t, "%s", response); |
212380e3 AC |
103 | t += rl; |
104 | cur_len += rl; | |
105 | } | |
106 | else | |
107 | break; | |
108 | } | |
109 | } | |
110 | ||
111 | sendto_one(source_p, "%s", buf); | |
112 | ||
113 | return 0; | |
114 | } |