]> jfr.im git - irc/quakenet/newserv.git/blame - chanserv/authtracker/authtracker_hooks.c
Don't log kill paths when a user is killed.
[irc/quakenet/newserv.git] / chanserv / authtracker / authtracker_hooks.c
CommitLineData
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>
11
249a68b8 12#define NTERFACER_AUTH "nterfacer"
13
84563ebd 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
20 * LOSTNICK. */
21
22unsigned int at_lastnum;
23time_t at_lastauthts;
24unsigned long at_lastuserid;
25
26unsigned long at_getuserid(nick *np) {
84563ebd 27 /* If they are not +r, forget it. */
28 if (!IsAccount(np))
29 return 0;
249a68b8 30
31 /* Ignore that pesky nterfacer */
32#ifdef NTERFACER_AUTH
33 if (!ircd_strcmp(np->authname, NTERFACER_AUTH))
34 return 0;
35#endif
84563ebd 36
6e3ceea8 37 /* Use the userid from authext only. */
84563ebd 38 if (np->auth)
39 return np->auth->userid;
40
84563ebd 41 Error("authtracker",ERR_WARNING,"Unable to get userID from IsAccount() user %s",np->nick);
42 return 0;
43}
44
45void at_handlequitorkill(int hooknum, void *arg) {
46 void **args=arg;
47 nick *np=args[0];
48 char *reason=args[1];
49 char *rreason;
673180ed 50 char resbuf[512];
84563ebd 51 unsigned long userid;
52
53 /* Ignore unauthed users, or those with no accountts */
54 if (!(userid=at_getuserid(np)) || !np->accountts)
55 return;
56
84563ebd 57 at_lastuserid=userid;
58 at_lastauthts=np->accountts;
59 at_lastnum=np->numeric;
60
673180ed 61 if (hooknum==HOOK_NICK_KILL && (rreason=strchr(reason,' '))) {
62 sprintf(resbuf,"Killed%s",rreason);
63 reason=resbuf;
64 }
84563ebd 65
66 at_logquit(userid, np->accountts, time(NULL), reason);
67}
68
69void at_handlelostnick(int hooknum, void *arg) {
70 nick *np=arg;
71 unsigned long userid;
72
73 if (!(userid=at_getuserid(np)) || !np->accountts)
74 return;
75
76 /* Don't do this for a user that just left normally (see above) */
77 if ((userid==at_lastuserid) && (np->accountts == at_lastauthts) && (np->numeric==at_lastnum))
78 return;
79
80 at_lostnick(np->numeric, userid, np->accountts, time(NULL), AT_NETSPLIT);
81}
82
83void at_newnick(int hooknum, void *arg) {
84 nick *np=arg;
85 unsigned long userid;
86
87 /* Ignore unauthed users, or those with no TS */
88 if (!(userid=at_getuserid(np)) || !np->accountts)
89 return;
90
91 /* OK, we've seen an authed user appear. If it's a known ghost we can zap it */
92 if (!at_foundnick(np->numeric, userid, np->accountts)) {
93 /* If we didn't zap a ghost then it's a new session */
94 at_lognewsession(userid, np);
95 }
96}
97
98void at_serverlinked(int hooknum, void *arg) {
99 unsigned long servernum=(unsigned long)arg;
100
101 at_serverback(servernum);
102}
103
104void at_hookinit() {
105 registerhook(HOOK_NICK_QUIT, at_handlequitorkill);
106 registerhook(HOOK_NICK_KILL, at_handlequitorkill);
107 registerhook(HOOK_NICK_LOSTNICK, at_handlelostnick);
6e3ceea8 108 registerhook(HOOK_NICK_NEWNICK, at_newnick);
109 registerhook(HOOK_NICK_ACCOUNT, at_newnick);
84563ebd 110 registerhook(HOOK_SERVER_LINKED, at_serverlinked);
111}
112
113void at_hookfini() {
114 deregisterhook(HOOK_NICK_QUIT, at_handlequitorkill);
115 deregisterhook(HOOK_NICK_KILL, at_handlequitorkill);
116 deregisterhook(HOOK_NICK_LOSTNICK, at_handlelostnick);
6e3ceea8 117 deregisterhook(HOOK_NICK_NEWNICK, at_newnick);
118 deregisterhook(HOOK_NICK_ACCOUNT, at_newnick);
84563ebd 119 deregisterhook(HOOK_SERVER_LINKED, at_serverlinked);
120}