]>
Commit | Line | Data |
---|---|---|
2d4ba67d | 1 | #include <stdio.h> |
1bbe1ac3 CP |
2 | #include "../core/hooks.h" |
3 | #include "../core/error.h" | |
4 | #include "trusts.h" | |
2b6e02e2 | 5 | |
2b6e02e2 CP |
6 | int trusts_loaddb(void); |
7 | void trusts_closedb(void); | |
1bbe1ac3 CP |
8 | void trusts_registerevents(void); |
9 | void trusts_deregisterevents(void); | |
10 | ||
2d4ba67d | 11 | static void statusfn(int, void *); |
2b6e02e2 | 12 | |
1bbe1ac3 CP |
13 | static int loaded; |
14 | ||
15 | int trusts_thext, trusts_nextuserext; | |
16 | ||
2b6e02e2 | 17 | void _init(void) { |
1bbe1ac3 CP |
18 | trusts_thext = registernickext("trustth"); |
19 | if(trusts_thext == -1) { | |
20 | Error("trusts", ERR_ERROR, "Unable to register first nick extension."); | |
21 | return; | |
22 | } | |
23 | ||
24 | trusts_nextuserext = registernickext("trustnext"); | |
25 | if(trusts_thext == -1) { | |
26 | releasenickext(trusts_thext); | |
27 | Error("trusts", ERR_ERROR, "Unable to register second nick extension."); | |
28 | return; | |
29 | } | |
30 | ||
2b6e02e2 CP |
31 | if(!trusts_loaddb()) |
32 | return; | |
1bbe1ac3 | 33 | loaded = 1; |
2d4ba67d CP |
34 | |
35 | registerhook(HOOK_CORE_STATSREQUEST, statusfn); | |
1bbe1ac3 | 36 | trusts_registerevents(); |
2b6e02e2 CP |
37 | } |
38 | ||
39 | void _fini(void) { | |
1bbe1ac3 CP |
40 | if(trusts_thext != -1) { |
41 | releasenickext(trusts_thext); | |
42 | releasenickext(trusts_nextuserext); | |
43 | } | |
44 | ||
45 | if(loaded) { | |
46 | deregisterhook(HOOK_CORE_STATSREQUEST, statusfn); | |
47 | trusts_deregisterevents(); | |
48 | } | |
2d4ba67d | 49 | |
1bbe1ac3 | 50 | trusts_closedb(); |
2d4ba67d CP |
51 | } |
52 | ||
2d4ba67d CP |
53 | static void statusfn(int hooknum, void *arg) { |
54 | if((long)arg > 10) { | |
55 | char message[100]; | |
bf5b66e5 | 56 | int groupcount = 0, hostcount = 0, usercount = 0; |
2d4ba67d CP |
57 | trustgroup *tg; |
58 | trusthost *th; | |
59 | ||
60 | for(tg=tglist;tg;tg=tg->next) { | |
bf5b66e5 | 61 | usercount+=tg->count; |
2d4ba67d CP |
62 | groupcount++; |
63 | for(th=tg->hosts;th;th=th->next) | |
64 | hostcount++; | |
65 | } | |
66 | ||
bf5b66e5 | 67 | snprintf(message, sizeof(message), "Trusts :%7d groups, %7d hosts, %7d users", groupcount, hostcount, usercount); |
2d4ba67d CP |
68 | triggerhook(HOOK_CORE_STATSREPLY, message); |
69 | } | |
2b6e02e2 | 70 | } |