]>
Commit | Line | Data |
---|---|---|
cfe0e8e4 CP |
1 | #include "../core/hooks.h" |
2 | #include "../control/control.h" | |
3 | #include "trusts.h" | |
4 | ||
2129448c CP |
5 | static int countext; |
6 | ||
cfe0e8e4 | 7 | static void policycheck(int hooknum, void *arg) { |
9097ab05 CP |
8 | void **args = arg; |
9 | nick *np = args[0]; | |
10 | long moving = (long)args[1]; | |
cfe0e8e4 | 11 | trusthost *th = gettrusthost(np); |
c2cc7b4c | 12 | trustgroup *tg; |
cfe0e8e4 | 13 | |
9097ab05 CP |
14 | if(moving) |
15 | return; | |
16 | ||
b9cafbd9 CP |
17 | if(!th) { |
18 | if(np->ipnode->usercount > 5) | |
c2cc7b4c | 19 | controlwall(NO_OPER, NL_TRUSTS, "Hard limit exceeded on IP: %s (untrusted) %d connected, 5 max.", IPtostr(np->p_ipaddr), np->ipnode->usercount); |
b9cafbd9 CP |
20 | return; |
21 | } | |
22 | ||
23 | tg = th->group; | |
2129448c CP |
24 | /* |
25 | * the purpose of this logic is to avoid spam like this: | |
26 | * WARNING: tgX exceeded limit: 11 connected vs 10 max | |
27 | * (goes back down to 10) | |
28 | * WARNING: tgX exceeded limit: 11 connected vs 10 max | |
29 | */ | |
30 | ||
31 | if(hooknum == HOOK_TRUSTS_NEWNICK) { | |
32 | if(tg->count > tg->maxusage) { | |
33 | if(tg->count > (long)tg->exts[countext]) { | |
34 | tg->exts[countext] = (void *)(long)tg->count; | |
35 | ||
36 | controlwall(NO_OPER, NL_TRUSTS, "Hard limit exceeded: '%s', %d connected, %d max.", tg->name->content, tg->count, tg->maxusage); | |
37 | } | |
38 | } | |
39 | } else { | |
40 | if(tg->count < tg->maxusage) | |
41 | tg->exts[countext] = (void *)(long)tg->count; | |
42 | } | |
cfe0e8e4 CP |
43 | } |
44 | ||
45 | void _init(void) { | |
2129448c CP |
46 | countext = registertgext("count"); |
47 | if(countext == -1) | |
48 | return; | |
49 | ||
cfe0e8e4 | 50 | registerhook(HOOK_TRUSTS_NEWNICK, policycheck); |
2129448c | 51 | registerhook(HOOK_TRUSTS_LOSTNICK, policycheck); |
cfe0e8e4 CP |
52 | } |
53 | ||
54 | void _fini(void) { | |
2129448c CP |
55 | if(countext == -1) |
56 | return; | |
57 | ||
58 | releasetgext(countext); | |
59 | ||
cfe0e8e4 | 60 | deregisterhook(HOOK_TRUSTS_NEWNICK, policycheck); |
2129448c | 61 | deregisterhook(HOOK_TRUSTS_LOSTNICK, policycheck); |
cfe0e8e4 | 62 | } |