Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / m_stats.c
1 /*
2  * IRC - Internet Relay Chat, ircd/m_stats.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 /*
91  * XXX - ack!!!
92  */
93 #include "s_stats.h"
94 #include "channel.h"
95 #include "class.h"
96 #include "client.h"
97 #include "gline.h"
98 #include "hash.h"
99 #include "ircd.h"
100 #include "ircd_alloc.h"
101 #include "ircd_chattr.h"
102 #include "ircd_reply.h"
103 #include "ircd_string.h"
104 #include "list.h"
105 #include "listener.h"
106 #include "match.h"
107 #include "motd.h"
108 #include "msg.h"
109 #include "numeric.h"
110 #include "numnicks.h"
111 #include "opercmds.h"
112 #include "s_bsd.h"
113 #include "s_conf.h"
114 #include "s_debug.h"
115 #include "s_misc.h"
116 #include "s_serv.h"
117 #include "s_user.h"
118 #include "send.h"
119 #include "struct.h"
120 #include "userload.h"
121
122 #include <assert.h>
123 #include <stdlib.h>
124 #include <string.h>
125
126
127 int report_klines(struct Client* sptr, char* mask, int limit_query)
128 {
129   int   wilds = 0;
130   int   count = 3;
131   char* user  = 0;
132   char* host;
133   const struct DenyConf* conf;
134
135   if (EmptyString(mask)) {
136     if (limit_query)
137       return need_more_params(sptr, "STATS K");
138     else
139       report_deny_list(sptr);
140     return 1;
141   }
142
143   if (!limit_query) {
144     wilds = string_has_wildcards(mask);
145     count = 1000;
146   }
147
148   if ((host = strchr(mask, '@'))) {
149     user = mask;
150     *host++ = '\0';
151   }
152   else {
153     host = mask;
154   }
155
156   for (conf = conf_get_deny_list(); conf; conf = conf->next) {
157     if ((!wilds && ((user || conf->hostmask) &&
158         !match(conf->hostmask, host) &&
159         (!user || !match(conf->usermask, user)))) ||
160         (wilds && !mmatch(host, conf->hostmask) &&
161         (!user || !mmatch(user, conf->usermask))))
162     {
163       send_reply(sptr, RPL_STATSKLINE, (conf->ip_kill) ? 'k' : 'K',
164                  conf->hostmask, conf->message, conf->usermask);
165       if (--count == 0)
166         return 1;
167     }
168   }
169   /* send_reply(sptr, RPL_ENDOFSTATS, stat); */
170   return 1;
171 }
172
173
174 /*
175  * m_stats - generic message handler
176  *
177  *    parv[0] = sender prefix
178  *    parv[1] = statistics selector (defaults to Message frequency)
179  *    parv[2] = target server (current server defaulted, if omitted)
180  * And 'stats l' and 'stats' L:
181  *    parv[3] = server mask ("*" defaulted, if omitted)
182  * Or for stats p,P:
183  *    parv[3] = port mask (returns p-lines when its port is matched by this)
184  * Or for stats k,K,i and I:
185  *    parv[3] = [user@]host.name  (returns which K/I-lines match this)
186  *           or [user@]host.mask  (returns which K/I-lines are mmatched by this)
187  *              (defaults to old reply if ommitted, when local or Oper)
188  *              A remote mask (something containing wildcards) is only
189  *              allowed for IRC Operators.
190  * Or for stats M:
191  *    parv[3] = time param
192  *    parv[4] = time param 
193  *    (see report_memleak_stats() in runmalloc.c for details)
194  *
195  * This function is getting really ugly. -Ghostwolf
196  */
197 int m_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
198 {
199   struct Message *mptr;
200   struct Client *acptr;
201   struct ConfItem *aconf;
202   char stat = parc > 1 ? parv[1][0] : '\0';
203   const char **infotext = statsinfo;
204   int i;
205
206   if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
207     return 0;
208
209   switch (stat)
210   {
211     case 'L':
212     case 'l':
213     {
214       int doall = 0;
215       int wilds = 0;
216       char *name = "*";
217
218       if (parc > 3 && !EmptyString(parv[3])) {
219         name = parv[3];
220         wilds = string_has_wildcards(name);
221       }
222       else
223         doall = 1;
224       /*
225        * Send info about connections which match, or all if the
226        * mask matches me.name.  Only restrictions are on those who
227        * are invisible not being visible to 'foreigners' who use
228        * a wild card based search to list it.
229        */
230       send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
231                  "SendM SendKBytes RcveM RcveKBytes :Open since");
232       for (i = 0; i <= HighestFd; i++)
233       {
234         if (!(acptr = LocalClientArray[i]))
235           continue;
236         /* Don't return clients when this is a request for `all' */
237         if (doall && IsUser(acptr))
238           continue;
239         /* Don't show invisible people to non opers unless they know the nick */
240         if (IsInvisible(acptr) && (doall || wilds) && !IsAnOper(acptr) && (acptr != sptr))
241           continue;
242         /* Only show the ones that match the given mask - if any */
243         if (!doall && wilds && match(name, acptr->name))
244           continue;
245         /* Skip all that do not match the specific query */
246         if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
247           continue;
248         send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
249                    "%s %u %u %u %u %u :%Tu", (*acptr->name) ? acptr->name : "<unregistered>",
250                    (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
251                    (int)acptr->sendK, (int)acptr->receiveM,
252                    (int)acptr->receiveK, CurrentTime - acptr->firsttime);
253       }
254       break;
255     }
256     case 'C':
257     case 'c':
258       report_configured_links(sptr, CONF_SERVER);
259       break;
260     case 'G':
261     case 'g': /* send glines */
262       gline_stats(sptr);
263       break;
264     case 'H':
265     case 'h':
266       report_configured_links(sptr, CONF_HUB | CONF_LEAF);
267       break;
268     case 'K':
269     case 'k':    /* display CONF_IPKILL as well as CONF_KILL -Kev */
270       if (0 == report_klines(sptr, (parc == 4) ? parv[3] : 0, 0))
271         return 0;
272       break;
273     case 'F':
274     case 'f':
275       report_feature_list(sptr);
276       break;
277     case 'I':
278     case 'i':
279     {
280       int wilds = 0;
281       int count = 1000;
282       char* host;
283
284       if (parc < 4) {
285         report_configured_links(sptr, CONF_CLIENT);
286         break;
287       }
288       if (EmptyString(parv[3]))
289         return need_more_params(sptr, "STATS I");
290
291       host = parv[3];
292       wilds = string_has_wildcards(host);
293
294       for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
295         if (CONF_CLIENT == aconf->status) {
296           if ((!wilds && (!match(aconf->host, host) ||
297               !match(aconf->name, host))) ||
298               (wilds && (!mmatch(host, aconf->host) ||
299               !mmatch(host, aconf->name))))
300           {
301             send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
302                        aconf->port, get_conf_class(aconf));
303             if (--count == 0)
304               break;
305           }
306         }
307       }
308       break;
309     }
310     case 'M':
311 #if !defined(NDEBUG)
312       send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
313                  fda_get_block_count());
314 #endif
315
316 #if 0
317 #ifdef MEMSIZESTATS
318       sendto_one(sptr, rpl_str(RPL_STATMEMTOT), /* XXX DEAD */
319           me.name, parv[0], get_mem_size(), get_alloc_cnt());
320 #endif
321 #ifdef MEMLEAKSTATS
322       report_memleak_stats(sptr, parc, parv);
323 #endif
324 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
325       sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring " /* XXX DEAD */
326           "is not enabled on this server", me.name, parv[0]);
327 #endif
328 #endif /* 0 */
329       break;
330     case 'm':
331       for (mptr = msgtab; mptr->cmd; mptr++)
332         if (mptr->count)
333           send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
334                      mptr->bytes);
335       break;
336     case 'o':
337     case 'O':
338       report_configured_links(sptr, CONF_OPS);
339       break;
340     case 'p':
341     case 'P':
342       /*
343        * show listener ports
344        * show hidden ports to opers, if there are more than 3 parameters,
345        * interpret the fourth parameter as the port number.
346        */ 
347       show_ports(sptr, 0, (parc > 3) ? atoi(parv[3]) : 0, 100);
348       break;
349     case 'R':
350     case 'r':
351 #ifdef DEBUGMODE
352       send_usage(sptr, parv[0]);
353 #endif
354       break;
355     case 'D':
356       report_crule_list(sptr, CRULE_ALL);
357       break;
358     case 'd':
359       report_crule_list(sptr, CRULE_MASK);
360       break;
361     case 't':
362       tstats(sptr, parv[0]);
363       break;
364     case 'T':
365       motd_report(sptr);
366       break;
367     case 'U':
368       report_configured_links(sptr, CONF_UWORLD);
369       break;
370     case 'u':
371     {
372       time_t nowr;
373
374       nowr = CurrentTime - me.since;
375       send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
376                  (nowr / 60) % 60, nowr % 60);
377       send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
378       break;
379     }
380     case 'W':
381     case 'w':
382       calc_load(sptr);
383       break;
384     case 'X':
385     case 'x':
386 #ifdef  DEBUGMODE
387       class_send_meminfo(sptr);
388       send_listinfo(sptr, parv[0]);
389 #endif
390       break;
391     case 'Y':
392     case 'y':
393       report_classes(sptr);
394       break;
395     case 'Z':
396     case 'z':
397       count_memory(sptr, parv[0]);
398       break;
399     default:
400       stat = '*';
401       while (*infotext)
402         sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, *infotext++);
403       break;
404   }
405   send_reply(sptr, RPL_ENDOFSTATS, stat);
406   return 0;
407 }
408
409 /*
410  * ms_stats - server message handler
411  *
412  *    parv[0] = sender prefix
413  *    parv[1] = statistics selector (defaults to Message frequency)
414  *    parv[2] = target server (current server defaulted, if omitted)
415  * And 'stats l' and 'stats' L:
416  *    parv[3] = server mask ("*" defaulted, if omitted)
417  * Or for stats p,P:
418  *    parv[3] = port mask (returns p-lines when its port is matched by this)
419  * Or for stats k,K,i and I:
420  *    parv[3] = [user@]host.name  (returns which K/I-lines match this)
421  *           or [user@]host.mask  (returns which K/I-lines are mmatched by this)
422  *              (defaults to old reply if ommitted, when local or Oper)
423  *              A remote mask (something containing wildcards) is only
424  *              allowed for IRC Operators.
425  * Or for stats M:
426  *    parv[3] = time param
427  *    parv[4] = time param 
428  *    (see report_memleak_stats() in runmalloc.c for details)
429  *
430  * This function is getting really ugly. -Ghostwolf
431  */
432 int ms_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
433 {
434   struct Message *mptr;
435   struct Client *acptr;
436   struct ConfItem *aconf;
437   char stat = parc > 1 ? parv[1][0] : '\0';
438   int i;
439
440   if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
441     return 0;
442
443   switch (stat)
444   {
445     case 'L':
446     case 'l':
447     {
448       int doall = 0;
449       int wilds = 0;
450       char *name = "*";
451
452       if (parc > 3 && !EmptyString(parv[3])) {
453         name = parv[3];
454         wilds = string_has_wildcards(name);
455       }
456       else
457         doall = 1;
458       /*
459        * Send info about connections which match, or all if the
460        * mask matches me.name.  Only restrictions are on those who
461        * are invisible not being visible to 'foreigners' who use
462        * a wild card based search to list it.
463        */
464       send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
465                  "SendM SendKBytes RcveM RcveKBytes :Open since");
466       for (i = 0; i <= HighestFd; i++)
467       {
468         if (!(acptr = LocalClientArray[i]))
469           continue;
470         /* Don't return clients when this is a request for `all' */
471         if (doall && IsUser(acptr))
472           continue;
473         /* Don't show invisible people to unauthorized people when using
474          * wildcards  -- Is this still needed now /stats is oper only ? 
475          * Not here, because ms_stats is specifically a remote command, 
476          * thus the check was removed. -Ghostwolf */
477         /* Only show the ones that match the given mask - if any */
478         if (!doall && wilds && match(name, acptr->name))
479           continue;
480         /* Skip all that do not match the specific query */
481         if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
482           continue;
483         send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
484                    "%s %u %u %u %u %u :%Tu", acptr->name,
485                    (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
486                    (int)acptr->sendK, (int)acptr->receiveM,
487                    (int)acptr->receiveK, CurrentTime - acptr->firsttime);
488       }
489       break;
490     }
491     case 'C':
492     case 'c':
493       report_configured_links(sptr, CONF_SERVER);
494       break;
495     case 'G':
496     case 'g': /* send glines */
497       gline_stats(sptr);
498       break;
499     case 'H':
500     case 'h':
501       report_configured_links(sptr, CONF_HUB | CONF_LEAF);
502       break;
503     case 'K':
504     case 'k':    /* display CONF_IPKILL as well as CONF_KILL -Kev */
505       if (0 == report_klines(sptr, (parc > 3) ? parv[3] : 0, !IsOper(sptr)))
506         return 0;
507       break;
508     case 'F':
509     case 'f':
510       report_feature_list(sptr);
511       break;
512     case 'I':
513     case 'i':
514     {
515       int   wilds = 0;
516       int   count = 3;
517       char* host;
518
519       if (parc < 4 && IsOper(sptr)) {
520         report_configured_links(sptr, CONF_CLIENT);
521         break;
522       }
523       if (parc < 4 || EmptyString(parv[3]))
524         return need_more_params(sptr, "STATS I");
525
526       if (IsOper(sptr)) {
527         wilds = string_has_wildcards(parv[3]);
528         count = 1000;
529       }
530
531       host = parv[3];
532
533       for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
534         if (CONF_CLIENT == aconf->status) {
535           if ((!wilds && (!match(aconf->host, host) ||
536               !match(aconf->name, host))) ||
537               (wilds && (!mmatch(host, aconf->host) ||
538               !mmatch(host, aconf->name))))
539           {
540             send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
541                        aconf->port, get_conf_class(aconf));
542             if (--count == 0)
543               break;
544           }
545         }
546       }
547       break;
548     }
549     case 'M':
550 #if !defined(NDEBUG)
551       send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
552                  fda_get_block_count());
553 #endif
554
555 #if 0
556 #ifdef MEMSIZESTATS
557       sendto_one(sptr, rpl_str(RPL_STATMEMTOT), /* XXX DEAD */
558           me.name, parv[0], get_mem_size(), get_alloc_cnt());
559 #endif
560 #ifdef MEMLEAKSTATS
561       report_memleak_stats(sptr, parc, parv);
562 #endif
563 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
564       sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring " /* XXX DEAD */
565           "is not enabled on this server", me.name, parv[0]);
566 #endif
567 #endif /* 0 */
568       break;
569     case 'm':
570       for (mptr = msgtab; mptr->cmd; mptr++)
571         if (mptr->count)
572           send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
573                      mptr->bytes);
574       break;
575     case 'o':
576     case 'O':
577       report_configured_links(sptr, CONF_OPS);
578       break;
579     case 'p':
580     case 'P':
581       /*
582        * show listener ports
583        * show hidden ports to opers, if there are more than 3 parameters,
584        * interpret the fourth parameter as the port number, limit non-local
585        * or non-oper results to 8 ports.
586        */ 
587       show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0, IsOper(sptr) ? 100 : 8);
588       break;
589     case 'R':
590     case 'r':
591 #ifdef DEBUGMODE
592       send_usage(sptr, parv[0]);
593 #endif
594       break;
595     case 'D':
596       report_crule_list(sptr, CRULE_ALL);
597       break;
598     case 'd':
599       report_crule_list(sptr, CRULE_MASK);
600       break;
601     case 't':
602       tstats(sptr, parv[0]);
603       break;
604     case 'T':
605       motd_report(sptr);
606       break;
607     case 'U':
608       report_configured_links(sptr, CONF_UWORLD);
609       break;
610     case 'u':
611     {
612       time_t nowr;
613
614       nowr = CurrentTime - me.since;
615       send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
616                  (nowr / 60) % 60, nowr % 60);
617       send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
618       break;
619     }
620     case 'W':
621     case 'w':
622       calc_load(sptr);
623       break;
624     case 'X':
625     case 'x':
626 #ifdef  DEBUGMODE
627       class_send_meminfo(sptr);
628       send_listinfo(sptr, parv[0]);
629 #endif
630       break;
631     case 'Y':
632     case 'y':
633       report_classes(sptr);
634       break;
635     case 'Z':
636     case 'z':
637       count_memory(sptr, parv[0]);
638       break;
639     default:
640       stat = '*';
641       break;
642   }
643   send_reply(sptr, RPL_ENDOFSTATS, stat);
644   return 0;
645 }
646
647 /*
648  * mo_stats - oper message handler
649  *
650  *    parv[0] = sender prefix
651  *    parv[1] = statistics selector (defaults to Message frequency)
652  *    parv[2] = target server (current server defaulted, if omitted)
653  * And 'stats l' and 'stats' L:
654  *    parv[3] = server mask ("*" defaulted, if omitted)
655  * Or for stats p,P:
656  *    parv[3] = port mask (returns p-lines when its port is matched by this)
657  * Or for stats k,K,i and I:
658  *    parv[3] = [user@]host.name  (returns which K/I-lines match this)
659  *           or [user@]host.mask  (returns which K/I-lines are mmatched by this)
660  *              (defaults to old reply if ommitted, when local or Oper)
661  *              A remote mask (something containing wildcards) is only
662  *              allowed for IRC Operators.
663  * Or for stats M:
664  *    parv[3] = time param
665  *    parv[4] = time param 
666  *    (see report_memleak_stats() in runmalloc.c for details)
667  *
668  * This function is getting really ugly. -Ghostwolf
669  */
670 int mo_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
671 {
672   struct Message*  mptr;
673   struct Client*   acptr;
674   struct ConfItem* aconf;
675   char             stat = parc > 1 ? parv[1][0] : '\0';
676   const char**     infotext = statsinfo;
677   int              i;
678
679   if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
680     return 0;
681
682   switch (stat)
683   {
684     case 'L':
685     case 'l':
686     {
687       int doall = 0, wilds = 0;
688       char* name = "*";
689       if (parc > 3 && !EmptyString(parv[3])) {
690         name = parv[3];
691         wilds = string_has_wildcards(name);
692       }
693       else
694         doall = 1;
695       /*
696        * Send info about connections which match, or all if the
697        * mask matches me.name.  Only restrictions are on those who
698        * are invisible not being visible to 'foreigners' who use
699        * a wild card based search to list it.
700        */
701       send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
702                  "SendM SendKBytes RcveM RcveKBytes :Open since");
703       for (i = 0; i <= HighestFd; i++)
704       {
705         if (!(acptr = LocalClientArray[i]))
706           continue;
707         /* Don't return clients when this is a request for `all' */
708         if (doall && IsUser(acptr))
709           continue;
710         /* Only show the ones that match the given mask - if any */
711         if (!doall && wilds && match(name, acptr->name))
712           continue;
713         /* Skip all that do not match the specific query */
714         if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
715           continue;
716         send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
717                    "%s %u %u %u %u %u :%Tu", acptr->name,
718                    (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
719                    (int)acptr->sendK, (int)acptr->receiveM,
720                    (int)acptr->receiveK, CurrentTime - acptr->firsttime);
721       }
722       break;
723     }
724     case 'C':
725     case 'c':
726       report_configured_links(sptr, CONF_SERVER);
727       break;
728     case 'G':
729     case 'g': /* send glines */
730       gline_stats(sptr);
731       break;
732     case 'H':
733     case 'h':
734       report_configured_links(sptr, CONF_HUB | CONF_LEAF);
735       break;
736     case 'K':
737     case 'k':    /* display CONF_IPKILL as well as CONF_KILL -Kev */
738       if (0 == report_klines(sptr, (parc > 3) ? parv[3] : 0, 0))
739         return 0;
740       break;
741     case 'F':
742     case 'f':
743       report_feature_list(sptr);
744       break;
745     case 'I':
746     case 'i':
747       {
748         int   wilds = 0;
749         int   count = 1000;
750         char* host;
751
752         if (parc < 4) {
753           report_configured_links(sptr, CONF_CLIENT);
754           break;
755         }
756         if (EmptyString(parv[3]))
757           return need_more_params(sptr, "STATS I");
758
759         host = parv[3];
760         wilds = string_has_wildcards(host);
761
762         for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
763           if (CONF_CLIENT == aconf->status) {
764             if ((!wilds && (!match(aconf->host, host) ||
765                 !match(aconf->name, host))) ||
766                 (wilds && (!mmatch(host, aconf->host) ||
767                 !mmatch(host, aconf->name))))
768             {
769               send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
770                          aconf->port, get_conf_class(aconf));
771               if (--count == 0)
772                 break;
773             }
774           }
775         }
776       }
777       break;
778     case 'M':
779 #if !defined(NDEBUG)
780       send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
781                  fda_get_block_count());
782 #endif
783
784 #if 0
785 #ifdef MEMSIZESTATS
786       sendto_one(sptr, rpl_str(RPL_STATMEMTOT), /* XXX DEAD */
787           me.name, parv[0], get_mem_size(), get_alloc_cnt());
788 #endif
789 #ifdef MEMLEAKSTATS
790       report_memleak_stats(sptr, parc, parv);
791 #endif
792 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
793       sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring " /* XXX DEAD */
794           "is not enabled on this server", me.name, parv[0]);
795 #endif
796 #endif /* 0 */
797       break;
798     case 'm':
799       for (mptr = msgtab; mptr->cmd; mptr++)
800         if (mptr->count)
801           send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
802                      mptr->bytes);
803       break;
804     case 'o':
805     case 'O':
806       report_configured_links(sptr, CONF_OPS);
807       break;
808     case 'p':
809     case 'P':
810       /*
811        * show listener ports
812        * show hidden ports to opers, if there are more than 3 parameters,
813        * interpret the fourth parameter as the port number, limit non-local
814        * or non-oper results to 8 ports.
815        */ 
816       show_ports(sptr, 1, (parc > 3) ? atoi(parv[3]) : 0, 100);
817       break;
818     case 'R':
819     case 'r':
820 #ifdef DEBUGMODE
821       send_usage(sptr, parv[0]);
822 #endif
823       break;
824     case 'D':
825       report_crule_list(sptr, CRULE_ALL);
826       break;
827     case 'd':
828       report_crule_list(sptr, CRULE_MASK);
829       break;
830     case 't':
831       tstats(sptr, parv[0]);
832       break;
833     case 'T':
834       motd_report(sptr);
835       break;
836     case 'U':
837       report_configured_links(sptr, CONF_UWORLD);
838       break;
839     case 'u':
840     {
841       time_t nowr;
842
843       nowr = CurrentTime - me.since;
844       send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
845                  (nowr / 60) % 60, nowr % 60);
846       send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
847       break;
848     }
849     case 'W':
850     case 'w':
851       calc_load(sptr);
852       break;
853     case 'X':
854     case 'x':
855 #ifdef  DEBUGMODE
856       class_send_meminfo(sptr);
857       send_listinfo(sptr, parv[0]);
858 #endif
859       break;
860     case 'Y':
861     case 'y':
862       report_classes(sptr);
863       break;
864     case 'Z':
865     case 'z':
866       count_memory(sptr, parv[0]);
867       break;
868     default:
869       stat = '*';
870       while (*infotext)
871         sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, *infotext++);
872       break;
873   }
874   send_reply(sptr, RPL_ENDOFSTATS, stat);
875   return 0;
876 }
877