]>
jfr.im git - irc/quakenet/newserv.git/blob - trusts/trusts.c
3 #include "../core/hooks.h"
4 #include "../core/error.h"
7 int trusts_loaddb(void);
8 void trusts_closedb(void);
9 void trusts_registerevents(void);
10 void trusts_deregisterevents(void);
12 static void statusfn(int, void *);
14 static int loaded
, unloaded
;
15 static sstring
*tgextnames
[MAXTGEXTS
];
17 int trusts_thext
, trusts_nextuserext
;
20 trusts_thext
= registernickext("trustth");
21 if(trusts_thext
== -1) {
22 Error("trusts", ERR_ERROR
, "Unable to register first nick extension.");
26 trusts_nextuserext
= registernickext("trustnext");
27 if(trusts_thext
== -1) {
28 releasenickext(trusts_thext
);
29 Error("trusts", ERR_ERROR
, "Unable to register second nick extension.");
37 registerhook(HOOK_CORE_STATSREQUEST
, statusfn
);
38 trusts_registerevents();
41 void trusts_unload(void) {
47 if(trusts_thext
!= -1) {
48 releasenickext(trusts_thext
);
49 releasenickext(trusts_nextuserext
);
53 deregisterhook(HOOK_CORE_STATSREQUEST
, statusfn
);
54 trusts_deregisterevents();
64 static void statusfn(int hooknum
, void *arg
) {
67 int groupcount
= 0, hostcount
= 0, usercount
= 0;
71 for(tg
=tglist
;tg
;tg
=tg
->next
) {
74 for(th
=tg
->hosts
;th
;th
=th
->next
)
78 snprintf(message
, sizeof(message
), "Trusts :%7d groups, %7d hosts, %7d users", groupcount
, hostcount
, usercount
);
79 triggerhook(HOOK_CORE_STATSREPLY
, message
);
83 int findtgext(const char *name
) {
86 for(i
=0;i
<MAXTGEXTS
;i
++)
87 if(tgextnames
[i
] && !strcmp(name
, tgextnames
[i
]->content
))
93 int registertgext(const char *name
) {
96 if(findtgext(name
) != -1) {
97 Error("trusts", ERR_WARNING
, "Tried to register duplicate trust group extension: %s.", name
);
101 for(i
=0;i
<MAXNICKEXTS
;i
++) {
103 tgextnames
[i
] = getsstring(name
, 100);
108 Error("trusts", ERR_WARNING
, "Tried to register too many trust group extensions: %s.", name
);
112 void releasetgext(int index
) {
115 freesstring(tgextnames
[index
]);
116 tgextnames
[index
] = NULL
;
118 for(tg
=tglist
;tg
;tg
=tg
->next
)
119 tg
->exts
[index
] = NULL
;