]> jfr.im git - irc/quakenet/newserv.git/blobdiff - clonehistogram/clonehistogram.c
BUILD: add require-all build mode
[irc/quakenet/newserv.git] / clonehistogram / clonehistogram.c
index cd5834c1c8e9106984090e775adce9628e3befb2..0d77ab8a200fd964af1d7c086425378d17a4622d 100644 (file)
@@ -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 <hostmask>\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;j<NICKHASHSIZE;j++) {
+    for(np2=nicktable[j];np2;np2=np2->next) {
+      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;