]>
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"
13 #define NTERFACER_AUTH "nterfacer"
15 /* OK, we need to deal separately with users who have definitely gone (QUIT
16 * or KILL) and those who has mysteriously vanished (lost in netsplit).
17 * There are hooks for all these things, but sadly QUIT and KILL also
18 * trigger the generic "lost nick" hook. Luckily, these things always
19 * happen one after the other without any intervening quits, so we will keep
20 * track of the last QUIT or KILL details and ignore the subsequent
23 unsigned int at_lastnum
;
25 unsigned long at_lastuserid
;
27 unsigned long at_getuserid(nick
*np
) {
28 /* If they are not +r, forget it. */
32 /* Ignore that pesky nterfacer */
34 if (!ircd_strcmp(np
->authname
, NTERFACER_AUTH
))
38 /* Use the userid from authext only. */
40 return np
->auth
->userid
;
42 Error("authtracker",ERR_WARNING
,"Unable to get userID from IsAccount() user %s",np
->nick
);
46 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
,' '))) {
63 sprintf(resbuf
,"Killed%s",rreason
);
67 at_logquit(userid
, np
->accountts
, time(NULL
), reason
);
70 void at_handlelostnick(int hooknum
, void *arg
) {
74 if (!(userid
=at_getuserid(np
)) || !np
->accountts
)
77 /* Don't do this for a user that just left normally (see above) */
78 if ((userid
==at_lastuserid
) && (np
->accountts
== at_lastauthts
) && (np
->numeric
==at_lastnum
))
81 at_lostnick(np
->numeric
, userid
, np
->accountts
, time(NULL
), AT_NETSPLIT
);
84 void at_newnick(int hooknum
, void *arg
) {
88 /* Ignore unauthed users, or those with no TS */
89 if (!(userid
=at_getuserid(np
)) || !np
->accountts
)
92 /* OK, we've seen an authed user appear. If it's a known ghost we can zap it */
93 if (!at_foundnick(np
->numeric
, userid
, np
->accountts
)) {
94 /* If we didn't zap a ghost then it's a new session */
95 at_lognewsession(userid
, np
);
99 void at_serverlinked(int hooknum
, void *arg
) {
100 unsigned long servernum
=(unsigned long)arg
;
102 at_serverback(servernum
);
106 registerhook(HOOK_NICK_QUIT
, at_handlequitorkill
);
107 registerhook(HOOK_NICK_KILL
, at_handlequitorkill
);
108 registerhook(HOOK_NICK_LOSTNICK
, at_handlelostnick
);
109 registerhook(HOOK_NICK_NEWNICK
, at_newnick
);
110 registerhook(HOOK_NICK_ACCOUNT
, at_newnick
);
111 registerhook(HOOK_SERVER_LINKED
, at_serverlinked
);
115 deregisterhook(HOOK_NICK_QUIT
, at_handlequitorkill
);
116 deregisterhook(HOOK_NICK_KILL
, at_handlequitorkill
);
117 deregisterhook(HOOK_NICK_LOSTNICK
, at_handlelostnick
);
118 deregisterhook(HOOK_NICK_NEWNICK
, at_newnick
);
119 deregisterhook(HOOK_NICK_ACCOUNT
, at_newnick
);
120 deregisterhook(HOOK_SERVER_LINKED
, at_serverlinked
);