]>
jfr.im git - irc/quakenet/newserv.git/blob - whowas/whowas.c
439caea9b76c29e7354260954b2d7f620289bc1d
3 #include "../core/hooks.h"
4 #include "../control/control.h"
5 #include "../irc/irc.h"
6 #include "../lib/irc_string.h"
7 #include "../lib/version.h"
12 whowas
*whowas_head
= NULL
, *whowas_tail
= NULL
;
15 whowas
*whowas_fromnick(nick
*np
) {
18 /* Create a new record. */
19 ww
= malloc(sizeof(whowas
));
20 memset(ww
, 0, sizeof(whowas
));
21 strncpy(ww
->nick
, np
->nick
, NICKLEN
);
22 strncpy(ww
->ident
, np
->ident
, USERLEN
);
23 strncpy(ww
->host
, np
->host
->name
->content
, HOSTLEN
);
24 memcpy(&ww
->ip
, &np
->p_ipaddr
, sizeof(struct irc_in_addr
));
25 strncpy(ww
->realname
, np
->realname
->name
->content
, REALLEN
);
26 ww
->seen
= getnettime();
31 void whowas_linkrecord(whowas
*ww
) {
33 whowas_head
->prev
= ww
;
35 ww
->next
= whowas_head
;
46 void whowas_unlinkrecord(whowas
*ww
) {
48 whowas_tail
= ww
->prev
;
51 ww
->prev
->next
= NULL
;
53 whowas_head
= ww
->prev
;
58 static void whowas_cleanup(void) {
63 /* Clean up old records. */
64 while (whowas_tail
&& (whowas_tail
->seen
< now
- WW_MAXAGE
|| whowas_count
>= WW_MAXENTRIES
)) {
65 whowas_unlinkrecord(whowas_tail
);
70 static void whowas_handlequitorkill(int hooknum
, void *arg
) {
73 char *reason
= args
[1];
80 /* Create a new record. */
81 ww
= whowas_fromnick(np
);
83 if (hooknum
== HOOK_NICK_KILL
) {
84 if ((rreason
= strchr(reason
, ' '))) {
85 sprintf(resbuf
, "Killed%s", rreason
);
89 ww
->type
= WHOWAS_KILL
;
91 ww
->type
= WHOWAS_QUIT
;
93 ww
->reason
= getsstring(reason
, WW_REASONLEN
);
95 whowas_linkrecord(ww
);
98 static void whowas_handlerename(int hooknum
, void *arg
) {
101 char *oldnick
= args
[1];
106 ww
= whowas_fromnick(np
);
107 ww
->type
= WHOWAS_RENAME
;
108 ww
->newnick
= getsstring(ww
->nick
, NICKLEN
);
109 strncpy(ww
->nick
, oldnick
, NICKLEN
);
110 ww
->nick
[NICKLEN
] = '\0';
112 whowas_linkrecord(ww
);
115 whowas
*whowas_chase(const char *nick
, int maxage
) {
121 for (ww
= whowas_head
; ww
; ww
= ww
->next
) {
122 if (ww
->seen
< now
- maxage
)
123 break; /* records are in timestamp order, we're done */
125 if (ircd_strcmp(ww
->nick
, nick
) == 0)
133 registerhook(HOOK_NICK_QUIT
, whowas_handlequitorkill
);
134 registerhook(HOOK_NICK_KILL
, whowas_handlequitorkill
);
135 registerhook(HOOK_NICK_RENAME
, whowas_handlerename
);
139 deregisterhook(HOOK_NICK_QUIT
, whowas_handlequitorkill
);
140 deregisterhook(HOOK_NICK_KILL
, whowas_handlequitorkill
);
141 deregisterhook(HOOK_NICK_RENAME
, whowas_handlerename
);
144 whowas_unlinkrecord(whowas_head
);