/[svn]/ircd-hybrid-7.2/modules/m_who.c
ViewVC logotype

Contents of /ircd-hybrid-7.2/modules/m_who.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 885 - (show annotations)
Wed Oct 31 18:09:24 2007 UTC (12 years, 8 months ago) by michael
File MIME type: text/x-chdr
File size: 10105 byte(s)
- Removed LazyLinks in 7.2 to stop people from asking why we keep
  broken code for half a decade. LL will be implemented in a smarter
  fashion in due time

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

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28