]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Implement whowaschase command.
authorGunnar Beutner <redacted>
Sun, 4 Aug 2013 23:05:11 +0000 (01:05 +0200)
committerGunnar Beutner <redacted>
Sun, 4 Aug 2013 23:05:11 +0000 (01:05 +0200)
--HG--
branch : shroudtrusts

whowas/whowas.c
whowas/whowas.h
whowas/whowas_commands.c

index 8679503836ee5c207e4c2d2c174f44fd53abaf00..d9b8c50fdbd0ba703004fa5aad22aa080855fd1c 100644 (file)
@@ -111,6 +111,23 @@ static void whowas_handlerename(int hooknum, void *arg) {
   whowas_linkrecord(ww);
 }
 
+whowas *whowas_chase(const char *nick, int maxage) {
+  whowas *ww;
+  time_t now;
+
+  now = getnettime();
+
+  for (ww = whowas_head; ww; ww = ww->next) {
+    if (ww->seen < now - maxage)
+      break; /* records are in timestamp order, we're done */
+
+    if (ircd_strcmp(ww->nick, nick) == 0)
+      return ww;
+  }
+
+  return NULL;
+}
+
 void _init(void) {
   registerhook(HOOK_NICK_QUIT, whowas_handlequitorkill);
   registerhook(HOOK_NICK_KILL, whowas_handlequitorkill);
index 64922dfde04723bec7dbb9c0a50fa04dbba563a5..9b679ab0be4bf1c5d5c6ad37a2239653d77e58ba 100644 (file)
@@ -28,3 +28,5 @@ extern int whowas_count;
 #define WHOWAS_QUIT 0
 #define WHOWAS_KILL 1
 #define WHOWAS_RENAME 2
+
+whowas *whowas_chase(const char *nick, int maxage);
index fa88341139661dc5af7d281402224ba74e3ea12b..778943100178ed5e6473173bef391dc468a8d7ef 100644 (file)
@@ -9,12 +9,24 @@
 
 MODULE_VERSION("");
 
+static void whowas_spewrecord(whowas *ww, nick *np) {
+  char timebuf[30];
+  char hostmask[WW_MASKLEN + 1];
+
+  snprintf(hostmask, sizeof(hostmask), "%s!%s@%s", ww->nick, ww->ident, ww->host);
+  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);
+}
+
 static int whowas_cmdwhowas(void *source, int cargc, char **cargv) {
-  nick *np = source;
+  nick *sender = source;
   char *pattern;
   whowas *ww;
   char hostmask[WW_MASKLEN + 1];
-  char timebuf[30];
   int matches = 0, limit = 500;
 
   if (cargc < 1)
@@ -31,28 +43,44 @@ static int whowas_cmdwhowas(void *source, int cargc, char **cargv) {
     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);
-      }
+      if (matches <= limit)
+        whowas_spewrecord(ww, sender);
+      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;
+  }
+
+  whowas_spewrecord(ww, sender);
+  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);
 }