forked from github/server
report directory in .ini file
sleep/retry when errno during report writing.
This commit is contained in:
parent
602853f0e2
commit
27c188ea1c
|
@ -134,35 +134,35 @@ void
|
||||||
report_item(const unit * owner, const item * i, const faction * viewer, const char ** name, const char ** basename, int * number, boolean singular)
|
report_item(const unit * owner, const item * i, const faction * viewer, const char ** name, const char ** basename, int * number, boolean singular)
|
||||||
{
|
{
|
||||||
assert(owner->number);
|
assert(owner->number);
|
||||||
if (owner->faction == viewer) {
|
if (owner->faction == viewer) {
|
||||||
if (name) *name = locale_string(viewer->locale, resourcename(i->type->rtype, ((i->number!=1 && !singular)?GR_PLURAL:0)));
|
if (name) *name = locale_string(viewer->locale, resourcename(i->type->rtype, ((i->number!=1 && !singular)?GR_PLURAL:0)));
|
||||||
if (basename) *basename = resourcename(i->type->rtype, 0);
|
if (basename) *basename = resourcename(i->type->rtype, 0);
|
||||||
if (number) *number = i->number;
|
if (number) *number = i->number;
|
||||||
} else if (i->type->rtype==r_silver) {
|
} else if (i->type->rtype==r_silver) {
|
||||||
int pp = i->number/owner->number;
|
int pp = i->number/owner->number;
|
||||||
if (number) *number = 1;
|
if (number) *number = 1;
|
||||||
if (pp > 50000 && dragonrace(owner->race)) {
|
if (pp > 50000 && dragonrace(owner->race)) {
|
||||||
if (name) *name = locale_string(viewer->locale, "dragonhoard");
|
if (name) *name = locale_string(viewer->locale, "dragonhoard");
|
||||||
if (basename) *basename = "dragonhoard";
|
if (basename) *basename = "dragonhoard";
|
||||||
} else if (pp > 5000) {
|
} else if (pp > 5000) {
|
||||||
if (name) *name = locale_string(viewer->locale, "moneychest");
|
if (name) *name = locale_string(viewer->locale, "moneychest");
|
||||||
if (basename) *basename = "moneychest";
|
if (basename) *basename = "moneychest";
|
||||||
} else if (pp > 500) {
|
} else if (pp > 500) {
|
||||||
if (name) *name = locale_string(viewer->locale, "moneybag");
|
if (name) *name = locale_string(viewer->locale, "moneybag");
|
||||||
if (basename) *basename = "moneybag";
|
if (basename) *basename = "moneybag";
|
||||||
} else {
|
} else {
|
||||||
if (number) *number = 0;
|
if (number) *number = 0;
|
||||||
if (name) *name = NULL;
|
if (name) *name = NULL;
|
||||||
if (basename) *basename = NULL;
|
if (basename) *basename = NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (name) *name = locale_string(viewer->locale, resourcename(i->type->rtype, NMF_APPEARANCE|((i->number!=1 && !singular)?GR_PLURAL:0)));
|
if (name) *name = locale_string(viewer->locale, resourcename(i->type->rtype, NMF_APPEARANCE|((i->number!=1 && !singular)?GR_PLURAL:0)));
|
||||||
if (basename) *basename = resourcename(i->type->rtype, NMF_APPEARANCE);
|
if (basename) *basename = resourcename(i->type->rtype, NMF_APPEARANCE);
|
||||||
if (number) {
|
if (number) {
|
||||||
if (fval(i->type, ITF_HERB)) *number = 1;
|
if (fval(i->type, ITF_HERB)) *number = 1;
|
||||||
else *number = i->number;
|
else *number = i->number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1267,12 +1267,13 @@ prepare_report(faction * f)
|
||||||
int
|
int
|
||||||
write_reports(faction * f, time_t ltime)
|
write_reports(faction * f, time_t ltime)
|
||||||
{
|
{
|
||||||
|
int backup = 1;
|
||||||
boolean gotit = false;
|
boolean gotit = false;
|
||||||
report_type * rtype = report_types;
|
report_type * rtype = report_types;
|
||||||
struct report_context ctx;
|
struct report_context ctx;
|
||||||
|
|
||||||
ctx.f = f;
|
ctx.f = f;
|
||||||
ctx.report_time = time(NULL);
|
ctx.report_time = time(NULL);
|
||||||
ctx.seen = prepare_report(f);
|
ctx.seen = prepare_report(f);
|
||||||
ctx.first = firstregion(f);
|
ctx.first = firstregion(f);
|
||||||
ctx.last = lastregion(f);
|
ctx.last = lastregion(f);
|
||||||
|
@ -1281,24 +1282,32 @@ write_reports(faction * f, time_t ltime)
|
||||||
get_seen_interval(&ctx);
|
get_seen_interval(&ctx);
|
||||||
get_addresses(&ctx);
|
get_addresses(&ctx);
|
||||||
|
|
||||||
printf("Reports for %s:", factionname(f));
|
do {
|
||||||
fflush(stdout);
|
errno = 0;
|
||||||
|
printf("Reports for %s:", factionname(f));
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
for (;rtype!=NULL;rtype=rtype->next) {
|
for (;rtype!=NULL;rtype=rtype->next) {
|
||||||
if (f->options & rtype->flag) {
|
if (f->options & rtype->flag) {
|
||||||
char filename[MAX_PATH];
|
char filename[MAX_PATH];
|
||||||
sprintf(filename, "%s/%d-%s.%s", reportpath(), turn, factionid(f), rtype->extension);
|
sprintf(filename, "%s/%d-%s.%s", reportpath(), turn, factionid(f), rtype->extension);
|
||||||
if (rtype->write(filename, &ctx)==0) {
|
if (rtype->write(filename, &ctx)==0) {
|
||||||
gotit = true;
|
gotit = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
puts(" DONE");
|
|
||||||
if (!gotit) {
|
|
||||||
log_warning(("No report for faction %s!\n", factionid(f)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
puts(" DONE");
|
||||||
|
if (!gotit) {
|
||||||
|
log_warning(("No report for faction %s!\n", factionid(f)));
|
||||||
|
}
|
||||||
|
if (errno) {
|
||||||
|
sprintf(buf, "Error writing reports, waiting %u seconds before retry.\n", backup);
|
||||||
|
perror(buf);
|
||||||
|
sleep(backup);
|
||||||
|
backup *= 2;
|
||||||
|
}
|
||||||
|
} while (errno);
|
||||||
freelist(ctx.addresses);
|
freelist(ctx.addresses);
|
||||||
seen_done(ctx.seen);
|
seen_done(ctx.seen);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -99,6 +99,7 @@ extern "C" {
|
||||||
# define HAVE_STRNCASECMP
|
# define HAVE_STRNCASECMP
|
||||||
# define HAVE_ACCESS
|
# define HAVE_ACCESS
|
||||||
# define HAVE_STAT
|
# define HAVE_STAT
|
||||||
|
# define HAVE_SLEEP
|
||||||
typedef struct stat stat_type;
|
typedef struct stat stat_type;
|
||||||
# include <dirent.h>
|
# include <dirent.h>
|
||||||
# define HAVE_READDIR
|
# define HAVE_READDIR
|
||||||
|
@ -127,6 +128,7 @@ typedef struct stat stat_type;
|
||||||
# define HAVE_STRICMP
|
# define HAVE_STRICMP
|
||||||
# define HAVE_STRNICMP
|
# define HAVE_STRNICMP
|
||||||
# define HAVE_STRDUP
|
# define HAVE_STRDUP
|
||||||
|
# define HAVE_SLEEP
|
||||||
# define snprintf _snprintf
|
# define snprintf _snprintf
|
||||||
# define HAVE_SNPRINTF
|
# define HAVE_SNPRINTF
|
||||||
# undef HAVE_STRCASECMP
|
# undef HAVE_STRCASECMP
|
||||||
|
@ -159,6 +161,9 @@ typedef struct _stat stat_type;
|
||||||
# define strdup _strdup
|
# define strdup _strdup
|
||||||
# define HAVE_STRDUP
|
# define HAVE_STRDUP
|
||||||
|
|
||||||
|
# define sleep _sleep
|
||||||
|
# define HAVE_SLEEP
|
||||||
|
|
||||||
# define stricmp(a, b) _stricmp(a, b)
|
# define stricmp(a, b) _stricmp(a, b)
|
||||||
# define HAVE_STRICMP
|
# define HAVE_STRICMP
|
||||||
|
|
||||||
|
|
|
@ -573,10 +573,6 @@ load_inifile(const char * filename)
|
||||||
if (d) {
|
if (d) {
|
||||||
const char * str;
|
const char * str;
|
||||||
|
|
||||||
lomem = iniparser_getint(d, "eressea:lomem", lomem)?1:0;
|
|
||||||
quiet = iniparser_getint(d, "eressea:verbose", 0)?0:1;
|
|
||||||
str = iniparser_getstr(d, "eressea:run");
|
|
||||||
if (str) luafile = str;
|
|
||||||
str = iniparser_getstr(d, "common:base");
|
str = iniparser_getstr(d, "common:base");
|
||||||
if (str) g_basedir = str;
|
if (str) g_basedir = str;
|
||||||
str = iniparser_getstr(d, "common:res");
|
str = iniparser_getstr(d, "common:res");
|
||||||
|
@ -585,6 +581,13 @@ load_inifile(const char * filename)
|
||||||
if (str) xmlfile = str;
|
if (str) xmlfile = str;
|
||||||
str = iniparser_getstr(d, "common:scripts");
|
str = iniparser_getstr(d, "common:scripts");
|
||||||
if (str) script_path = str;
|
if (str) script_path = str;
|
||||||
|
lomem = iniparser_getint(d, "common:lomem", lomem)?1:0;
|
||||||
|
|
||||||
|
quiet = iniparser_getint(d, "eressea:verbose", 0)?0:1;
|
||||||
|
str = iniparser_getstr(d, "eressea:run");
|
||||||
|
if (str) luafile = str;
|
||||||
|
str = iniparser_getstr(d, "eressea:report");
|
||||||
|
if (str) g_reportdir = str;
|
||||||
}
|
}
|
||||||
inifile = d;
|
inifile = d;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue