]> jfr.im git - irc/quakenet/newserv.git/commitdiff
CHANSERV: Add support to count calls, and "showcommands -v" to show the
authorsplidge <redacted>
Tue, 5 May 2009 14:29:19 +0000 (15:29 +0100)
committersplidge <redacted>
Tue, 5 May 2009 14:29:19 +0000 (15:29 +0100)
counts.

chanserv/chanservstdcmds.c
chanserv/chanservuser.c

index eb47137f559275b22aff5f80b7cfa47fb21c3e61..ff06dfbe7b1afe7c9eb0b3f992f4014787cdc76f 100644 (file)
@@ -91,6 +91,7 @@ int cs_doshowcommands(void *source, int cargc, char **cargv) {
   cmdsummary *summary;
   char cmdbuf[50];
   char *ct;
+  unsigned int dumpcount=0;
   
   n=getcommandlist(cscommands, cmdlist, 200);
   rup=getreguserfromnick(sender);
@@ -102,7 +103,49 @@ int cs_doshowcommands(void *source, int cargc, char **cargv) {
 
   chanservstdmessage(sender, QM_COMMANDLIST);
 
+  if (cargc>0 && rup && UIsDev(rup) && !ircd_strcmp(cargv[0], "-v")) {
+    dumpcount=1;
+  }
+
   for (i=0;i<n;i++) {
+    /* Generate the appropriate strings for the command name (including 
+     * prefixes for privileged users) and the summary text.
+     *
+     * We do this before we're sure we will print the command to make things
+     * easier when we are doing -v */    
+    summary=(cmdsummary *)cmdlist[i]->ext;
+    
+    if (rup && UHasStaffPriv(rup)) {
+      if (cmdlist[i]->level & QCMD_DEV) {
+        sprintf(cmdbuf,"+d %s",cmdlist[i]->command->content);
+      } else if(cmdlist[i]->level & QCMD_ADMIN) {
+        sprintf(cmdbuf,"+a %s",cmdlist[i]->command->content);
+      } else if(cmdlist[i]->level & QCMD_OPER) {
+        sprintf(cmdbuf,"+o %s",cmdlist[i]->command->content);
+      } else if(cmdlist[i]->level & QCMD_HELPER) {
+        sprintf(cmdbuf,"+h %s",cmdlist[i]->command->content);
+      } else if(cmdlist[i]->level & QCMD_STAFF) {
+        sprintf(cmdbuf,"+q %s",cmdlist[i]->command->content);
+      } else {
+        sprintf(cmdbuf,"   %s",cmdlist[i]->command->content);
+      }
+      ct=cmdbuf;
+    } else {
+      ct=cmdlist[i]->command->content;
+    }
+    
+    if (summary->bylang[lang]) {
+      message=summary->bylang[lang]->content;
+    } else if (summary->bylang[0]) {
+      message=summary->bylang[0]->content;
+    } else {
+      message=summary->def->content;
+    }
+    
+    if (dumpcount) {
+      chanservsendmessage(sender,"%-20s %u", cmdbuf, cmdlist[i]->calls);
+      continue;
+    }
     
     if (cargc>0 && !match2strings(cargv[0],cmdlist[i]->command->content))
       continue;
@@ -138,35 +181,7 @@ int cs_doshowcommands(void *source, int cargc, char **cargv) {
        (!rup || !UIsDev(rup) || !IsOper(sender)))
       continue;
     
-    summary=(cmdsummary *)cmdlist[i]->ext;
-    
-    if (rup && UHasStaffPriv(rup)) {
-      if (cmdlist[i]->level & QCMD_DEV) {
-        sprintf(cmdbuf,"+d %s",cmdlist[i]->command->content);
-      } else if(cmdlist[i]->level & QCMD_ADMIN) {
-        sprintf(cmdbuf,"+a %s",cmdlist[i]->command->content);
-      } else if(cmdlist[i]->level & QCMD_OPER) {
-        sprintf(cmdbuf,"+o %s",cmdlist[i]->command->content);
-      } else if(cmdlist[i]->level & QCMD_HELPER) {
-        sprintf(cmdbuf,"+h %s",cmdlist[i]->command->content);
-      } else if(cmdlist[i]->level & QCMD_STAFF) {
-        sprintf(cmdbuf,"+q %s",cmdlist[i]->command->content);
-      } else {
-        sprintf(cmdbuf,"   %s",cmdlist[i]->command->content);
-      }
-      ct=cmdbuf;
-    } else {
-      ct=cmdlist[i]->command->content;
-    }
-    
-    if (summary->bylang[lang]) {
-      message=summary->bylang[lang]->content;
-    } else if (summary->bylang[0]) {
-      message=summary->bylang[0]->content;
-    } else {
-      message=summary->def->content;
-    }
-    
+    /* We passed all the checks, send the message */    
     chanservsendmessage(sender, "%-20s %s",ct, message);
   }
 
index de27c8027eacc687db77fca7be26388a4dbd28e9..00d780b54985ed4f49bc3dc66ac5d94473f3d683 100644 (file)
@@ -111,6 +111,7 @@ void chanservuserhandler(nick *target, int message, void **params) {
       }
       cmd=findcommandintree(csctcpcommands, cargv[0]+1, 1);
       if (cmd) {
+       cmd->calls++;
        rejoinline(cargv[1],cargc-1);
        cmd->handler((void *)sender, cargc-1, &(cargv[1]));
       }      
@@ -173,6 +174,8 @@ void chanservuserhandler(nick *target, int message, void **params) {
        break;
       }
       
+      cmd->calls++;
+      
       if (cmd->maxparams < (cargc-1)) {
        rejoinline(cargv[cmd->maxparams],cargc-(cmd->maxparams));
        cargc=(cmd->maxparams)+1;