]> jfr.im git - irc/quakenet/newserv.git/blob - trusts/trusts_policy.c
Allow developers to override some of the TG/TH limits.
[irc/quakenet/newserv.git] / trusts / trusts_policy.c
1 #include "../core/hooks.h"
2 #include "../control/control.h"
3 #include "../lib/irc_string.h"
4 #include "trusts.h"
5
6 static int countext;
7
8 static void policycheck(int hooknum, void *arg) {
9 void **args = arg;
10 nick *np = args[0];
11 long moving = (long)args[1];
12 trusthost *th = gettrusthost(np);
13 trustgroup *tg;
14
15 if(moving)
16 return;
17
18 if(!th)
19 return;
20
21 tg = th->group;
22
23 if(th->maxpernode && np->ipnode->usercount > th->maxpernode) {
24 controlwall(NO_OPER, NL_TRUSTS, "Hard connection limit exceeded on IP: %s (group: %s) %d connected, %d max.", IPtostr(np->p_ipaddr), tg->name->content, np->ipnode->usercount, th->maxpernode);
25 return;
26 }
27
28 /*
29 * the purpose of this logic is to avoid spam like this:
30 * WARNING: tgX exceeded limit: 11 connected vs 10 max
31 * (goes back down to 10)
32 * WARNING: tgX exceeded limit: 11 connected vs 10 max
33 */
34
35 if(hooknum == HOOK_TRUSTS_NEWNICK) {
36 if(tg->trustedfor && tg->count > tg->trustedfor) {
37 /*
38 if(tg->count > (long)tg->exts[countext]) {
39
40 tg->exts[countext] = (void *)(long)tg->count;
41 */
42 controlwall(NO_OPER, NL_TRUSTS, "Hard connection limit exceeded: '%s', %d connected, %d max.", tg->name->content, tg->count, tg->trustedfor);
43 }
44 /*
45 }
46 */
47 if((tg->mode == 1) && (np->ident[0] == '~'))
48 controlwall(NO_OPER, NL_TRUSTS, "Ident required: '%s' %s!%s@%s.", tg->name->content, np->nick, np->ident, np->host->name->content);
49
50 if(tg->maxperident > 0) {
51 int identcount = 0;
52 trusthost *th2;
53 nick *tnp;
54
55 for(th2=tg->hosts;th2;th2=th2->next) {
56 for(tnp=th2->users;tnp;tnp=nextbytrust(tnp)) {
57 if(!ircd_strcmp(tnp->ident, np->ident))
58 identcount++;
59 }
60 }
61
62 if(identcount > tg->maxperident)
63 controlwall(NO_OPER, NL_TRUSTS, "Hard ident limit exceeded: '%s' %s!%s@%s, %d connected, %d max.", tg->name->content, np->nick, np->ident, np->host->name->content, identcount, tg->maxperident);
64 }
65 } else {
66 if(tg->count < tg->maxusage)
67 tg->exts[countext] = (void *)(long)tg->count;
68 }
69 }
70
71 void _init(void) {
72 countext = registertgext("count");
73 if(countext == -1)
74 return;
75
76 registerhook(HOOK_TRUSTS_NEWNICK, policycheck);
77 registerhook(HOOK_TRUSTS_LOSTNICK, policycheck);
78 }
79
80 void _fini(void) {
81 if(countext == -1)
82 return;
83
84 releasetgext(countext);
85
86 deregisterhook(HOOK_TRUSTS_NEWNICK, policycheck);
87 deregisterhook(HOOK_TRUSTS_LOSTNICK, policycheck);
88 }