]> jfr.im git - irc/quakenet/newserv.git/blobdiff - helpmod2/hconf.c
nickwatch: Implement hook for messages/notices.
[irc/quakenet/newserv.git] / helpmod2 / hconf.c
index fc33e08bf66dcc6dd1bc960efbd68cb54a7c7a2c..2de5ba2ac36b8e13121d9ef9a00a5783df751d72 100644 (file)
@@ -1,4 +1,3 @@
-
 #include <stdio.h>
 #include <ctype.h>
 #include <string.h>
@@ -9,6 +8,7 @@
 #include "helpmod.h"
 #include "hterm.h"
 
+static int hconf_version;
 
 static void helpmod_line_fix(char **ptr)
 {
@@ -28,6 +28,9 @@ int helpmod_config_read(const char *fname)
     FILE *in;
     char buf[512], *ptr;
 
+    /* Assume G 2.0 configuration */
+    hconf_version = HELPMOD_VERSION_2_0;
+
     if ((in = fopen(fname,"rt")) == NULL)
         return -1;
 
@@ -48,7 +51,15 @@ int helpmod_config_read(const char *fname)
             continue;
 
         /* check what kind of a line it was */
-        if (!strcmp(ptr, "channel"))
+       if (!strcmp(ptr, "version"))
+       { /* If no version is present, then the assumed G 2.0 version is used */
+           if (helpmod_config_read_version(in))
+               Error("helpmod", ERR_WARNING, "Reading of database entry 'version' failed");
+
+           if (hconf_version > HELPMOD_VERSION_INTERNAL)
+               Error("helpmod", ERR_WARNING, "Database version is higher than the current version");
+       }
+       else if (!strcmp(ptr, "channel"))
         {
             if (helpmod_config_read_channel(in))
                 Error("helpmod", ERR_WARNING, "Reading of database entry 'channel' failed");
@@ -88,7 +99,7 @@ int helpmod_config_read(const char *fname)
             if (helpmod_config_read_ticket(in))
                 Error("helpmod", ERR_WARNING, "Reading of database entry 'ticket' failed");
         }
-        else
+       else
             Error("helpmod", ERR_WARNING, "Unknown database entry '%s'", ptr);
     }
 
