ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_who.c
Revision: 1230
Committed: Thu Sep 22 19:41:19 2011 UTC (12 years, 6 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_who.c
File size: 10128 byte(s)
Log Message:
- cleanup module loader. Make module api more flexible

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_who.c: Shows who is on a channel.
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 "common.h"
28 #include "handlers.h"
29 #include "client.h"
30 #include "channel.h"
31 #include "channel_mode.h"
32 #include "hash.h"
33 #include "ircd.h"
34 #include "numeric.h"
35 #include "s_serv.h"
36 #include "send.h"
37 #include "irc_string.h"
38 #include "sprintf_irc.h"
39 #include "s_conf.h"
40 #include "msg.h"
41 #include "parse.h"
42 #include "modules.h"
43
44 static void who_global(struct Client *, char *, int);
45 static void do_who(struct Client *, struct Client *,
46 const char *, const char *);
47 static void do_who_on_channel(struct Client *, struct Channel *,
48 const char *, int, int);
49
50 /*
51 ** m_who
52 ** parv[0] = sender prefix
53 ** parv[1] = nickname mask list
54 ** parv[2] = additional selection flag, only 'o' for now.
55 */
56 static void
57 m_who(struct Client *client_p, struct Client *source_p,
58 int parc, char *parv[])
59 {
60 struct Client *target_p;
61 char *mask = parv[1];
62 dlink_node *lp;
63 int server_oper = parc > 2 ? (*parv[2] == 'o') : 0; /* Show OPERS only */
64 struct Channel *chptr;
65
66 /* See if mask is there, collapse it or return if not there */
67 if (EmptyString(mask))
68 {
69 who_global(source_p, mask, server_oper);
70 sendto_one(source_p, form_str(RPL_ENDOFWHO),
71 me.name, source_p->name, "*");
72 return;
73 }
74
75 /* mask isn't NULL at this point. repeat after me... -db */
76 collapse(mask);
77
78 /* '/who *' */
79 if (mask[0] == '*' && !mask[1])
80 {
81 if ((lp = source_p->channel.head) != NULL)
82 {
83 struct Channel *mychannel = ((struct Membership *)lp->data)->chptr;
84 do_who_on_channel(source_p, mychannel, mychannel->chname, YES,
85 server_oper);
86 }
87
88 sendto_one(source_p, form_str(RPL_ENDOFWHO), me.name, source_p->name, "*");
89 return;
90 }
91
92 /* '/who #some_channel' */
93 if (IsChanPrefix(*mask))
94 {
95 /* List all users on a given channel */
96 if ((chptr = hash_find_channel(mask)) != NULL)
97 {
98 if (IsMember(source_p, chptr))
99 do_who_on_channel(source_p, chptr, chptr->chname, YES, server_oper);
100 else if (!SecretChannel(chptr))
101 do_who_on_channel(source_p, chptr, chptr->chname, NO, server_oper);
102 }
103
104 sendto_one(source_p, form_str(RPL_ENDOFWHO),
105 me.name, source_p->name, mask);
106 return;
107 }
108
109 /* '/who nick' */
110 if (((target_p = hash_find_client(mask)) != NULL) &&
111 IsClient(target_p) && (!server_oper || HasUMode(target_p, UMODE_OPER)))
112 {
113 DLINK_FOREACH(lp, target_p->channel.head)
114 {
115 chptr = ((struct Membership *) lp->data)->chptr;
116 if (PubChannel(chptr) || IsMember(source_p, chptr))
117 break;
118 }
119
120 if (lp != NULL)
121 do_who(source_p, target_p, chptr->chname,
122 get_member_status(lp->data, !!HasCap(source_p, CAP_MULTI_PREFIX)));
123 else
124 do_who(source_p, target_p, NULL, "");
125
126 sendto_one(source_p, form_str(RPL_ENDOFWHO),
127 me.name, source_p->name, mask);
128 return;
129 }
130
131 /* '/who 0' */
132 if (mask[0] == '0' && !mask[1])
133 who_global(source_p, NULL, server_oper);
134 else
135 who_global(source_p, mask, server_oper);
136
137 /* Wasn't a nick, wasn't a channel, wasn't a '*' so ... */
138 sendto_one(source_p, form_str(RPL_ENDOFWHO),
139 me.name, source_p->name, mask);
140 }
141
142 /* who_common_channel
143 * inputs - pointer to client requesting who
144 * - pointer to channel member chain.
145 * - char * mask to match
146 * - int if oper on a server or not
147 * - pointer to int maxmatches
148 * output - NONE
149 * side effects - lists matching clients on specified channel,
150 * marks matched clients.
151 *
152 */
153 static void
154 who_common_channel(struct Client *source_p, struct Channel *chptr,
155 char *mask, int server_oper, int *maxmatches)
156 {
157 dlink_node *ptr;
158 struct Client *target_p;
159
160 DLINK_FOREACH(ptr, chptr->members.head)
161 {
162 target_p = ((struct Membership *)ptr->data)->client_p;
163
164 if (!HasUMode(target_p, UMODE_INVISIBLE) || HasFlag(target_p, FLAGS_MARK))
165 continue;
166
167 if (server_oper && !HasUMode(target_p, UMODE_OPER))
168 continue;
169
170 AddFlag(target_p, FLAGS_MARK);
171
172 assert(target_p->servptr != NULL);
173
174 if ((mask == NULL) ||
175 match(mask, target_p->name) || match(mask, target_p->username) ||
176 match(mask, target_p->host) ||
177 ((!ConfigServerHide.hide_servers || HasUMode(source_p, UMODE_OPER)) &&
178 match(mask, target_p->servptr->name)) ||
179 match(mask, target_p->info))
180 {
181 do_who(source_p, target_p, NULL, "");
182
183 if (*maxmatches > 0)
184 {
185 if (--(*maxmatches) == 0)
186 return;
187 }
188 }
189 }
190 }
191
192 /* who_global()
193 *
194 * inputs - pointer to client requesting who
195 * - char * mask to match
196 * - int if oper on a server or not
197 * output - NONE
198 * side effects - do a global scan of all clients looking for match
199 * this is slightly expensive on EFnet ...
200 */
201 static void
202 who_global(struct Client *source_p, char *mask, int server_oper)
203 {
204 struct Channel *chptr;
205 struct Client *target_p;
206 dlink_node *lp;
207 dlink_node *lp_next;
208 dlink_node *gcptr;
209 dlink_node *gcptr_next;
210 int maxmatches = 500;
211 static time_t last_used = 0;
212
213 if (!HasUMode(source_p, UMODE_OPER))
214 {
215 if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
216 {
217 /* safe enough to give this on a local connect only */
218 sendto_one(source_p, form_str(RPL_LOAD2HI), me.name, source_p->name);
219 return;
220 }
221
222 last_used = CurrentTime;
223 }
224
225 /* first, list all matching invisible clients on common channels */
226 DLINK_FOREACH_SAFE(lp, lp_next, source_p->channel.head)
227 {
228 chptr = ((struct Membership *)lp->data)->chptr;
229 who_common_channel(source_p, chptr, mask, server_oper, &maxmatches);
230 }
231
232 /* second, list all matching visible clients */
233 DLINK_FOREACH_SAFE(gcptr, gcptr_next, global_client_list.head)
234 {
235 target_p = gcptr->data;
236
237 if (!IsClient(target_p))
238 continue;
239
240 if (HasUMode(target_p, UMODE_INVISIBLE))
241 {
242 DelFlag(target_p, FLAGS_MARK);
243 continue;
244 }
245
246 if (server_oper && !HasUMode(target_p, UMODE_OPER))
247 continue;
248
249 assert(target_p->servptr != NULL);
250
251 if (!mask ||
252 match(mask, target_p->name) || match(mask, target_p->username) ||
253 match(mask, target_p->host) || match(mask, target_p->servptr->name) ||
254 match(mask, target_p->info))
255 {
256 do_who(source_p, target_p, NULL, "");
257
258 if (maxmatches > 0)
259 {
260 if (--maxmatches == 0)
261 return;
262 }
263 }
264 }
265 }
266
267 /* do_who_on_channel()
268 *
269 * inputs - pointer to client requesting who
270 * - pointer to channel to do who on
271 * - The "real name" of this channel
272 * - int if source_p is a server oper or not
273 * - int if client is member or not
274 * - int server_op flag
275 * output - NONE
276 * side effects - do a who on given channel
277 */
278 static void
279 do_who_on_channel(struct Client *source_p, struct Channel *chptr,
280 const char *chname, int member, int server_oper)
281 {
282 dlink_node *ptr = NULL, *ptr_next = NULL;
283 struct Client *target_p;
284 struct Membership *ms;
285
286 DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->members.head)
287 {
288 ms = ptr->data;
289 target_p = ms->client_p;
290
291 if (member || !HasUMode(target_p, UMODE_INVISIBLE))
292 {
293 if (server_oper && !HasUMode(target_p, UMODE_OPER))
294 continue;
295 do_who(source_p, target_p, chname, get_member_status(ms, !!HasCap(source_p, CAP_MULTI_PREFIX)));
296 }
297 }
298 }
299
300 /* do_who()
301 *
302 * inputs - pointer to client requesting who
303 * - pointer to client to do who on
304 * - The reported name
305 * - channel flags
306 * output - NONE
307 * side effects - do a who on given person
308 */
309 static void
310 do_who(struct Client *source_p, struct Client *target_p,
311 const char *chname, const char *op_flags)
312 {
313 char status[8]; /* G*#@%+\0 */
314
315 if (HasUMode(source_p, UMODE_OPER))
316 snprintf(status, sizeof(status), "%c%s%s%s", target_p->away ? 'G' : 'H',
317 HasUMode(target_p, UMODE_OPER) ? "*" : "",
318 IsCaptured(target_p) ? "#" : "", op_flags);
319 else
320 snprintf(status, sizeof(status), "%c%s%s", target_p->away ? 'G' : 'H',
321 HasUMode(target_p, UMODE_OPER) ? "*" : "", op_flags);
322
323 if (ConfigServerHide.hide_servers)
324 {
325 sendto_one(source_p, form_str(RPL_WHOREPLY), me.name, source_p->name,
326 (chname) ? (chname) : "*",
327 target_p->username, target_p->host,
328 HasUMode(source_p, UMODE_OPER) ? target_p->servptr->name : "*",
329 target_p->name, status, 0, target_p->info);
330 }
331 else
332 {
333 sendto_one(source_p, form_str(RPL_WHOREPLY), me.name, source_p->name,
334 (chname) ? (chname) : "*", target_p->username,
335 target_p->host, target_p->servptr->name, target_p->name,
336 status, target_p->hopcount, target_p->info);
337 }
338 }
339
340 static struct Message who_msgtab = {
341 "WHO", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
342 {m_unregistered, m_who, m_ignore, m_ignore, m_who, m_ignore}
343 };
344
345 static void
346 module_init(void)
347 {
348 mod_add_cmd(&who_msgtab);
349 }
350
351 static void
352 module_exit(void)
353 {
354 mod_del_cmd(&who_msgtab);
355 }
356
357 struct module module_entry = {
358 .node = { NULL, NULL, NULL },
359 .name = NULL,
360 .version = "$Revision$",
361 .handle = NULL,
362 .modinit = module_init,
363 .modexit = module_exit,
364 .flags = 0
365 };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision