Writing individual factions' reports is now a lua command. but it probably needs some initialization, must check.

Also, a bit more error reporting when i.e. the report path cannot be created. time for a chek on a linux box.
This commit is contained in:
Enno Rehling 2005-04-27 12:18:05 +00:00
parent 21fcb3d167
commit 1f4ec6520b
6 changed files with 127 additions and 98 deletions

View File

@ -918,8 +918,6 @@ static void
cr_find_address(FILE * F, const faction * uf, const faction_list * addresses) cr_find_address(FILE * F, const faction * uf, const faction_list * addresses)
{ {
const faction_list * flist = addresses; const faction_list * flist = addresses;
if (!quiet)
puts(" - gebe Adressen heraus (CR)");
while (flist!=NULL) { while (flist!=NULL) {
const faction * f = flist->data; const faction * f = flist->data;
if (uf!=f && f->no != MONSTER_FACTION) { if (uf!=f && f->no != MONSTER_FACTION) {
@ -1105,9 +1103,6 @@ report_computer(FILE * F, faction * f, const faction_list * addresses,
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
/* initialisations, header and lists */ /* initialisations, header and lists */
fprintf(stdout, "Reports für %s: CR\r", factionname(f));
fflush(stdout);
fprintf(F, "VERSION %d\n", C_REPORT_VERSION); fprintf(F, "VERSION %d\n", C_REPORT_VERSION);
fprintf(F, "\"%s\";locale\n", locale_name(f->locale)); fprintf(F, "\"%s\";locale\n", locale_name(f->locale));
fprintf(F, "%d;noskillpoints\n", 1); fprintf(F, "%d;noskillpoints\n", 1);

View File

@ -1109,8 +1109,6 @@ parse_quit(void)
puts(" - beseitige Spieler, die sich zu lange nicht mehr gemeldet haben..."); puts(" - beseitige Spieler, die sich zu lange nicht mehr gemeldet haben...");
remove("inactive");
for (f = factions; f; f = f->next) { for (f = factions; f; f = f->next) {
if(fval(f, FFL_NOIDLEOUT)) f->lastorders = turn; if(fval(f, FFL_NOIDLEOUT)) f->lastorders = turn;
if (NMRTimeout()>0 && turn - f->lastorders >= NMRTimeout()) { if (NMRTimeout()>0 && turn - f->lastorders >= NMRTimeout()) {

View File

@ -83,6 +83,11 @@
#include <limits.h> #include <limits.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef HAVE_STAT
#include <sys/types.h>
#include <sys/stat.h>
#endif
extern int quiet; extern int quiet;
extern int *storms; extern int *storms;
extern int weeks_per_month; extern int weeks_per_month;
@ -326,8 +331,6 @@ rpsnr(FILE * F, const char * s, int offset)
} }
} }
static faction *current_faction = NULL;
int outi; int outi;
char outbuf[4096]; char outbuf[4096];
@ -1582,9 +1585,6 @@ order_template(FILE * F, faction * f)
plane *pl; plane *pl;
region *last = f->last?f->last:lastregion(f); region *last = f->last?f->last:lastregion(f);
fprintf(stdout, "Reports für %s: ZV\r", factionname(f));
fflush(stdout);
rps_nowrap(F, ""); rps_nowrap(F, "");
rnl(F); rnl(F);
rps_nowrap(F, LOC(f->locale, "nr_template")); rps_nowrap(F, LOC(f->locale, "nr_template"));
@ -2001,9 +2001,6 @@ report(FILE *F, faction * f, const faction_list * addresses,
ix = Pow(O_STATISTICS); ix = Pow(O_STATISTICS);
wants_stats = (f->options & ix); wants_stats = (f->options & ix);
fprintf(stdout, "Reports für %s: NR\r", factionname(f));
fflush(stdout);
m = msg_message("nr_header_date", "game date", global.gamename, pzTime); m = msg_message("nr_header_date", "game date", global.gamename, pzTime);
nr_render(m, f->locale, buf, sizeof(buf), f); nr_render(m, f->locale, buf, sizeof(buf), f);
msg_release(m); msg_release(m);
@ -2680,87 +2677,120 @@ struct fsee {
} * see; } * see;
} * fsee[FMAXHASH]; } * fsee[FMAXHASH];
#define REPORT_NR (1 << O_REPORT)
#define REPORT_CR (1 << O_COMPUTER)
#define REPORT_ZV (1 << O_ZUGVORLAGE)
#define REPORT_ZIP (1 << O_COMPRESS)
#define REPORT_BZIP2 (1 << O_BZIP2)
int
write_reports(faction * f, time_t ltime)
{
FILE * F;
boolean gotit = false;
faction_list * addresses;
char zTime[64];
static boolean dir_exists = false;
#ifdef HAVE_STAT
stat_type st;
if (!dir_exists && stat(reportpath(), &st)==-1) {
errno = 0;
makedir(reportpath(), 0700);
dir_exists = true;
}
#else
if (!dir_exists) {
if (makedir(reportpath(), 0700)!=0) {
if (errno!=EEXIST) {
perror("could not create reportpath");
return -1;
}
dir_exists = true;
}
#endif
strftime(zTime, sizeof(zTime), "%A, %d. %B %Y, %H:%M", localtime(&ltime));
printf("Reports für %s: \r", factionname(f));
fflush(stdout);
prepare_report(f);
addresses = get_addresses(f);
/* NR schreiben: */
if (!nonr && (f->options & REPORT_NR)) {
fprintf(stdout, "Reports für %s: NR\r", factionname(f));
fflush(stdout);
sprintf(buf, "%s/%d-%s.nr", reportpath(), turn, factionid(f));
F = cfopen(buf, "wt");
if (F) {
int status = report(F, f, addresses, zTime);
fclose(F);
gotit = true;
if (status!=0) return status; /* catch errors */
}
}
/* CR schreiben: */
if (!nocr && (f->options & REPORT_CR || f->age<3)) {
fprintf(stdout, "Reports für %s: CR\r", factionname(f));
fflush(stdout);
sprintf(buf, "%s/%d-%s.cr", reportpath(), turn, factionid(f));
F = cfopen(buf, "wt");
if (F) {
int status = report_computer(F, f, addresses, ltime);
fclose(F);
gotit = true;
if (status!=0) return status; /* catch errors */
}
}
/* ZV schreiben: */
if (f->options & REPORT_ZV) {
fprintf(stdout, "Reports für %s: ZV\r", factionname(f));
fflush(stdout);
sprintf(buf, "%s/%d-%s.txt", reportpath(), turn, factionid(f));
F = cfopen(buf, "wt");
if (F) {
int status = order_template(F, f);
fclose(F);
if (status!=0) return status; /* catch errors */
}
}
if (!gotit) {
log_error(("no report for faction %s!\n", factionid(f)));
}
freelist(addresses);
putc('\n', stdout);
return 0;
}
int int
reports(void) reports(void)
{ {
faction *f; faction *f;
boolean gotit; FILE *shfp, *BAT;
FILE *shfp, *F, *BAT;
int wants_report, wants_computer_report,
wants_compressed, wants_bzip2;
time_t ltime = time(NULL); time_t ltime = time(NULL);
char pzTime[64];
const char * str; const char * str;
int retval = 0;
#ifdef _GNU_SOURCE
strftime(pzTime, 64, "%A, %-e. %B %Y, %-k:%M", localtime(&ltime));
#else
strftime(pzTime, 64, "%A, %d. %B %Y, %H:%M", localtime(&ltime));
#endif
nmr_warnings(); nmr_warnings();
#ifdef DMALLOC
assert(dmalloc_verify ( NULL ));
#endif
makedir(reportpath(), 0700);
BAT = openbatch(); BAT = openbatch();
wants_report = 1 << O_REPORT;
wants_computer_report = 1 << O_COMPUTER;
wants_compressed = 1 << O_COMPRESS;
wants_bzip2 = 1 << O_BZIP2;
printf("\n"); printf("\n");
report_donations(); report_donations();
remove_empty_units(); remove_empty_units();
log_printf("Updating region intervals\n"); log_printf("Updating region intervals\n");
update_intervals(); update_intervals();
log_printf("Report timestamp - %s\n", pzTime);
for (f = factions; f; f = f->next) { for (f = factions; f; f = f->next) {
faction_list * addresses; int error = write_reports(f, ltime);
attrib * a = a_find(f->attribs, &at_reportspell); if (error) retval = error;
current_faction = f;
gotit = false;
printf("Reports für %s: \r", factionname(f)); if (f->no > 0 && f->email && BAT) {
fflush(stdout);
prepare_report(f);
addresses = get_addresses(f);
/* NR schreiben: */
if (!nonr && (f->options & wants_report)) {
sprintf(buf, "%s/%d-%s.nr", reportpath(), turn, factionid(f));
F = cfopen(buf, "wt");
if (F) {
int status = report(F, f, addresses, pzTime);
fclose(F);
gotit = true;
if (status!=0) return status; /* catch errors */
}
}
/* CR schreiben: */
if (!nocr && (f->options & wants_computer_report || f->age<3)) {
sprintf(buf, "%s/%d-%s.cr", reportpath(), turn, factionid(f));
F = cfopen(buf, "wt");
if (F) {
int status = report_computer(F, f, addresses, ltime);
fclose(F);
gotit = true;
if (status!=0) return status; /* catch errors */
}
}
/* ZV schreiben: */
if (f->options & (1 << O_ZUGVORLAGE)) {
sprintf(buf, "%s/%d-%s.txt", reportpath(), turn, factionid(f));
F = cfopen(buf, "wt");
if (F) {
int status = order_template(F, f);
fclose(F);
if (status!=0) return status; /* catch errors */
}
}
if (f->no > 0 && f->email && BAT) {
sprintf(buf, "%s/%s.sh", reportpath(), factionid(f)); sprintf(buf, "%s/%s.sh", reportpath(), factionid(f));
shfp = fopen(buf, "w"); shfp = fopen(buf, "w");
fprintf(shfp,"#!/bin/sh\n\nPATH=%s\n\n",MailitPath()); fprintf(shfp,"#!/bin/sh\n\nPATH=%s\n\n",MailitPath());
@ -2772,7 +2802,7 @@ reports(void)
fprintf(BAT, "\n\ndate;echo %s\n", f->email); fprintf(BAT, "\n\ndate;echo %s\n", f->email);
if (f->no > 0 && f->options & wants_compressed) { if (f->no > 0 && f->options & REPORT_ZIP) {
if(f->age == 1) { if(f->age == 1) {
#if KEEP_UNZIPPED == 1 #if KEEP_UNZIPPED == 1
@ -2811,7 +2841,7 @@ reports(void)
turn, factionid(f), turn, factionid(f),
turn, factionid(f)); turn, factionid(f));
} else if(f->options & wants_bzip2) { } else if(f->options & REPORT_BZIP2) {
if (f->age == 1) { if (f->age == 1) {
fprintf(shfp, fprintf(shfp,
@ -2825,7 +2855,7 @@ reports(void)
fprintf(shfp, "eresseamail.bzip2 $addr \"%s %s\"", global.gamename, gamedate_short(f->locale)); fprintf(shfp, "eresseamail.bzip2 $addr \"%s %s\"", global.gamename, gamedate_short(f->locale));
if (!nonr && f->options & wants_report) if (!nonr && f->options & REPORT_NR)
fprintf(shfp, fprintf(shfp,
" \\\n\t\"application/x-bzip2\" \"Report\" %d-%s.nr.bz2", " \\\n\t\"application/x-bzip2\" \"Report\" %d-%s.nr.bz2",
turn,factionid(f)); turn,factionid(f));
@ -2835,7 +2865,7 @@ reports(void)
" \\\n\t\"application/x-bzip2\" \"Zugvorlage\" %d-%s.txt.bz2", " \\\n\t\"application/x-bzip2\" \"Zugvorlage\" %d-%s.txt.bz2",
turn,factionid(f)); turn,factionid(f));
if (!nocr && (f->options & wants_computer_report || f->age<3)) if (!nocr && (f->options & REPORT_CR || f->age<3))
fprintf(shfp, fprintf(shfp,
" \\\n\t\"application/x-bzip2\" \"Computer-Report\" %d-%s.cr.bz2", " \\\n\t\"application/x-bzip2\" \"Computer-Report\" %d-%s.cr.bz2",
turn, factionid(f)); turn, factionid(f));
@ -2848,7 +2878,7 @@ reports(void)
" \\\n\t\"text/plain\" \"Willkommen\" ../res/%s/%s/welcome.txt", global.welcomepath, locale_name(f->locale)); " \\\n\t\"text/plain\" \"Willkommen\" ../res/%s/%s/welcome.txt", global.welcomepath, locale_name(f->locale));
} }
if (!nonr && f->options & wants_report) if (!nonr && f->options & REPORT_NR)
fprintf(shfp, fprintf(shfp,
" \\\n\t\"text/plain\" \"Report\" %d-%s.nr", " \\\n\t\"text/plain\" \"Report\" %d-%s.nr",
turn, factionid(f)); turn, factionid(f));
@ -2858,7 +2888,7 @@ reports(void)
" \\\n\t\"text/plain\" \"Zugvorlage\" %d-%s.txt", " \\\n\t\"text/plain\" \"Zugvorlage\" %d-%s.txt",
turn, factionid(f)); turn, factionid(f));
if (!nocr && (f->options & wants_computer_report || f->age<3)) if (!nocr && (f->options & REPORT_CR || f->age<3))
fprintf(shfp, fprintf(shfp,
" \\\n\t\"text/x-eressea-cr\" \"Computer-Report\" %d-%s.cr", " \\\n\t\"text/x-eressea-cr\" \"Computer-Report\" %d-%s.cr",
turn, factionid(f)); turn, factionid(f));
@ -2867,16 +2897,6 @@ reports(void)
fprintf(BAT, ". %s.sh %s\n", factionid(f), f->email); fprintf(BAT, ". %s.sh %s\n", factionid(f), f->email);
fclose(shfp); fclose(shfp);
} }
if (!gotit)
printf("* Fehler: Kein Report für Partei Nr. %s!\n",
factionid(f));
while (a) {
attrib * a_old = a;
a = a->nexttype;
a_remove(&f->attribs, a_old);
}
freelist(addresses);
putc('\n', stdout); putc('\n', stdout);
} }
@ -2887,9 +2907,8 @@ reports(void)
} }
/* schliesst BAT und verschickt Zeitungen und Kommentare */ /* schliesst BAT und verschickt Zeitungen und Kommentare */
closebatch(BAT); closebatch(BAT);
current_faction = NULL;
seen_done(); seen_done();
return 0; return retval;
} }
void void

View File

@ -46,7 +46,8 @@ const char *hp_status(const struct unit * u);
extern void spskill(const struct locale * lang, const struct unit * u, skill_t sk, int *dh, int days); /* mapper */ extern void spskill(const struct locale * lang, const struct unit * u, skill_t sk, int *dh, int days); /* mapper */
extern void spunit(struct strlist ** SP, const struct faction * f, const struct unit * u, int indent, int mode); extern void spunit(struct strlist ** SP, const struct faction * f, const struct unit * u, int indent, int mode);
int reports(void); extern int reports(void);
extern int write_reports(struct faction * f, time_t ltime);
extern const struct unit *ucansee(const struct faction *f, const struct unit *u, const struct unit *x); extern const struct unit *ucansee(const struct faction *f, const struct unit *u, const struct unit *x);

View File

@ -107,10 +107,11 @@ extern "C" {
# define HAVE_STRCASECMP # define HAVE_STRCASECMP
# define HAVE_STRNCASECMP # define HAVE_STRNCASECMP
# define HAVE_ACCESS # define HAVE_ACCESS
# define HAVE_STAT
typedef struct stat stat_type;
# include <dirent.h> # include <dirent.h>
# define HAVE_READDIR # define HAVE_READDIR
# define HAVE_OPENDIR # define HAVE_OPENDIR
# include <sys/stat.h>
# define HAVE_MKDIR_WITH_PERMISSION # define HAVE_MKDIR_WITH_PERMISSION
# include <string.h> # include <string.h>
# define HAVE_STRDUP # define HAVE_STRDUP
@ -130,6 +131,8 @@ extern "C" {
# include <io.h> # include <io.h>
# define HAVE_MKDIR_WITHOUT_PERMISSION # define HAVE_MKDIR_WITHOUT_PERMISSION
# define HAVE_ACCESS # define HAVE_ACCESS
# define HAVE_STAT
typedef struct stat stat_type;
# define HAVE_STRICMP # define HAVE_STRICMP
# define HAVE_STRNICMP # define HAVE_STRNICMP
# define HAVE_STRDUP # define HAVE_STRDUP
@ -148,10 +151,15 @@ extern "C" {
# define snprintf _snprintf # define snprintf _snprintf
# define HAVE_SNPRINTF # define HAVE_SNPRINTF
/* MSVC has _access */ /* MSVC has _access, not access */
# define access(f, m) _access(f, m) # define access(f, m) _access(f, m)
# define HAVE_ACCESS # define HAVE_ACCESS
/* MSVC has _stat, not stat */
# define HAVE_STAT
# define stat(a, b) _stat(a, b)
typedef struct _stat stat_type;
/* MSVC has _strdup */ /* MSVC has _strdup */
# define strdup _strdup # define strdup _strdup
# define HAVE_STRDUP # define HAVE_STRDUP

View File

@ -189,6 +189,13 @@ get_direction(const char * name)
return NODIRECTION; return NODIRECTION;
} }
int
lua_writereport(faction * f)
{
time_t ltime = time(0);
return write_reports(f, ltime);
}
void void
bind_eressea(lua_State * L) bind_eressea(lua_State * L)
{ {
@ -199,6 +206,7 @@ bind_eressea(lua_State * L)
def("write_game", &write_game), def("write_game", &write_game),
def("write_passwords", &writepasswd), def("write_passwords", &writepasswd),
def("write_reports", &reports), def("write_reports", &reports),
def("write_report", &lua_writereport),
def("init_summary", &init_summary), def("init_summary", &init_summary),
def("write_summary", &write_summary), def("write_summary", &write_summary),
def("read_orders", &readorders), def("read_orders", &readorders),