@@ -101,16 +112,29 @@ int helpmod_config_read(const char *fname)
 int helpmod_config_write(const char *fname)
 {
     FILE *out;
-    /*char buf[512];*/
     time_t timer = time(NULL);
 
     if ((out = fopen(fname,"wt")) == NULL)
         return -1;
 
-    fprintf(out, "%% H2 version %s database\n", HELPMOD_VERSION);
+    fprintf(out, "%% G2 version %s database\n", HELPMOD_VERSION);
     fprintf(out, "%% %s\n\n", asctime(localtime(&timer)));
 
 
+    { /* version */
+       fprintf(out, "%% G internal version\n");
+        fprintf(out, "version\n");
+        helpmod_config_write_version(out);
+    }
+
+    { /* globals */
+
+        fprintf(out,"\n%% global variables\n");
+        fprintf(out,"%%  hstat_cycle\n");
+        fprintf(out,"globals\n");
+        helpmod_config_write_globals(out);
+    }
+
     { /* lamercontrol profiles */
         hlc_profile *ptr = hlc_profiles;
 
@@ -149,7 +173,7 @@ int helpmod_config_write(const char *fname)
 
         fprintf(out,"\n%% account structure:\n");
         fprintf(out,"%%  name (string):\n");
-        fprintf(out,"%%  level (integer):\n");
+        fprintf(out,"%%  level (integer) flags (integer) last_activity (integer):\n");
 
         for(;ptr;ptr=ptr->next)
         {
@@ -223,14 +247,6 @@ int helpmod_config_write(const char *fname)
         }
     }
 
-    { /* globals */
-
-        fprintf(out,"\n%% global variables\n");
-        fprintf(out,"%%  hstat_cycle\n");
-        fprintf(out,"globals\n");
-        helpmod_config_write_globals(out);
-    }
-
     fclose(out);
 
     return 0;
@@ -241,7 +257,7 @@ int helpmod_config_read_channel(FILE *in)
     hchannel *hchan;
 
     char buf[256],*ptr=(char*)buf;
-    int flags, entries, i;
+    int flags, entries, idlekick, i;
     /* name */
     fgets(buf, 256, in);
     if (feof(in))
@@ -275,6 +291,26 @@ int helpmod_config_read_channel(FILE *in)
 
     hchan->lc_profile = hlc_get(ptr);
 
+    if (hconf_version >= HELPMOD_VERSION_2_11)
+    {
+       fgets((ptr = buf), 256, in);
+       if (feof(in))
+           return -1;
+       helpmod_line_fix(&ptr);
+
+       if (sscanf(ptr, "%d", &idlekick) != 1)
+           return -1;
+
+        hchan->max_idle = idlekick;
+
+       fgets((ptr = buf), 256, in);
+       if (feof(in))
+           return -1;
+       helpmod_line_fix(&ptr);
+
+        hchan->ticket_message = getsstring(ptr,strlen(ptr));
+    }
+
     /* censor entries for channel, a bit complex */
     fgets((ptr = buf), 256, in);
     if (feof(in))
@@ -286,19 +322,36 @@ int helpmod_config_read_channel(FILE *in)
         return -1;
     for (i = 0;i<entries;i++)
     {
-        char buf2[512], *ptr2;
+       char buf2[512], *ptr2;
+       int type;
 
         fgets((ptr = buf), 256, in);
-        if (feof(in))
+       if (feof(in))
             return -1;
         helpmod_line_fix(&ptr);
 
+       if (hconf_version >= HELPMOD_VERSION_2_10)
+       {
+           if (!sscanf(ptr, "%d", &type))
+               return -1;
+
+           fgets((ptr = buf), 256, in);
+           if (feof(in))
+               return -1;
+           helpmod_line_fix(&ptr);
+       }
+       else
+            type = HCENSOR_KICK;
+
         fgets((ptr2 = buf2), 256, in);
         if (feof(in))
             return -1;
         helpmod_line_fix(&ptr2);
 
-        hcensor_add(&hchan->censor, ptr, ptr2);
+       if (ptr2[0] == '\0')
+            ptr2 = NULL;
+
+        hcensor_add(&hchan->censor, ptr, ptr2, type);
     }
     /* channel specific hterms */
     fgets((ptr = buf), 256, in);
@@ -328,15 +381,23 @@ int helpmod_config_write_channel(FILE *out, hchannel *target)
     if (target->lc_profile == NULL)
         fprintf(out, "\t(null)\n");
     else
-        fprintf(out, "\t%s\n", target->lc_profile->name->content);
+       fprintf(out, "\t%s\n", target->lc_profile->name->content);
+
+    fprintf(out, "\t%d\n", target->max_idle);
+
+    if (target->ticket_message == NULL)
+       fprintf(out, "\t(null)\n");
+    else
+       fprintf(out, "\t%s\n", target->ticket_message->content);
 
     fprintf(out, "\t%d %% censor\n", hcensor_count(target->censor));
     {
         hcensor *hcens = target->censor;
         for (;hcens;hcens = hcens->next)
-        {
+       {
+            fprintf(out, "\t\t%d\n", hcens->type);
             fprintf(out, "\t\t%s\n", hcens->pattern->content);
-            fprintf(out, "\t\t%s\n", hcens->reason->content);
+           fprintf(out, "\t\t%s\n", hcens->reason?hcens->reason->content:"");
         }
     }
 
@@ -361,7 +422,7 @@ int helpmod_config_read_account(FILE *in)
     int nstats;
 
     char buf[256],*ptr=(char*)buf;
-    int flags, level;
+    int flags, level, last_activity = time(NULL);
 
     fgets(ptr = buf, 256, in);
     if (feof(in))
@@ -374,12 +435,24 @@ int helpmod_config_read_account(FILE *in)
     if (feof(in))
         return -1;
     helpmod_line_fix(&ptr);
+    if (hconf_version < HELPMOD_VERSION_2_11)
+    {
+       if (sscanf(ptr, "%x %x", (unsigned int*)&level, (unsigned int*)&flags) != 2)
+           return -1;
+    }
+    else
+       if (sscanf(ptr, "%x %x %x", (unsigned int*)&level, (unsigned int*)&flags, (unsigned int *)&last_activity) != 3)
+           return -1;
 
-    if (sscanf(ptr, "%x %x", (unsigned int*)&level, (unsigned int*)&flags) != 2)
-        return -1;
+    if (hconf_version < HELPMOD_VERSION_2_16)
+    { /* For the new friend userlevel */
+       if (level >= H_FRIEND)
+           level++;
+    }
 
     hack->level = level;
     hack->flags = flags;
+    hack->last_activity = last_activity;
 
     fgets(ptr = buf, 256, in);
     if (feof(in))
@@ -406,7 +479,7 @@ int helpmod_config_write_account(FILE *out, haccount *target)
 {
     hstat_account *tmp;
     fprintf(out, "\t%s\n", target->name->content);
-    fprintf(out, "\t%x\t%x\n", target->level, target->flags);
+    fprintf(out, "\t%x\t%x\t%x\n", target->level, target->flags, (unsigned int)target->last_activity);
 
     fprintf(out, "\t%d %% statistics for this channel\n", hstat_account_count(target->stats));
     for (tmp = target->stats;tmp;tmp = tmp->next)
@@ -447,7 +520,7 @@ int helpmod_config_write_ban(FILE *out, hban *hb)
 {
     fprintf(out, "\t%s\n", bantostring(hb->real_ban));
     fprintf(out, "\t%s\n", hb->reason?hb->reason->content:NULL);
-    fprintf(out, "\t%d\n", hb->expiration);
+    fprintf(out, "\t%u\n", (unsigned int)hb->expiration);
     return 0;
 }
 
@@ -465,7 +538,7 @@ int helpmod_config_read_hlc_profile(FILE *in)
     helpmod_line_fix(&ptr);
 
     if ((hlc_prof = hlc_add(ptr)) == NULL)
-        return -1;
+       return -1;
 
     /*  caps */
     fgets(ptr = buf, 256, in);
@@ -590,10 +663,18 @@ int helpmod_config_read_chanstats(FILE *in, hstat_channel *hs_chan)
         if (i < 7) /* days */
             entry = &hs_chan->week[(hstat_day() + i) % 7];
         else /* weeks */
-            entry = &hs_chan->longterm[(hstat_week() + (i-7)) % 7];
+            entry = &hs_chan->longterm[(hstat_week() + (i-7)) % 10];
 
-        if (sscanf(buf, "%d %d %d %d %d %d", &entry->time_spent, &entry->prime_time_spent, &entry->joins, &entry->queue_use, &entry->lines, &entry->words) != 6)
+       if (hconf_version < HELPMOD_VERSION_2_10)
+       {
+           if (sscanf(buf, "%d %d %d %d %d %d", &entry->time_spent, &entry->prime_time_spent, &entry->joins, &entry->queue_use, &entry->lines, &entry->words) != 6)
             return -1;
+       }
+       else
+       {
+           if (sscanf(buf, "%d %d %d %d %d %d %d %d", &entry->active_time, &entry->staff_active_time, &entry->time_spent, &entry->prime_time_spent, &entry->joins, &entry->queue_use, &entry->lines, &entry->words) != 8)
+               return -1;
+       }
     }
     return 0;
 }
@@ -608,9 +689,9 @@ int helpmod_config_write_chanstats(FILE *out, hstat_channel *hs_chan)
         if (i < 7) /* days */
             entry = &hs_chan->week[(hstat_day() + i) % 7];
         else /* weeks */
-            entry = &hs_chan->longterm[(hstat_week() + (i-7)) % 7];
+            entry = &hs_chan->longterm[(hstat_week() + (i-7)) % 10];
 
-        fprintf(out, "\t%d %d %d %d %d %d\n", entry->time_spent, entry->prime_time_spent, entry->joins, entry->queue_use, entry->lines, entry->words);
+        fprintf(out, "\t%d %d %d %d %d %d %d %d\n", entry->active_time, entry->staff_active_time, entry->time_spent, entry->prime_time_spent, entry->joins, entry->queue_use, entry->lines, entry->words);
     }
     return 0;
 }
