]>
jfr.im git - irc/quakenet/newserv.git/blob - request/request_fasttrack.c
3 #include "../core/schedule.h"
4 #include "../irc/irc.h"
5 #include "../lib/irc_string.h"
6 #include "request_fasttrack.h"
8 typedef struct rq_fasttrack
{
14 struct rq_fasttrack
*next
;
17 static rq_fasttrack
*ftlist
;
19 /* our fast-track extension */
22 static void rq_cleanup_fasttrack(void *arg
);
23 static void rqhook_account(int hook
, void *arg
);
25 int rq_initfasttrack(void) {
26 rqnext
= registernickext("request_fasttrack");
30 registerhook(HOOK_NICK_NEWNICK
, &rqhook_account
);
31 registerhook(HOOK_NICK_ACCOUNT
, &rqhook_account
);
33 schedulerecurring(time(NULL
)+1, 0, 3600, rq_cleanup_fasttrack
, NULL
);
38 void rq_finifasttrack(void) {
39 rq_fasttrack
*ft
, *next
;
41 deregisterhook(HOOK_NICK_NEWNICK
, &rqhook_account
);
42 deregisterhook(HOOK_NICK_ACCOUNT
, &rqhook_account
);
50 releasenickext(rqnext
);
53 static void rqhook_account(int hook
, void *arg
) {
54 nick
*np
= (nick
*)arg
;
57 /* Auth might be null for the newnick hook. */
61 /* Try to find an existing fasttrack record for this user. */
62 for(ft
=ftlist
;ft
;ft
=ft
->next
) {
63 if(np
->auth
->userid
==ft
->userid
) {
64 np
->exts
[rqnext
] = ft
;
70 static void rq_cleanup_fasttrack(void *arg
) {
71 time_t now
= getnettime();
72 rq_fasttrack
**pft
, *ft
;
80 for(ft
=*pft
;pft
&& *pft
;pft
=&((*pft
)->next
)) {
83 for(j
=0;j
<NICKHASHSIZE
&& !foundnick
;j
++) {
84 for(tnp
=nicktable
[j
];tnp
;tnp
=tnp
->next
) {
85 if(tnp
->exts
[rqnext
]==ft
) {
92 if(ft
->refill_time
< now
) {
99 static rq_fasttrack
*rq_getfasttrack(nick
*np
) {
102 /* Use an existing fast-track record if the nick has one. */
104 return np
->exts
[rqnext
];
109 ft
= malloc(sizeof(rq_fasttrack
));
114 ft
->userid
= np
->auth
->userid
;
121 np
->exts
[rqnext
] = ft
;
126 int rq_tryfasttrack(nick
*np
) {
127 rq_fasttrack
*ft
= rq_getfasttrack(np
);
129 /* Don't fast-track if we can't find a fast-track record. */
133 /* Refill targets if necessary. */
134 if(getnettime() > ft
->refill_time
) {
135 ft
->targets
= RQ_FASTTRACK_TARGETS
;
136 ft
->refill_time
= getnettime() + RQ_FASTTRACK_TIMEOUT
;
139 /* Check if we have a free target. */