]> jfr.im git - irc/quakenet/newserv.git/blame - miscreply/stats.c
CHANSERV: better batcher error handling for expired accounts/accounts with no email.
[irc/quakenet/newserv.git] / miscreply / stats.c
CommitLineData
7bec4aeb 1/* stats.c */
2
3#include "miscreply.h"
7bec4aeb 4#include "../lib/irc_string.h"
5#include "../irc/irc.h"
6#include "../core/error.h"
7bec4aeb 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 */
22int handlestatsmsg(void *source, int cargc, char **cargv) {
23
a7697869 24 nick *snick; /* struct nick for source nick */
25 char *sourcenum = (char *)source; /* source user numeric */
26 char *statstype; /* stats paramenter */
7bec4aeb 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];
7bec4aeb 36
37 /* find source user */
38 if (!(snick = miscreply_finduser(sourcenum, "STATS")))
39 return CMD_OK;
40
7bec4aeb 41
42 /* stats commands */
43 if (!strcmp(statstype, "m") || !strcasecmp(statstype, "commands")) {
a7697869 44 stats_commands(sourcenum);
7bec4aeb 45 }
46
47
48 /* stats features */
49 else if (!strcasecmp(statstype, "f") ||
a7697869 50 !strcasecmp(statstype, "features") || !strcasecmp(statstype, "featuresall")) {
7bec4aeb 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)
a7697869 56 irc_send("%s 238 %s F HIDDEN_HOST %s", getmynumeric(), sourcenum, HIS_HIDDENHOST);
7bec4aeb 57 if (HIS_SERVERNAME)
a7697869 58 irc_send("%s 238 %s F HIS_SERVERNAME %s", getmynumeric(), sourcenum, HIS_SERVERNAME);
7bec4aeb 59 if (HIS_SERVERDESC)
a7697869 60 irc_send("%s 238 %s F HIS_SERVERINFO %s", getmynumeric(), sourcenum, HIS_SERVERDESC);
7bec4aeb 61 }
62
63
a7697869 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 */
7bec4aeb 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 */
a7697869 73 irc_send("%s 217 %s P none 0 :0x2000", getmynumeric(), sourcenum);
7bec4aeb 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 */
a7697869 83 irc_send("%s 242 %s :Server Up %s", getmynumeric(), sourcenum, longtoduration(time(NULL)-starttime, 0));
7bec4aeb 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 */
a7697869 88 irc_send("%s 250 %s :Highest connection count: 10 (9 clients)", getmynumeric(), sourcenum);
7bec4aeb 89 }
90
91
92 /* tell user what stats we have */
93 else {
94 statstype = "*";
a7697869 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);
7bec4aeb 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 */
a7697869 108 irc_send("%s 219 %s %s :End of /STATS report", getmynumeric(), sourcenum, statstype);
7bec4aeb 109
110 return CMD_OK;
111}