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