void gline_activate(gline *agline, time_t lastmod, int propagate) {
time_t now = getnettime();
+
agline->flags |= GLINE_ACTIVE;
if (lastmod)
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;
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);
#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
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);
char *mask, *reason;
char creator[32];
glinebuf gbuf;
-#if SNIRCD_VERSION <= 134
+#if SNIRCD_VERSION < 140
gline *gl;
#endif
return CMD_ERROR;
}
-#if SNIRCD_VERSION <= 134
+#if SNIRCD_VERSION < 140
gl = findgline(mask);
if (gl) {
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;
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.");
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);
/* 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;
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);