]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Implement snircd gline destruction command.
authorGunnar Beutner <redacted>
Sat, 13 Jul 2013 15:43:17 +0000 (17:43 +0200)
committerGunnar Beutner <redacted>
Sat, 13 Jul 2013 15:43:17 +0000 (17:43 +0200)
--HG--
branch : shroudtrusts

glines/glines.c
glines/glines.h
glines/glines_commands.c
glines/glines_handler.c

index 8d036c144546d9a01a3365fd74bc6cf1636e5983..b64a3deffcc6e1389626300cabc94d2d46f3d251 100644 (file)
@@ -109,6 +109,7 @@ gline *findgline(const char *mask) {
 
 void gline_activate(gline *agline, time_t lastmod, int propagate) {
   time_t now = getnettime();
+
   agline->flags |= GLINE_ACTIVE;
 
   if (lastmod)
@@ -124,7 +125,25 @@ void gline_activate(gline *agline, time_t lastmod, int propagate) {
 
 void gline_deactivate(gline *agline, time_t lastmod, int propagate) {
   time_t now = getnettime();
+
+  agline->flags &= ~GLINE_ACTIVE;
+
+  if (lastmod)
+    agline->lastmod = lastmod;
+  else if (now <= agline->lastmod)
+    agline->lastmod++;
+  else
+    agline->lastmod = now;
+
+  if (propagate)
+    gline_propagate(agline);
+}
+
+void gline_destroy(gline *agline, time_t lastmod, int propagate) {
+  time_t now = getnettime();
+
   agline->flags &= ~GLINE_ACTIVE;
+  agline->flags |= GLINE_DESTROYED;
 
   if (lastmod)
     agline->lastmod = lastmod;
@@ -135,10 +154,26 @@ void gline_deactivate(gline *agline, time_t lastmod, int propagate) {
 
   if (propagate)
     gline_propagate(agline);
+
+  removegline(agline);
 }
 
 void gline_propagate(gline *agline) {
-  if (agline->flags & GLINE_ACTIVE) {
+  if (agline->flags & GLINE_DESTROYED) {
+    controlwall(NO_OPER, NL_GLINES, "Destroying G-Line on '%s' lasting %s with reason '%s', created by: %s",
+      glinetostring(agline), longtoduration(agline->expire-getnettime(), 0),
+      agline->reason->content, agline->creator->content);
+
+#if 1
+    irc_send("%s GL * %%-%s %lu %lu :%s\r\n", mynumeric->content,
+      glinetostring(agline), agline->expire - getnettime(),
+      agline->lastmod, agline->reason->content);
+#else
+    controlwall(NO_OPER, NL_GLINES, "%s GL * %%-%s %lu %lu :%s\r\n", mynumeric->content,
+      glinetostring(agline), agline->expire - getnettime(),
+      agline->lastmod, agline->reason->content);
+#endif
+  } else if (agline->flags & GLINE_ACTIVE) {
     controlwall(NO_OPER, NL_GLINES, "Activating G-Line on '%s' lasting %s with reason '%s', created by: %s",
       glinetostring(agline), longtoduration(agline->expire-getnettime(), 0),
       agline->reason->content, agline->creator->content);
index 94efec24f1a08f1143c57cbded7e1346776e1c1c..a5c7a72417efb3441bf12657ad03dfd356dce11a 100644 (file)
@@ -27,7 +27,9 @@
 #define GLINE_REALNAME    8   /* Gline includes a realname */
 #define GLINE_ACTIVATE    16  /* Gline should be activated */
 #define GLINE_DEACTIVATE  32  /* Gline should be deactivated */
-#define GLINE_ACTIVE      64  /* Gline is active */
+#define GLINE_DESTROY     64  /* Gline should be destroyed */
+#define GLINE_ACTIVE      128 /* Gline is active */
+#define GLINE_DESTROYED   256 /* Gline is destroyed */
 
 /**
  * glist flags
@@ -85,6 +87,7 @@ extern gline *glinelist;
 gline *findgline(const char *);
 void gline_propagate(gline *);
 void gline_deactivate(gline *, time_t, int);
+void gline_destroy(gline *, time_t, int);
 void gline_activate(gline *agline, time_t lastmod, int propagate);
 int glineequal(gline *, gline *);
 int gline_match_mask(gline *gla, gline *glb);
index 5c48a62a85e2767ab7cc2066b6b9e3af229f21ec..8e3384ed761543909fa75348006ea64a46d33fb0 100644 (file)
@@ -75,7 +75,7 @@ static int glines_gline_helper(void *source, int cargc, char **cargv, int sanity
   char *mask, *reason;
   char creator[32];
   glinebuf gbuf;
-#if SNIRCD_VERSION <= 134
+#if SNIRCD_VERSION < 140
   gline *gl;
 #endif
 
@@ -103,7 +103,7 @@ static int glines_gline_helper(void *source, int cargc, char **cargv, int sanity
     return CMD_ERROR;
   }
 
-#if SNIRCD_VERSION <= 134
+#if SNIRCD_VERSION < 140
   gl = findgline(mask);
 
   if (gl) {
@@ -733,6 +733,31 @@ static int glines_cmdglist(void *source, int cargc, char **cargv) {
   return CMD_OK;
 }
 
+static int glines_cmdcleanupglines(void *source, int cargc, char **cargv) {
+  nick *sender = source;
+  gline **pnext, *gl;
+  int count;
+  
+  count = 0;
+  
+  for (pnext = &glinelist; *pnext; pnext = &((*pnext)->next)) {
+    gl = *pnext;
+    
+    if (!(gl->flags & GLINE_ACTIVE)) {
+      gline_destroy(gl, 0, 1);
+      count++;
+    }
+    
+    if (!*pnext)
+      break;
+  }
+  
+  controlwall(NO_OPER, NL_GLINES, "%s CLEANUPGLINES'd %d G-Lines.",
+    controlid(sender), count);
+  
+  return CMD_OK;
+}
+
 static int glines_cmdsyncglines(void *source, int cargc, char **cargv) {
   nick *sender = source;
   gline *gl;
@@ -799,6 +824,7 @@ static void registercommands(int hooknum, void *arg) {
   registercontrolhelpcmd("trustungline", NO_OPER, 2, glines_cmdtrustungline, "Usage: trustungline <#id|name> <user>\nRemoves a gline that was previously set with trustgline.");
   registercontrolhelpcmd("glstats", NO_OPER, 0, glines_cmdglstats, "Usage: glstat\nShows statistics about G-Lines.");
   registercontrolhelpcmd("glist", NO_OPER, 2, glines_cmdglist, "Usage: glist [-flags] <mask>\nLists matching G-Lines.\nValid flags are:\n-c: Count G-Lines.\n-f: Find G-Lines active on <mask>.\n-x: Find G-Lines matching <mask> exactly.\n-R: Find G-lines on realnames.\n-o: Search for glines by owner.\n-r: Search for glines by reason.\n-i: Include inactive glines.");
+  registercontrolhelpcmd("cleanupglines", NO_OPER, 0, glines_cmdcleanupglines, "Usage: cleanupglines\nDestroys all deactivated G-Lines.");
   registercontrolhelpcmd("syncglines", NO_DEVELOPER, 0, glines_cmdsyncglines, "Usage: syncglines\nSends all G-Lines to all other servers.");
   registercontrolhelpcmd("loadglines", NO_DEVELOPER, 0, glines_cmdloadglines, "Usage: loadglines\nForce load of glines.");
   registercontrolhelpcmd("saveglines", NO_DEVELOPER, 0, glines_cmdsaveglines, "Usage: saveglines\nForce save of glines.");
@@ -820,6 +846,7 @@ static void deregistercommands(int hooknum, void *arg) {
   deregistercontrolcmd("trustungline", glines_cmdtrustungline);
   deregistercontrolcmd("glstats", glines_cmdglstats);
   deregistercontrolcmd("glist", glines_cmdglist);
+  deregistercontrolcmd("cleanupglines", glines_cmdcleanupglines);
   deregistercontrolcmd("syncglines", glines_cmdsyncglines);
   deregistercontrolcmd("loadglines", glines_cmdloadglines);
   deregistercontrolcmd("saveglines", glines_cmdsaveglines);
index cc88f198f370361b0274636260f14dff01dff6b4..6a2c1b88f27b20c5d9cc7d4a77673f5ee22b9064 100644 (file)
@@ -80,6 +80,12 @@ int handleglinemsg(void *source, int cargc, char **cargv) {
   /* 2nd param is mask */
   mask = cargv[1];
 
+  /* snircd 1.3.5 can destroy glines, no #if here */
+  if (*mask == '%') {
+    flags |= GLINE_DESTROY;
+    mask++;
+  }
+
   switch (*mask) {
     case '+':
       flags |= GLINE_ACTIVATE;
@@ -167,12 +173,22 @@ int handleglinemsg(void *source, int cargc, char **cargv) {
         case 5:
           /* asuka last mod */
           lastmod = atoi(cargv[3]);
-          gline_deactivate(agline, lastmod, 0);
+          
+          if (flags & GLINE_DESTROY)
+            gline_destroy(agline, lastmod, 0);
+          else
+            gline_deactivate(agline, lastmod, 0);
+
           break;
         case 6:
           /* snircd */
           lastmod = atoi(cargv[3]);
-          gline_deactivate(agline, lastmod, 0);
+
+          if (flags & GLINE_DESTROY)
+            gline_destroy(agline, lastmod, 0);
+          else
+            gline_deactivate(agline, lastmod, 0);
+
           break;
         default:
           Error("gline", ERR_WARNING, "Gline Deactivate with invalid number (%d) of arguments", cargc);