]>
jfr.im git - irc/quakenet/newserv.git/blob - trusts/events.c
1 #include "../core/hooks.h"
4 static void __counthandler(int hooknum
, void *arg
);
6 static void __newnick(int hooknum
, void *arg
) {
11 host
= irc_in_addr_v4_to_int(&sender
->p_ipaddr
);
12 th
= th_getbyhost(host
);
14 settrusthost(sender
, th
);
16 setnextbytrust(sender
, NULL
);
20 setnextbytrust(sender
, th
->users
);
23 /* sucks we have to do this, at least until we get priority hooks */
24 __counthandler(HOOK_TRUSTS_NEWNICK
, sender
);
25 triggerhook(HOOK_TRUSTS_NEWNICK
, sender
);
28 static void __lostnick(int hooknum
, void *arg
) {
29 nick
*sender
= arg
, *np
, *lp
;
30 trusthost
*th
= gettrusthost(sender
);
35 __counthandler(HOOK_TRUSTS_LOSTNICK
, sender
);
36 triggerhook(HOOK_TRUSTS_LOSTNICK
, sender
);
39 * we need to erase this nick from the trusthost list
40 * stored in the ->nextbytrust (ext) pointers in each nick
43 for(np
=th
->users
,lp
=NULL
;np
;lp
=np
,np
=nextbytrust(np
)) {
48 setnextbytrust(lp
, nextbytrust(np
));
50 th
->users
= nextbytrust(np
);
57 static void __counthandler(int hooknum
, void *arg
) {
58 time_t t
= time(NULL
);
59 trusthost
*th
= gettrusthost((nick
*)arg
);
60 trustgroup
*tg
= th
->group
;
62 tg
->lastseen
= th
->lastseen
= t
;
63 if(hooknum
== HOOK_TRUSTS_NEWNICK
) {
65 if(th
->count
> th
->maxusage
)
66 th
->maxusage
= th
->count
;
69 if(tg
->count
> tg
->maxusage
)
70 tg
->maxusage
= tg
->count
;
77 static int hooksregistered
;
79 static void __dbloaded(int hooknum
, void *arg
) {
87 registerhook(HOOK_NICK_NEWNICK
, __newnick
);
88 registerhook(HOOK_NICK_LOSTNICK
, __lostnick
);
90 /* registerhook(HOOK_TRUSTS_NEWNICK, __counthandler);
91 registerhook(HOOK_TRUSTS_LOSTNICK, __counthandler);
94 /* we could do it by host, but hosts and ips are not bijective :( */
95 for(i
=0;i
<NICKHASHSIZE
;i
++)
96 for(np
=nicktable
[i
];np
;np
=np
->next
)
100 static void __dbclosed(int hooknum
, void *arg
) {
105 deregisterhook(HOOK_NICK_NEWNICK
, __newnick
);
106 deregisterhook(HOOK_NICK_LOSTNICK
, __lostnick
);
109 deregisterhook(HOOK_TRUSTS_NEWNICK, __counthandler);
110 deregisterhook(HOOK_TRUSTS_LOSTNICK, __counthandler);
114 void trusts_deregisterevents(void) {
115 deregisterhook(HOOK_TRUSTS_DB_LOADED
, __dbloaded
);
116 deregisterhook(HOOK_TRUSTS_DB_CLOSED
, __dbclosed
);
121 void trusts_registerevents(void) {
122 registerhook(HOOK_TRUSTS_DB_LOADED
, __dbloaded
);
123 registerhook(HOOK_TRUSTS_DB_CLOSED
, __dbclosed
);