]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Regexgline now has a hit counter, also show type in listing in a more human-friendly...
authorChris Porter <redacted>
Mon, 18 Aug 2008 17:27:49 +0000 (18:27 +0100)
committerChris Porter <redacted>
Mon, 18 Aug 2008 17:27:49 +0000 (18:27 +0100)
regexgline/regexgline.c
regexgline/regexgline.h

index c133c3143a670bfe9053a276edafc09a4ab95805..87b0ae7e63295a4ccbed70c4989531bc63c1c75b 100644 (file)
@@ -22,7 +22,7 @@
 #define DELAYED_HOST_GLINE   5
 #define DELAYED_KILL         6
 
-MODULE_VERSION("");
+MODULE_VERSION("1.41");
 
 typedef struct rg_glinenode {
   nick *np;
@@ -355,12 +355,12 @@ static void dbloadfini(DBConn *dbconn, void *arg) {
                          "Duration is represented as 3d, 3M etc.\n"
                          "Class is one of the following: %s\n"
                          "Type is an integer which represents the following:\n"
-                         "1 - Instant USER@IP GLINE\n"
-                         "2 - Instant *@IP GLINE\n"
-                         "3 - Instant KILL\n"
-                         "4 - Delayed USER@IP GLINE\n"
-                         "5 - Delayed *@IP GLINE\n"
-                         "6 - Delayed KILL",
+                         "1 - Instant USER@IP GLINE (igu)\n"
+                         "2 - Instant *@IP GLINE (igh)\n"
+                         "3 - Instant KILL (ik)\n"
+                         "4 - Delayed USER@IP GLINE (dgu)\n"
+                         "5 - Delayed *@IP GLINE (dgh)\n"
+                         "6 - Delayed KILL (dk)",
                          allclasses);
 
   registercontrolhelpcmd("regexgline", NO_OPER, 5, &rg_gline, helpbuf);
@@ -652,7 +652,7 @@ int rg_glist(void *source, int cargc, char **cargv) {
     }
     
     rg_logevent(np, "regexglist", "%s", cargv[0]);
-    controlreply(np, "Mask                      Expires              Set by          Class    Type Reason");
+    controlreply(np, "Mask                      Expires              Set by          Class    Type  Hits  Reason");
     for(rp=rg_list;rp;rp=rp->next)
       if(pcre_exec(regex, hint, rp->mask->content, rp->mask->length, 0, 0, NULL, 0) >= 0)
         rg_displaygline(np, rp);
@@ -663,7 +663,7 @@ int rg_glist(void *source, int cargc, char **cargv) {
     
   } else {
     rg_logevent(np, "regexglist", "");
-    controlreply(np, "Mask                      Expires              Set by          Class    Type Reason");
+    controlreply(np, "Mask                      Expires              Set by          Class    Type  Hits  Reason");
     for(rp=rg_list;rp;rp=rp->next)
       rg_displaygline(np, rp);
   }
@@ -672,8 +672,39 @@ int rg_glist(void *source, int cargc, char **cargv) {
   return CMD_OK;
 }
 
+char *displaytype(int type) {
+  char *ctype;
+  static char ctypebuf[10];
+
+  switch(type) {
+    case 1:
+      ctype = "igu";
+      break;
+    case 2:
+      ctype = "igh";
+      break;
+    case 3:
+      ctype = "ik";
+      break;
+    case 4:
+      ctype = "dgu";
+      break;
+    case 5:
+      ctype = "dgh";
+      break;
+    case 6:
+      ctype = "dk";
+      break;
+    default:
+      ctype = "??";
+  }
+
+  snprintf(ctypebuf, sizeof(ctype), "%1d:%s", type, ctype);
+  return ctypebuf;
+}
+
 void rg_displaygline(nick *np, struct rg_struct *rp) { /* could be a macro? I'll assume the C compiler inlines it */
-  controlreply(np, "%-25s %-20s %-15s %-8s %-4d %s", rp->mask->content, longtoduration(rp->expires - time(NULL), 0), rp->setby->content, rp->class, rp->type, rp->reason->content);
+  controlreply(np, " %-25s %-20s %-15s %-8s %-5s %-5lu %s", rp->mask->content, longtoduration(rp->expires - time(NULL), 0), rp->setby->content, rp->class, displaytype(rp->type), rp->hits, rp->reason->content);
 }
 
 int rg_spew(void *source, int cargc, char **cargv) {
@@ -1049,6 +1080,8 @@ void rg_logevent(nick *np, char *event, char *details, ...) {
 void rg_loggline(struct rg_struct *rg, nick *np) {
   char eenick[RG_QUERY_BUF_SIZE], eeuser[RG_QUERY_BUF_SIZE], eehost[RG_QUERY_BUF_SIZE], eereal[RG_QUERY_BUF_SIZE];
 
+  rg->hits++;
+
   /* @paul: disabled */
 
   return;
index bd3db0fcd9b5c26c67b16c2c031d10fa34141db5..74895e6d2d3b11bc17497068e20c1cbc192f00b1 100644 (file)
@@ -46,6 +46,7 @@ typedef struct rg_struct {
   pcre_extra       *hint;     /* pcre hint       */
   long             glineid;   /* gline ID */
   const char       *class;    /* class of gline */
+  unsigned long    hits;      /* hits since we were loaded */
   struct rg_struct *next;     /* ... pointer to next item */
 } rg_struct;