X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/blobdiff_plain/7ba25fd07774fd8bda98bbda4938df1fafe8a399..b403aacd5cdc928a6cb62f4dcc128a882fa96aa9:/clonehistogram/clonehistogram.c diff --git a/clonehistogram/clonehistogram.c b/clonehistogram/clonehistogram.c index cd5834c1..0d77ab8a 100644 --- a/clonehistogram/clonehistogram.c +++ b/clonehistogram/clonehistogram.c @@ -3,17 +3,24 @@ #include "../control/control.h" #include "../lib/irc_string.h" #include "../localuser/localuserchannel.h" +#include "../lib/version.h" + +MODULE_VERSION(""); int ch_clonehistogram(void *source, int cargc, char **cargv); +int ch_chanhistogram(void *source, int cargc, char **cargv); #define MAX_CLONES 5 +#define MAX_CHANS 20 void _init() { registercontrolhelpcmd("clonehistogram", NO_OPER, 1, ch_clonehistogram, "Usage: clonehistogram \nShows the distribution of user clone counts of a given mask."); + registercontrolhelpcmd("chanhistogram", NO_OPER, 1, ch_chanhistogram, "Usage: chanhistogram\nShows the channel histogram."); } void _fini () { deregistercontrolcmd("clonehistogram", ch_clonehistogram); + deregistercontrolcmd("chanhistogram", ch_chanhistogram); } void histoutput(nick *np, int clonecount, int amount, int total) { @@ -27,6 +34,34 @@ void histoutput(nick *np, int clonecount, int amount, int total) { controlreply(np, "%s%d %06.2f%% %s", (clonecount<1)?">":"=", abs(clonecount), percentage, max); } +int ch_chanhistogram(void *source, int cargc, char **cargv) { + nick *np = (nick *)source; + nick *np2; + int count[MAX_CHANS + 2], j, n, total = 0; + + memset(count, 0, sizeof(count)); + + for (j=0;jnext) { + total++; + n = np2->channels->cursi; + if(n > MAX_CHANS) { + count[MAX_CHANS + 1]++; + } else { + count[n]++; + } + } + } + + + for(j=1;j<=MAX_CHANS;j++) + histoutput(np, j, count[j], total); + + histoutput(np, -(MAX_CHANS + 1), count[MAX_CHANS + 1], total); + + return CMD_OK; +} + int ch_clonehistogram(void *source, int cargc, char **cargv) { nick *np = (nick *)source; int count[MAX_CLONES + 1], j, total = 0, totalusers = 0;