]> jfr.im git - irc/quakenet/newserv.git/blob - localuser/localuserstats.c
Add MODULE_VERSION to all default modules.
[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
9 #include <stdarg.h>
10 #include <stdio.h>
11 #include <assert.h>
12 #include <string.h>
13
14 MODULE_VERSION("")
15
16 int handleserverstats(void *source, int cargc, char **cargv);
17 int handleserverstatsend(void *source, int cargc, char **cargv);
18
19 #define RPL_STATSCLINE 213
20 #define RPL_STATSCOMMANDS 212
21 #define RPL_STATSCONN 250
22 #define RPL_STATSDLINE 275
23 #define RPL_STATSENGINE 237
24 #define RPL_STATSHLINE 244
25 #define RPL_STATSILINE 215
26 #define RPL_STATSKLINE 216
27 #define RPL_STATSLINKINFO 211
28 #define RPL_STATSLLINE 241
29 #define RPL_STATSOLINE 243
30 #define RPL_STATSQLINE 228
31 #define RPL_STATSSLINE 398
32 #define RPL_STATSULINE 248
33 #define RPL_STATSUPTIME 242
34 #define RPL_STATSVERBOSE 236
35 #define RPL_TEXT 304
36
37 const int numerics[] = { RPL_STATSCLINE, RPL_STATSCOMMANDS, RPL_STATSCONN, RPL_STATSDLINE,
38 RPL_STATSENGINE, RPL_STATSHLINE, RPL_STATSILINE, RPL_STATSKLINE,
39 RPL_STATSLINKINFO, RPL_STATSLLINE, RPL_STATSOLINE, RPL_STATSQLINE,
40 RPL_STATSSLINE, RPL_STATSULINE, RPL_STATSUPTIME, RPL_STATSVERBOSE,
41 RPL_TEXT, 0 };
42 void _init() {
43 const int *i;
44 registernumerichandler(219,&handleserverstats,4);
45
46 for(i=&numerics[0];*i;i++)
47 registernumerichandler(*i,&handleserverstats,4);
48 }
49
50 void _fini() {
51 const int *i;
52 deregisternumerichandler(219,&handleserverstats);
53
54 for(i=&numerics[0];*i;i++)
55 deregisternumerichandler(*i,&handleserverstats);
56 }
57
58 /* stats look something like:
59 * XX 242 XXyyy :data
60 */
61
62 int handleserverstats(void *source, int cargc, char **cargv) {
63 void *nargs[3];
64 nick *target;
65 static char outbuffer[BUFSIZE * 2 + 5];
66 long numeric = (long)source, i;
67
68 if (cargc<4) {
69 return CMD_OK;
70 }
71
72 if (!(target=getnickbynumeric(numerictolong(cargv[2],5)))) {
73 Error("localuserchannel",ERR_WARNING,"Got stats for unknown local user %s.",cargv[2]);
74 return CMD_OK;
75 }
76
77 if (homeserver(target->numeric) != mylongnum) {
78 Error("localuserchannel",ERR_WARNING,"Got stats for non-local user %s.",target->nick);
79 return CMD_OK;
80 }
81
82 outbuffer[0] = '\0';
83
84 /* bloody inefficient */
85 for(i=3;i<cargc;i++) {
86 if(i != 3)
87 strcat(outbuffer, " ");
88 if(i == cargc - 1)
89 strcat(outbuffer, ":");
90
91 strcat(outbuffer, cargv[i]);
92 }
93 outbuffer[sizeof(outbuffer) - 1] = '\0';
94
95 if(numeric != 219) {
96 nargs[0]=(void *)cargv[0];
97 nargs[1]=(void *)numeric;
98 nargs[2]=(void *)outbuffer;
99
100 if (umhandlers[target->numeric&MAXLOCALUSER]) {
101 (umhandlers[target->numeric&MAXLOCALUSER])(target, LU_STATS, nargs);
102 }
103 } else {
104 if (umhandlers[target->numeric&MAXLOCALUSER]) {
105 (umhandlers[target->numeric&MAXLOCALUSER])(target, LU_STATS_END, (void *)outbuffer);
106 }
107 }
108
109 return CMD_OK;
110 }
111