]> jfr.im git - irc/quakenet/newserv.git/blame - whowas/whowas_commands.c
whowas: Fix how we copy account names.
[irc/quakenet/newserv.git] / whowas / whowas_commands.c
CommitLineData
363e3ed0
GB
1#include <stdio.h>
2#include <string.h>
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"
8#include "whowas.h"
9
10MODULE_VERSION("");
11
4030a47e 12static int whowas_cmdwhowas(void *source, int cargc, char **cargv) {
56cab147 13 nick *sender = source;
363e3ed0
GB
14 char *pattern;
15 whowas *ww;
0eb4cbd3 16 nick *np;
363e3ed0 17 char hostmask[WW_MASKLEN + 1];
363e3ed0
GB
18 int matches = 0, limit = 500;
19
20 if (cargc < 1)
21 return CMD_USAGE;
22
23 pattern = cargv[0];
24
25 if (cargc > 1)
26 limit = strtol(cargv[1], NULL, 10);
27
28 for (ww = whowas_head; ww; ww = ww->next) {
0eb4cbd3
GB
29 np = ww->nick;
30 snprintf(hostmask, sizeof(hostmask), "%s!%s@%s", np->nick, np->ident, np->host->name->content);
363e3ed0
GB
31
32 if (match2strings(pattern, hostmask)) {
33 matches++;
34
56cab147 35 if (matches <= limit)
0eb4cbd3 36 controlreply(sender, "%s", whowas_format(ww));
56cab147
GB
37 else if (matches == limit + 1)
38 controlreply(sender, "--- More than %d matches, skipping the rest", limit);
363e3ed0
GB
39 }
40 }
41
56cab147
GB
42 controlreply(sender, "--- Found %d entries.", matches);
43
44 return CMD_OK;
45}
46
47static int whowas_cmdwhowaschase(void *source, int cargc, char **cargv) {
48 nick *sender = source;
49 whowas *ww;
50
51 if (cargc < 1)
52 return CMD_USAGE;
53
54 ww = whowas_chase(cargv[0], 900);
55
56 if (!ww) {
57 controlreply(sender, "No whowas record found.");
58 return CMD_OK;
59 }
60
0eb4cbd3 61 controlreply(sender, "%s", whowas_format(ww));
56cab147 62 controlreply(sender, "Done.");
363e3ed0
GB
63
64 return CMD_OK;
65}
66
67void _init(void) {
4030a47e 68 registercontrolhelpcmd("whowas", NO_OPER, 2, &whowas_cmdwhowas, "Usage: whowas <mask> ?limit?\nLooks up information about recently disconnected users.");
56cab147 69 registercontrolhelpcmd("whowaschase", NO_OPER, 2, &whowas_cmdwhowaschase, "Usage: whowaschase <nick>\nFinds most-recent whowas record for a nick.");
363e3ed0
GB
70}
71
72void _fini(void) {
4030a47e 73 deregistercontrolcmd("whowas", &whowas_cmdwhowas);
56cab147 74 deregistercontrolcmd("whowaschase", &whowas_cmdwhowaschase);
363e3ed0 75}