@@ -641,7 +722,7 @@ int helpmod_config_read_stats(FILE *in, hstat_account *hs_acc)
         if (i < 7) /* days */
             entry = &hs_acc->week[(hstat_day() + i) % 7];
         else /* weeks */
-            entry = &hs_acc->longterm[(hstat_week() + (i-7)) % 7];
+            entry = &hs_acc->longterm[(hstat_week() + (i-7)) % 10];
 
         if (sscanf(buf, "%d %d %d %d", &entry->time_spent, &entry->prime_time_spent, &entry->lines, &entry->words) != 4)
             return -1;
@@ -661,7 +742,7 @@ int helpmod_config_write_stats(FILE *out, hstat_account *hs_acc)
         if (i < 7) /* days */
             entry = &hs_acc->week[(hstat_day() + i) % 7];
         else /* weeks */
-            entry = &hs_acc->longterm[(hstat_week() + (i-7)) % 7];
+            entry = &hs_acc->longterm[(hstat_week() + (i-7)) % 10];
 
         fprintf(out, "\t%d %d %d %d\n", entry->time_spent, entry->prime_time_spent, entry->lines, entry->words);
     }
@@ -749,7 +830,22 @@ int helpmod_config_read_ticket(FILE *in)
         return -1;
 
     if (tmp > time(NULL))
