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