1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* m_names.c: Shows the users who are online. |
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 "tools.h" |
27 |
#include "handlers.h" |
28 |
#include "channel.h" |
29 |
#include "channel_mode.h" |
30 |
#include "client.h" |
31 |
#include "common.h" /* bleah */ |
32 |
#include "hash.h" |
33 |
#include "irc_string.h" |
34 |
#include "sprintf_irc.h" |
35 |
#include "ircd.h" |
36 |
#include "list.h" |
37 |
#include "numeric.h" |
38 |
#include "send.h" |
39 |
#include "s_serv.h" |
40 |
#include "s_conf.h" |
41 |
#include "msg.h" |
42 |
#include "parse.h" |
43 |
#include "modules.h" |
44 |
|
45 |
|
46 |
static void names_all_visible_channels(struct Client *); |
47 |
static void names_non_public_non_secret(struct Client *); |
48 |
|
49 |
static void m_names(struct Client *, struct Client *, int, char *[]); |
50 |
static void ms_names(struct Client *, struct Client *, int, char *[]); |
51 |
|
52 |
struct Message names_msgtab = { |
53 |
"NAMES", 0, 0, 0, 0, MFLG_SLOW, 0, |
54 |
{m_unregistered, m_names, ms_names, m_ignore, m_names, m_ignore} |
55 |
}; |
56 |
|
57 |
#ifndef STATIC_MODULES |
58 |
void |
59 |
_modinit(void) |
60 |
{ |
61 |
mod_add_cmd(&names_msgtab); |
62 |
} |
63 |
|
64 |
void |
65 |
_moddeinit(void) |
66 |
{ |
67 |
mod_del_cmd(&names_msgtab); |
68 |
} |
69 |
|
70 |
const char *_version = "$Revision$"; |
71 |
#endif |
72 |
|
73 |
/************************************************************************ |
74 |
* m_names() - Added by Jto 27 Apr 1989 |
75 |
************************************************************************/ |
76 |
|
77 |
/* |
78 |
** m_names |
79 |
** parv[0] = sender prefix |
80 |
** parv[1] = channel |
81 |
*/ |
82 |
static void |
83 |
m_names(struct Client *client_p, struct Client *source_p, |
84 |
int parc, char *parv[]) |
85 |
{ |
86 |
struct Channel *chptr = NULL; |
87 |
char *s; |
88 |
char *para = parc > 1 ? parv[1] : NULL; |
89 |
|
90 |
if (!EmptyString(para)) |
91 |
{ |
92 |
while (*para == ',') |
93 |
para++; |
94 |
|
95 |
if ((s = strchr(para, ',')) != NULL) |
96 |
*s = '\0'; |
97 |
|
98 |
if (*para == '\0') |
99 |
return; |
100 |
|
101 |
if (!check_channel_name(para)) |
102 |
{ |
103 |
sendto_one(source_p, form_str(ERR_BADCHANNAME), |
104 |
me.name, source_p->name, para); |
105 |
return; |
106 |
} |
107 |
|
108 |
if ((chptr = hash_find_channel(para)) != NULL) |
109 |
channel_member_names(source_p, chptr, 1); |
110 |
else |
111 |
sendto_one(source_p, form_str(RPL_ENDOFNAMES), |
112 |
me.name, source_p->name, para); |
113 |
} |
114 |
else |
115 |
{ |
116 |
names_all_visible_channels(source_p); |
117 |
names_non_public_non_secret(source_p); |
118 |
sendto_one(source_p, form_str(RPL_ENDOFNAMES), |
119 |
me.name, source_p->name, "*"); |
120 |
} |
121 |
} |
122 |
|
123 |
/* names_all_visible_channels() |
124 |
* |
125 |
* inputs - pointer to client struct requesting names |
126 |
* output - none |
127 |
* side effects - lists all visible channels whee! |
128 |
*/ |
129 |
static void |
130 |
names_all_visible_channels(struct Client *source_p) |
131 |
{ |
132 |
dlink_node *ptr; |
133 |
struct Channel *chptr; |
134 |
|
135 |
/* |
136 |
* First, do all visible channels (public and the one user self is) |
137 |
*/ |
138 |
DLINK_FOREACH(ptr, global_channel_list.head) |
139 |
{ |
140 |
chptr = ptr->data; |
141 |
|
142 |
/* Find users on same channel (defined by chptr) */ |
143 |
channel_member_names(source_p, chptr, 0); |
144 |
} |
145 |
} |
146 |
|
147 |
/* names_non_public_non_secret() |
148 |
* |
149 |
* inputs - pointer to client struct requesting names |
150 |
* output - none |
151 |
* side effects - lists all non public non secret channels |
152 |
*/ |
153 |
static void |
154 |
names_non_public_non_secret(struct Client *source_p) |
155 |
{ |
156 |
int mlen, tlen, cur_len; |
157 |
int reply_to_send = NO; |
158 |
int shown_already; |
159 |
dlink_node *gc2ptr, *lp; |
160 |
struct Client *c2ptr; |
161 |
struct Channel *ch3ptr = NULL; |
162 |
char buf[IRCD_BUFSIZE]; |
163 |
char *t; |
164 |
|
165 |
mlen = ircsprintf(buf,form_str(RPL_NAMREPLY), |
166 |
me.name, source_p->name, "*", "*"); |
167 |
cur_len = mlen; |
168 |
t = buf + mlen; |
169 |
|
170 |
/* Second, do all non-public, non-secret channels in one big sweep */ |
171 |
DLINK_FOREACH(gc2ptr, global_client_list.head) |
172 |
{ |
173 |
c2ptr = gc2ptr->data; |
174 |
|
175 |
if (!IsClient(c2ptr) || IsInvisible(c2ptr)) |
176 |
continue; |
177 |
|
178 |
shown_already = NO; |
179 |
|
180 |
/* We already know the user is not +i. If they are on no common |
181 |
* channels with source_p, they have not been shown yet. */ |
182 |
DLINK_FOREACH(lp, c2ptr->channel.head) |
183 |
{ |
184 |
ch3ptr = ((struct Membership *) lp->data)->chptr; |
185 |
|
186 |
if (IsMember(source_p, ch3ptr)) |
187 |
{ |
188 |
shown_already = YES; |
189 |
break; |
190 |
} |
191 |
} |
192 |
|
193 |
if (shown_already) |
194 |
continue; |
195 |
|
196 |
tlen = strlen(c2ptr->name); |
197 |
if (cur_len + tlen + 1 > IRCD_BUFSIZE - 2) |
198 |
{ |
199 |
sendto_one(source_p, "%s", buf); |
200 |
cur_len = mlen; |
201 |
t = buf + mlen; |
202 |
} |
203 |
|
204 |
strcpy(t, c2ptr->name); |
205 |
t += tlen; |
206 |
|
207 |
*t++ = ' '; |
208 |
*t = 0; |
209 |
|
210 |
cur_len += tlen + 1; |
211 |
|
212 |
reply_to_send = YES; |
213 |
} |
214 |
|
215 |
if (reply_to_send) |
216 |
sendto_one(source_p, "%s", buf); |
217 |
} |
218 |
|
219 |
static void |
220 |
ms_names(struct Client *client_p, struct Client *source_p, |
221 |
int parc, char *parv[]) |
222 |
{ |
223 |
/* If its running as a hub, and linked with lazy links |
224 |
* then allow leaf to use normal client m_names() |
225 |
* other wise, ignore it. |
226 |
*/ |
227 |
if (ServerInfo.hub) |
228 |
{ |
229 |
if (!IsCapable(client_p->from, CAP_LL)) |
230 |
return; |
231 |
} |
232 |
|
233 |
if (IsClient(source_p)) |
234 |
m_names(client_p, source_p, parc, parv); |
235 |
} |