X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/blobdiff_plain/8fca89d6e1c17082687a3abcc1d54267543d4465..cd9baaa220c4afdfbbb25d4c4f6c8aa1f02fe637:/whowas/whowas.c diff --git a/whowas/whowas.c b/whowas/whowas.c index c2cece6d..9e2cdb3c 100644 --- a/whowas/whowas.c +++ b/whowas/whowas.c @@ -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; @@ -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++) { + for (i = 0; i < whowasmax; i++) { ww = &whowasrecs[i]; whowas_clean(ww); } + + free(whowasrecs); }