]> jfr.im git - irc/quakenet/newserv.git/blobdiff - newsearch/formats.c
CHANSERV: better batcher error handling for expired accounts/accounts with no email.
[irc/quakenet/newserv.git] / newsearch / formats.c
index ec60f589476b1519774c1559a6c595f15d221a4b..edc0ebce016d081846471e587669c22a47209071 100644 (file)
@@ -9,14 +9,54 @@
 #include "../lib/splitline.h"
 #include "../lib/version.h"
 
-void printnick(nick *sender, nick *np) {
+void printnick(searchCtx *ctx, nick *sender, nick *np) {
   char hostbuf[HOSTLEN+NICKLEN+USERLEN+4];
 
-  controlreply(sender,"%s [%s] (%s) (%s)",visiblehostmask(np,hostbuf),
-              IPtostr(np->p_ipaddr), printflags(np->umodes, umodeflags), np->realname->name->content);
+  ctx->reply(sender,"%s [%s] (%s) (%s)",visiblehostmask(np,hostbuf),
+              IPtostr(np->ipaddress), printflags(np->umodes, umodeflags), np->realname->name->content);
 }
 
-void printchannel(nick *sender, chanindex *cip) {
+void printnick_channels(searchCtx *ctx, nick *sender, nick *np) {
+  char chanlistbuf[512];
+  unsigned int bufpos=0, overflow=0;
+  channel **cs, *cp;
+  unsigned int i;
+  unsigned long *lp;
+  
+  /* Include the default format too */
+  printnick(ctx, sender,np);
+  
+  /* Now add the channels.. */
+  cs=(channel **)(np->channels->content);
+  for (i=0;i<np->channels->cursi;i++) {
+    cp=cs[i];
+    
+    if (!(lp=getnumerichandlefromchanhash(cp->users,np->numeric)))
+      /* "Impossible" error case - nick not on this channel */
+      continue;
+    
+    if (bufpos + cp->index->name->length > 400) {
+      overflow=1;
+      break;
+    }
+    
+    if (*lp & CUMODE_OP) {
+      chanlistbuf[bufpos++]='@';
+    } else if (*lp & CUMODE_VOICE) {
+      chanlistbuf[bufpos++]='+';
+    }
+    
+    bufpos+=sprintf(chanlistbuf+bufpos,"%s ",cp->index->name->content);
+  }
+  
+  if (!bufpos) {
+    ctx->reply(sender,"  Not an any channels.");
+  } else {
+    ctx->reply(sender,"  On channel%s: %s%s",np->channels->cursi>1?"s":"", chanlistbuf, overflow?"[...]":"");
+  }
+}
+
+void printchannel(searchCtx *ctx, nick *sender, chanindex *cip) {
   /* shamelessly stolen from (now defunct) chansearch.c */
   int i;
   int op,voice,peon;
@@ -29,7 +69,7 @@ void printchannel(nick *sender, chanindex *cip) {
   marker=nexthostmarker();
   
   if (cip->channel==NULL) {
-    controlreply(sender,"[         Channel currently empty          ] %s",cip->name->content);
+    ctx->reply(sender,"[         Channel currently empty          ] %s",cip->name->content);
   } else {
     cuhp=cip->channel->users;
     for (i=0;i<cuhp->hashsize;i++) {
@@ -55,21 +95,21 @@ void printchannel(nick *sender, chanindex *cip) {
         }
       }
     }
-    controlreply(sender,"[ %4dU %4d@ %4d+ %4d %4d* %4dk %4dH ] %s (%s)",cuhp->totalusers,op,voice,peon,oper,
+    ctx->reply(sender,"[ %4dU %4d@ %4d+ %4d %4d* %4dk %4dH ] %s (%s)",cuhp->totalusers,op,voice,peon,oper,
       service,hosts,cip->name->content, printflags(cip->channel->flags, cmodeflags));
   }
 }
 
 
-void printchannel_topic(nick *sender, chanindex *cip) {
+void printchannel_topic(searchCtx *ctx, nick *sender, chanindex *cip) {
   if (cip->channel==NULL) {
-    controlreply(sender,"[   empty  ] %-30s",cip->name->content);
+    ctx->reply(sender,"[   empty  ] %-30s",cip->name->content);
   } else {
-    controlreply(sender,"[%4u users] %s (%s)",cip->channel->users->totalusers,cip->name->content,cip->channel->topic?cip->channel->topic->content:"no topic");
+    ctx->reply(sender,"[%4u users] %s (%s)",cip->channel->users->totalusers,cip->name->content,cip->channel->topic?cip->channel->topic->content:"no topic");
   }
 }
 
-void printchannel_services(nick *sender, chanindex *cip) {
+void printchannel_services(searchCtx *ctx, nick *sender, chanindex *cip) {
   int i;
   chanuserhash *cuhp;
   char servlist[300];
@@ -78,7 +118,7 @@ void printchannel_services(nick *sender, chanindex *cip) {
   int servs=0;
   
   if (cip->channel==NULL) {
-    controlreply(sender,"%-30s empty",cip->name->content);
+    ctx->reply(sender,"%-30s empty",cip->name->content);
   } else {
     cuhp=cip->channel->users;
     for (i=0;i<cuhp->hashsize;i++) {
@@ -101,8 +141,16 @@ void printchannel_services(nick *sender, chanindex *cip) {
       }
     }  
      
-    controlreply(sender,"%-30s %5d user%c %2d service%c %s%s%s",cip->name->content,cuhp->totalusers,
+    ctx->reply(sender,"%-30s %5d user%c %2d service%c %s%s%s",cip->name->content,cuhp->totalusers,
                          cuhp->totalusers>1?'s':' ',servs,(servs==1)?' ':'s',servs?"(":"",slpos?servlist:"",servs?")":"");
   }
 }
 
+void printuser(searchCtx *ctx, nick *sender, authname *aup) {
+  ctx->reply(sender,"%d", aup->userid);
+}
+
+void printwhowas(searchCtx *ctx, nick *sender, whowas *ww) {
+  ctx->reply(sender,"%s", whowas_format(ww));
+  ctx->reply(sender,"%s", whowas_formatchannels(ww));
+}