]> jfr.im git - irc/quakenet/newserv.git/blob - localuser/localuserstats.c
Update the help for INVITE to reflect new functionality.
[irc/quakenet/newserv.git] / localuser / localuserstats.c
1 /* Functions for retrieving stats from the network to local users */
2
3 #include "localuser.h"
4 #include "../nick/nick.h"
5 #include "../irc/irc.h"
6 #include "../core/error.h"
7 #include "../lib/version.h"
8 #include "../lib/stringbuf.h"
9
10 #include <stdarg.h>
11 #include <stdio.h>
12 #include <assert.h>
13 #include <string.h>
14
15 MODULE_VERSION("")
16
17 int handleserverstats(void *source, int cargc, char **cargv);
18 int handleserverstatsend(void *source, int cargc, char **cargv);
19
20 #define RPL_STATSLINKINFO 211
21 #define RPL_STATSCOMMANDS 212
22 #define RPL_STATSCLINE 213
23 #define RPL_STATSNLINE 214 /* unused */
24 #define RPL_STATSILINE 215
25 #define RPL_STATSKLINE 216
26 #define RPL_STATSPLINE 217 /* Undernet extension */
27 #define RPL_STATSYLINE 218
28 #define RPL_STATSJLINE 222 /* Undernet extension */
29 #define RPL_STATSALINE 226 /* Hybrid, Undernet */
30 #define RPL_STATSQLINE 228 /* Undernet extension */
31 #define RPL_STATSVERBOSE 236 /* Undernet verbose server list */
32 #define RPL_STATSENGINE 237 /* Undernet engine name */
33 #define RPL_STATSFLINE 238 /* Undernet feature lines */
34 #define RPL_STATSLLINE 241 /* Undernet dynamicly loaded modules */
35 #define RPL_STATSUPTIME 242
36 #define RPL_STATSOLINE 243
37 #define RPL_STATSHLINE 244
38 #define RPL_STATSTLINE 246 /* Undernet extension */
39 #define RPL_STATSGLINE 247 /* Undernet extension */
40 #define RPL_STATSULINE 248 /* Undernet extension */
41 #define RPL_STATSCONN 250 /* Undernet extension */
42 #define RPL_STATSDLINE 275 /* Undernet extension */
43 #define RPL_STATSRLINE 276 /* Undernet extension */
44 #define RPL_STATSSLINE 398 /* QuakeNet extension -froo */
45
46 #define RPL_ENDOFSTATS 219
47
48 const int numerics[] = { RPL_STATSLINKINFO, RPL_STATSCOMMANDS, RPL_STATSCLINE, RPL_STATSNLINE, RPL_STATSILINE, RPL_STATSKLINE,
49 RPL_STATSPLINE, RPL_STATSYLINE, RPL_STATSJLINE, RPL_STATSALINE, RPL_STATSQLINE, RPL_STATSVERBOSE,
50 RPL_STATSENGINE, RPL_STATSFLINE, RPL_STATSLLINE, RPL_STATSUPTIME, RPL_STATSOLINE, RPL_STATSHLINE,
51 RPL_STATSTLINE, RPL_STATSGLINE,RPL_STATSULINE, RPL_STATSCONN, RPL_STATSDLINE, RPL_STATSRLINE,
52 RPL_STATSSLINE, 0 };
53
54 void _init() {
55 const int *i;
56 registernumerichandler(RPL_ENDOFSTATS,&handleserverstats,4);
57
58 for(i=&numerics[0];*i;i++)
59 registernumerichandler(*i,&handleserverstats,4);
60 }
61
62 void _fini() {
63 const int *i;
64 deregisternumerichandler(RPL_ENDOFSTATS,&handleserverstats);
65
66 for(i=&numerics[0];*i;i++)
67 deregisternumerichandler(*i,&handleserverstats);
68 }
69
70 /* stats look something like:
71 * XX 242 XXyyy :data
72 */
73
74 int handleserverstats(void *source, int cargc, char **cargv) {
75 void *nargs[3];
76 nick *target;
77 char outbuffer[BUFSIZE * 2 + 5];
78 long numeric = (long)source, i;
79 StringBuf buf;
80
81 if (cargc<4) {
82 return CMD_OK;
83 }
84
85 if (!(target=getnickbynumeric(numerictolong(cargv[2],5)))) {
86 Error("localuserchannel",ERR_WARNING,"Got stats for unknown local user %s.",cargv[2]);
87 return CMD_OK;
88 }
89
90 if (homeserver(target->numeric) != mylongnum) {
91 Error("localuserchannel",ERR_WARNING,"Got stats for non-local user %s.",target->nick);
92 return CMD_OK;
93 }
94
95 sbinit(&buf, outbuffer, sizeof(outbuffer));
96
97 /* bloody inefficient */
98 for(i=3;i<cargc;i++) {
99 if(i != 3)
100 sbaddchar(&buf, ' ');
101 if(i == cargc - 1)
102 sbaddchar(&buf, ':');
103
104 sbaddstr(&buf, cargv[i]);
105 }
106 sbterminate(&buf);
107
108 if(numeric != RPL_ENDOFSTATS) {
109 nargs[0]=(void *)cargv[0];
110 nargs[1]=(void *)numeric;
111 nargs[2]=(void *)outbuffer;
112
113 if (umhandlers[target->numeric&MAXLOCALUSER]) {
114 (umhandlers[target->numeric&MAXLOCALUSER])(target, LU_STATS, nargs);
115 }
116 } else {
117 if (umhandlers[target->numeric&MAXLOCALUSER]) {
118 (umhandlers[target->numeric&MAXLOCALUSER])(target, LU_STATS_END, (void *)outbuffer);
119 }
120 }
121
122 return CMD_OK;
123 }
124