+int controlwhois(void *sender, int cargc, char **cargv) {
+ authname *an;
+ no_autheduser *au;
+ nick *np = (nick *)sender;
+
+ if(cargc < 1)
+ return controlwhois_plain(sender, cargc, cargv);
+
+ if(cargv[0][0] != '#') {
+ if(cargv[0][0] == '*')
+ cargv[0][0] = '#';
+ return controlwhois_plain(sender, cargc, cargv);
+ }
+
+ an = findauthnamebyname(cargv[0] + 1);
+ if(!an) {
+ controlreply(np, "Account not registered.");
+ return CMD_OK;
+ }
+
+ au = noperserv_get_autheduser(an);
+ if(!au) {
+ controlreply(np, "User does not have a NOperserv account.");
+ return CMD_OK;
+ }
+
+ controlreply(np, "Account : %s", au->authname->name);
+
+ hooknick = np;
+
+ registerhook(HOOK_CONTROL_WHOISREPLY, &handlewhois);
+ noperserv_whois_account_handler(HOOK_CONTROL_WHOISREQUEST_AUTHEDUSER, (void *)au);
+ deregisterhook(HOOK_CONTROL_WHOISREPLY, &handlewhois);
+
+ controlreply(np, "Flags : %s", printflags(NOGetAuthLevel(au), no_userflags));
+
+ return CMD_OK;
+}
+
+void noperserv_whois_handler(int hooknum, void *arg) {
+ char message[100];
+ nick *np = (nick *)arg;
+ no_autheduser *au;
+ if(!np)
+ return;
+
+ if(IsAccount(np)) {
+ au = NOGetAuthedUser(np);
+ if(au) {
+ snprintf(message, sizeof(message), "Flags : %s", printflags(NOGetAuthLevel(au), no_userflags));
+ noperserv_whois_account_handler(HOOK_CONTROL_WHOISREQUEST_AUTHEDUSER, (void *)au);
+ } else {
+ snprintf(message, sizeof(message), "Flags : (user not known)");
+ noperserv_whois_account_handler(HOOK_CONTROL_WHOISREQUEST_AUTHNAME, (void *)np->authname);
+ }
+ triggerhook(HOOK_CONTROL_WHOISREPLY, message);
+ }
+}
+
+/* mmm, hacky */
+void noperserv_whois_account_handler(int hooknum, void *arg) {
+ int count = 0, found = 0;
+ char nickbuffer[(NICKLEN + 2) * NO_NICKS_PER_WHOIS_LINE - 1]; /* since we don't need space or comma for the first item we're fine NULL wise */
+ char accountspace[NICKLEN + 3]; /* space, comma, null */
+ char message[1024];
+ nick *np;
+
+ nickbuffer[0] = '\0';
+ if(hooknum == HOOK_CONTROL_WHOISREQUEST_AUTHEDUSER) {
+ /* we can just read out the authed user linked list */
+ no_autheduser *au = (void *)arg;
+
+ if(au->authname->nicks)
+ found = 1;
+
+ for(np=au->authname->nicks;np;np=np->nextbyauthname) {
+ snprintf(accountspace, sizeof(accountspace), "%s%s", count++?", ":"", np->nick);
+ strncat(nickbuffer, accountspace, sizeof(nickbuffer));
+ nickbuffer[sizeof(nickbuffer) - 1] = '\0';
+
+ if(count >= NO_NICKS_PER_WHOIS_LINE) {
+ snprintf(message, sizeof(message), "Authed : %s", nickbuffer);
+ triggerhook(HOOK_CONTROL_WHOISREPLY, message);
+ nickbuffer[0] = '\0';
+ count = 0;
+ }
+ }
+ } else {
+ /* inefficient way */
+ char *authname = (char *)arg;
+ int i = 0;
+ nick *sp;
+
+ for(;i<NICKHASHSIZE;i++)
+ for(sp=nicktable[i];sp;sp=sp->next)
+ if(IsAccount(sp) && !ircd_strcmp(sp->authname, authname)) {
+ found = 1;
+
+ snprintf(accountspace, sizeof(accountspace), "%s%s", count++?", ":"", sp->nick);
+ strncat(nickbuffer, accountspace, sizeof(nickbuffer));
+ nickbuffer[sizeof(nickbuffer) - 1] = '\0';
+
+ if(count >= NO_NICKS_PER_WHOIS_LINE) {
+ snprintf(message, sizeof(message), "Authed : %s", nickbuffer);
+ triggerhook(HOOK_CONTROL_WHOISREPLY, message);
+ nickbuffer[0] = '\0';
+ count = 0;
+ }
+ }
+ }
+
+ if(!found) {
+ snprintf(message, sizeof(message), "Authed : (no nicks authed)");
+ triggerhook(HOOK_CONTROL_WHOISREPLY, message);
+ } else if(nickbuffer[0]) {
+ snprintf(message, sizeof(message), "Authed : %s", nickbuffer);
+ triggerhook(HOOK_CONTROL_WHOISREPLY, message);
+ }
+}
+
+int controllistusers(void *sender, int cargc, char **cargv) {
+ nick *np = (nick *)sender;
+ int i, count = 0;
+ authname *anp;
+ no_autheduser *au;
+
+ hooknick = np;
+
+ registerhook(HOOK_CONTROL_WHOISREPLY, &handlewhois);
+
+ for (i=0;i<AUTHNAMEHASHSIZE;i++) {
+ for (anp=authnametable[i];anp;anp=anp->next) {
+ au = noperserv_get_autheduser(anp);
+ if(!au)
+ continue;
+
+ if (count > 0)
+ controlreply(np, "---");
+
+ controlreply(np, "Account : %s", au->authname->name);
+ noperserv_whois_account_handler(HOOK_CONTROL_WHOISREQUEST_AUTHEDUSER, (void *)au);
+ controlreply(np, "Flags : %s", printflags(NOGetAuthLevel(au), no_userflags));
+
+ count++;
+ }
+ }
+
+ deregisterhook(HOOK_CONTROL_WHOISREPLY, &handlewhois);
+
+ controlreply(np, "--- Found %d users.", count);
+
+ return CMD_OK;
+}
+