#include <stdio.h>
#include <string.h>
+#include <stdint.h>
MODULE_VERSION("");
void rotatechanstats();
void savechanstats();
void loadchanstats();
+int dochanstatssave(void *source, int argc, char **argv);
int dochanstats(void *source, int argc, char **argv);
int doexpirecheck(void *source, int cargc, char **cargv);
int douserhistogram(void *source, int cargc, char **cargv);
void dohist_days(int *data, float *bounds, int cats, int days);
void dohist_namelen(int *data, float *bounds, int cats);
+#define EXPIREMIN 4
+
void _init() {
time_t now,when;
Error("chanstats",ERR_ERROR,"Couldn't register channel extension");
failedinit=1;
} else {
- initchanstatsalloc();
lastday=(getnettime()/(24*3600));
uponehour=0;
sampleindex=-1;
/* Work out when to take the next sample */
now=getnettime();
if (now < chanstats_lastsample) {
- Error("chanstats",ERR_WARNING,"Last sample time in future (%d > %d)",chanstats_lastsample,now);
+ Error("chanstats",ERR_WARNING,"Last sample time in future (%jd > %jd)",(intmax_t)chanstats_lastsample,(intmax_t)now);
when=now;
} else if (now<(chanstats_lastsample+SAMPLEINTERVAL)) {
lastday=chanstats_lastsample/(24*3600);
}
lastsave=now;
- registercontrolcmd("chanstats",10,1,&dochanstats);
- registercontrolcmd("channelhistogram",10,13,&dochanhistogram);
- registercontrolcmd("userhistogram",10,1,&douserhistogram);
- registercontrolcmd("expirecheck",10,1,&doexpirecheck);
+ registercontrolhelpcmd("chanstats",NO_OPER,1,&dochanstats, "Show usage statistics for a channel");
+ registercontrolhelpcmd("channelhistogram",NO_OPER,13,&dochanhistogram, "Display a histogram of network channel sizes");
+ registercontrolhelpcmd("userhistogram",NO_OPER,1,&douserhistogram, "Display a user histogram of channel size");
+ registercontrolhelpcmd("expirecheck",NO_DEVELOPER,1,&doexpirecheck, "Check if channel has too few users for services");
+ registercontrolhelpcmd("chanstatssave",NO_DEVELOPER,1, &dochanstatssave, "Usage: chanstatssave\nForce a save of chanstats data");
schedulerecurring(when,0,SAMPLEINTERVAL,&doupdate,NULL);
}
}
deregistercontrolcmd("channelhistogram",&dochanhistogram);
deregistercontrolcmd("userhistogram",&douserhistogram);
deregistercontrolcmd("expirecheck",&doexpirecheck);
+ deregistercontrolcmd("chanstatssave",&dochanstatssave);
releasechanext(csext);
cstsfreeall();
}
}
if (cip->channel!=NULL) {
- currentusers=countuniquehosts(cip->channel);
+ channel *cp = cip->channel;
+ int i;
+ nick *np;
+
+ currentusers=countuniquehosts(cp);
+
+ for (i=0;i<cp->users->hashsize;i++) {
+ if (cp->users->content[i]==nouser)
+ continue;
+
+ if ((np=getnickbynumeric(cp->users->content[i]))==NULL) {
+ Error("channel",ERR_ERROR,"Found unknown numeric %lu on channel %s",cp->users->content[i],cp->index->name->content);
+ continue;
+ }
+
+ if (IsXOper(np) || IsService(np))
+ currentusers--;
+ }
+
csp->todaysamples++;
} else {
currentusers=0;
chanindex *cip;
chanstats *chp;
- if ((fp=fopen("chanstats","w"))==NULL) {
+ if ((fp=fopen("data/chanstats","w"))==NULL) {
return;
}
chanstats *chp;
chanindex *cip;
- if ((fp=fopen("chanstats","r"))==NULL) {
+ if ((fp=fopen("data/chanstats","r"))==NULL) {
Error("chanstats",ERR_ERROR,"Unable to load channel stats file");
return;
}
return CMD_OK;
}
-#define EXPIREMIN 4
-
int doexpirecheck(void *source, int cargc, char **cargv) {
nick *sender=(nick *)source;
chanindex *cip;
/* Did they hit the minimum today? */
if (csp->todaymax >= EXPIREMIN) {
+ controlreply(sender,"OK %s",cargv[0]);
return CMD_OK;
}
/* Or recently? */
for (i=0;i<HISTORYDAYS;i++) {
if (csp->lastmax[i] >= EXPIREMIN) {
+ controlreply(sender,"OK %s",cargv[0]);
return CMD_OK;
}
}
}
}
}
+
+int dochanstatssave(void *source, int cargc, char **cargv) {
+ nick *sender=(nick *)source;
+
+ controlreply(sender,"Saving Chanstats..");
+ savechanstats();
+ controlreply(sender,"Chanstats saved");
+ return CMD_OK;
+}