]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Add chanhistogram to clonehistogram, should probably rename the module...
authorChris Porter <redacted>
Fri, 8 Feb 2008 18:04:46 +0000 (18:04 +0000)
committerChris Porter <redacted>
Fri, 8 Feb 2008 18:04:46 +0000 (18:04 +0000)
clonehistogram/clonehistogram.c

index cd5834c1c8e9106984090e775adce9628e3befb2..f9e92003b3cebca2ddf86dfb125ea7467c48cdac 100644 (file)
@@ -5,15 +5,19 @@
 #include "../localuser/localuserchannel.h"
 
 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 +31,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;