]>
Commit | Line | Data |
---|---|---|
84563ebd | 1 | /* authtracker module: Tracks when users come and go... */ |
2 | ||
3 | #include "authtracker.h" | |
4 | #include "../chanserv.h" | |
5 | #include "../../core/hooks.h" | |
6 | #include "../../nick/nick.h" | |
249a68b8 | 7 | #include "../../lib/irc_string.h" |
84563ebd | 8 | |
9 | #include <time.h> | |
10 | #include <string.h> | |
df196dd2 | 11 | #include <stdio.h> |
84563ebd | 12 | |
249a68b8 | 13 | #define NTERFACER_AUTH "nterfacer" |
14 | ||
84563ebd | 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 | |
21 | * LOSTNICK. */ | |
22 | ||
23 | unsigned int at_lastnum; | |
24 | time_t at_lastauthts; | |
25 | unsigned long at_lastuserid; | |
26 | ||
27 | unsigned long at_getuserid(nick *np) { | |
84563ebd | 28 | /* If they are not +r, forget it. */ |
29 | if (!IsAccount(np)) | |
30 | return 0; | |
249a68b8 | 31 | |
32 | /* Ignore that pesky nterfacer */ | |
33 | #ifdef NTERFACER_AUTH | |
34 | if (!ircd_strcmp(np->authname, NTERFACER_AUTH)) | |
35 | return 0; | |
36 | #endif | |
84563ebd | 37 | |
6e3ceea8 | 38 | /* Use the userid from authext only. */ |
84563ebd | 39 | if (np->auth) |
40 | return np->auth->userid; | |
41 | ||
84563ebd | 42 | Error("authtracker",ERR_WARNING,"Unable to get userID from IsAccount() user %s",np->nick); |
43 | return 0; | |
44 | } | |
45 | ||
46 | void at_handlequitorkill(int hooknum, void *arg) { | |
47 | void **args=arg; | |
48 | nick *np=args[0]; | |
49 | char *reason=args[1]; | |
50 | char *rreason; | |
673180ed | 51 | char resbuf[512]; |
84563ebd | 52 | unsigned long userid; |
53 | ||
54 | /* Ignore unauthed users, or those with no accountts */ | |
55 | if (!(userid=at_getuserid(np)) || !np->accountts) | |
56 | return; | |
57 | ||
84563ebd | 58 | at_lastuserid=userid; |
59 | at_lastauthts=np->accountts; | |
60 | at_lastnum=np->numeric; | |
61 | ||
673180ed | 62 | if (hooknum==HOOK_NICK_KILL && (rreason=strchr(reason,' '))) { |
63 | sprintf(resbuf,"Killed%s",rreason); | |
64 | reason=resbuf; | |
65 | } | |
84563ebd | 66 | |
67 | at_logquit(userid, np->accountts, time(NULL), reason); | |
68 | } | |
69 | ||
70 | void at_handlelostnick(int hooknum, void *arg) { | |
71 | nick *np=arg; | |
72 | unsigned long userid; | |
73 | ||
74 | if (!(userid=at_getuserid(np)) || !np->accountts) | |
75 | return; | |
76 | ||
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)) | |
79 | return; | |
80 | ||
81 | at_lostnick(np->numeric, userid, np->accountts, time(NULL), AT_NETSPLIT); | |
82 | } | |
83 | ||
84 | void at_newnick(int hooknum, void *arg) { | |
85 | nick *np=arg; | |
86 | unsigned long userid; | |
87 | ||
88 | /* Ignore unauthed users, or those with no TS */ | |
89 | if (!(userid=at_getuserid(np)) || !np->accountts) | |
90 | return; | |
91 | ||
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); | |
96 | } | |
97 | } | |
98 | ||
99 | void at_serverlinked(int hooknum, void *arg) { | |
100 | unsigned long servernum=(unsigned long)arg; | |
101 | ||
102 | at_serverback(servernum); | |
103 | } | |
104 | ||
105 | void at_hookinit() { | |
106 | registerhook(HOOK_NICK_QUIT, at_handlequitorkill); | |
107 | registerhook(HOOK_NICK_KILL, at_handlequitorkill); | |
108 | registerhook(HOOK_NICK_LOSTNICK, at_handlelostnick); | |
6e3ceea8 | 109 | registerhook(HOOK_NICK_NEWNICK, at_newnick); |
110 | registerhook(HOOK_NICK_ACCOUNT, at_newnick); | |
84563ebd | 111 | registerhook(HOOK_SERVER_LINKED, at_serverlinked); |
112 | } | |
113 | ||
114 | void at_hookfini() { | |
115 | deregisterhook(HOOK_NICK_QUIT, at_handlequitorkill); | |
116 | deregisterhook(HOOK_NICK_KILL, at_handlequitorkill); | |
117 | deregisterhook(HOOK_NICK_LOSTNICK, at_handlelostnick); | |
6e3ceea8 | 118 | deregisterhook(HOOK_NICK_NEWNICK, at_newnick); |
119 | deregisterhook(HOOK_NICK_ACCOUNT, at_newnick); | |
84563ebd | 120 | deregisterhook(HOOK_SERVER_LINKED, at_serverlinked); |
121 | } |