]> jfr.im git - irc/quakenet/newserv.git/blobdiff - whowas/whowas.c
Merge pull request #1 from meeb/meeb
[irc/quakenet/newserv.git] / whowas / whowas.c
index 3809eb77139979af84378fb9b0f3c182c0cb3415..9e2cdb3c74d6f9e753a3e3445a24a2549e514a51 100644 (file)
@@ -5,17 +5,20 @@
 #include "../irc/irc.h"
 #include "../lib/irc_string.h"
 #include "../lib/version.h"
+#include "../core/config.h"
 #include "whowas.h"
 
 MODULE_VERSION("");
 
-whowas whowasrecs[WW_MAXENTRIES];
+whowas *whowasrecs;
 int whowasoffset = 0;
+int whowasmax;
 
 whowas *whowas_fromnick(nick *np, int standalone) {
   whowas *ww;
   nick *wnp;
   struct irc_in_addr ipaddress_canonical;
+  void *args[2];
 
   /* Create a new record. */
   if (standalone)
@@ -23,7 +26,7 @@ whowas *whowas_fromnick(nick *np, int standalone) {
   else {
     ww = &whowasrecs[whowasoffset];
     whowas_clean(ww);
-    whowasoffset = (whowasoffset + 1) % WW_MAXENTRIES;
+    whowasoffset = (whowasoffset + 1) % whowasmax;
   }
 
   memset(ww, 0, sizeof(whowas));
@@ -66,6 +69,10 @@ whowas *whowas_fromnick(nick *np, int standalone) {
   ww->timestamp = getnettime();
   ww->type = WHOWAS_USED;
 
+  args[0] = ww;
+  args[1] = np;
+  triggerhook(HOOK_WHOWAS_NEWRECORD, args);
+
   return ww;
 }
 
@@ -75,6 +82,8 @@ void whowas_clean(whowas *ww) {
   if (!ww || ww->type == WHOWAS_UNUSED)
     return;
 
+  triggerhook(HOOK_WHOWAS_LOSTRECORD, ww);
+
   np = &ww->nick;
   freesstring(np->host->name);
   freehost(np->host);
@@ -85,8 +94,9 @@ void whowas_clean(whowas *ww) {
   freesstring(np->opername);
   freeauthname(np->auth);
   freesstring(np->away);
-
+  derefnode(iptree, np->ipnode);
   freesstring(ww->reason);
+  freesstring(ww->newnick);
   ww->type = WHOWAS_UNUSED;
 }
 
@@ -145,8 +155,8 @@ whowas *whowas_chase(const char *target, int maxage) {
 
   now = getnettime();
 
-  for (i = whowasoffset + WW_MAXENTRIES - 1; i >= whowasoffset; i--) {
-    ww = &whowasrecs[i % WW_MAXENTRIES];
+  for (i = whowasoffset + whowasmax - 1; i >= whowasoffset; i--) {
+    ww = &whowasrecs[i % whowasmax];
 
     if (ww->type == WHOWAS_UNUSED)
       continue;
@@ -172,7 +182,7 @@ const char *whowas_format(whowas *ww) {
   snprintf(hostmask, sizeof(hostmask), "%s!%s@%s%s%s [%s] (%s)",
            np->nick, np->ident, np->host->name->content,
            np->auth ? "/" : "", np->auth ? np->authname : "",
-           IPtostr(np->p_ipaddr),
+           IPtostr(np->ipaddress),
            printflags(np->umodes, umodeflags));
   strftime(timebuf, sizeof(timebuf), "%d/%m/%y %H:%M:%S", localtime(&(ww->timestamp)));
 
@@ -184,6 +194,32 @@ const char *whowas_format(whowas *ww) {
   return buf;
 }
 
+const char *whowas_formatchannels(whowas *ww) {
+  static char buf[512];
+  int i, first = 1;
+
+  strcpy(buf, "Channels: ");
+
+  for (i = 0; i < WW_MAXCHANNELS; i++) {
+    if (!ww->channels[i])
+      break;
+
+    if (!first)
+      strncat(buf, ", ", sizeof(buf));
+    else
+      first = 0;
+
+    strncat(buf, ww->channels[i]->name->content, sizeof(buf));
+  }
+
+  if (!ww->channels[0])
+    strncat(buf, "(No channels.)", sizeof(buf));
+
+  buf[sizeof(buf) - 1] = '\0';
+
+  return buf;
+}
+
 unsigned int nextwhowasmarker() {
   whowas *ww;
   int i;
@@ -193,8 +229,8 @@ unsigned int nextwhowasmarker() {
 
   if (!whowasmarker) {
     /* If we wrapped to zero, zap the marker on all records */
-    for (i = 0; i < WW_MAXENTRIES; i++) {
-      ww = &whowasrecs[i % WW_MAXENTRIES];
+    for (i = 0; i < whowasmax; i++) {
+      ww = &whowasrecs[i % whowasmax];
       ww->marker=0;
     }
 
@@ -205,6 +241,13 @@ unsigned int nextwhowasmarker() {
 }
 
 void _init(void) {
+  {
+    sstring *temp = getcopyconfigitem("whowas", "maxentries", XStringify(WW_DEFAULT_MAXENTRIES), 10);
+    whowasmax = atoi(temp->content);
+    freesstring(temp);
+  }
+  whowasrecs = calloc(whowasmax, sizeof(whowas));
+
   registerhook(HOOK_NICK_QUIT, whowas_handlequitorkill);
   registerhook(HOOK_NICK_KILL, whowas_handlequitorkill);
   registerhook(HOOK_NICK_RENAME, whowas_handlerename);
@@ -218,8 +261,10 @@ void _fini(void) {
   deregisterhook(HOOK_NICK_KILL, whowas_handlequitorkill);
   deregisterhook(HOOK_NICK_RENAME, whowas_handlerename);
 
-  for (i = 0; i < WW_MAXENTRIES; i++) {
-    ww = &whowasrecs[i % WW_MAXENTRIES];
+  for (i = 0; i < whowasmax; i++) {
+    ww = &whowasrecs[i];
     whowas_clean(ww);
   }
+
+  free(whowasrecs);
 }