From fa1e81f6ac62d9bed24602f60058c2f9555f36cc Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 23 Feb 2018 21:24:15 +0100 Subject: [PATCH] write a log of dead factions. --- src/eressea.c | 19 ++++++++----------- src/kernel/config.c | 2 +- src/kernel/faction.c | 22 +++++++++++++++++++++- src/kernel/faction.h | 1 + src/main.c | 1 + 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/eressea.c b/src/eressea.c index 03f194238..81f19b5a6 100644 --- a/src/eressea.c +++ b/src/eressea.c @@ -4,6 +4,7 @@ #include "kernel/calendar.h" #include "kernel/config.h" #include "kernel/curse.h" +#include "kernel/faction.h" #include "kernel/building.h" #include "kernel/equipment.h" #include "kernel/item.h" @@ -37,22 +38,17 @@ #include #include +/* manually free() everything at exit? */ +#undef CLEANUP_CODE + void game_done(void) { -#undef CLEANUP_CODE + log_dead_factions(); + #ifdef CLEANUP_CODE - /* Diese Routine enfernt allen allokierten Speicher wieder. Das ist nur - * zum Debugging interessant, wenn man Leak Detection hat, und nach - * nicht freigegebenem Speicher sucht, der nicht bis zum Ende benoetigt - * wird (temporaere Hilsstrukturen) */ - - free_game(); - + free_gamedata(); creport_cleanup(); -#ifdef REPORT_FORMAT_NR report_cleanup(); -#endif -#endif calendar_cleanup(); free_functions(); free_config(); @@ -60,6 +56,7 @@ void game_done(void) free_locales(); kernel_done(); dblib_close(); +#endif } void game_init(void) diff --git a/src/kernel/config.c b/src/kernel/config.c index 05690e301..8c7e64afe 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -778,8 +778,8 @@ void free_gamedata(void) free(forbidden_ids); forbidden_ids = NULL; - free_donations(); free_factions(); + free_donations(); free_units(); free_regions(); free_borders(); diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 36f467c6e..165551f8f 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -738,7 +738,6 @@ void remove_empty_factions(void) faction *f = *fp; if (!(f->_alive && f->units!=NULL) && !fval(f, FFL_NOIDLEOUT)) { - log_debug("dead: %s", factionname(f)); destroyfaction(fp); } else { @@ -876,6 +875,27 @@ int writepasswd(void) return 1; } +void log_dead_factions(void) +{ + if (dead_factions) { + const char *logname = config_get("game.deadlog"); + if (logname) { + FILE *F; + char path[PATH_MAX]; + + join_path(basepath(), logname, path, sizeof(path)); + F = fopen(path, "at"); + if (F) { + faction *f; + for (f = dead_factions; f; f = f->next) { + fprintf(F, "%d\t%d\t%d\t%s\t%s\t%s\n", turn, f->lastorders, f->age, itoa36(f->no), f->email, f->name); + } + fclose(F); + } + } + } +} + void free_factions(void) { #ifdef DMAXHASH int i; diff --git a/src/kernel/faction.h b/src/kernel/faction.h index 25913e73d..8d13f64d1 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -133,6 +133,7 @@ extern "C" { void renumber_faction(faction * f, int no); void free_factions(void); + void log_dead_factions(void); void remove_empty_factions(void); void update_interval(struct faction *f, struct region *r); diff --git a/src/main.c b/src/main.c index ae6d2158c..489d0d868 100644 --- a/src/main.c +++ b/src/main.c @@ -82,6 +82,7 @@ static void load_inifile(void) static const char * valid_keys[] = { "game.id", + "game.deadlog", "game.name", "game.start", "game.locale",