-
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "helpmod.h"
#include "hterm.h"
+static int hconf_version;
static void helpmod_line_fix(char **ptr)
{
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;
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");
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);
}
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;
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)
{
}
}
- { /* 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;
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))
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))
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);
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:"");
}
}
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))
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))
{
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)
{
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;
}
helpmod_line_fix(&ptr);
if ((hlc_prof = hlc_add(ptr)) == NULL)
- return -1;
+ return -1;
/* caps */
fgets(ptr = buf, 256, in);
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;
}
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;
}
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;
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);
}
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;
}
{
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;
}