]> jfr.im git - irc/quakenet/newserv.git/blobdiff - whowas/whowas_commands.c
CHANSERV: better batcher error handling for expired accounts/accounts with no email.
[irc/quakenet/newserv.git] / whowas / whowas_commands.c
index fa88341139661dc5af7d281402224ba74e3ea12b..db688ae29dfd2de7759e958821710a72bd35bba6 100644 (file)
 MODULE_VERSION("");
 
 static int whowas_cmdwhowas(void *source, int cargc, char **cargv) {
-  nick *np = source;
+  nick *sender = source;
   char *pattern;
   whowas *ww;
+  nick *np;
+  int i;
   char hostmask[WW_MASKLEN + 1];
-  char timebuf[30];
   int matches = 0, limit = 500;
 
   if (cargc < 1)
@@ -25,34 +26,58 @@ static int whowas_cmdwhowas(void *source, int cargc, char **cargv) {
   if (cargc > 1)
     limit = strtol(cargv[1], NULL, 10);
 
-  for (ww = whowas_head; ww; ww = ww->next) {
-    snprintf(hostmask, sizeof(hostmask), "%s!%s@%s", ww->nick, ww->ident, ww->host);
+  for (i = whowasoffset; i < whowasoffset + whowasmax; i++) {
+    ww = &whowasrecs[i % whowasmax];
+
+    if (ww->type == WHOWAS_UNUSED)
+      continue;
+
+    np = &ww->nick;
+    snprintf(hostmask, sizeof(hostmask), "%s!%s@%s", np->nick, np->ident, np->host->name->content);
 
     if (match2strings(pattern, hostmask)) {
       matches++;
 
       if (matches <= limit) {
-        strftime(timebuf, 30, "%d/%m/%y %H:%M:%S", localtime(&(ww->seen)));
-
-        if (ww->type == WHOWAS_RENAME)
-          controlreply(np, "[%s] NICK %s (%s) -> %s", timebuf, hostmask, ww->realname, ww->newnick->content);
-        else
-          controlreply(np, "[%s] %s %s (%s): %s", timebuf, (ww->type == WHOWAS_QUIT) ? "QUIT" : "KILL", hostmask, ww->realname, ww->reason->content);
-      } else if (matches == limit + 1) {
-        controlreply(np, "--- More than %d matches, skipping the rest", limit);
-      }
+        controlreply(sender, "%s", whowas_format(ww));
+        controlreply(sender, "%s", whowas_formatchannels(ww));
+      } else if (matches == limit + 1)
+        controlreply(sender, "--- More than %d matches, skipping the rest", limit);
     }
   }
 
-  controlreply(np, "--- Found %d entries.", matches);
+  controlreply(sender, "--- Found %d entries.", matches);
+
+  return CMD_OK;
+}
+
+static int whowas_cmdwhowaschase(void *source, int cargc, char **cargv) {
+  nick *sender = source;
+  whowas *ww;
+
+  if (cargc < 1)
+    return CMD_USAGE;
+
+  ww = whowas_chase(cargv[0], 900);
+
+  if (!ww) {
+    controlreply(sender, "No whowas record found.");
+    return CMD_OK;
+  }
+
+  controlreply(sender, "%s", whowas_format(ww));
+  controlreply(sender, "%s", whowas_formatchannels(ww));
+  controlreply(sender, "Done.");
 
   return CMD_OK;
 }
 
 void _init(void) {
   registercontrolhelpcmd("whowas", NO_OPER, 2, &whowas_cmdwhowas, "Usage: whowas <mask> ?limit?\nLooks up information about recently disconnected users.");
+  registercontrolhelpcmd("whowaschase", NO_OPER, 2, &whowas_cmdwhowaschase, "Usage: whowaschase <nick>\nFinds most-recent whowas record for a nick.");
 }
 
 void _fini(void) {
   deregistercontrolcmd("whowas", &whowas_cmdwhowas);
+  deregistercontrolcmd("whowaschase", &whowas_cmdwhowaschase);
 }