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 struct Message *mptr;
152 struct Client *acptr;
153 struct ConfItem *aconf;
154 char stat = parc > 1 ? parv[1][0] : '\0';
155 const char **infotext = statsinfo;
158 if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
166 int doall = 0, wilds = 0;
168 if (parc > 3 && *parv[3])
172 wilds = (*name == '*' || *name == '?');
173 for (p = name + 1; *p; ++p)
174 if ((*p == '*' || *p == '?') && p[-1] != '\\')
183 * Send info about connections which match, or all if the
184 * mask matches me.name. Only restrictions are on those who
185 * are invisible not being visible to 'foreigners' who use
186 * a wild card based search to list it.
188 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
189 "SendM SendKBytes RcveM RcveKBytes :Open since");
190 for (i = 0; i <= HighestFd; i++)
192 if (!(acptr = LocalClientArray[i]))
194 /* Don't return clients when this is a request for `all' */
195 if (doall && IsUser(acptr))
197 /* Don't show invisible people to non opers unless they know the nick */
198 if (IsInvisible(acptr) && (doall || wilds) && !IsAnOper(acptr) && (acptr != sptr))
200 /* Only show the ones that match the given mask - if any */
201 if (!doall && wilds && match(name, acptr->name))
203 /* Skip all that do not match the specific query */
204 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
206 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
207 "%s %u %u %u %u %u :%Tu", (*acptr->name) ? acptr->name : "<unregistered>",
208 (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
209 (int)acptr->sendK, (int)acptr->receiveM,
210 (int)acptr->receiveK, CurrentTime - acptr->firsttime);
216 report_configured_links(sptr, CONF_SERVER);
219 case 'g': /* send glines */
224 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
229 case 'k': /* display CONF_IPKILL as well
233 char *user, *host, *p;
234 int conf_status = (stat == 'k' || stat == 'K') ? CONF_KLINE : CONF_CLIENT;
237 report_configured_links(sptr, conf_status);
242 for (p = parv[3]; *p; p++)
250 if (*p == '?' || *p == '*')
259 if (conf_status == CONF_CLIENT)
261 user = 0; /* Not used, but to avoid compiler warning. */
267 if ((host = strchr(parv[3], '@')))
278 for (aconf = GlobalConfList; aconf; aconf = aconf->next)
280 if ((aconf->status & conf_status))
282 if (conf_status == CONF_KLINE)
284 if ((!wilds && ((user || aconf->host[1]) &&
285 !match(aconf->host, host) &&
286 (!user || !match(aconf->name, user)))) ||
287 (wilds && !mmatch(host, aconf->host) &&
288 (!user || !mmatch(user, aconf->name))))
290 send_reply(sptr, RPL_STATSKLINE,
291 (aconf->status & CONF_KILL) ? 'K' : 'k', aconf->host,
292 aconf->passwd, aconf->name, aconf->port,
293 get_conf_class(aconf));
298 else if (conf_status == CONF_CLIENT)
300 if ((!wilds && (!match(aconf->host, host) ||
301 !match(aconf->name, host))) ||
302 (wilds && (!mmatch(host, aconf->host) ||
303 !mmatch(host, aconf->name))))
305 send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
306 aconf->port, get_conf_class(aconf));
317 send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
318 fda_get_block_count());
323 sendto_one(sptr, rpl_str(RPL_STATMEMTOT), /* XXX DEAD */
324 me.name, parv[0], get_mem_size(), get_alloc_cnt());
327 report_memleak_stats(sptr, parc, parv);
329 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
330 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring " /* XXX DEAD */
331 "is not enabled on this server", me.name, parv[0]);
336 for (mptr = msgtab; mptr->cmd; mptr++)
338 send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
343 report_configured_links(sptr, CONF_OPS);
348 * show listener ports
349 * show hidden ports to opers, if there are more than 3 parameters,
350 * interpret the fourth parameter as the port number.
352 show_ports(sptr, 0, (parc > 3) ? atoi(parv[3]) : 0, 100);
357 send_usage(sptr, parv[0]);
361 report_configured_links(sptr, CONF_CRULEALL);
364 report_configured_links(sptr, CONF_CRULE);
367 tstats(sptr, parv[0]);
370 report_configured_links(sptr, CONF_TLINES);
373 report_configured_links(sptr, CONF_UWORLD);
379 nowr = CurrentTime - me.since;
380 send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
381 (nowr / 60) % 60, nowr % 60);
382 send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
387 struct ConfClass *cltmp;
389 for (cltmp = FirstClass(); cltmp; cltmp = NextClass(cltmp)) {
390 if (Links(cltmp) > 0)
391 send_reply(sptr,RPL_TRACECLASS, ConClass(cltmp), Links(cltmp));
402 send_listinfo(sptr, parv[0]);
407 report_classes(sptr);
411 count_memory(sptr, parv[0]);
416 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, *infotext++);
419 send_reply(sptr, RPL_ENDOFSTATS, stat);
424 * ms_stats - server message handler
426 * parv[0] = sender prefix
427 * parv[1] = statistics selector (defaults to Message frequency)
428 * parv[2] = target server (current server defaulted, if omitted)
429 * And 'stats l' and 'stats' L:
430 * parv[3] = server mask ("*" defaulted, if omitted)
432 * parv[3] = port mask (returns p-lines when its port is matched by this)
433 * Or for stats k,K,i and I:
434 * parv[3] = [user@]host.name (returns which K/I-lines match this)
435 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
436 * (defaults to old reply if ommitted, when local or Oper)
437 * A remote mask (something containing wildcards) is only
438 * allowed for IRC Operators.
440 * parv[3] = time param
441 * parv[4] = time param
442 * (see report_memleak_stats() in runmalloc.c for details)
444 * This function is getting really ugly. -Ghostwolf
446 int ms_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
448 struct Message *mptr;
449 struct Client *acptr;
450 struct ConfItem *aconf;
451 char stat = parc > 1 ? parv[1][0] : '\0';
454 if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
462 int doall = 0, wilds = 0;
464 if (parc > 3 && *parv[3])
468 wilds = (*name == '*' || *name == '?');
469 for (p = name + 1; *p; ++p)
470 if ((*p == '*' || *p == '?') && p[-1] != '\\')
479 * Send info about connections which match, or all if the
480 * mask matches me.name. Only restrictions are on those who
481 * are invisible not being visible to 'foreigners' who use
482 * a wild card based search to list it.
484 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
485 "SendM SendKBytes RcveM RcveKBytes :Open since");
486 for (i = 0; i <= HighestFd; i++)
488 if (!(acptr = LocalClientArray[i]))
490 /* Don't return clients when this is a request for `all' */
491 if (doall && IsUser(acptr))
493 /* Don't show invisible people to unauthorized people when using
494 * wildcards -- Is this still needed now /stats is oper only ?
495 * Not here, because ms_stats is specifically a remote command,
496 * thus the check was removed. -Ghostwolf */
497 /* Only show the ones that match the given mask - if any */
498 if (!doall && wilds && match(name, acptr->name))
500 /* Skip all that do not match the specific query */
501 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
503 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
504 "%s %u %u %u %u %u :%Tu", acptr->name,
505 (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
506 (int)acptr->sendK, (int)acptr->receiveM,
507 (int)acptr->receiveK, CurrentTime - acptr->firsttime);
513 report_configured_links(sptr, CONF_SERVER);
516 case 'g': /* send glines */
521 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
526 case 'k': /* display CONF_IPKILL as well
530 char *user, *host, *p;
531 int conf_status = (stat == 'k' || stat == 'K') ? CONF_KLINE : CONF_CLIENT;
532 if (IsOper(sptr) && parc < 4)
534 report_configured_links(sptr, conf_status);
537 if (parc < 4 || *parv[3] == '\0')
538 return need_more_params(sptr,
539 (conf_status & CONF_KLINE) ? "STATS K" : "STATS I");
542 for (p = parv[3]; *p; p++)
550 if (*p == '?' || *p == '*')
564 if (conf_status == CONF_CLIENT)
566 user = 0; /* Not used, but to avoid compiler warning. */
572 if ((host = strchr(parv[3], '@')))
583 for (aconf = GlobalConfList; aconf; aconf = aconf->next)
585 if ((aconf->status & conf_status))
587 if (conf_status == CONF_KLINE)
589 if ((!wilds && ((user || aconf->host[1]) &&
590 !match(aconf->host, host) &&
591 (!user || !match(aconf->name, user)))) ||
592 (wilds && !mmatch(host, aconf->host) &&
593 (!user || !mmatch(user, aconf->name))))
595 send_reply(sptr, RPL_STATSKLINE,
596 (aconf->status & CONF_KILL) ? 'K' : 'k', aconf->host,
597 aconf->passwd, aconf->name, aconf->port,
598 get_conf_class(aconf));
603 else if (conf_status == CONF_CLIENT)
605 if ((!wilds && (!match(aconf->host, host) ||
606 !match(aconf->name, host))) ||
607 (wilds && (!mmatch(host, aconf->host) ||
608 !mmatch(host, aconf->name))))
610 send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
611 aconf->port, get_conf_class(aconf));
622 send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
623 fda_get_block_count());
628 sendto_one(sptr, rpl_str(RPL_STATMEMTOT), /* XXX DEAD */
629 me.name, parv[0], get_mem_size(), get_alloc_cnt());
632 report_memleak_stats(sptr, parc, parv);
634 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
635 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring " /* XXX DEAD */
636 "is not enabled on this server", me.name, parv[0]);
641 for (mptr = msgtab; mptr->cmd; mptr++)
643 send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
648 report_configured_links(sptr, CONF_OPS);
653 * show listener ports
654 * show hidden ports to opers, if there are more than 3 parameters,
655 * interpret the fourth parameter as the port number, limit non-local
656 * or non-oper results to 8 ports.
658 show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0, IsOper(sptr) ? 100 : 8);
663 send_usage(sptr, parv[0]);
667 report_configured_links(sptr, CONF_CRULEALL);
670 report_configured_links(sptr, CONF_CRULE);
673 tstats(sptr, parv[0]);
676 report_configured_links(sptr, CONF_TLINES);
679 report_configured_links(sptr, CONF_UWORLD);
685 nowr = CurrentTime - me.since;
686 send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
687 (nowr / 60) % 60, nowr % 60);
688 send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
693 struct ConfClass *cltmp;
695 for (cltmp = FirstClass(); cltmp; cltmp = NextClass(cltmp)) {
696 if (Links(cltmp) > 0)
697 send_reply(sptr,RPL_TRACECLASS, ConClass(cltmp), Links(cltmp));
709 send_listinfo(sptr, parv[0]);
714 report_classes(sptr);
718 count_memory(sptr, parv[0]);
724 send_reply(sptr, RPL_ENDOFSTATS, stat);
729 * mo_stats - oper message handler
731 * parv[0] = sender prefix
732 * parv[1] = statistics selector (defaults to Message frequency)
733 * parv[2] = target server (current server defaulted, if omitted)
734 * And 'stats l' and 'stats' L:
735 * parv[3] = server mask ("*" defaulted, if omitted)
737 * parv[3] = port mask (returns p-lines when its port is matched by this)
738 * Or for stats k,K,i and I:
739 * parv[3] = [user@]host.name (returns which K/I-lines match this)
740 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
741 * (defaults to old reply if ommitted, when local or Oper)
742 * A remote mask (something containing wildcards) is only
743 * allowed for IRC Operators.
745 * parv[3] = time param
746 * parv[4] = time param
747 * (see report_memleak_stats() in runmalloc.c for details)
749 * This function is getting really ugly. -Ghostwolf
751 int mo_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
753 struct Message *mptr;
754 struct Client *acptr;
755 struct ConfItem *aconf;
756 char stat = parc > 1 ? parv[1][0] : '\0';
757 const char **infotext = statsinfo;
760 if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME)
768 int doall = 0, wilds = 0;
770 if (parc > 3 && *parv[3])
774 wilds = (*name == '*' || *name == '?');
775 for (p = name + 1; *p; ++p)
776 if ((*p == '*' || *p == '?') && p[-1] != '\\')
785 * Send info about connections which match, or all if the
786 * mask matches me.name. Only restrictions are on those who
787 * are invisible not being visible to 'foreigners' who use
788 * a wild card based search to list it.
790 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO, "Connection SendQ "
791 "SendM SendKBytes RcveM RcveKBytes :Open since");
792 for (i = 0; i <= HighestFd; i++)
794 if (!(acptr = LocalClientArray[i]))
796 /* Don't return clients when this is a request for `all' */
797 if (doall && IsUser(acptr))
799 /* Only show the ones that match the given mask - if any */
800 if (!doall && wilds && match(name, acptr->name))
802 /* Skip all that do not match the specific query */
803 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
805 send_reply(sptr, SND_EXPLICIT | RPL_STATSLINKINFO,
806 "%s %u %u %u %u %u :%Tu", acptr->name,
807 (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
808 (int)acptr->sendK, (int)acptr->receiveM,
809 (int)acptr->receiveK, CurrentTime - acptr->firsttime);
815 report_configured_links(sptr, CONF_SERVER);
818 case 'g': /* send glines */
823 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
828 case 'k': /* display CONF_IPKILL as well
832 char *user, *host, *p;
833 int conf_status = (stat == 'k' || stat == 'K') ? CONF_KLINE : CONF_CLIENT;
836 report_configured_links(sptr, conf_status);
841 for (p = parv[3]; *p; p++)
849 if (*p == '?' || *p == '*')
858 if (conf_status == CONF_CLIENT)
860 user = 0; /* Not used, but to avoid compiler warning. */
866 if ((host = strchr(parv[3], '@')))
877 for (aconf = GlobalConfList; aconf; aconf = aconf->next)
879 if ((aconf->status & conf_status))
881 if (conf_status == CONF_KLINE)
883 if ((!wilds && ((user || aconf->host[1]) &&
884 !match(aconf->host, host) &&
885 (!user || !match(aconf->name, user)))) ||
886 (wilds && !mmatch(host, aconf->host) &&
887 (!user || !mmatch(user, aconf->name))))
889 send_reply(sptr, RPL_STATSKLINE,
890 (aconf->status & CONF_KILL) ? 'K' : 'k', aconf->host,
891 aconf->passwd, aconf->name, aconf->port,
892 get_conf_class(aconf));
897 else if (conf_status == CONF_CLIENT)
899 if ((!wilds && (!match(aconf->host, host) ||
900 !match(aconf->name, host))) ||
901 (wilds && (!mmatch(host, aconf->host) ||
902 !mmatch(host, aconf->name))))
904 send_reply(sptr, RPL_STATSILINE, 'I', aconf->host, aconf->name,
905 aconf->port, get_conf_class(aconf));
916 send_reply(sptr, RPL_STATMEMTOT, fda_get_byte_count(),
917 fda_get_block_count());
922 sendto_one(sptr, rpl_str(RPL_STATMEMTOT), /* XXX DEAD */
923 me.name, parv[0], get_mem_size(), get_alloc_cnt());
926 report_memleak_stats(sptr, parc, parv);
928 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
929 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring " /* XXX DEAD */
930 "is not enabled on this server", me.name, parv[0]);
935 for (mptr = msgtab; mptr->cmd; mptr++)
937 send_reply(sptr, RPL_STATSCOMMANDS, mptr->cmd, mptr->count,
942 report_configured_links(sptr, CONF_OPS);
947 * show listener ports
948 * show hidden ports to opers, if there are more than 3 parameters,
949 * interpret the fourth parameter as the port number, limit non-local
950 * or non-oper results to 8 ports.
952 show_ports(sptr, 1, (parc > 3) ? atoi(parv[3]) : 0, 100);
957 send_usage(sptr, parv[0]);
961 report_configured_links(sptr, CONF_CRULEALL);
964 report_configured_links(sptr, CONF_CRULE);
967 tstats(sptr, parv[0]);
970 report_configured_links(sptr, CONF_TLINES);
973 report_configured_links(sptr, CONF_UWORLD);
979 nowr = CurrentTime - me.since;
980 send_reply(sptr, RPL_STATSUPTIME, nowr / 86400, (nowr / 3600) % 24,
981 (nowr / 60) % 60, nowr % 60);
982 send_reply(sptr, RPL_STATSCONN, max_connection_count, max_client_count);
992 send_listinfo(sptr, parv[0]);
997 report_classes(sptr);
1001 count_memory(sptr, parv[0]);
1006 sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :%s", sptr, *infotext++);
1009 send_reply(sptr, RPL_ENDOFSTATS, stat);
1017 * parv[0] = sender prefix
1018 * parv[1] = statistics selector (defaults to Message frequency)
1019 * parv[2] = target server (current server defaulted, if omitted)
1020 * And 'stats l' and 'stats' L:
1021 * parv[3] = server mask ("*" defaulted, if omitted)
1023 * parv[3] = port mask (returns p-lines when its port is matched by this)
1024 * Or for stats k,K,i and I:
1025 * parv[3] = [user@]host.name (returns which K/I-lines match this)
1026 * or [user@]host.mask (returns which K/I-lines are mmatched by this)
1027 * (defaults to old reply if ommitted, when local or Oper)
1028 * A remote mask (something containing wildcards) is only
1029 * allowed for IRC Operators.
1031 * parv[3] = time param
1032 * parv[4] = time param
1033 * (see report_memleak_stats() in runmalloc.c for details)
1035 * This function is getting really ugly. -Ghostwolf
1037 int m_stats(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
1039 static char Sformat[] = ":%s %d %s Connection SendQ SendM SendKBytes "
1040 "RcveM RcveKBytes :Open since";
1041 static char Lformat[] = ":%s %d %s %s %u %u %u %u %u :" TIME_T_FMT;
1042 struct Message *mptr;
1043 struct Client *acptr;
1044 struct Gline* gline;
1045 struct ConfItem *aconf;
1046 char stat = parc > 1 ? parv[1][0] : '\0';
1049 /* m_stats is so obnoxiously full of special cases that the different
1050 * hunt_server() possiblites were becoming very messy. It now uses a
1051 * switch() so as to be easier to read and update as params change.
1056 /* open to all, standard # of params */
1060 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv) /* XXX DEAD */
1066 /* open to all, varying # of params */
1076 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv) /* XXX DEAD */
1082 if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv) /* XXX DEAD */
1089 /* oper only, varying # of params */
1096 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv) /* XXX DEAD */
1102 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s %s :%s", 2, parc, /* XXX DEAD */
1103 parv) != HUNTED_ISME)
1106 else if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv) /* XXX DEAD */
1112 /* oper only, standard # of params */
1115 if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv) /* XXX DEAD */
1127 int doall = 0, wilds = 0;
1129 if (parc > 3 && *parv[3])
1133 wilds = (*name == '*' || *name == '?');
1134 for (p = name + 1; *p; ++p)
1135 if ((*p == '*' || *p == '?') && p[-1] != '\\')
1144 * Send info about connections which match, or all if the
1145 * mask matches me.name. Only restrictions are on those who
1146 * are invisible not being visible to 'foreigners' who use
1147 * a wild card based search to list it.
1149 sendto_one(sptr, Sformat, me.name, RPL_STATSLINKINFO, parv[0]); /* XXX DEAD */
1150 for (i = 0; i <= HighestFd; i++)
1152 if (!(acptr = LocalClientArray[i]))
1154 /* Don't return clients when this is a request for `all' */
1155 if (doall && IsUser(acptr))
1157 /* Don't show invisible people to unauthorized people when using
1158 * wildcards -- Is this still needed now /stats is oper only ? */
1159 if (IsInvisible(acptr) && (doall || wilds) &&
1160 !(MyConnect(sptr) && IsOper(sptr)) &&
1161 !IsAnOper(acptr) && (acptr != sptr))
1163 /* Only show the ones that match the given mask - if any */
1164 if (!doall && wilds && match(name, acptr->name))
1166 /* Skip all that do not match the specific query */
1167 if (!(doall || wilds) && 0 != ircd_strcmp(name, acptr->name))
1169 sendto_one(sptr, Lformat, me.name, RPL_STATSLINKINFO, parv[0], /* XXX DEAD */
1171 (int)DBufLength(&acptr->sendQ), (int)acptr->sendM,
1172 (int)acptr->sendK, (int)acptr->receiveM, (int)acptr->receiveK,
1173 CurrentTime - acptr->firsttime);
1179 report_configured_links(sptr, CONF_SERVER);
1182 case 'g': /* send glines */
1183 gline_remove_expired(TStime());
1184 for (gline = GlobalGlineList; gline; gline = gline->next) {
1185 sendto_one(sptr, rpl_str(RPL_STATSGLINE), me.name, /* XXX DEAD */
1186 sptr->name, 'G', gline->name, gline->host,
1187 gline->expire, gline->reason);
1192 report_configured_links(sptr, CONF_HUB | CONF_LEAF);
1197 case 'k': /* display CONF_IPKILL as well
1198 as CONF_KILL -Kev */
1201 char *user, *host, *p;
1202 int conf_status = (stat == 'k' || stat == 'K') ? CONF_KLINE : CONF_CLIENT;
1203 if ((MyUser(sptr) || IsOper(sptr)) && parc < 4)
1205 report_configured_links(sptr, conf_status);
1208 if (parc < 4 || *parv[3] == '\0')
1209 return need_more_params(sptr,
1210 (conf_status & CONF_KLINE) ? "STATS K" : "STATS I");
1213 for (p = parv[3]; *p; p++)
1221 if (*p == '?' || *p == '*')
1227 if (!(MyConnect(sptr) || IsOper(sptr)))
1235 if (conf_status == CONF_CLIENT)
1237 user = 0; /* Not used, but to avoid compiler warning. */
1243 if ((host = strchr(parv[3], '@')))
1254 for (aconf = GlobalConfList; aconf; aconf = aconf->next)
1256 if ((aconf->status & conf_status))
1258 if (conf_status == CONF_KLINE)
1260 if ((!wilds && ((user || aconf->host[1]) &&
1261 !match(aconf->host, host) &&
1262 (!user || !match(aconf->name, user)))) ||
1263 (wilds && !mmatch(host, aconf->host) &&
1264 (!user || !mmatch(user, aconf->name))))
1266 sendto_one(sptr, rpl_str(RPL_STATSKLINE), me.name, /* XXX DEAD */
1267 sptr->name, 'K', aconf->host, aconf->passwd, aconf->name,
1268 aconf->port, get_conf_class(aconf));
1273 else if (conf_status == CONF_CLIENT)
1275 if ((!wilds && (!match(aconf->host, host) ||
1276 !match(aconf->name, host))) ||
1277 (wilds && (!mmatch(host, aconf->host) ||
1278 !mmatch(host, aconf->name))))
1280 sendto_one(sptr, rpl_str(RPL_STATSILINE), me.name, /* XXX DEAD */
1281 sptr->name, 'I', aconf->host, aconf->name,
1282 aconf->port, get_conf_class(aconf));
1292 #if !defined(NDEBUG)
1293 sendto_one(sptr, rpl_str(RPL_STATMEMTOT), /* XXX DEAD */
1294 me.name, parv[0], fda_get_byte_count(), fda_get_block_count());
1299 sendto_one(sptr, rpl_str(RPL_STATMEMTOT), /* XXX DEAD */
1300 me.name, parv[0], get_mem_size(), get_alloc_cnt());
1303 report_memleak_stats(sptr, parc, parv);
1305 #if !defined(MEMSIZESTATS) && !defined(MEMLEAKSTATS)
1306 sendto_one(sptr, ":%s NOTICE %s :stats M : Memory allocation monitoring " /* XXX DEAD */
1307 "is not enabled on this server", me.name, parv[0]);
1312 for (mptr = msgtab; mptr->cmd; mptr++)
1314 sendto_one(sptr, rpl_str(RPL_STATSCOMMANDS), /* XXX DEAD */
1315 me.name, parv[0], mptr->cmd, mptr->count, mptr->bytes);
1319 report_configured_links(sptr, CONF_OPS);
1324 * show listener ports
1325 * show hidden ports to opers, if there are more than 3 parameters,
1326 * interpret the fourth parameter as the port number, limit non-local
1327 * or non-oper results to 8 ports.
1329 show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0,
1330 (MyUser(sptr) || IsOper(sptr)) ? 100 : 8);
1335 send_usage(sptr, parv[0]);
1339 report_configured_links(sptr, CONF_CRULEALL);
1342 report_configured_links(sptr, CONF_CRULE);
1345 tstats(sptr, parv[0]);
1348 report_configured_links(sptr, CONF_TLINES);
1351 report_configured_links(sptr, CONF_UWORLD);
1357 nowr = CurrentTime - me.since;
1358 sendto_one(sptr, rpl_str(RPL_STATSUPTIME), me.name, parv[0], /* XXX DEAD */
1359 nowr / 86400, (nowr / 3600) % 24, (nowr / 60) % 60, nowr % 60);
1360 sendto_one(sptr, rpl_str(RPL_STATSCONN), me.name, parv[0], /* XXX DEAD */
1361 max_connection_count, max_client_count);
1371 send_listinfo(sptr, parv[0]);
1376 report_classes(sptr);
1380 count_memory(sptr, parv[0]);
1386 sendto_one(sptr, rpl_str(RPL_ENDOFSTATS), me.name, parv[0], stat); /* XXX DEAD */