]> jfr.im git - irc/quakenet/newserv.git/blobdiff - nterface/nterfacer_control.c
Cleanup dependencies.
[irc/quakenet/newserv.git] / nterface / nterfacer_control.c
index f60c10d13f4ae5a418ce3fceac2d20bca1e467db..fea23fb2b23819a161ee1344e514db82d6cba4cd 100644 (file)
@@ -1,37 +1,28 @@
 /*
   nterfacer newserv control module
-  Copyright (C) 2004 Chris Porter.
-
-  v1.05
-    - modified whois to take into account channels with ','
-    - made ison take multiple arguments
-    - added isaccounton
-  v1.04
-    - added status/onchan/servicesonchan
-  v1.03
-    - added multiple targets for channel/nick notice/message commands
-  v1.02
-    - added channel message, nick message/notice commands
-    - generalised error messages
-  v1.01
-    - whois fixed to notice BUF_OVER
+  Copyright (C) 2004-2007 Chris Porter.
 */
 
-#include "../chanstats/chanstats.h"
+#include <string.h>
+
 #include "../localuser/localuserchannel.h"
 #include "../channel/channel.h"
-#include "../lib/strlcat.h"
+#include "../lib/strlfunc.h"
 #include "../control/control.h"
 #include "../core/hooks.h"
+#include "../nick/nick.h"
+#include "../lib/flags.h"
 #include "../lib/irc_string.h"
+#include "../lib/version.h"
+#include "../authhash/authhash.h"
 
 #include "library.h"
 #include "nterfacer_control.h"
 
-struct service_node *node;
+MODULE_VERSION("");
 
-int handle_chanstats(struct rline *li, int argc, char **argv);
 int handle_ison(struct rline *li, int argc, char **argv);
+int handle_isaccounton(struct rline *li, int argc, char **argv);
 int handle_whois(struct rline *li, int argc, char **argv);
 int handle_message(struct rline *li, int argc, char **argv);
 int handle_notice(struct rline *li, int argc, char **argv);
@@ -39,127 +30,48 @@ int handle_channel(struct rline *li, int argc, char **argv);
 int handle_onchan(struct rline *li, int argc, char **argv);
 int handle_status(struct rline *li, int argc, char **argv);
 int handle_servicesonchan(struct rline *li, int argc, char **argv);
-int handle_isaccounton(struct rline *li, int argc, char **argv);
+int handle_counthost(struct rline *li, int argc, char **argv);
 
 struct rline *grli; /* used inline for status */
