]>
jfr.im git - irc/quakenet/newserv.git/blob - trusts/trusts.c
3 #include "../lib/version.h"
4 #include "../core/hooks.h"
5 #include "../core/error.h"
6 #include "../core/nsmalloc.h"
7 #include "../server/server.h"
12 void trusts_registerevents(void);
13 void trusts_deregisterevents(void);
15 static void statusfn(int, void *);
17 static sstring
*tgextnames
[MAXTGEXTS
];
19 int trusts_thext
, trusts_nextuserext
;
23 trusts_thext
= registernickext("trustth");
24 if(trusts_thext
== -1) {
25 Error("trusts", ERR_ERROR
, "Unable to register first nick extension.");
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.");
36 registerhook(HOOK_CORE_STATSREQUEST
, statusfn
);
37 trusts_registerevents();
41 if(trusts_thext
!= -1) {
42 releasenickext(trusts_thext
);
43 releasenickext(trusts_nextuserext
);
46 deregisterhook(HOOK_CORE_STATSREQUEST
, statusfn
);
47 trusts_deregisterevents();
49 nscheckfreeall(POOL_TRUSTS
);
52 static void statusfn(int hooknum
, void *arg
) {
55 int groupcount
= 0, hostcount
= 0, usercount
= 0;
59 for(tg
=tglist
;tg
;tg
=tg
->next
) {
62 for(th
=tg
->hosts
;th
;th
=th
->next
)
66 snprintf(message
, sizeof(message
), "Trusts :%7d groups, %7d hosts, %7d users", groupcount
, hostcount
, usercount
);
67 triggerhook(HOOK_CORE_STATSREPLY
, message
);
71 int findtgext(const char *name
) {
74 for(i
=0;i
<MAXTGEXTS
;i
++)
75 if(tgextnames
[i
] && !strcmp(name
, tgextnames
[i
]->content
))
81 int registertgext(const char *name
) {
84 if(findtgext(name
) != -1) {
85 Error("trusts", ERR_WARNING
, "Tried to register duplicate trust group extension: %s.", name
);
89 for(i
=0;i
<MAXNICKEXTS
;i
++) {
91 tgextnames
[i
] = getsstring(name
, 100);
96 Error("trusts", ERR_WARNING
, "Tried to register too many trust group extensions: %s.", name
);
100 void releasetgext(int index
) {
103 freesstring(tgextnames
[index
]);
104 tgextnames
[index
] = NULL
;
106 for(tg
=tglist
;tg
;tg
=tg
->next
)
107 tg
->exts
[index
] = NULL
;
110 int trusts_fullyonline(void) {
114 return serverlist
[myhub
].linkstate
== LS_LINKED
;