-        hticket_add(buf3, tmp, hchannel_get_by_name(buf2));
+    {
+       if (hconf_version < HELPMOD_VERSION_2_17)
+           hticket_add(buf3, tmp, hchannel_get_by_name(buf2), NULL);
+       else
+       {
+           fgets(ptr = buf, 256, in);
+           if (feof(in))
+               return -1;
+           helpmod_line_fix(&ptr);
+
+           if (*ptr == '\0')
+               hticket_add(buf3, tmp, hchannel_get_by_name(buf2), NULL);
+           else
+                hticket_add(buf3, tmp, hchannel_get_by_name(buf2), ptr);
+       }
+    }
 
     return 0;
 }
@@ -758,7 +854,33 @@ int helpmod_config_write_ticket(FILE *out, hticket *htick, hchannel *hchan)
 {
     fprintf(out, "\t%s\n", hchannel_get_name(hchan));
     fprintf(out, "\t%s\n", htick->authname);
-    fprintf(out, "\t%u\n", htick->time_expiration);
+    fprintf(out, "\t%u\n", (unsigned int)htick->time_expiration);
+    if (htick->message)
+       fprintf(out, "\t%s\n", htick->message->content);
+    else
+        fprintf(out, "\n");
+
+    return 0;
+}
+
+int helpmod_config_read_version(FILE *in)
+{
+    char buf[256], *ptr=(char*)buf;
+
+    fgets(ptr = buf, 256, in);
+    if (feof(in))
+        return -1;
+    helpmod_line_fix(&ptr);
+
+    if (sscanf(ptr, "%d", &hconf_version) != 1)
+        return -1;
+
+    return 0;
+}
+
+int helpmod_config_write_version(FILE *out)
+{
+    fprintf(out, "\t%d\n", HELPMOD_VERSION_INTERNAL);
 
     return 0;
 }