#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];
}
registerhook(HOOK_CORE_STATSREQUEST, statusfn);
+ registerhook(HOOK_CONTROL_WHOISREQUEST, &whoisfn);
trusts_registerevents();
}
}
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->p_ipaddr, th->nodebits));
+ triggerhook(HOOK_CONTROL_WHOISREPLY, message);
+
+ patricia_node_t *node;
+ int usercount = 0;
+
+ node = refnode(iptree, &(np->p_ipaddr), 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];