]> jfr.im git - irc/quakenet/newserv.git/blobdiff - trusts/trusts.c
CHANSERV: remove accidental sendemail from SETEMAIL command.
[irc/quakenet/newserv.git] / trusts / trusts.c
index c15ea114d33140fc5f6679af63c1137142b4e930..c34974bbad50aa2619d8b648c0cc8cc606e65b28 100644 (file)
@@ -1,15 +1,19 @@
 #include <stdio.h>
 #include <string.h>
+#include "../lib/version.h"
 #include "../core/hooks.h"
 #include "../core/error.h"
 #include "../core/nsmalloc.h"
 #include "../server/server.h"
 #include "trusts.h"
 
+MODULE_VERSION("");
+
 void trusts_registerevents(void);
 void trusts_deregisterevents(void);
 
 static void statusfn(int, void *);
+static void whoisfn(int, void *);
 
 static sstring *tgextnames[MAXTGEXTS];
 
@@ -31,6 +35,7 @@ void _init(void) {
   }
 
   registerhook(HOOK_CORE_STATSREQUEST, statusfn);
+  registerhook(HOOK_CONTROL_WHOISREQUEST, &whoisfn);
   trusts_registerevents();
 }
 
@@ -41,11 +46,52 @@ void _fini(void) {
   }
 
   deregisterhook(HOOK_CORE_STATSREQUEST, statusfn);
+  deregisterhook(HOOK_CONTROL_WHOISREQUEST, &whoisfn);
   trusts_deregisterevents();
 
   nscheckfreeall(POOL_TRUSTS);
 }
 
+static void whoisfn(int hooknum, void *arg) {
+  trusthost *th;
+  char message[512];
+  nick *np = (nick *)arg;
+
+  if(!np)
+    return;
+
+  th = gettrusthost(np);
+
+  if(!th)
+    return;
+
+  snprintf(message, sizeof(message), "Trustgroup: %s (#%d)", th->group->name->content, th->group->id);
+  triggerhook(HOOK_CONTROL_WHOISREPLY, message);
+
+  if (th->maxpernode > 0) {
+    snprintf(message, sizeof(message), "Node      : %s", CIDRtostr(np->ipaddress, th->nodebits));
+    triggerhook(HOOK_CONTROL_WHOISREPLY, message);
+
+    patricia_node_t *node;
+    int usercount = 0;
+
+    node = refnode(iptree, &(np->ipaddress), th->nodebits);
+    usercount = node->usercount;
+    derefnode(iptree, node);
+
+    snprintf(message, sizeof(message), "Node      : Usage: %d/%d", usercount, th->maxpernode);
+    triggerhook(HOOK_CONTROL_WHOISREPLY, message);
+  }
+
+  if (th->group->trustedfor > 0) {
+    snprintf(message, sizeof(message), "Trusthost : %s", CIDRtostr(th->ip, th->bits));
+    triggerhook(HOOK_CONTROL_WHOISREPLY, message);
+
+    snprintf(message, sizeof(message), "Trustgroup : Usage: %d/%d", th->group->count, th->group->trustedfor);
+    triggerhook(HOOK_CONTROL_WHOISREPLY, message);
+  }
+}
+
 static void statusfn(int hooknum, void *arg) {
   if((long)arg > 10) {
     char message[100];
@@ -83,7 +129,7 @@ int registertgext(const char *name) {
     return -1;
   }
 
-  for(i=0;i<MAXNICKEXTS;i++) {
+  for(i=0;i<MAXTGEXTS;i++) {
     if(!tgextnames[i]) {
       tgextnames[i] = getsstring(name, 100);
       return i;