]>
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 void trusts_newnick(nick
*sender
, int moving
) {
9 struct irc_in_addr ipaddress
;
11 ip_canonicalize_tunnel(&ipaddress
, &sender
->p_ipaddr
);
13 th
= th_getbyhost(&ipaddress
);
15 settrusthost(sender
, th
);
17 setnextbytrust(sender
, NULL
);
19 setnextbytrust(sender
, th
->users
);
21 setipnodebits(sender
, th
->nodebits
);
25 arg
[1] = (void *)(long)moving
;
27 /* sucks we have to do this, at least until we get priority hooks */
28 __counthandler(HOOK_TRUSTS_NEWNICK
, arg
);
30 triggerhook(HOOK_TRUSTS_NEWNICK
, arg
);
33 static void __newnick(int hooknum
, void *arg
) {
34 trusts_newnick(arg
, 0);
37 void trusts_lostnick(nick
*sender
, int moving
) {
39 trusthost
*th
= gettrusthost(sender
);
43 arg
[1] = (void *)(long)moving
;
45 __counthandler(HOOK_TRUSTS_LOSTNICK
, arg
);
46 triggerhook(HOOK_TRUSTS_LOSTNICK
, arg
);
52 * we need to erase this nick from the trusthost list
53 * stored in the ->nextbytrust (ext) pointers in each nick
56 for(np
=th
->users
,lp
=NULL
;np
;lp
=np
,np
=nextbytrust(np
)) {
61 setnextbytrust(lp
, nextbytrust(np
));
63 th
->users
= nextbytrust(np
);
70 static void __lostnick(int hooknum
, void *arg
) {
71 trusts_lostnick(arg
, 0);
74 static void __counthandler(int hooknum
, void *arg
) {
75 time_t t
= time(NULL
);
77 trusthost
*th
= gettrusthost((nick
*)args
[0]);
84 tg
->lastseen
= th
->lastseen
= t
;
85 if(hooknum
== HOOK_TRUSTS_NEWNICK
) {
87 if(th
->count
> th
->maxusage
)
88 th
->maxusage
= th
->count
;
91 if(tg
->count
> tg
->maxusage
)
92 tg
->maxusage
= tg
->count
;
99 static int hooksregistered
;
101 static void __dbloaded(int hooknum
, void *arg
) {
109 registerhook(HOOK_NICK_NEWNICK
, __newnick
);
110 registerhook(HOOK_NICK_LOSTNICK
, __lostnick
);
112 /* registerhook(HOOK_TRUSTS_NEWNICK, __counthandler);
113 registerhook(HOOK_TRUSTS_LOSTNICK, __counthandler);
116 /* we could do it by host, but hosts and ips are not bijective :( */
117 for(i
=0;i
<NICKHASHSIZE
;i
++)
118 for(np
=nicktable
[i
];np
;np
=np
->next
)
122 static void __dbclosed(int hooknum
, void *arg
) {
127 deregisterhook(HOOK_NICK_NEWNICK
, __newnick
);
128 deregisterhook(HOOK_NICK_LOSTNICK
, __lostnick
);
131 deregisterhook(HOOK_TRUSTS_NEWNICK, __counthandler);
132 deregisterhook(HOOK_TRUSTS_LOSTNICK, __counthandler);
136 void trusts_deregisterevents(void) {
137 deregisterhook(HOOK_TRUSTS_DB_LOADED
, __dbloaded
);
138 deregisterhook(HOOK_TRUSTS_DB_CLOSED
, __dbclosed
);
143 void trusts_registerevents(void) {
144 registerhook(HOOK_TRUSTS_DB_LOADED
, __dbloaded
);
145 registerhook(HOOK_TRUSTS_DB_CLOSED
, __dbclosed
);