Author: Bleep <tomh@inxpress.net>
[ircu2.10.12-pk.git] / ircd / m_who.c
1 /*
2  * IRC - Internet Relay Chat, ircd/m_who.c
3  * Copyright (C) 1990 Jarkko Oikarinen and
4  *                    University of Oulu, Computing Center
5  *
6  * See file AUTHORS in IRC package for additional names of
7  * the programmers.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 1, or (at your option)
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *
23  * $Id$
24  */
25
26 /*
27  * m_functions execute protocol messages on this server:
28  *
29  *    cptr    is always NON-NULL, pointing to a *LOCAL* client
30  *            structure (with an open socket connected!). This
31  *            identifies the physical socket where the message
32  *            originated (or which caused the m_function to be
33  *            executed--some m_functions may call others...).
34  *
35  *    sptr    is the source of the message, defined by the
36  *            prefix part of the message if present. If not
37  *            or prefix not found, then sptr==cptr.
38  *
39  *            (!IsServer(cptr)) => (cptr == sptr), because
40  *            prefixes are taken *only* from servers...
41  *
42  *            (IsServer(cptr))
43  *                    (sptr == cptr) => the message didn't
44  *                    have the prefix.
45  *
46  *                    (sptr != cptr && IsServer(sptr) means
47  *                    the prefix specified servername. (?)
48  *
49  *                    (sptr != cptr && !IsServer(sptr) means
50  *                    that message originated from a remote
51  *                    user (not local).
52  *
53  *            combining
54  *
55  *            (!IsServer(sptr)) means that, sptr can safely
56  *            taken as defining the target structure of the
57  *            message in this server.
58  *
59  *    *Always* true (if 'parse' and others are working correct):
60  *
61  *    1)      sptr->from == cptr  (note: cptr->from == cptr)
62  *
63  *    2)      MyConnect(sptr) <=> sptr == cptr (e.g. sptr
64  *            *cannot* be a local connection, unless it's
65  *            actually cptr!). [MyConnect(x) should probably
66  *            be defined as (x == x->from) --msa ]
67  *
68  *    parc    number of variable parameter strings (if zero,
69  *            parv is allowed to be NULL)
70  *
71  *    parv    a NULL terminated list of parameter pointers,
72  *
73  *                    parv[0], sender (prefix string), if not present
74  *                            this points to an empty string.
75  *                    parv[1]...parv[parc-1]
76  *                            pointers to additional parameters
77  *                    parv[parc] == NULL, *always*
78  *
79  *            note:   it is guaranteed that parv[0]..parv[parc-1] are all
80  *                    non-NULL pointers.
81  */
82 #if 0
83 /*
84  * No need to include handlers.h here the signatures must match
85  * and we don't need to force a rebuild of all the handlers everytime
86  * we add a new one to the list. --Bleep
87  */
88 #include "handlers.h"
89 #endif /* 0 */
90 #include "channel.h"
91 #include "client.h"
92 #include "hash.h"
93 #include "ircd.h"
94 #include "ircd_chattr.h"
95 #include "ircd_log.h"
96 #include "ircd_reply.h"
97 #include "ircd_string.h"
98 #include "match.h"
99 #include "numeric.h"
100 #include "numnicks.h"
101 #include "send.h"
102 #include "support.h"
103 #include "whocmds.h"
104
105
106 #include <assert.h>
107 #include <string.h>
108
109
110 /*
111  * A little spin-marking utility to tell us wich clients we have already
112  * processed and wich not
113  */
114 static int who_marker = 0;
115 static void move_marker(void)
116 {
117   if (!++who_marker)
118   {
119     struct Client *cptr = GlobalClientList;
120     while (cptr)
121     {
122       cptr->marker = 0;
123       cptr = cptr->next;
124     }
125     who_marker++;
126   }
127 }
128
129 #define CheckMark(x, y) ((x == y) ? 0 : (x = y))
130 #define Process(cptr) CheckMark(cptr->marker, who_marker)
131
132 /*
133  * m_who - generic message handler
134  *
135  *  parv[0] = sender prefix
136  *  parv[1] = nickname mask list
137  *  parv[2] = additional selection flag, only 'o' for now.
138  *            and %flags to specify what fields to output
139  *            plus a ,querytype if the t flag is specified
140  *            so the final thing will be like o%tnchu,777
141  *  parv[3] = _optional_ parameter that overrides parv[1]
142  *            This can be used as "/quote who foo % :The Black Hacker
143  *            to find me, parv[3] _can_ contain spaces !.
144  */
145 int m_who(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
146 {
147   char *mask;           /* The mask we are looking for              */
148   char ch;                      /* Scratch char register                    */
149   struct Channel *chptr;                /* Channel to show                          */
150   struct Client *acptr;         /* Client to show                           */
151
152   int bitsel;                   /* Mask of selectors to apply               */
153   int matchsel;                 /* Wich fields the match should apply on    */
154   int counter;                  /* Query size counter,
155                                    initially used to count fields           */
156   int commas;                   /* Does our mask contain any comma ?
157                                    If so is a list..                        */
158   int fields;                   /* Mask of fields to show                   */
159   int isthere = 0;              /* When this set the user is member of chptr */
160   char *nick;                   /* Single element extracted from
161                                    the mask list                            */
162   char *p;                      /* Scratch char pointer                     */
163   char *qrt;                    /* Pointer to the query type                */
164   static char mymask[512];      /* To save the mask before corrupting it    */
165
166   /* Let's find where is our mask, and if actually contains something */
167   mask = ((parc > 1) ? parv[1] : 0);
168   if (parc > 3 && parv[3])
169     mask = parv[3];
170   if (mask && ((mask[0] == '\0') ||
171       (mask[1] == '\0' && ((mask[0] == '0') || (mask[0] == '*')))))
172     mask = 0;
173
174   /* Evaluate the flags now, we consider the second parameter 
175      as "matchFlags%fieldsToInclude,querytype"           */
176   bitsel = fields = counter = matchsel = 0;
177   qrt = 0;
178   if (parc > 2 && parv[2] && *parv[2])
179   {
180     p = parv[2];
181     while (((ch = *(p++))) && (ch != '%') && (ch != ','))
182       switch (ch)
183       {
184         case 'o':
185         case 'O':
186           bitsel |= WHOSELECT_OPER;
187           continue;
188         case 'x':
189         case 'X':
190           bitsel |= WHOSELECT_EXTRA;
191 #ifdef WPATH
192           if (IsAnOper(sptr))
193             write_log(WPATH, "# " TIME_T_FMT " %s!%s@%s WHO %s %s\n",
194                 CurrentTime, sptr->name, sptr->user->username, sptr->user->host,
195                 (BadPtr(parv[3]) ? parv[1] : parv[3]), parv[2]);
196 #endif /* WPATH */
197           continue;
198         case 'n':
199         case 'N':
200           matchsel |= WHO_FIELD_NIC;
201           continue;
202         case 'u':
203         case 'U':
204           matchsel |= WHO_FIELD_UID;
205           continue;
206         case 'h':
207         case 'H':
208           matchsel |= WHO_FIELD_HOS;
209           continue;
210         case 'i':
211         case 'I':
212           matchsel |= WHO_FIELD_NIP;
213           continue;
214         case 's':
215         case 'S':
216           matchsel |= WHO_FIELD_SER;
217           continue;
218         case 'r':
219         case 'R':
220           matchsel |= WHO_FIELD_REN;
221           continue;
222       }
223     if (ch == '%')
224       while ((ch = *p++) && (ch != ','))
225       {
226         counter++;
227         switch (ch)
228         {
229           case 'c':
230           case 'C':
231             fields |= WHO_FIELD_CHA;
232             break;
233           case 'd':
234           case 'D':
235             fields |= WHO_FIELD_DIS;
236             break;
237           case 'f':
238           case 'F':
239             fields |= WHO_FIELD_FLA;
240             break;
241           case 'h':
242           case 'H':
243             fields |= WHO_FIELD_HOS;
244             break;
245           case 'i':
246           case 'I':
247             fields |= WHO_FIELD_NIP;
248             break;
249           case 'n':
250           case 'N':
251             fields |= WHO_FIELD_NIC;
252             break;
253           case 'r':
254           case 'R':
255             fields |= WHO_FIELD_REN;
256             break;
257           case 's':
258           case 'S':
259             fields |= WHO_FIELD_SER;
260             break;
261           case 't':
262           case 'T':
263             fields |= WHO_FIELD_QTY;
264             break;
265           case 'u':
266           case 'U':
267             fields |= WHO_FIELD_UID;
268             break;
269           default:
270             break;
271         }
272       };
273     if (ch)
274       qrt = p;
275   }
276
277   if (!matchsel)
278     matchsel = WHO_FIELD_DEF;
279   if (!fields)
280     counter = 7;
281
282   if (qrt && (fields & WHO_FIELD_QTY))
283   {
284     p = qrt;
285     if (!((*p > '9') || (*p < '0')))
286       p++;
287     if (!((*p > '9') || (*p < '0')))
288       p++;
289     if (!((*p > '9') || (*p < '0')))
290       p++;
291     *p = '\0';
292   }
293   else
294     qrt = 0;
295
296   /* I'd love to add also a check on the number of matches fields per time */
297   counter = (2048 / (counter + 4));
298   if (mask && (strlen(mask) > 510))
299     mask[510] = '\0';
300   move_marker();
301   commas = (mask && strchr(mask, ','));
302
303   /* First treat mask as a list of plain nicks/channels */
304   if (mask)
305   {
306     strcpy(mymask, mask);
307     for (p = 0, nick = ircd_strtok(&p, mymask, ","); nick;
308         nick = ircd_strtok(&p, 0, ","))
309     {
310       if (IsChannelName(nick) && (chptr = FindChannel(nick)))
311       {
312         isthere = (find_channel_member(sptr, chptr) != 0);
313         if (isthere || SEE_CHANNEL(sptr, chptr, bitsel))
314         {
315           struct Membership* member;
316           for (member = chptr->members; member; member = member->next_member)
317           {
318             acptr = member->user;
319             if ((bitsel & WHOSELECT_OPER) && !(IsAnOper(acptr)))
320               continue;
321             if ((acptr != sptr) && (member->status & CHFL_ZOMBIE))
322               continue;
323             if (!(isthere || (SEE_USER(sptr, acptr, bitsel))))
324               continue;
325             if (!Process(acptr))        /* This can't be moved before other checks */
326               continue;
327             if (!(isthere || (SHOW_MORE(sptr, counter))))
328               break;
329             do_who(sptr, acptr, chptr, fields, qrt);
330           }
331         }
332       }
333       else
334       {
335         if ((acptr = FindUser(nick)) &&
336             ((!(bitsel & WHOSELECT_OPER)) || IsAnOper(acptr)) &&
337             Process(acptr) && SHOW_MORE(sptr, counter))
338         {
339           do_who(sptr, acptr, 0, fields, qrt);
340         }
341       }
342     }
343   }
344
345   /* If we didn't have any comma in the mask treat it as a
346      real mask and try to match all relevant fields */
347   if (!(commas || (counter < 1)))
348   {
349     int minlen, cset;
350     static struct in_mask imask;
351     if (mask)
352     {
353       matchcomp(mymask, &minlen, &cset, mask);
354       if (matchcompIP(&imask, mask))
355         matchsel &= ~WHO_FIELD_NIP;
356       if ((minlen > NICKLEN) || !(cset & NTL_IRCNK))
357         matchsel &= ~WHO_FIELD_NIC;
358       if ((matchsel & WHO_FIELD_SER) &&
359           ((minlen > HOSTLEN) || (!(cset & NTL_IRCHN))
360           || (!markMatchexServer(mymask, minlen))))
361         matchsel &= ~WHO_FIELD_SER;
362       if ((minlen > USERLEN) || !(cset & NTL_IRCUI))
363         matchsel &= ~WHO_FIELD_UID;
364       if ((minlen > HOSTLEN) || !(cset & NTL_IRCHN))
365         matchsel &= ~WHO_FIELD_HOS;
366     }
367
368     /* First of all loop through the clients in common channels */
369     if ((!(counter < 1)) && matchsel) {
370       struct Membership* member;
371       struct Membership* chan;
372       for (chan = sptr->user->channel; chan; chan = chan->next_channel) {
373         chptr = chan->channel;
374         for (member = chptr->members; member; member = member->next_member)
375         {
376           acptr = member->user;
377           if (!(IsUser(acptr) && Process(acptr)))
378             continue;           /* Now Process() is at the beginning, if we fail
379                                    we'll never have to show this acptr in this query */
380           if ((bitsel & WHOSELECT_OPER) && !IsAnOper(acptr))
381             continue;
382           if ((mask) &&
383               ((!(matchsel & WHO_FIELD_NIC))
384               || matchexec(acptr->name, mymask, minlen))
385               && ((!(matchsel & WHO_FIELD_UID))
386               || matchexec(acptr->user->username, mymask, minlen))
387               && ((!(matchsel & WHO_FIELD_SER))
388               || (!(acptr->user->server->flags & FLAGS_MAP)))
389               && ((!(matchsel & WHO_FIELD_HOS))
390               || matchexec(acptr->user->host, mymask, minlen))
391               && ((!(matchsel & WHO_FIELD_REN))
392               || matchexec(acptr->info, mymask, minlen))
393               && ((!(matchsel & WHO_FIELD_NIP))
394               || ((((acptr->ip.s_addr & imask.mask.s_addr) !=
395               imask.bits.s_addr)) || (imask.fall
396               && matchexec(ircd_ntoa((const char*) &acptr->ip), mymask, minlen)))))
397             continue;
398           if (!SHOW_MORE(sptr, counter))
399             break;
400           do_who(sptr, acptr, chptr, fields, qrt);
401         }
402       }
403     }
404     /* Loop through all clients :-\, if we still have something to match to 
405        and we can show more clients */
406     if ((!(counter < 1)) && matchsel)
407       for (acptr = me.prev; acptr; acptr = acptr->prev)
408       {
409         if (!(IsUser(acptr) && Process(acptr)))
410           continue;
411         if ((bitsel & WHOSELECT_OPER) && !IsAnOper(acptr))
412           continue;
413         if (!(SEE_USER(sptr, acptr, bitsel)))
414           continue;
415         if ((mask) &&
416             ((!(matchsel & WHO_FIELD_NIC))
417             || matchexec(acptr->name, mymask, minlen))
418             && ((!(matchsel & WHO_FIELD_UID))
419             || matchexec(acptr->user->username, mymask, minlen))
420             && ((!(matchsel & WHO_FIELD_SER))
421             || (!(acptr->user->server->flags & FLAGS_MAP)))
422             && ((!(matchsel & WHO_FIELD_HOS))
423             || matchexec(acptr->user->host, mymask, minlen))
424             && ((!(matchsel & WHO_FIELD_REN))
425             || matchexec(acptr->info, mymask, minlen))
426             && ((!(matchsel & WHO_FIELD_NIP))
427             || ((((acptr->ip.s_addr & imask.mask.s_addr) != imask.bits.s_addr))
428             || (imask.fall
429             && matchexec(ircd_ntoa((const char*) &acptr->ip), mymask, minlen)))))
430           continue;
431         if (!SHOW_MORE(sptr, counter))
432           break;
433         do_who(sptr, acptr, 0, fields, qrt);
434       }
435   }
436
437   /* Make a clean mask suitable to be sent in the "end of" */
438   if (mask && (p = strchr(mask, ' ')))
439     *p = '\0';
440   sendto_one(sptr, rpl_str(RPL_ENDOFWHO),
441       me.name, parv[0], BadPtr(mask) ? "*" : mask);
442
443   /* Notify the user if we decided that his query was too long */
444   if (counter < 0)
445     sendto_one(sptr, err_str(ERR_QUERYTOOLONG), me.name, parv[0], "WHO");
446
447   return 0;
448 }
449
450
451 #if 0
452 /*
453  *  m_who
454  *
455  *  parv[0] = sender prefix
456  *  parv[1] = nickname mask list
457  *  parv[2] = additional selection flag, only 'o' for now.
458  *            and %flags to specify what fields to output
459  *            plus a ,querytype if the t flag is specified
460  *            so the final thing will be like o%tnchu,777
461  *  parv[3] = _optional_ parameter that overrides parv[1]
462  *            This can be used as "/quote who foo % :The Black Hacker
463  *            to find me, parv[3] _can_ contain spaces !.
464  */
465
466 int m_who(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
467 {
468   char *mask;           /* The mask we are looking for              */
469   char ch;                      /* Scratch char register                    */
470   struct Channel *chptr;                /* Channel to show                          */
471   struct Client *acptr;         /* Client to show                           */
472
473   int bitsel;                   /* Mask of selectors to apply               */
474   int matchsel;                 /* Wich fields the match should apply on    */
475   int counter;                  /* Query size counter,
476                                    initially used to count fields           */
477   int commas;                   /* Does our mask contain any comma ?
478                                    If so is a list..                        */
479   int fields;                   /* Mask of fields to show                   */
480   int isthere = 0;              /* When this set the user is member of chptr */
481   char *nick;                   /* Single element extracted from
482                                    the mask list                            */
483   char *p;                      /* Scratch char pointer                     */
484   char *qrt;                    /* Pointer to the query type                */
485   static char mymask[512];      /* To save the mask before corrupting it    */
486
487   /* Let's find where is our mask, and if actually contains something */
488   mask = ((parc > 1) ? parv[1] : 0);
489   if (parc > 3 && parv[3])
490     mask = parv[3];
491   if (mask && ((mask[0] == '\0') ||
492       (mask[1] == '\0' && ((mask[0] == '0') || (mask[0] == '*')))))
493     mask = 0;
494
495   /* Evaluate the flags now, we consider the second parameter 
496      as "matchFlags%fieldsToInclude,querytype"           */
497   bitsel = fields = counter = matchsel = 0;
498   qrt = 0;
499   if (parc > 2 && parv[2] && *parv[2])
500   {
501     p = parv[2];
502     while (((ch = *(p++))) && (ch != '%') && (ch != ','))
503       switch (ch)
504       {
505         case 'o':
506         case 'O':
507           bitsel |= WHOSELECT_OPER;
508           continue;
509         case 'x':
510         case 'X':
511           bitsel |= WHOSELECT_EXTRA;
512 #ifdef WPATH
513           if (IsAnOper(sptr))
514             write_log(WPATH, "# " TIME_T_FMT " %s!%s@%s WHO %s %s\n",
515                 CurrentTime, sptr->name, sptr->user->username, sptr->user->host,
516                 (BadPtr(parv[3]) ? parv[1] : parv[3]), parv[2]);
517 #endif /* WPATH */
518           continue;
519         case 'n':
520         case 'N':
521           matchsel |= WHO_FIELD_NIC;
522           continue;
523         case 'u':
524         case 'U':
525           matchsel |= WHO_FIELD_UID;
526           continue;
527         case 'h':
528         case 'H':
529           matchsel |= WHO_FIELD_HOS;
530           continue;
531         case 'i':
532         case 'I':
533           matchsel |= WHO_FIELD_NIP;
534           continue;
535         case 's':
536         case 'S':
537           matchsel |= WHO_FIELD_SER;
538           continue;
539         case 'r':
540         case 'R':
541           matchsel |= WHO_FIELD_REN;
542           continue;
543       }
544     if (ch == '%')
545       while ((ch = *p++) && (ch != ','))
546       {
547         counter++;
548         switch (ch)
549         {
550           case 'c':
551           case 'C':
552             fields |= WHO_FIELD_CHA;
553             break;
554           case 'd':
555           case 'D':
556             fields |= WHO_FIELD_DIS;
557             break;
558           case 'f':
559           case 'F':
560             fields |= WHO_FIELD_FLA;
561             break;
562           case 'h':
563           case 'H':
564             fields |= WHO_FIELD_HOS;
565             break;
566           case 'i':
567           case 'I':
568             fields |= WHO_FIELD_NIP;
569             break;
570           case 'n':
571           case 'N':
572             fields |= WHO_FIELD_NIC;
573             break;
574           case 'r':
575           case 'R':
576             fields |= WHO_FIELD_REN;
577             break;
578           case 's':
579           case 'S':
580             fields |= WHO_FIELD_SER;
581             break;
582           case 't':
583           case 'T':
584             fields |= WHO_FIELD_QTY;
585             break;
586           case 'u':
587           case 'U':
588             fields |= WHO_FIELD_UID;
589             break;
590           default:
591             break;
592         }
593       };
594     if (ch)
595       qrt = p;
596   }
597
598   if (!matchsel)
599     matchsel = WHO_FIELD_DEF;
600   if (!fields)
601     counter = 7;
602
603   if (qrt && (fields & WHO_FIELD_QTY))
604   {
605     p = qrt;
606     if (!((*p > '9') || (*p < '0')))
607       p++;
608     if (!((*p > '9') || (*p < '0')))
609       p++;
610     if (!((*p > '9') || (*p < '0')))
611       p++;
612     *p = '\0';
613   }
614   else
615     qrt = 0;
616
617   /* I'd love to add also a check on the number of matches fields per time */
618   counter = (2048 / (counter + 4));
619   if (mask && (strlen(mask) > 510))
620     mask[510] = '\0';
621   move_marker();
622   commas = (mask && strchr(mask, ','));
623
624   /* First treat mask as a list of plain nicks/channels */
625   if (mask)
626   {
627     strcpy(mymask, mask);
628     for (p = 0, nick = ircd_strtok(&p, mymask, ","); nick;
629         nick = ircd_strtok(&p, 0, ","))
630     {
631       if (IsChannelName(nick) && (chptr = FindChannel(nick)))
632       {
633         isthere = (find_channel_member(sptr, chptr) != 0);
634         if (isthere || SEE_CHANNEL(sptr, chptr, bitsel))
635         {
636           struct Membership* member;
637           for (member = chptr->members; member; member = member->next_member)
638           {
639             acptr = member->user;
640             if ((bitsel & WHOSELECT_OPER) && !(IsAnOper(acptr)))
641               continue;
642             if ((acptr != sptr) && (member->status & CHFL_ZOMBIE))
643               continue;
644             if (!(isthere || (SEE_USER(sptr, acptr, bitsel))))
645               continue;
646             if (!Process(acptr))        /* This can't be moved before other checks */
647               continue;
648             if (!(isthere || (SHOW_MORE(sptr, counter))))
649               break;
650             do_who(sptr, acptr, chptr, fields, qrt);
651           }
652         }
653       }
654       else
655       {
656         if ((acptr = FindUser(nick)) &&
657             ((!(bitsel & WHOSELECT_OPER)) || IsAnOper(acptr)) &&
658             Process(acptr) && SHOW_MORE(sptr, counter))
659         {
660           do_who(sptr, acptr, 0, fields, qrt);
661         }
662       }
663     }
664   }
665
666   /* If we didn't have any comma in the mask treat it as a
667      real mask and try to match all relevant fields */
668   if (!(commas || (counter < 1)))
669   {
670     int minlen, cset;
671     static struct in_mask imask;
672     if (mask)
673     {
674       matchcomp(mymask, &minlen, &cset, mask);
675       if (matchcompIP(&imask, mask))
676         matchsel &= ~WHO_FIELD_NIP;
677       if ((minlen > NICKLEN) || !(cset & NTL_IRCNK))
678         matchsel &= ~WHO_FIELD_NIC;
679       if ((matchsel & WHO_FIELD_SER) &&
680           ((minlen > HOSTLEN) || (!(cset & NTL_IRCHN))
681           || (!markMatchexServer(mymask, minlen))))
682         matchsel &= ~WHO_FIELD_SER;
683       if ((minlen > USERLEN) || !(cset & NTL_IRCUI))
684         matchsel &= ~WHO_FIELD_UID;
685       if ((minlen > HOSTLEN) || !(cset & NTL_IRCHN))
686         matchsel &= ~WHO_FIELD_HOS;
687     }
688
689     /* First of all loop through the clients in common channels */
690     if ((!(counter < 1)) && matchsel) {
691       struct Membership* member;
692       struct Membership* chan;
693       for (chan = sptr->user->channel; chan; chan = chan->next_channel) {
694         chptr = chan->channel;
695         for (member = chptr->members; member; member = member->next_member)
696         {
697           acptr = member->user;
698           if (!(IsUser(acptr) && Process(acptr)))
699             continue;           /* Now Process() is at the beginning, if we fail
700                                    we'll never have to show this acptr in this query */
701           if ((bitsel & WHOSELECT_OPER) && !IsAnOper(acptr))
702             continue;
703           if ((mask) &&
704               ((!(matchsel & WHO_FIELD_NIC))
705               || matchexec(acptr->name, mymask, minlen))
706               && ((!(matchsel & WHO_FIELD_UID))
707               || matchexec(acptr->user->username, mymask, minlen))
708               && ((!(matchsel & WHO_FIELD_SER))
709               || (!(acptr->user->server->flags & FLAGS_MAP)))
710               && ((!(matchsel & WHO_FIELD_HOS))
711               || matchexec(acptr->user->host, mymask, minlen))
712               && ((!(matchsel & WHO_FIELD_REN))
713               || matchexec(acptr->info, mymask, minlen))
714               && ((!(matchsel & WHO_FIELD_NIP))
715               || ((((acptr->ip.s_addr & imask.mask.s_addr) !=
716               imask.bits.s_addr)) || (imask.fall
717               && matchexec(inet_ntoa(acptr->ip), mymask, minlen)))))
718             continue;
719           if (!SHOW_MORE(sptr, counter))
720             break;
721           do_who(sptr, acptr, chptr, fields, qrt);
722         }
723       }
724     }
725     /* Loop through all clients :-\, if we still have something to match to 
726        and we can show more clients */
727     if ((!(counter < 1)) && matchsel)
728       for (acptr = me.prev; acptr; acptr = acptr->prev)
729       {
730         if (!(IsUser(acptr) && Process(acptr)))
731           continue;
732         if ((bitsel & WHOSELECT_OPER) && !IsAnOper(acptr))
733           continue;
734         if (!(SEE_USER(sptr, acptr, bitsel)))
735           continue;
736         if ((mask) &&
737             ((!(matchsel & WHO_FIELD_NIC))
738             || matchexec(acptr->name, mymask, minlen))
739             && ((!(matchsel & WHO_FIELD_UID))
740             || matchexec(acptr->user->username, mymask, minlen))
741             && ((!(matchsel & WHO_FIELD_SER))
742             || (!(acptr->user->server->flags & FLAGS_MAP)))
743             && ((!(matchsel & WHO_FIELD_HOS))
744             || matchexec(acptr->user->host, mymask, minlen))
745             && ((!(matchsel & WHO_FIELD_REN))
746             || matchexec(acptr->info, mymask, minlen))
747             && ((!(matchsel & WHO_FIELD_NIP))
748             || ((((acptr->ip.s_addr & imask.mask.s_addr) != imask.bits.s_addr))
749             || (imask.fall
750             && matchexec(inet_ntoa(acptr->ip), mymask, minlen)))))
751           continue;
752         if (!SHOW_MORE(sptr, counter))
753           break;
754         do_who(sptr, acptr, 0, fields, qrt);
755       }
756   }
757
758   /* Make a clean mask suitable to be sent in the "end of" */
759   if (mask && (p = strchr(mask, ' ')))
760     *p = '\0';
761   sendto_one(sptr, rpl_str(RPL_ENDOFWHO),
762       me.name, parv[0], BadPtr(mask) ? "*" : mask);
763
764   /* Notify the user if we decided that his query was too long */
765   if (counter < 0)
766     sendto_one(sptr, err_str(ERR_QUERYTOOLONG), me.name, parv[0], "WHO");
767
768   return 0;
769 }
770 #endif /* 0 */
771