#include <stdio.h>
+#include "../lib/version.h"
+#include "../core/schedule.h"
+#include "../control/control.h"
#include "glines.h"
+MODULE_VERSION("");
+
static int glstore_savefile(const char *file) {
FILE *fp;
gline *gl;
for (gl = glinelist; gl; gl = gl->next) {
fprintf(fp, "%s %jd,%jd,%jd,%d,%s,%s\n",
glinetostring(gl), (intmax_t)gl->expire, (intmax_t)gl->lastmod, (intmax_t)gl->lifetime,
- gl->flags & ~(GLINE_HOSTMASK | GLINE_IPMASK | GLINE_BADCHAN | GLINE_REALNAME),
- gl->creator->content, gl->reason->content);
+ (gl->flags & GLINE_ACTIVE) ? 1 : 0,
+ gl->creator->content, gl->reason ? gl->reason->content : "");
count++;
}
FILE *fp;
char mask[512], creator[512], reason[512];
intmax_t expire, lastmod, lifetime;
- int flags, count;
+ int active, count;
gline *gl;
fp = fopen(file, "r");
count = 0;
while (!feof(fp)) {
- if (fscanf(fp, "%[^ ]%jd,%jd,%jd,%d,%[^,],%[^\n]\n", mask, &expire, &lastmod, &lifetime, &flags, creator, reason) != 7)
+ if (fscanf(fp, "%[^ ]%jd,%jd,%jd,%d,%[^,],%[^\n]\n", mask, &expire, &lastmod, &lifetime, &active, creator, reason) != 7)
continue;
count++;
gl->creator = getsstring(creator, 512);
- gl->flags |= flags;
+ gl->flags |= active ? GLINE_ACTIVE : 0;
gl->reason = getsstring(reason, 512);
gl->expire = expire;
return glstore_loadfile(path);
}
+static int glines_cmdsaveglines(void *source, int cargc, char **cargv) {
+ nick *sender = source;
+ int count;
+
+ count = glstore_save();
+
+ if (count < 0)
+ controlreply(sender, "An error occured while saving G-Lines.");
+ else
+ controlreply(sender, "Saved %d G-Line%s.", count, (count == 1) ? "" : "s");
+
+ return CMD_OK;
+}
+
+static int glines_cmdloadglines(void *source, int cargc, char **cargv) {
+ nick *sender = source;
+ int count;
+
+ count = glstore_load();
+
+ if (count < 0)
+ controlreply(sender, "An error occured while loading the G-Lines file.");
+ else
+ controlreply(sender, "Loaded %d G-Line%s.", count, (count == 1) ? "" : "s");
+
+ return CMD_OK;
+}
+
+static void glines_sched_save(void *arg) {
+ glstore_save();
+}
+
+void _init() {
+ 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.");
+
+ schedulerecurring(time(NULL), 0, GLSTORE_SAVE_INTERVAL, &glines_sched_save, NULL);
+
+ glstore_load();
+}
+
+void _fini() {
+ deregistercontrolcmd("loadglines", glines_cmdloadglines);
+ deregistercontrolcmd("saveglines", glines_cmdsaveglines);
+
+ deleteschedule(NULL, glines_sched_save, NULL);
+}