2 * IRC - Internet Relay Chat, ircd/m_stats.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
6 * See file AUTHORS in IRC package for additional names of
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)
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.
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.
27 * m_functions execute protocol messages on this server:
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...).
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.
39 * (!IsServer(cptr)) => (cptr == sptr), because
40 * prefixes are taken *only* from servers...
43 * (sptr == cptr) => the message didn't
46 * (sptr != cptr && IsServer(sptr) means
47 * the prefix specified servername. (?)
49 * (sptr != cptr && !IsServer(sptr) means
50 * that message originated from a remote
55 * (!IsServer(sptr)) means that, sptr can safely
56 * taken as defining the target structure of the
57 * message in this server.
59 * *Always* true (if 'parse' and others are working correct):
61 * 1) sptr->from == cptr (note: cptr->from == cptr)
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 ]
68 * parc number of variable parameter strings (if zero,
69 * parv is allowed to be NULL)
71 * parv a NULL terminated list of parameter pointers,
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*
79 * note: it is guaranteed that parv[0]..parv[parc-1] are all
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
100 #include "ircd_alloc.h"
101 #include "ircd_chattr.h"
102 #include "ircd_reply.h"
103 #include "ircd_string.h"
105 #include "listener.h"
109 #include "numnicks.h"
110 #include "opercmds.h"
119 #include "userload.h"
127 * m_stats - generic message handler
129 * parv[0] = sender prefix
130 * parv[1] = statistics selector (defaults to Message frequency)
131 * parv[2] = target server (current server defaulted, if omitted)
132 * And 'stats l' and 'stats' L:
133 * parv[3] = server mask ("*" defaulted, if omitted)
135 * parv[3] = port mask (returns p-lines when its port is matched by this)
136 * Or for stats k,K,i and I:
137 * parv[3] = [user@]host.name (returns which K/I-lines match this)
138 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
139 * (defaults to old reply if ommitted, when local or Oper)
140 * A remote mask (something containing wildcards) is only
141 * allowed for IRC Operators.
143 * parv[3] = time param
144 * parv[4] = time param
145 * (see report_memleak_stats() in runmalloc.c for details)
147 * This function is getting really ugly. -Ghostwolf
149 int m_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
151 static char Sformat[] = ":%s %d %s Connection SendQ SendM SendKBytes "
152 "RcveM RcveKBytes :Open since";
153 static char Lformat[] = ":%s %d %s %s %u %u %u %u %u :" TIME_T_FMT;
154 struct Message *mptr;
155 struct Client *acptr;
156 struct ConfItem *aconf;
157 char stat = parc > 1 ? parv[1][0] : '\0';
158 const char **infotext = statsinfo;
161 if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
169 int doall = 0, wilds = 0;
171 if (parc > 3 && *parv[3])
175 wilds = (*name == '*' || *name == '?');
176 for (p = name + 1; *p; ++p)
177 if ((*p == '*' || *p == '?') && p[-1] != '\\')
186 * Send info about connections which match, or all if the
187 * mask matches me.name. Only restrictions are on those who
188 * are invisible not being visible to 'foreigners' who use
189 * a wild card based search to list it.
191 sendto_one(sptr, Sformat, me.name, RPL_STATSLINKINFO, parv[0]);
192 for (i = 0; i <= HighestFd; i++)
194 if (!(acptr = LocalClientArray[i]))
196 /* Don't return clients when this is a request for `all' */
197 if (doall && IsUser(acptr))
199 /* Don't show invisible people to non opers unless they know the nick */
200 if (IsInvisible(acptr) && (doall || wilds) && !IsAnOper(acptr) && (acptr != sptr))
202 /* Only show the ones that match the given mask - if any */
203 if (!doall && wilds && match(name, acptr->name))
205 /* Skip all that do not match the specific query */
206 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
208 sendto_one(sptr, Lformat, me.name, RPL_STATSLINKINFO, parv[0],
209 acptr->name, (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
210 (int)acptr->sendK, (int)acptr->receiveM, (int)acptr->receiveK,
211 CurrentTime - acptr->firsttime);
217 report_configured_links(sptr, CONF_SERVER);
220 case 'g': /* send glines */
225 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
230 case 'k': /* display CONF_IPKILL as well
234 char *user, *host, *p;
235 int conf_status = (stat == 'k' || stat == 'K') ? CONF_KLINE : CONF_CLIENT;
238 report_configured_links(sptr, conf_status);
243 for (p = parv[3]; *p; p++)
251 if (*p == '?' || *p == '*')
260 if (conf_status == CONF_CLIENT)
262 user = 0; /* Not used, but to avoid compiler warning. */
268 if ((host = strchr(parv[3], '@')))
279 for (aconf = GlobalConfList; aconf; aconf = aconf->next)
281 if ((aconf->status & conf_status))
283 if (conf_status == CONF_KLINE)
285 if ((!wilds && ((user || aconf->host[1]) &&
286 !match(aconf->host, host) &&
287 (!user || !match(aconf->name, user)))) ||
288 (wilds && !mmatch(host, aconf->host) &&
289 (!user || !mmatch(user, aconf->name))))
291 sendto_one(sptr, rpl_str(RPL_STATSKLINE), me.name,
292 sptr->name, (aconf->status & CONF_KILL) ? 'K' : 'k',
293 aconf->host, aconf->passwd, aconf->name,
294 aconf->port, get_conf_class(aconf));
299 else if (conf_status == CONF_CLIENT)
301 if ((!wilds && (!match(aconf->host, host) ||
302 !match(aconf->name, host))) ||
303 (wilds && (!mmatch(host, aconf->host) ||
304 !mmatch(host, aconf->name))))
306 sendto_one(sptr, rpl_str(RPL_STATSILINE), me.name,
307 sptr->name, 'I', aconf->host, aconf->name,
308 aconf->port, get_conf_class(aconf));
319 sendto_one(sptr, rpl_str(RPL_STATMEMTOT),
320 me.name, parv[0], fda_get_byte_count(), fda_get_block_count());
325 sendto_one(sptr, rpl_str(RPL_STATMEMTOT),
326 me.name, parv[0], get_mem_size(), get_alloc_cnt());
329 report_memleak_stats(sptr, parc, parv);
331 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
332 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring "
333 "is not enabled on this server", me.name, parv[0]);
338 for (mptr = msgtab; mptr->cmd; mptr++)
340 sendto_one(sptr, rpl_str(RPL_STATSCOMMANDS),
341 me.name, parv[0], mptr->cmd, mptr->count, mptr->bytes);
345 report_configured_links(sptr, CONF_OPS);
350 * show listener ports
351 * show hidden ports to opers, if there are more than 3 parameters,
352 * interpret the fourth parameter as the port number.
354 show_ports(sptr, 0, (parc > 3) ? atoi(parv[3]) : 0, 100);
359 send_usage(sptr, parv[0]);
363 report_configured_links(sptr, CONF_CRULEALL);
366 report_configured_links(sptr, CONF_CRULE);
369 tstats(sptr, parv[0]);
372 report_configured_links(sptr, CONF_TLINES);
375 report_configured_links(sptr, CONF_UWORLD);
381 nowr = CurrentTime - me.since;
382 sendto_one(sptr, rpl_str(RPL_STATSUPTIME), me.name, parv[0],
383 nowr / 86400, (nowr / 3600) % 24, (nowr / 60) % 60, nowr % 60);
384 sendto_one(sptr, rpl_str(RPL_STATSCONN), me.name, parv[0],
385 max_connection_count, max_client_count);
395 send_listinfo(sptr, parv[0]);
400 report_classes(sptr);
404 count_memory(sptr, parv[0]);
408 while (*infotext) sendto_one(sptr, ":%s NOTICE %s :%s", me.name, parv[0], *infotext++);
411 sendto_one(sptr, rpl_str(RPL_ENDOFSTATS), me.name, parv[0], stat);
416 * ms_stats - server message handler
418 * parv[0] = sender prefix
419 * parv[1] = statistics selector (defaults to Message frequency)
420 * parv[2] = target server (current server defaulted, if omitted)
421 * And 'stats l' and 'stats' L:
422 * parv[3] = server mask ("*" defaulted, if omitted)
424 * parv[3] = port mask (returns p-lines when its port is matched by this)
425 * Or for stats k,K,i and I:
426 * parv[3] = [user@]host.name (returns which K/I-lines match this)
427 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
428 * (defaults to old reply if ommitted, when local or Oper)
429 * A remote mask (something containing wildcards) is only
430 * allowed for IRC Operators.
432 * parv[3] = time param
433 * parv[4] = time param
434 * (see report_memleak_stats() in runmalloc.c for details)
436 * This function is getting really ugly. -Ghostwolf
438 int ms_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
440 static char Sformat[] = ":%s %d %s Connection SendQ SendM SendKBytes "
441 "RcveM RcveKBytes :Open since";
442 static char Lformat[] = ":%s %d %s %s %u %u %u %u %u :" TIME_T_FMT;
443 struct Message *mptr;
444 struct Client *acptr;
445 struct ConfItem *aconf;
446 char stat = parc > 1 ? parv[1][0] : '\0';
449 if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
457 int doall = 0, wilds = 0;
459 if (parc > 3 && *parv[3])
463 wilds = (*name == '*' || *name == '?');
464 for (p = name + 1; *p; ++p)
465 if ((*p == '*' || *p == '?') && p[-1] != '\\')
474 * Send info about connections which match, or all if the
475 * mask matches me.name. Only restrictions are on those who
476 * are invisible not being visible to 'foreigners' who use
477 * a wild card based search to list it.
479 sendto_one(sptr, Sformat, me.name, RPL_STATSLINKINFO, parv[0]);
480 for (i = 0; i <= HighestFd; i++)
482 if (!(acptr = LocalClientArray[i]))
484 /* Don't return clients when this is a request for `all' */
485 if (doall && IsUser(acptr))
487 /* Don't show invisible people to unauthorized people when using
488 * wildcards -- Is this still needed now /stats is oper only ?
489 * Not here, because ms_stats is specifically a remote command,
490 * thus the check was removed. -Ghostwolf */
491 /* Only show the ones that match the given mask - if any */
492 if (!doall && wilds && match(name, acptr->name))
494 /* Skip all that do not match the specific query */
495 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
497 sendto_one(sptr, Lformat, me.name, RPL_STATSLINKINFO, parv[0],
498 acptr->name, (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
499 (int)acptr->sendK, (int)acptr->receiveM, (int)acptr->receiveK,
500 CurrentTime - acptr->firsttime);
506 report_configured_links(sptr, CONF_SERVER);
509 case 'g': /* send glines */
514 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
519 case 'k': /* display CONF_IPKILL as well
523 char *user, *host, *p;
524 int conf_status = (stat == 'k' || stat == 'K') ? CONF_KLINE : CONF_CLIENT;
525 if (IsOper(sptr) && parc < 4)
527 report_configured_links(sptr, conf_status);
530 if (parc < 4 || *parv[3] == '\0')
531 return need_more_params(sptr,
532 (conf_status & CONF_KLINE) ? "STATS K" : "STATS I");
535 for (p = parv[3]; *p; p++)
543 if (*p == '?' || *p == '*')
557 if (conf_status == CONF_CLIENT)
559 user = 0; /* Not used, but to avoid compiler warning. */
565 if ((host = strchr(parv[3], '@')))
576 for (aconf = GlobalConfList; aconf; aconf = aconf->next)
578 if ((aconf->status & conf_status))
580 if (conf_status == CONF_KLINE)
582 if ((!wilds && ((user || aconf->host[1]) &&
583 !match(aconf->host, host) &&
584 (!user || !match(aconf->name, user)))) ||
585 (wilds && !mmatch(host, aconf->host) &&
586 (!user || !mmatch(user, aconf->name))))
588 sendto_one(sptr, rpl_str(RPL_STATSKLINE), me.name,
589 sptr->name, (aconf->status & CONF_KILL) ? 'K' : 'k',
590 aconf->host, aconf->passwd, aconf->name,
591 aconf->port, get_conf_class(aconf));
596 else if (conf_status == CONF_CLIENT)
598 if ((!wilds && (!match(aconf->host, host) ||
599 !match(aconf->name, host))) ||
600 (wilds && (!mmatch(host, aconf->host) ||
601 !mmatch(host, aconf->name))))
603 sendto_one(sptr, rpl_str(RPL_STATSILINE), me.name,
604 sptr->name, 'I', aconf->host, aconf->name,
605 aconf->port, get_conf_class(aconf));
616 sendto_one(sptr, rpl_str(RPL_STATMEMTOT),
617 me.name, parv[0], fda_get_byte_count(), fda_get_block_count());
622 sendto_one(sptr, rpl_str(RPL_STATMEMTOT),
623 me.name, parv[0], get_mem_size(), get_alloc_cnt());
626 report_memleak_stats(sptr, parc, parv);
628 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
629 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring "
630 "is not enabled on this server", me.name, parv[0]);
635 for (mptr = msgtab; mptr->cmd; mptr++)
637 sendto_one(sptr, rpl_str(RPL_STATSCOMMANDS),
638 me.name, parv[0], mptr->cmd, mptr->count, mptr->bytes);
642 report_configured_links(sptr, CONF_OPS);
647 * show listener ports
648 * show hidden ports to opers, if there are more than 3 parameters,
649 * interpret the fourth parameter as the port number, limit non-local
650 * or non-oper results to 8 ports.
652 show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0, IsOper(sptr) ? 100 : 8);
657 send_usage(sptr, parv[0]);
661 report_configured_links(sptr, CONF_CRULEALL);
664 report_configured_links(sptr, CONF_CRULE);
667 tstats(sptr, parv[0]);
670 report_configured_links(sptr, CONF_TLINES);
673 report_configured_links(sptr, CONF_UWORLD);
679 nowr = CurrentTime - me.since;
680 sendto_one(sptr, rpl_str(RPL_STATSUPTIME), me.name, parv[0],
681 nowr / 86400, (nowr / 3600) % 24, (nowr / 60) % 60, nowr % 60);
682 sendto_one(sptr, rpl_str(RPL_STATSCONN), me.name, parv[0],
683 max_connection_count, max_client_count);
693 send_listinfo(sptr, parv[0]);
698 report_classes(sptr);
702 count_memory(sptr, parv[0]);
708 sendto_one(sptr, rpl_str(RPL_ENDOFSTATS), me.name, parv[0], stat);
713 * mo_stats - oper message handler
715 * parv[0] = sender prefix
716 * parv[1] = statistics selector (defaults to Message frequency)
717 * parv[2] = target server (current server defaulted, if omitted)
718 * And 'stats l' and 'stats' L:
719 * parv[3] = server mask ("*" defaulted, if omitted)
721 * parv[3] = port mask (returns p-lines when its port is matched by this)
722 * Or for stats k,K,i and I:
723 * parv[3] = [user@]host.name (returns which K/I-lines match this)
724 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
725 * (defaults to old reply if ommitted, when local or Oper)
726 * A remote mask (something containing wildcards) is only
727 * allowed for IRC Operators.
729 * parv[3] = time param
730 * parv[4] = time param
731 * (see report_memleak_stats() in runmalloc.c for details)
733 * This function is getting really ugly. -Ghostwolf
735 int mo_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
737 static char Sformat[] = ":%s %d %s Connection SendQ SendM SendKBytes "
738 "RcveM RcveKBytes :Open since";
739 static char Lformat[] = ":%s %d %s %s %u %u %u %u %u :" TIME_T_FMT;
740 struct Message *mptr;
741 struct Client *acptr;
742 struct ConfItem *aconf;
743 char stat = parc > 1 ? parv[1][0] : '\0';
744 const char **infotext = statsinfo;
747 if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
755 int doall = 0, wilds = 0;
757 if (parc > 3 && *parv[3])
761 wilds = (*name == '*' || *name == '?');
762 for (p = name + 1; *p; ++p)
763 if ((*p == '*' || *p == '?') && p[-1] != '\\')
772 * Send info about connections which match, or all if the
773 * mask matches me.name. Only restrictions are on those who
774 * are invisible not being visible to 'foreigners' who use
775 * a wild card based search to list it.
777 sendto_one(sptr, Sformat, me.name, RPL_STATSLINKINFO, parv[0]);
778 for (i = 0; i <= HighestFd; i++)
780 if (!(acptr = LocalClientArray[i]))
782 /* Don't return clients when this is a request for `all' */
783 if (doall && IsUser(acptr))
785 /* Only show the ones that match the given mask - if any */
786 if (!doall && wilds && match(name, acptr->name))
788 /* Skip all that do not match the specific query */
789 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
791 sendto_one(sptr, Lformat, me.name, RPL_STATSLINKINFO, parv[0],
792 acptr->name, (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
793 (int)acptr->sendK, (int)acptr->receiveM, (int)acptr->receiveK,
794 CurrentTime - acptr->firsttime);
800 report_configured_links(sptr, CONF_SERVER);
803 case 'g': /* send glines */
808 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
813 case 'k': /* display CONF_IPKILL as well
817 char *user, *host, *p;
818 int conf_status = (stat == 'k' || stat == 'K') ? CONF_KLINE : CONF_CLIENT;
821 report_configured_links(sptr, conf_status);
826 for (p = parv[3]; *p; p++)
834 if (*p == '?' || *p == '*')
843 if (conf_status == CONF_CLIENT)
845 user = 0; /* Not used, but to avoid compiler warning. */
851 if ((host = strchr(parv[3], '@')))
862 for (aconf = GlobalConfList; aconf; aconf = aconf->next)
864 if ((aconf->status & conf_status))
866 if (conf_status == CONF_KLINE)
868 if ((!wilds && ((user || aconf->host[1]) &&
869 !match(aconf->host, host) &&
870 (!user || !match(aconf->name, user)))) ||
871 (wilds && !mmatch(host, aconf->host) &&
872 (!user || !mmatch(user, aconf->name))))
874 sendto_one(sptr, rpl_str(RPL_STATSKLINE), me.name,
875 sptr->name, (aconf->status & CONF_KILL) ? 'K' : 'k',
876 aconf->host, aconf->passwd, aconf->name,
877 aconf->port, get_conf_class(aconf));
882 else if (conf_status == CONF_CLIENT)
884 if ((!wilds && (!match(aconf->host, host) ||
885 !match(aconf->name, host))) ||
886 (wilds && (!mmatch(host, aconf->host) ||
887 !mmatch(host, aconf->name))))
889 sendto_one(sptr, rpl_str(RPL_STATSILINE), me.name,
890 sptr->name, 'I', aconf->host, aconf->name,
891 aconf->port, get_conf_class(aconf));
902 sendto_one(sptr, rpl_str(RPL_STATMEMTOT),
903 me.name, parv[0], fda_get_byte_count(), fda_get_block_count());
908 sendto_one(sptr, rpl_str(RPL_STATMEMTOT),
909 me.name, parv[0], get_mem_size(), get_alloc_cnt());
912 report_memleak_stats(sptr, parc, parv);
914 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
915 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring "
916 "is not enabled on this server", me.name, parv[0]);
921 for (mptr = msgtab; mptr->cmd; mptr++)
923 sendto_one(sptr, rpl_str(RPL_STATSCOMMANDS),
924 me.name, parv[0], mptr->cmd, mptr->count, mptr->bytes);
928 report_configured_links(sptr, CONF_OPS);
933 * show listener ports
934 * show hidden ports to opers, if there are more than 3 parameters,
935 * interpret the fourth parameter as the port number, limit non-local
936 * or non-oper results to 8 ports.
938 show_ports(sptr, 1, (parc > 3) ? atoi(parv[3]) : 0, 100);
943 send_usage(sptr, parv[0]);
947 report_configured_links(sptr, CONF_CRULEALL);
950 report_configured_links(sptr, CONF_CRULE);
953 tstats(sptr, parv[0]);
956 report_configured_links(sptr, CONF_TLINES);
959 report_configured_links(sptr, CONF_UWORLD);
965 nowr = CurrentTime - me.since;
966 sendto_one(sptr, rpl_str(RPL_STATSUPTIME), me.name, parv[0],
967 nowr / 86400, (nowr / 3600) % 24, (nowr / 60) % 60, nowr % 60);
968 sendto_one(sptr, rpl_str(RPL_STATSCONN), me.name, parv[0],
969 max_connection_count, max_client_count);
979 send_listinfo(sptr, parv[0]);
984 report_classes(sptr);
988 count_memory(sptr, parv[0]);
992 while (*infotext) sendto_one(sptr, ":%s NOTICE %s :%s", me.name, parv[0], *infotext++);
995 sendto_one(sptr, rpl_str(RPL_ENDOFSTATS), me.name, parv[0], stat);
1003 * parv[0] = sender prefix
1004 * parv[1] = statistics selector (defaults to Message frequency)
1005 * parv[2] = target server (current server defaulted, if omitted)
1006 * And 'stats l' and 'stats' L:
1007 * parv[3] = server mask ("*" defaulted, if omitted)
1009 * parv[3] = port mask (returns p-lines when its port is matched by this)
1010 * Or for stats k,K,i and I:
1011 * parv[3] = [user@]host.name (returns which K/I-lines match this)
1012 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
1013 * (defaults to old reply if ommitted, when local or Oper)
1014 * A remote mask (something containing wildcards) is only
1015 * allowed for IRC Operators.
1017 * parv[3] = time param
1018 * parv[4] = time param
1019 * (see report_memleak_stats() in runmalloc.c for details)
1021 * This function is getting really ugly. -Ghostwolf
1023 int m_stats(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
1025 static char Sformat[] = ":%s %d %s Connection SendQ SendM SendKBytes "
1026 "RcveM RcveKBytes :Open since";
1027 static char Lformat[] = ":%s %d %s %s %u %u %u %u %u :" TIME_T_FMT;
1028 struct Message *mptr;
1029 struct Client *acptr;
1030 struct Gline* gline;
1031 struct ConfItem *aconf;
1032 char stat = parc > 1 ? parv[1][0] : '\0';
1035 /* m_stats is so obnoxiously full of special cases that the different
1036 * hunt_server() possiblites were becoming very messy. It now uses a
1037 * switch() so as to be easier to read and update as params change.
1042 /* open to all, standard # of params */
1046 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
1052 /* open to all, varying # of params */
1062 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv)
1068 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
1075 /* oper only, varying # of params */
1082 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv)
1088 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s %s :%s", 2, parc,
1089 parv) != HUNTED_ISME)
1092 else if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
1098 /* oper only, standard # of params */
1101 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv)
1113 int doall = 0, wilds = 0;
1115 if (parc > 3 && *parv[3])
1119 wilds = (*name == '*' || *name == '?');
1120 for (p = name + 1; *p; ++p)
1121 if ((*p == '*' || *p == '?') && p[-1] != '\\')
1130 * Send info about connections which match, or all if the
1131 * mask matches me.name. Only restrictions are on those who
1132 * are invisible not being visible to 'foreigners' who use
1133 * a wild card based search to list it.
1135 sendto_one(sptr, Sformat, me.name, RPL_STATSLINKINFO, parv[0]);
1136 for (i = 0; i <= HighestFd; i++)
1138 if (!(acptr = LocalClientArray[i]))
1140 /* Don't return clients when this is a request for `all' */
1141 if (doall && IsUser(acptr))
1143 /* Don't show invisible people to unauthorized people when using
1144 * wildcards -- Is this still needed now /stats is oper only ? */
1145 if (IsInvisible(acptr) && (doall || wilds) &&
1146 !(MyConnect(sptr) && IsOper(sptr)) &&
1147 !IsAnOper(acptr) && (acptr != sptr))
1149 /* Only show the ones that match the given mask - if any */
1150 if (!doall && wilds && match(name, acptr->name))
1152 /* Skip all that do not match the specific query */
1153 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
1155 sendto_one(sptr, Lformat, me.name, RPL_STATSLINKINFO, parv[0],
1157 (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
1158 (int)acptr->sendK, (int)acptr->receiveM, (int)acptr->receiveK,
1159 CurrentTime - acptr->firsttime);
1165 report_configured_links(sptr, CONF_SERVER);
1168 case 'g': /* send glines */
1169 gline_remove_expired(TStime());
1170 for (gline = GlobalGlineList; gline; gline = gline->next) {
1171 sendto_one(sptr, rpl_str(RPL_STATSGLINE), me.name,
1172 sptr->name, 'G', gline->name, gline->host,
1173 gline->expire, gline->reason);
1178 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
1183 case 'k': /* display CONF_IPKILL as well
1184 as CONF_KILL -Kev */
1187 char *user, *host, *p;
1188 int conf_status = (stat == 'k' || stat == 'K') ? CONF_KLINE : CONF_CLIENT;
1189 if ((MyUser(sptr) || IsOper(sptr)) && parc < 4)
1191 report_configured_links(sptr, conf_status);
1194 if (parc < 4 || *parv[3] == '\0')
1195 return need_more_params(sptr,
1196 (conf_status & CONF_KLINE) ? "STATS K" : "STATS I");
1199 for (p = parv[3]; *p; p++)
1207 if (*p == '?' || *p == '*')
1213 if (!(MyConnect(sptr) || IsOper(sptr)))
1221 if (conf_status == CONF_CLIENT)
1223 user = 0; /* Not used, but to avoid compiler warning. */
1229 if ((host = strchr(parv[3], '@')))
1240 for (aconf = GlobalConfList; aconf; aconf = aconf->next)
1242 if ((aconf->status & conf_status))
1244 if (conf_status == CONF_KLINE)
1246 if ((!wilds && ((user || aconf->host[1]) &&
1247 !match(aconf->host, host) &&
1248 (!user || !match(aconf->name, user)))) ||
1249 (wilds && !mmatch(host, aconf->host) &&
1250 (!user || !mmatch(user, aconf->name))))
1252 sendto_one(sptr, rpl_str(RPL_STATSKLINE), me.name,
1253 sptr->name, 'K', aconf->host, aconf->passwd, aconf->name,
1254 aconf->port, get_conf_class(aconf));
1259 else if (conf_status == CONF_CLIENT)
1261 if ((!wilds && (!match(aconf->host, host) ||
1262 !match(aconf->name, host))) ||
1263 (wilds && (!mmatch(host, aconf->host) ||
1264 !mmatch(host, aconf->name))))
1266 sendto_one(sptr, rpl_str(RPL_STATSILINE), me.name,
1267 sptr->name, 'I', aconf->host, aconf->name,
1268 aconf->port, get_conf_class(aconf));
1278 #if !defined(NDEBUG)
1279 sendto_one(sptr, rpl_str(RPL_STATMEMTOT),
1280 me.name, parv[0], fda_get_byte_count(), fda_get_block_count());
1285 sendto_one(sptr, rpl_str(RPL_STATMEMTOT),
1286 me.name, parv[0], get_mem_size(), get_alloc_cnt());
1289 report_memleak_stats(sptr, parc, parv);
1291 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
1292 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring "
1293 "is not enabled on this server", me.name, parv[0]);
1298 for (mptr = msgtab; mptr->cmd; mptr++)
1300 sendto_one(sptr, rpl_str(RPL_STATSCOMMANDS),
1301 me.name, parv[0], mptr->cmd, mptr->count, mptr->bytes);
1305 report_configured_links(sptr, CONF_OPS);
1310 * show listener ports
1311 * show hidden ports to opers, if there are more than 3 parameters,
1312 * interpret the fourth parameter as the port number, limit non-local
1313 * or non-oper results to 8 ports.
1315 show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0,
1316 (MyUser(sptr) || IsOper(sptr)) ? 100 : 8);
1321 send_usage(sptr, parv[0]);
1325 report_configured_links(sptr, CONF_CRULEALL);
1328 report_configured_links(sptr, CONF_CRULE);
1331 tstats(sptr, parv[0]);
1334 report_configured_links(sptr, CONF_TLINES);
1337 report_configured_links(sptr, CONF_UWORLD);
1343 nowr = CurrentTime - me.since;
1344 sendto_one(sptr, rpl_str(RPL_STATSUPTIME), me.name, parv[0],
1345 nowr / 86400, (nowr / 3600) % 24, (nowr / 60) % 60, nowr % 60);
1346 sendto_one(sptr, rpl_str(RPL_STATSCONN), me.name, parv[0],
1347 max_connection_count, max_client_count);
1357 send_listinfo(sptr, parv[0]);
1362 report_classes(sptr);
1366 count_memory(sptr, parv[0]);
1372 sendto_one(sptr, rpl_str(RPL_ENDOFSTATS), me.name, parv[0], stat);