]>
jfr.im git - irc/quakenet/newserv.git/blob - trusts/trusts.c
3 #include "../core/hooks.h"
4 #include "../core/error.h"
5 #include "../core/nsmalloc.h"
8 int trusts_loaddb(void);
9 void trusts_closedb(void);
10 void trusts_registerevents(void);
11 void trusts_deregisterevents(void);
13 static void statusfn(int, void *);
15 static int loaded
, unloaded
;
16 static sstring
*tgextnames
[MAXTGEXTS
];
18 int trusts_thext
, trusts_nextuserext
;
21 trusts_thext
= registernickext("trustth");
22 if(trusts_thext
== -1) {
23 Error("trusts", ERR_ERROR
, "Unable to register first nick extension.");
27 trusts_nextuserext
= registernickext("trustnext");
28 if(trusts_thext
== -1) {
29 releasenickext(trusts_thext
);
30 Error("trusts", ERR_ERROR
, "Unable to register second nick extension.");
38 registerhook(HOOK_CORE_STATSREQUEST
, statusfn
);
39 trusts_registerevents();
42 void trusts_unload(void) {
48 if(trusts_thext
!= -1) {
49 releasenickext(trusts_thext
);
50 releasenickext(trusts_nextuserext
);
54 deregisterhook(HOOK_CORE_STATSREQUEST
, statusfn
);
55 trusts_deregisterevents();
63 nscheckfreeall(POOL_TRUSTS
);
66 static void statusfn(int hooknum
, void *arg
) {
69 int groupcount
= 0, hostcount
= 0, usercount
= 0;
73 for(tg
=tglist
;tg
;tg
=tg
->next
) {
76 for(th
=tg
->hosts
;th
;th
=th
->next
)
80 snprintf(message
, sizeof(message
), "Trusts :%7d groups, %7d hosts, %7d users", groupcount
, hostcount
, usercount
);
81 triggerhook(HOOK_CORE_STATSREPLY
, message
);
85 int findtgext(const char *name
) {
88 for(i
=0;i
<MAXTGEXTS
;i
++)
89 if(tgextnames
[i
] && !strcmp(name
, tgextnames
[i
]->content
))
95 int registertgext(const char *name
) {
98 if(findtgext(name
) != -1) {
99 Error("trusts", ERR_WARNING
, "Tried to register duplicate trust group extension: %s.", name
);
103 for(i
=0;i
<MAXNICKEXTS
;i
++) {
105 tgextnames
[i
] = getsstring(name
, 100);
110 Error("trusts", ERR_WARNING
, "Tried to register too many trust group extensions: %s.", name
);
114 void releasetgext(int index
) {
117 freesstring(tgextnames
[index
]);
118 tgextnames
[index
] = NULL
;
120 for(tg
=tglist
;tg
;tg
=tg
->next
)
121 tg
->exts
[index
] = NULL
;