📄 m_stats.c
字号:
/* * IRC - Internet Relay Chat, src/modules/out.c * (C) 2004 The UnrealIRCd Team * * See file AUTHORS in IRC package for additional names of * the programmers. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 1, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#include "config.h"#include "struct.h"#include "common.h"#include "sys.h"#include "numeric.h"#include "msg.h"#include "proto.h"#include "channel.h"#include <time.h>#include <sys/stat.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#ifdef _WIN32#include <io.h>#endif#include <fcntl.h>#include "h.h"#ifdef STRIPBADWORDS#include "badwords.h"#endif#ifdef _WIN32#include "version.h"#endifDLLFUNC int m_stats(aClient *cptr, aClient *sptr, int parc, char *parv[]);#define MSG_STATS "STATS" #define TOK_STATS "2" ModuleHeader MOD_HEADER(m_stats) = { "m_stats", "$Id: m_stats.c,v 1.1.6.8 2006/12/22 21:10:33 syzop Exp $", "command /stats", "3.2-b8-1", NULL };DLLFUNC int MOD_INIT(m_stats)(ModuleInfo *modinfo){ add_Command(MSG_STATS, TOK_STATS, m_stats, 3); MARK_AS_OFFICIAL_MODULE(modinfo); return MOD_SUCCESS;}DLLFUNC int MOD_LOAD(m_stats)(int module_load){ return MOD_SUCCESS;}DLLFUNC int MOD_UNLOAD(m_stats)(int module_unload){ if (del_Command(MSG_STATS, TOK_STATS, m_stats) < 0) { sendto_realops("Failed to delete commands when unloading %s", MOD_HEADER(m_stats).name); } return MOD_SUCCESS;}extern MODVAR int max_connection_count;extern char *get_client_name2(aClient *, int);int stats_banversion(aClient *, char *);int stats_links(aClient *, char *);int stats_denylinkall(aClient *, char *);int stats_gline(aClient *, char *);int stats_exceptban(aClient *, char *);int stats_allow(aClient *, char *);int stats_command(aClient *, char *);int stats_oper(aClient *, char *);int stats_port(aClient *, char *);int stats_bannick(aClient *, char *);int stats_usage(aClient *, char *);int stats_traffic(aClient *, char *);int stats_uline(aClient *, char *);int stats_vhost(aClient *, char *);int stats_mem(aClient *, char *);int stats_badwords(aClient *, char *);int stats_denylinkauto(aClient *, char *);int stats_exceptthrottle(aClient *, char *);int stats_denydcc(aClient *, char *);int stats_kline(aClient *, char *);int stats_banrealname(aClient *, char *);int stats_sqline(aClient *, char *);int stats_linkinfoint(aClient *, char *, int);int stats_linkinfo(aClient *, char *);int stats_linkinfoall(aClient *, char *);int stats_chanrestrict(aClient *, char *);int stats_shun(aClient *, char *);int stats_set(aClient *, char *);int stats_tld(aClient *, char *);int stats_uptime(aClient *, char *);int stats_denyver(aClient *, char *);int stats_notlink(aClient *, char *);int stats_class(aClient *, char *);int stats_zip(aClient *, char *);int stats_officialchannels(aClient *, char *);int stats_spamfilter(aClient *, char *);#define SERVER_AS_PARA 0x1#define FLAGS_AS_PARA 0x2struct statstab { char flag; char *longflag; int (*func)(aClient *sptr, char *para); int options;};/* Must be listed lexicographically *//* Long flags must be lowercase */struct statstab StatsTable[] = { { 'B', "banversion", stats_banversion, 0 }, { 'C', "link", stats_links, 0 }, { 'D', "denylinkall", stats_denylinkall, 0 }, { 'E', "exceptban", stats_exceptban, 0 }, { 'F', "denydcc", stats_denydcc, 0 }, { 'G', "gline", stats_gline, FLAGS_AS_PARA }, { 'H', "link", stats_links, 0 }, { 'I', "allow", stats_allow, 0 }, { 'K', "kline", stats_kline, 0 }, { 'L', "linkinfoall", stats_linkinfoall, SERVER_AS_PARA }, { 'M', "command", stats_command, 0 }, { 'O', "oper", stats_oper, 0 }, { 'P', "port", stats_port, 0 }, { 'Q', "sqline", stats_sqline, FLAGS_AS_PARA }, { 'R', "usage", stats_usage, 0 }, { 'S', "set", stats_set, 0 }, { 'T', "traffic", stats_traffic, 0 }, { 'U', "uline", stats_uline, 0 }, { 'V', "vhost", stats_vhost, 0 }, { 'X', "notlink", stats_notlink, 0 }, { 'Y', "class", stats_class, 0 }, { 'Z', "mem", stats_mem, 0 }, { 'b', "badword", stats_badwords, 0 }, { 'c', "link", stats_links, 0 }, { 'd', "denylinkauto", stats_denylinkauto, 0 }, { 'e', "exceptthrottle",stats_exceptthrottle, 0 }, { 'f', "spamfilter", stats_spamfilter, FLAGS_AS_PARA }, { 'g', "gline", stats_gline, FLAGS_AS_PARA }, { 'h', "link", stats_links, 0 }, { 'j', "officialchans", stats_officialchannels, 0 }, { 'k', "kline", stats_kline, 0 }, { 'l', "linkinfo", stats_linkinfo, SERVER_AS_PARA }, { 'm', "command", stats_command, 0 }, { 'n', "banrealname", stats_banrealname, 0 }, { 'o', "oper", stats_oper, 0 }, { 'q', "bannick", stats_bannick, FLAGS_AS_PARA }, { 'r', "chanrestrict", stats_chanrestrict, 0 }, { 's', "shun", stats_shun, FLAGS_AS_PARA }, { 't', "tld", stats_tld, 0 }, { 'u', "uptime", stats_uptime, 0 }, { 'v', "denyver", stats_denyver, 0 }, { 'x', "notlink", stats_notlink, 0 }, { 'y', "class", stats_class, 0 }, { 'z', "zip", stats_zip, 0 }, { 0, NULL, NULL, 0 }};int stats_compare(char *s1, char *s2){ /* The long stats flags are always lowercase */ while (*s1 == tolower(*s2)) { if (*s1 == 0) return 0; s1++; s2++; } return 1;} inline struct statstab *stats_binary_search(char c) { int start = 0; int stop = sizeof(StatsTable)/sizeof(StatsTable[0])-1; int mid; while (start <= stop) { mid = (start+stop)/2; if (c < StatsTable[mid].flag) stop = mid-1; else if (StatsTable[mid].flag == c) return &StatsTable[mid]; else start = mid+1; } return NULL;}inline struct statstab *stats_search(char *s) { int i; for (i = 0; StatsTable[i].flag; i++) if (!stats_compare(StatsTable[i].longflag,s)) return &StatsTable[i]; return NULL;}inline char *stats_combine_parv(char *p1, char *p2){ static char buf[BUFSIZE+1]; strcpy(buf, p1); strcat(buf, " "); strcat(buf, p2); return buf;}inline void stats_help(aClient *sptr){ sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "/Stats flags:"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "B - banversion - Send the ban version list"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "b - badword - Send the badwords list"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "C - link - Send the link block list"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "d - denylinkauto - Send the deny link (auto) block list"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "D - denylinkall - Send the deny link (all) block list"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "e - exceptthrottle - Send the except throttle block list"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "E - exceptban - Send the except ban and except tkl block list"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "f - spamfilter - Send the spamfilter list"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "F - denydcc - Send the deny dcc and allow dcc block lists"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "G - gline - Send the gline and gzline list"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, " Extended flags: [+/-mrs] [mask] [reason] [setby]"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, " m Return glines matching/not matching the specified mask"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, " r Return glines with a reason matching/not matching the specified reason"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, " s Return glines set by/not set by clients matching the specified name"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "I - allow - Send the allow block list"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "j - officialchans - Send the offical channels list"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "K - kline - Send the ban user/ban ip/except ban block list"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "l - linkinfo - Send link information"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "L - linkinfoall - Send all link information"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "M - command - Send list of how many times each command was used"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "n - banrealname - Send the ban realname block list"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "O - oper - Send the oper block list"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "P - port - Send information about ports"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "q - bannick - Send the ban nick block list"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "Q - sqline - Send the global qline list"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "r - chanrestrict - Send the channel deny/allow block list");#ifdef DEBUGMODE sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "R - usage - Send usage information");#endif sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "S - set - Send the set block list"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "s - shun - Send the shun list"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, " Extended flags: [+/-mrs] [mask] [reason] [setby]"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, " m Return shuns matching/not matching the specified mask"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, " r Return shuns with a reason matching/not matching the specified reason"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, " s Return shuns set by/not set by clients matching the specified name"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "t - tld - Send the tld block list"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "T - traffic - Send traffic information"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "u - uptime - Send the server uptime and connection count"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "U - uline - Send the ulines block list"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "v - denyver - Send the deny version block list"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "V - vhost - Send the vhost block list"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "X - notlink - Send the list of servers that are not current linked"); sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "Y - class - Send the class block list");#ifdef ZIP_LINKS sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "z - zip - Send compression information about ziplinked servers");#endif sendto_one(sptr, rpl_str(RPL_STATSHELP), me.name, sptr->name, "Z - mem - Send memory usage information");}inline int stats_operonly_short(char c){ char l; if (!OPER_ONLY_STATS) return 0; if (*OPER_ONLY_STATS == '*') return 1; if (strchr(OPER_ONLY_STATS, c)) return 1; l = tolower(c); /* Hack for the flags that are case insensitive */ if (l == 'o' || l == 'y' || l == 'k' || l == 'g' || l == 'x' || l == 'c' || l =='f' || l == 'i' || l == 'h') { if (islower(c) && strchr(OPER_ONLY_STATS, toupper(c))) return 1; else if (isupper(c) && strchr(OPER_ONLY_STATS, tolower(c))) return 1; } /* Hack for c/C/H/h */ if (l == 'c') { if (strpbrk(OPER_ONLY_STATS, "hH")) return 1; } else if (l == 'h') if (strpbrk(OPER_ONLY_STATS, "cC")) return 1; return 0;}inline int stats_operonly_long(char *s){ OperStat *os; for (os = iConf.oper_only_stats_ext; os; os = (OperStat *)os->next) { if (!stricmp(os->flag, s)) return 1; } return 0;}/* This is pretty slow, but it isn't used often so it isn't a big deal */inline char *stats_operonly_long_to_short(){ static char buffer[BUFSIZE+1]; int i = 0; OperStat *os; for (os = iConf.oper_only_stats_ext; os; os = (OperStat *)os->next) { struct statstab *stat = stats_search(os->flag); if (!stat) continue; if (!strchr(OPER_ONLY_STATS, stat->flag)) buffer[i++] = stat->flag; } buffer[i] = 0; return buffer;}DLLFUNC CMD_FUNC(m_stats){ struct statstab *stat; if (parc == 3 && parv[2][0] != '+' && parv[2][0] != '-') { if (hunt_server_token(cptr, sptr, MSG_STATS, TOK_STATS, "%s :%s", 2, parc, parv) != HUNTED_ISME) return 0; } else if (parc == 4 && parv[2][0] != '+' && parv[2][0] != '-') { if (hunt_server_token(cptr, sptr, MSG_STATS, TOK_STATS, "%s %s %s", 2, parc, parv) != HUNTED_ISME) return 0; } if (parc < 2 || !*parv[1]) { stats_help(sptr); sendto_one(sptr, rpl_str(RPL_ENDOFSTATS), me.name, parv[0], '*'); return 0; } /* Decide if we are looking for 1 char or a string */ if (parv[1][0] && !parv[1][1]) { if (!IsAnOper(sptr) && stats_operonly_short(parv[1][0])) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -