]> jfr.im git - irc/quakenet/newserv.git/blob - miscreply/stats.c
TRUSTS: require sqlite
[irc/quakenet/newserv.git] / miscreply / stats.c
1 /* stats.c */
2
3 #include "miscreply.h"
4 #include "../lib/irc_string.h"
5 #include "../irc/irc.h"
6 #include "../core/error.h"
7
8 #include <string.h>
9 #include <strings.h>
10
11
12
13 /* handle remote stats request
14 *
15 * <source numeric> STATS/R <stats type> <target server numeric> [<extra param>]
16 *
17 * cargv[0] = stats type
18 * cargv[1] = target server numeric
19 * cargv[2] = extra param (ignored)
20 *
21 */
22 int handlestatsmsg(void *source, int cargc, char **cargv) {
23
24 nick *snick; /* struct nick for source nick */
25 char *sourcenum = (char *)source; /* source user numeric */
26 char *statstype; /* stats paramenter */
27
28 /* check parameters */
29 if (cargc < 2) {
30 miscreply_needmoreparams(sourcenum, "STATS");
31 return CMD_OK;
32 }
33
34 /* get the parameters */
35 statstype = cargv[0];
36
37 /* find source user */
38 if (!(snick = miscreply_finduser(sourcenum, "STATS")))
39 return CMD_OK;
40
41
42 /* stats commands */
43 if (!strcmp(statstype, "m") || !strcasecmp(statstype, "commands")) {
44 stats_commands(sourcenum);
45 }
46
47
48 /* stats features */
49 else if (!strcasecmp(statstype, "f") ||
50 !strcasecmp(statstype, "features") || !strcasecmp(statstype, "featuresall")) {
51 /*
52 * 238 RPL_STATSFLINE "source 238 target F feature value"
53 * "irc.netsplit.net 217 foobar F HIDDEN_HOST users.quakenet.org"
54 */
55 if (HIS_HIDDENHOST)
56 irc_send("%s 238 %s F HIDDEN_HOST %s", getmynumeric(), sourcenum, HIS_HIDDENHOST);
57 if (HIS_SERVERNAME)
58 irc_send("%s 238 %s F HIS_SERVERNAME %s", getmynumeric(), sourcenum, HIS_SERVERNAME);
59 if (HIS_SERVERDESC)
60 irc_send("%s 238 %s F HIS_SERVERINFO %s", getmynumeric(), sourcenum, HIS_SERVERDESC);
61 }
62
63
64 /* stats ports
65 * NOTE: operserv uses this for lag check prior to sending out SETTIME
66 * as long as operserv is used, newserv must reply to STATS p
67 */
68 else if (!strcasecmp(statstype, "p") || !strcasecmp(statstype, "ports")) {
69 /*
70 * 217 RPL_STATSPLINE "source 217 target P port connection_count flags state"
71 * "irc.netsplit.net 217 foobar P 6667 10435 C active"
72 */
73 irc_send("%s 217 %s P none 0 :0x2000", getmynumeric(), sourcenum);
74 }
75
76
77 /* stats uptime */
78 else if (!strcmp(statstype, "u") || !strcasecmp(statstype, "uptime")) {
79 /*
80 * 242 RPL_STATSUPTIME "source 242 target :Server Up N days HH:NN:SS"
81 * "irc.netsplit.net 217 foobar :Server Up 0 days, 0:28:56"
82 */
83 irc_send("%s 242 %s :Server Up %s", getmynumeric(), sourcenum, longtoduration(time(NULL)-starttime, 0));
84 /*
85 * 250 RPL_STATSCONN "source 250 target :Highest connection count: count (count_clients clients)"
86 * "irc.netsplit.net 250 foobar :Highest connection count: 25001 (25000 clients)"
87 */
88 irc_send("%s 250 %s :Highest connection count: 10 (9 clients)", getmynumeric(), sourcenum);
89 }
90
91
92 /* tell user what stats we have */
93 else {
94 statstype = "*";
95 /* NOTICE/O */
96 irc_send("%s O %s :m (commands) - Message usage information.", getmynumeric(), sourcenum);
97 irc_send("%s O %s :f (features) - Feature settings.", getmynumeric(), sourcenum);
98 irc_send("%s O %s :p (ports) - Listening ports.", getmynumeric(), sourcenum);
99 irc_send("%s O %s :u (uptime) - Current uptime & highest connection count.", getmynumeric(), sourcenum);
100 }
101
102
103 /* end of stats
104 *
105 * 219 RPL_ENDOFSTATS "source 219 target type :End of /STATS report"
106 * "irc.netsplit.net 391 foobar P :End of /STATS report"
107 */
108 irc_send("%s 219 %s %s :End of /STATS report", getmynumeric(), sourcenum, statstype);
109
110 return CMD_OK;
111 }