]>
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) {
41 deregisterhook(HOOK_NICK_NEWNICK
, &rqhook_account
);
42 deregisterhook(HOOK_NICK_ACCOUNT
, &rqhook_account
);
44 for(ft
=ftlist
;ft
;ft
=ft
->next
)
47 releasenickext(rqnext
);
50 static void rqhook_account(int hook
, void *arg
) {
51 nick
*np
= (nick
*)arg
;
54 /* Auth might be null for the newnick hook. */
58 /* Try to find an existing fasttrack record for this user. */
59 for(ft
=ftlist
;ft
;ft
=ft
->next
) {
60 if(np
->auth
->userid
==ft
->userid
) {
61 np
->exts
[rqnext
] = ft
;
67 static void rq_cleanup_fasttrack(void *arg
) {
71 static rq_fasttrack
*rq_getfasttrack(nick
*np
) {
74 /* Use an existing fast-track record if the nick has one. */
76 return np
->exts
[rqnext
];
81 ft
= malloc(sizeof(rq_fasttrack
));
86 ft
->userid
= np
->auth
->userid
;
90 np
->exts
[rqnext
] = ft
;
95 int rq_tryfasttrack(nick
*np
) {
96 rq_fasttrack
*ft
= rq_getfasttrack(np
);
98 /* Don't fast-track if we can't find a fast-track record. */
102 /* Refill targets if necessary. */
103 if(getnettime() > ft
->refill_time
) {
104 ft
->targets
= RQ_FASTTRACK_TARGETS
;
105 ft
->refill_time
= getnettime() + RQ_FASTTRACK_TIMEOUT
;
108 /* Check if we have a free target. */