+struct service_node *n_node;
 
 void _init(void) {
-  node = register_service("N");
-  if(!node)
+  n_node = register_service("N");
+  if(!n_node)
     return;
 
-  register_handler(node, "chanstats", 1, handle_chanstats);
-  register_handler(node, "ison", 1, handle_ison);
-  register_handler(node, "whois", 1, handle_whois);
-  register_handler(node, "msg", 2, handle_message);
-  register_handler(node, "notice", 2, handle_notice);
-  register_handler(node, "chanmsg", 2, handle_channel);
-  register_handler(node, "onchan", 2, handle_onchan);
-  register_handler(node, "status", 0, handle_status);
-  register_handler(node, "servicesonchan", 1, handle_servicesonchan);
-  register_handler(node, "isaccounton", 1, handle_isaccounton);
+  register_handler(n_node, "ison", 1, handle_ison);
+  register_handler(n_node, "isaccounton", 1, handle_isaccounton);
+  register_handler(n_node, "whois", 1, handle_whois);
+  register_handler(n_node, "msg", 2, handle_message);
+  register_handler(n_node, "notice", 2, handle_notice);
+  register_handler(n_node, "chanmsg", 2, handle_channel);
+  register_handler(n_node, "onchan", 2, handle_onchan);
+  register_handler(n_node, "status", 0, handle_status);
+  register_handler(n_node, "servicesonchan", 1, handle_servicesonchan);
+  register_handler(n_node, "counthost", 1, handle_counthost);
 }
 
 void _fini(void) {
-  if(node)
-    deregister_service(node);
-}
-
-int handle_chanstats(struct rline *li, int argc, char **argv) {
-  chanstats *csp;
-  chanindex *cip;
-  int i,j,k,l;
-  int tot,emp;
-  int themax;
-  float details[13];
-  
-  cip=findchanindex(argv[0]);
-  
-  if (cip==NULL)
-    return ri_error(li, ERR_TARGET_NOT_FOUND, "Channel not found");
-
-  csp=cip->exts[csext];
-
-  if (csp==NULL)
-    return ri_error(li, ERR_CHANSTATS_STATS_NOT_FOUND, "Stats not found");
-
-  if (uponehour==0) {
-    details[0] = -1;
-    details[1] = -1;
-  } else {
-    tot=0; emp=0;
-    for(i=0;i<SAMPLEHISTORY;i++) {
-      tot+=csp->lastsamples[i];
-      if (csp->lastsamples[i]==0) {
-        emp++;
-      }
-    }
-    details[0] = tot/SAMPLEHISTORY;
-    details[1] = emp/SAMPLEHISTORY * 100;
-
-  }
-
-  details[2] = csp->todayusers/todaysamples;
-  details[3] = ((float)(todaysamples-csp->todaysamples)/todaysamples)*100;
-  details[4] = csp->todaymax;
-
-  themax=csp->lastmax[0];
-
-  details[5] = csp->lastdays[0]/10;
-  details[6] = ((float)(lastdaysamples[0]-csp->lastdaysamples[0])/lastdaysamples[0])*100;
-  details[7] = themax;
-  
-  /* 7-day average */
-  j=k=l=0;
-  for (i=0;i<7;i++) {
-    j+=csp->lastdays[i];
-    k+=csp->lastdaysamples[i];
-    l+=lastdaysamples[i];
-    if (csp->lastmax[i]>themax) {
-      themax=csp->lastmax[i];
-    }
-  }
-
-  details[8] = j/70;
-  details[9] = ((l-k)*100)/l;
-  details[10] = themax;
-
-  /* 14-day average: continuation of last loop */
-  for (;i<14;i++) {
-    j+=csp->lastdays[i];
-    k+=csp->lastdaysamples[i];
-    l+=lastdaysamples[i];
-    if (csp->lastmax[i]>themax) {
-      themax=csp->lastmax[i];
-    }
-  }
-
-  details[11] = j/140;
-  details[12] = ((l-k)*100)/l;
-  details[13] = themax;
-
-  ri_append(li, "%.1f", details[0]);
-  ri_append(li, "%.1f%%", details[1]);
-  for(j=2;j<14;) {
-    ri_append(li, "%.1f", details[j++]);
-    ri_append(li, "%.1f%%", details[j++]);
-    ri_append(li, "%d%%", details[j++]);
-  }
-
-  return ri_final(li);
+  if(n_node)
+    deregister_service(n_node);
 }
 
 int handle_ison(struct rline *li, int argc, char **argv) {
   int i;
   for(i=0;i<argc;i++)
-    ri_append(li, "%d", getnickbynick(argv[i])?1:0);
+    if(ri_append(li, "%d", getnickbynick(argv[i])?1:0) == BF_OVER)
+      return ri_error(li, BF_OVER, "Buffer overflow");
+
   return ri_final(li);
 }
 
 int handle_isaccounton(struct rline *li, int argc, char **argv) {
   int i;
   for(i=0;i<argc;i++)
-    ri_append(li, "%d", getnickbynick(argv[i])?1:0);
+    if(ri_append(li, "%d", getnickbyauth(argv[i])?1:0) == BF_OVER)
+      return ri_error(li, BF_OVER, "Buffer overflow");
+
   return ri_final(li);
 }
 
@@ -177,6 +89,7 @@ int handle_whois(struct rline *li, int argc, char **argv) {
   ri_append(li, "%s", np->host->name->content);
   ri_append(li, "%s", np->realname->name->content);
   ri_append(li, "%s", np->authname);
+  ri_append(li, "%s", printflags(np->umodes, umodeflags));
   
   channels = np->channels->content;
 
@@ -247,6 +160,7 @@ int handle_onchan(struct rline *li, int argc, char **argv) {
 }
 
 void handle_nterfacerstats(int hooknum, void *arg) {
+  /* hmm, not much we can do here, @ppa */
   ri_append(grli, "%s", (char *)arg);
 }
 
@@ -272,10 +186,39 @@ int handle_servicesonchan(struct rline *li, int argc, char **argv) {
     if(cp->users->content[i] != nouser) {      
       np = getnickbynumeric(cp->users->content[i]);
       if(np && IsService(np) && np->nick[0] && !np->nick[1])
-        ri_append(li, "%s", np->nick);
+        if(ri_append(li, "%s", np->nick) == BF_OVER)
+          return ri_error(li, BF_OVER, "Buffer overflow");
     }
   }
 #endif
 
   return ri_final(li);
 }
+
+int handle_counthost(struct rline *li, int argc, char **argv) {
+  int i, j;
+  unsigned int results[100];
+  host *hp;
+  if(argc > 100)
+    return ri_error(li, ERR_TOO_MANY_ARGS, "Too many arguments");
+
+  memset(results, 0, sizeof(results));
+
+  for(j=0;j<argc;j++)
+    collapse(argv[j]);
+
+  for(i=0;i<HOSTHASHSIZE;i++)
+    for(hp=hosttable[i];hp;hp=hp->next)
+      for(j=0;j<argc;j++)
+        if(!match(argv[j], hp->name->content))
+          results[j]+=hp->clonecount;
+
+  for(j=0;j<argc;j++)
+    if(ri_append(li, "%d", results[j]) == BF_OVER)
+      return ri_error(li, BF_OVER, "Buffer overflow");
+
+
+  return ri_final(li);
+}
+
+