#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)
else {
ww = &whowasrecs[whowasoffset];
whowas_clean(ww);
- whowasoffset = (whowasoffset + 1) % WW_MAXENTRIES;
+ whowasoffset = (whowasoffset + 1) % whowasmax;
}
memset(ww, 0, sizeof(whowas));
ww->timestamp = getnettime();
ww->type = WHOWAS_USED;
+ args[0] = ww;
+ args[1] = np;
+ triggerhook(HOOK_WHOWAS_NEWRECORD, args);
+
return ww;
}
if (!ww || ww->type == WHOWAS_UNUSED)
return;
+ triggerhook(HOOK_WHOWAS_LOSTRECORD, ww);
+
np = &ww->nick;
freesstring(np->host->name);
freehost(np->host);
freesstring(np->opername);
freeauthname(np->auth);
freesstring(np->away);
-
+ derefnode(iptree, np->ipnode);
freesstring(ww->reason);
+ freesstring(ww->newnick);
ww->type = WHOWAS_UNUSED;
}
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;
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;
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;
}
}
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);
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);
}