#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 int loaded;
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();
}
releasenickext(trusts_nextuserext);
}
- if(loaded) {
- deregisterhook(HOOK_CORE_STATSREQUEST, statusfn);
- trusts_deregisterevents();
- }
-
- trusts_closedb(1);
+ 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->group->trustedfor>0) {
+ snprintf(message, sizeof(message), "Trustgroup: Usage: %d/%d", th->group->count, th->group->trustedfor);
+ triggerhook(HOOK_CONTROL_WHOISREPLY, message);
+ }
+ if(th->maxpernode>0) {
+ snprintf(message, sizeof(message), "Trusthost : %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), "Trusthost : Usage: %d/%d", usercount, th->maxpernode);
+ triggerhook(HOOK_CONTROL_WHOISREPLY, message);
+ } else {
+ snprintf(message, sizeof(message), "Trusthost : %s", CIDRtostr(th->ip, th->bits));
+ triggerhook(HOOK_CONTROL_WHOISREPLY, message);
+ }
+}
+
static void statusfn(int hooknum, void *arg) {
if((long)arg > 10) {
char message[100];
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;
+}
+