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