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