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