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