ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_who.c
Revision: 314
Committed: Fri Dec 23 10:59:55 2005 UTC (20 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 10603 byte(s)
Log Message:
- Don't pace "WHO #somechan" and "WHO *" as this breaks several clients

File Contents

# User Rev Content
1 adx 30 /*
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 knight 31 * $Id$
23 adx 30 */
24     #include "stdinc.h"
25     #include "common.h"
26     #include "handlers.h"
27     #include "client.h"
28     #include "channel.h"
29     #include "channel_mode.h"
30     #include "hash.h"
31     #include "ircd.h"
32     #include "numeric.h"
33     #include "s_serv.h"
34     #include "send.h"
35     #include "s_conf.h"
36     #include "msg.h"
37     #include "parse.h"
38     #include "modules.h"
39    
40 adx 270 static time_t last_used = 0;
41    
42 adx 30 static void m_who(struct Client *, struct Client *, int, char **);
43     static void ms_who(struct Client *, struct Client *, int, char **);
44    
45     struct Message who_msgtab = {
46     "WHO", 0, 0, 2, 0, MFLG_SLOW, 0,
47     {m_unregistered, m_who, ms_who, m_ignore, m_who, m_ignore}
48     };
49    
50     #ifndef STATIC_MODULES
51     void
52     _modinit(void)
53     {
54     mod_add_cmd(&who_msgtab);
55     }
56    
57     void
58     _moddeinit(void)
59     {
60     mod_del_cmd(&who_msgtab);
61     }
62    
63 knight 31 const char *_version = "$Revision$";
64 adx 30 #endif
65    
66 michael 314 static void who_global(struct Client *, char *, int);
67     static void do_who(struct Client *, struct Client *,
68     const char *, const char *);
69     static void do_who_on_channel(struct Client *, struct Channel *, const char *,
70     int, int);
71 adx 30
72     /*
73     ** m_who
74     ** parv[0] = sender prefix
75     ** parv[1] = nickname mask list
76     ** parv[2] = additional selection flag, only 'o' for now.
77     */
78     static void
79     m_who(struct Client *client_p, struct Client *source_p,
80     int parc, char *parv[])
81     {
82     struct Client *target_p;
83     char *mask = parv[1];
84     dlink_node *lp;
85     int server_oper = parc > 2 ? (*parv[2] == 'o') : 0; /* Show OPERS only */
86     struct Channel *chptr;
87     const char *from, *to;
88    
89     if (IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
90     {
91     from = me.id;
92     to = source_p->id;
93     }
94     else
95     {
96     from = me.name;
97     to = source_p->name;
98     }
99    
100     /* See if mask is there, collapse it or return if not there */
101     if (mask == NULL || !*mask)
102     {
103     who_global(source_p, mask, server_oper);
104     sendto_one(source_p, form_str(RPL_ENDOFWHO),
105     from, to, "*");
106     return;
107     }
108    
109     /* mask isn't NULL at this point. repeat after me... -db */
110     collapse(mask);
111    
112     /* '/who *' */
113     if (mask[0] == '*' && !mask[1])
114     {
115     if ((lp = source_p->channel.head) != NULL)
116     {
117     struct Channel *mychannel = ((struct Membership *)lp->data)->chptr;
118     do_who_on_channel(source_p, mychannel, mychannel->chname, YES,
119     server_oper);
120     }
121    
122     sendto_one(source_p, form_str(RPL_ENDOFWHO), from, to, "*");
123     return;
124     }
125    
126     /* '/who #some_channel' */
127     if (IsChanPrefix(*mask))
128     {
129     /* List all users on a given channel */
130     if ((chptr = hash_find_channel(mask)) != NULL)
131     {
132     if (IsMember(source_p, chptr))
133     do_who_on_channel(source_p, chptr, chptr->chname, YES, server_oper);
134     else if (!SecretChannel(chptr))
135     do_who_on_channel(source_p, chptr, chptr->chname, NO, server_oper);
136     }
137    
138     sendto_one(source_p, form_str(RPL_ENDOFWHO),
139     from, to, mask);
140     return;
141     }
142    
143     /* '/who nick' */
144     if (((target_p = find_client(mask)) != NULL) &&
145     IsClient(target_p) && (!server_oper || IsOper(target_p)))
146     {
147     if (IsServer(client_p))
148     client_burst_if_needed(client_p,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 adx 270 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 adx 30 {
218     do_who(source_p, target_p, NULL, "");
219    
220     if (*maxmatches > 0)
221     {
222 adx 270 if (--(*maxmatches) == 0)
223     return;
224 adx 30 }
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 adx 270 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 adx 30 /* 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 adx 270 match(mask, target_p->host) || match(mask, target_p->servptr->name) ||
291     match(mask, target_p->info))
292 adx 30 {
293     do_who(source_p, target_p, NULL, "");
294    
295     if (maxmatches > 0)
296     {
297     if (--maxmatches == 0)
298 adx 270 return;
299 adx 30 }
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 michael 314 dlink_node *ptr = NULL, *ptr_next = NULL;
320 adx 30 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 adx 270 continue;
332 adx 30 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     }
389    
390     /*
391     ** ms_who()
392     ** parv[0] = sender prefix
393     ** parv[1] = nickname mask list
394     ** parv[2] = additional selection flag, only 'o' for now.
395     */
396     static void
397     ms_who(struct Client *client_p, struct Client *source_p,
398     int parc, char *parv[])
399     {
400 michael 314 /*
401     * If it's running as a hub, and linked with lazy links
402 adx 30 * then allow leaf to use normal client m_who()
403     * other wise, ignore it.
404     */
405     if (IsClient(source_p) && ServerInfo.hub &&
406     IsCapable(client_p->from, CAP_LL))
407     m_who(client_p, source_p, parc, parv);
408     }

Properties

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