]>
jfr.im git - irc/quakenet/newserv.git/blob - whowas/whowas.c
3 #include "../core/hooks.h"
4 #include "../control/control.h"
5 #include "../irc/irc.h"
6 #include "../lib/irc_string.h"
9 static whowas
*wwhead
, *wwtail
;
12 int ww_cmdwhowas(void *source
, int cargc
, char **cargv
) {
16 char hostmask
[WW_MASKLEN
+1];
18 int matches
= 0, limit
= 500;
26 limit
= strtol(cargv
[1], NULL
, 10);
28 for(ww
=wwhead
;ww
;ww
=ww
->next
) {
29 snprintf(hostmask
, sizeof(hostmask
), "%s!%s@%s", ww
->nick
, ww
->ident
, ww
->host
);
31 if (match2strings(pattern
, hostmask
)) {
35 strftime(timebuf
, 30, "%d/%m/%y %H:%M:%S", localtime(&(ww
->seen
)));
37 controlreply(np
, "[%s] %s (%s): %s", timebuf
, hostmask
, ww
->realname
, ww
->reason
->content
);
38 } else if(matches
==limit
+1) {
39 controlreply(np
, "--- More than %d matches, skipping the rest", limit
);
44 controlreply(np
, "--- Found %d entries.", matches
);
49 void ww_handlequitorkill(int hooknum
, void *arg
) {
60 /* Clean up old records. */
61 while((ww
= wwtail
) && (ww
->seen
< now
- WW_MAXAGE
|| wwcount
>= WW_MAXENTRIES
)) {
65 ww
->prev
->next
= NULL
;
73 /* Create a new record. */
74 ww
= malloc(sizeof(whowas
));
75 strncpy(ww
->nick
, np
->nick
, NICKLEN
);
76 strncpy(ww
->ident
, np
->ident
, USERLEN
);
77 strncpy(ww
->host
, np
->host
->name
->content
, HOSTLEN
);
78 strncpy(ww
->realname
, np
->realname
->name
->content
, REALLEN
);
79 ww
->seen
= getnettime();
81 if(hooknum
==HOOK_NICK_KILL
&& (rreason
=strchr(reason
,' '))) {
82 sprintf(resbuf
,"Killed%s",rreason
);
86 ww
->reason
= getsstring(reason
, WW_REASONLEN
);
103 registerhook(HOOK_NICK_QUIT
, ww_handlequitorkill
);
104 registerhook(HOOK_NICK_KILL
, ww_handlequitorkill
);
106 registercontrolhelpcmd("whowas", NO_OPER
, 2, &ww_cmdwhowas
, "Usage: whowas <mask> ?limit?\nLooks up information about recently disconnected users.");
112 deregisterhook(HOOK_NICK_QUIT
, ww_handlequitorkill
);
113 deregisterhook(HOOK_NICK_KILL
, ww_handlequitorkill
);
115 deregistercontrolcmd("whowas", &ww_cmdwhowas
);
117 while((ww
= wwhead
)) {