]> jfr.im git - irc/quakenet/newserv.git/blame - trusts/trusts.c
Remove test #ifs around the GL commands.
[irc/quakenet/newserv.git] / trusts / trusts.c
CommitLineData
2d4ba67d 1#include <stdio.h>
2129448c 2#include <string.h>
c4610da5 3#include "../lib/version.h"
1bbe1ac3
CP
4#include "../core/hooks.h"
5#include "../core/error.h"
45989eab 6#include "../core/nsmalloc.h"
82a316e7 7#include "../server/server.h"
1bbe1ac3 8#include "trusts.h"
2b6e02e2 9
c4610da5
GB
10MODULE_VERSION("");
11
1bbe1ac3
CP
12void trusts_registerevents(void);
13void trusts_deregisterevents(void);
14
2d4ba67d 15static void statusfn(int, void *);
2b6e02e2 16
2129448c 17static sstring *tgextnames[MAXTGEXTS];
1bbe1ac3
CP
18
19int trusts_thext, trusts_nextuserext;
b9c52ee0 20int trustsdbloaded;
1bbe1ac3 21
2b6e02e2 22void _init(void) {
1bbe1ac3
CP
23 trusts_thext = registernickext("trustth");
24 if(trusts_thext == -1) {
25 Error("trusts", ERR_ERROR, "Unable to register first nick extension.");
26 return;
27 }
28
29 trusts_nextuserext = registernickext("trustnext");
30 if(trusts_thext == -1) {
31 releasenickext(trusts_thext);
32 Error("trusts", ERR_ERROR, "Unable to register second nick extension.");
33 return;
34 }
35
2d4ba67d 36 registerhook(HOOK_CORE_STATSREQUEST, statusfn);
1bbe1ac3 37 trusts_registerevents();
2b6e02e2
CP
38}
39
83bccee3 40void _fini(void) {
1bbe1ac3
CP
41 if(trusts_thext != -1) {
42 releasenickext(trusts_thext);
43 releasenickext(trusts_nextuserext);
44 }
45
b9c52ee0
CP
46 deregisterhook(HOOK_CORE_STATSREQUEST, statusfn);
47 trusts_deregisterevents();
2d4ba67d 48
45989eab 49 nscheckfreeall(POOL_TRUSTS);
45e8ce62
CP
50}
51
2d4ba67d
CP
52static void statusfn(int hooknum, void *arg) {
53 if((long)arg > 10) {
54 char message[100];
bf5b66e5 55 int groupcount = 0, hostcount = 0, usercount = 0;
2d4ba67d
CP
56 trustgroup *tg;
57 trusthost *th;
58
59 for(tg=tglist;tg;tg=tg->next) {
bf5b66e5 60 usercount+=tg->count;
2d4ba67d
CP
61 groupcount++;
62 for(th=tg->hosts;th;th=th->next)
63 hostcount++;
64 }
65
bf5b66e5 66 snprintf(message, sizeof(message), "Trusts :%7d groups, %7d hosts, %7d users", groupcount, hostcount, usercount);
2d4ba67d
CP
67 triggerhook(HOOK_CORE_STATSREPLY, message);
68 }
2b6e02e2 69}
2129448c
CP
70
71int findtgext(const char *name) {
72 int i;
73
74 for(i=0;i<MAXTGEXTS;i++)
75 if(tgextnames[i] && !strcmp(name, tgextnames[i]->content))
76 return i;
77
78 return -1;
79}
80
81int registertgext(const char *name) {
82 int i;
83
84 if(findtgext(name) != -1) {
85 Error("trusts", ERR_WARNING, "Tried to register duplicate trust group extension: %s.", name);
86 return -1;
87 }
88
89 for(i=0;i<MAXNICKEXTS;i++) {
90 if(!tgextnames[i]) {
91 tgextnames[i] = getsstring(name, 100);
92 return i;
93 }
94 }
95
96 Error("trusts", ERR_WARNING, "Tried to register too many trust group extensions: %s.", name);
97 return -1;
98}
99
100void releasetgext(int index) {
101 trustgroup *tg;
102
103 freesstring(tgextnames[index]);
104 tgextnames[index] = NULL;
105
106 for(tg=tglist;tg;tg=tg->next)
107 tg->exts[index] = NULL;
108}
82a316e7
CP
109
110int trusts_fullyonline(void) {
111 if(myhub == -1)
112 return 0;
113
114 return serverlist[myhub].linkstate == LS_LINKED;
115}
116