]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/authtracker/authtracker_hooks.c
1 /* authtracker module: Tracks when users come and go... */
3 #include "authtracker.h"
4 #include "../chanserv.h"
5 #include "../../core/hooks.h"
6 #include "../../nick/nick.h"
7 #include "../../lib/irc_string.h"
12 #define NTERFACER_AUTH "nterfacer"
14 /* OK, we need to deal separately with users who have definitely gone (QUIT
15 * or KILL) and those who has mysteriously vanished (lost in netsplit).
16 * There are hooks for all these things, but sadly QUIT and KILL also
17 * trigger the generic "lost nick" hook. Luckily, these things always
18 * happen one after the other without any intervening quits, so we will keep
19 * track of the last QUIT or KILL details and ignore the subsequent
22 unsigned int at_lastnum
;
24 unsigned long at_lastuserid
;
26 unsigned long at_getuserid(nick
*np
) {
29 /* If they are not +r, forget it. */
33 /* Ignore that pesky nterfacer */
35 if (!ircd_strcmp(np
->authname
, NTERFACER_AUTH
))
39 /* Use the userid from authext only. */
41 return np
->auth
->userid
;
43 Error("authtracker",ERR_WARNING
,"Unable to get userID from IsAccount() user %s",np
->nick
);
47 void at_handlequitorkill(int hooknum
, void *arg
) {
54 /* Ignore unauthed users, or those with no accountts */
55 if (!(userid
=at_getuserid(np
)) || !np
->accountts
)
59 at_lastauthts
=np
->accountts
;
60 at_lastnum
=np
->numeric
;
62 if (hooknum
==HOOK_NICK_KILL
&& (rreason
=strchr(reason
,'@')))
65 at_logquit(userid
, np
->accountts
, time(NULL
), reason
);
68 void at_handlelostnick(int hooknum
, void *arg
) {
72 if (!(userid
=at_getuserid(np
)) || !np
->accountts
)
75 /* Don't do this for a user that just left normally (see above) */
76 if ((userid
==at_lastuserid
) && (np
->accountts
== at_lastauthts
) && (np
->numeric
==at_lastnum
))
79 at_lostnick(np
->numeric
, userid
, np
->accountts
, time(NULL
), AT_NETSPLIT
);
82 void at_newnick(int hooknum
, void *arg
) {
86 /* Ignore unauthed users, or those with no TS */
87 if (!(userid
=at_getuserid(np
)) || !np
->accountts
)
90 /* OK, we've seen an authed user appear. If it's a known ghost we can zap it */
91 if (!at_foundnick(np
->numeric
, userid
, np
->accountts
)) {
92 /* If we didn't zap a ghost then it's a new session */
93 at_lognewsession(userid
, np
);
97 void at_serverlinked(int hooknum
, void *arg
) {
98 unsigned long servernum
=(unsigned long)arg
;
100 at_serverback(servernum
);
104 registerhook(HOOK_NICK_QUIT
, at_handlequitorkill
);
105 registerhook(HOOK_NICK_KILL
, at_handlequitorkill
);
106 registerhook(HOOK_NICK_LOSTNICK
, at_handlelostnick
);
107 registerhook(HOOK_NICK_NEWNICK
, at_newnick
);
108 registerhook(HOOK_NICK_ACCOUNT
, at_newnick
);
109 registerhook(HOOK_SERVER_LINKED
, at_serverlinked
);
113 deregisterhook(HOOK_NICK_QUIT
, at_handlequitorkill
);
114 deregisterhook(HOOK_NICK_KILL
, at_handlequitorkill
);
115 deregisterhook(HOOK_NICK_LOSTNICK
, at_handlelostnick
);
116 deregisterhook(HOOK_NICK_NEWNICK
, at_newnick
);
117 deregisterhook(HOOK_NICK_ACCOUNT
, at_newnick
);
118 deregisterhook(HOOK_SERVER_LINKED
, at_serverlinked
);