write a log of dead factions.

This commit is contained in:
Enno Rehling 2018-02-23 21:24:15 +01:00
parent 5a1c6d87ca
commit fa1e81f6ac
5 changed files with 32 additions and 13 deletions

View file

@ -4,6 +4,7 @@
#include "kernel/calendar.h" #include "kernel/calendar.h"
#include "kernel/config.h" #include "kernel/config.h"
#include "kernel/curse.h" #include "kernel/curse.h"
#include "kernel/faction.h"
#include "kernel/building.h" #include "kernel/building.h"
#include "kernel/equipment.h" #include "kernel/equipment.h"
#include "kernel/item.h" #include "kernel/item.h"
@ -37,22 +38,17 @@
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
/* manually free() everything at exit? */
#undef CLEANUP_CODE
void game_done(void) void game_done(void)
{ {
#undef CLEANUP_CODE log_dead_factions();
#ifdef CLEANUP_CODE #ifdef CLEANUP_CODE
/* Diese Routine enfernt allen allokierten Speicher wieder. Das ist nur free_gamedata();
* 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();
creport_cleanup(); creport_cleanup();
#ifdef REPORT_FORMAT_NR
report_cleanup(); report_cleanup();
#endif
#endif
calendar_cleanup(); calendar_cleanup();
free_functions(); free_functions();
free_config(); free_config();
@ -60,6 +56,7 @@ void game_done(void)
free_locales(); free_locales();
kernel_done(); kernel_done();
dblib_close(); dblib_close();
#endif
} }
void game_init(void) void game_init(void)

View file

@ -778,8 +778,8 @@ void free_gamedata(void)
free(forbidden_ids); free(forbidden_ids);
forbidden_ids = NULL; forbidden_ids = NULL;
free_donations();
free_factions(); free_factions();
free_donations();
free_units(); free_units();
free_regions(); free_regions();
free_borders(); free_borders();

View file

@ -738,7 +738,6 @@ void remove_empty_factions(void)
faction *f = *fp; faction *f = *fp;
if (!(f->_alive && f->units!=NULL) && !fval(f, FFL_NOIDLEOUT)) { if (!(f->_alive && f->units!=NULL) && !fval(f, FFL_NOIDLEOUT)) {
log_debug("dead: %s", factionname(f));
destroyfaction(fp); destroyfaction(fp);
} }
else { else {
@ -876,6 +875,27 @@ int writepasswd(void)
return 1; 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) { void free_factions(void) {
#ifdef DMAXHASH #ifdef DMAXHASH
int i; int i;

View file

@ -133,6 +133,7 @@ extern "C" {
void renumber_faction(faction * f, int no); void renumber_faction(faction * f, int no);
void free_factions(void); void free_factions(void);
void log_dead_factions(void);
void remove_empty_factions(void); void remove_empty_factions(void);
void update_interval(struct faction *f, struct region *r); void update_interval(struct faction *f, struct region *r);

View file

@ -82,6 +82,7 @@ static void load_inifile(void)
static const char * valid_keys[] = { static const char * valid_keys[] = {
"game.id", "game.id",
"game.deadlog",
"game.name", "game.name",
"game.start", "game.start",
"game.locale", "game.locale",