]>
jfr.im git - irc/quakenet/newserv.git/blob - trusts/events.c
1 #include "../core/hooks.h"
4 static int eventsregistered
;
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 triggerhook(HOOK_TRUSTS_NEWNICK
, sender
);
26 static void __lostnick(int hooknum
, void *arg
) {
27 nick
*sender
= arg
, *np
, *lp
;
28 trusthost
*th
= gettrusthost(sender
);
33 triggerhook(HOOK_TRUSTS_LOSTNICK
, sender
);
36 * we need to erase this nick from the trusthost list
37 * stored in the ->nextbytrust (ext) pointers in each nick
40 for(np
=th
->users
,lp
=NULL
;np
;lp
=np
,np
=nextbytrust(np
)) {
45 setnextbytrust(lp
, nextbytrust(np
));
47 th
->users
= nextbytrust(np
);
54 static void __counthandler(int hooknum
, void *arg
) {
55 trusthost
*th
= gettrusthost((nick
*)arg
);
57 if(hooknum
== HOOK_TRUSTS_NEWNICK
) {
66 static void __dbloaded(int hooknum
, void *arg
) {
72 registerhook(HOOK_NICK_NEWNICK
, __newnick
);
73 registerhook(HOOK_NICK_LOSTNICK
, __lostnick
);
75 registerhook(HOOK_TRUSTS_NEWNICK
, __counthandler
);
76 registerhook(HOOK_TRUSTS_LOSTNICK
, __counthandler
);
78 /* we could do it by host, but hosts and ips are not bijective :( */
79 for(i
=0;i
<NICKHASHSIZE
;i
++)
80 for(np
=nicktable
[i
];np
;np
=np
->next
)
84 void trusts_registerevents(void) {
85 registerhook(HOOK_TRUSTS_DB_LOADED
, __dbloaded
);
91 void trusts_deregisterevents(void) {
92 if(eventsregistered
) {
93 deregisterhook(HOOK_NICK_NEWNICK
, __newnick
);
94 deregisterhook(HOOK_NICK_LOSTNICK
, __lostnick
);
96 deregisterhook(HOOK_TRUSTS_NEWNICK
, __counthandler
);
97 deregisterhook(HOOK_TRUSTS_LOSTNICK
, __counthandler
);
100 deregisterhook(HOOK_TRUSTS_DB_LOADED
, __dbloaded
);