#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"
-int trusts_loaddb(void);
-void trusts_closedb(void);
+MODULE_VERSION("");
+
void trusts_registerevents(void);
void trusts_deregisterevents(void);
static void statusfn(int, void *);
+static void whoisfn(int, void *);
-static int loaded, unloaded;
static sstring *tgextnames[MAXTGEXTS];
int trusts_thext, trusts_nextuserext;
+int trustsdbloaded;
void _init(void) {
trusts_thext = registernickext("trustth");
return;
}
- if(!trusts_loaddb())
- return;
- loaded = 1;
-
registerhook(HOOK_CORE_STATSREQUEST, statusfn);
+ registerhook(HOOK_CONTROL_WHOISREQUEST, &whoisfn);
trusts_registerevents();
}
-void trusts_unload(void) {
- if(unloaded)
- return;
-
- unloaded = 1;
-
+void _fini(void) {
if(trusts_thext != -1) {
releasenickext(trusts_thext);
releasenickext(trusts_nextuserext);
}
- if(loaded) {
- deregisterhook(HOOK_CORE_STATSREQUEST, statusfn);
- trusts_deregisterevents();
- }
+ deregisterhook(HOOK_CORE_STATSREQUEST, statusfn);
+ deregisterhook(HOOK_CONTROL_WHOISREQUEST, &whoisfn);
+ trusts_deregisterevents();
- trusts_closedb();
+ nscheckfreeall(POOL_TRUSTS);
}
-void _fini(void) {
- trusts_unload();
- 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) {
for(tg=tglist;tg;tg=tg->next)
tg->exts[index] = NULL;
}
+
+int trusts_fullyonline(void) {
+ if(myhub == -1)
+ return 0;
+
+ return serverlist[myhub].linkstate == LS_LINKED;
+}
+