From 0cfdee021848d1a35672dcdd889ad7d4249b79b3 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 29 Nov 2020 17:14:29 +0100 Subject: [PATCH] https://bugs.eressea.de/view.php?id=2712 Make the reports.lua script not break passwords of new players. --- scripts/reports.lua | 5 ++++- src/bindings.c | 2 +- src/reports.c | 19 ++++++++++--------- src/reports.h | 2 +- src/reports.test.c | 8 ++++++-- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/scripts/reports.lua b/scripts/reports.lua index 1cd0302b9..70d8bb9f9 100644 --- a/scripts/reports.lua +++ b/scripts/reports.lua @@ -1,4 +1,7 @@ dofile('config.lua') eressea.read_game(get_turn() .. '.dat') init_reports() -write_reports() +-- do not use write_reports, since it will change passwords +for f in factions() do + write_report(f) +end diff --git a/src/bindings.c b/src/bindings.c index 453c29d08..ac153680a 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -366,7 +366,7 @@ static int tolua_write_report(lua_State * L) { faction *f = (faction *)tolua_tousertype(L, 1, 0); if (f) { - int result = write_reports(f); + int result = write_reports(f, NULL); lua_pushinteger(L, result); } else { diff --git a/src/reports.c b/src/reports.c index a513552ef..6c66bb420 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1569,21 +1569,15 @@ void finish_reports(report_context *ctx) { } } -int write_reports(faction * f) +int write_reports(faction * f, const char *password) { bool gotit = false; struct report_context ctx; const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 }; report_type *rtype; - char buffer[PASSWORD_MAXSIZE], *password = NULL; if (noreports) { return false; } - if (f->lastorders == 0 || f->age <= 1) { - /* neue Parteien, oder solche die noch NIE einen Zug gemacht haben, - * kriegen ein neues Passwort: */ - password = faction_genpassword(f, buffer); - } prepare_report(&ctx, f, password); get_addresses(&ctx); log_debug("Reports for %s", factionname(f)); @@ -1666,7 +1660,8 @@ int reports(void) FILE *mailit; int retval = 0; char path[PATH_MAX]; - const char * rpath = reportpath(); + char buffer[PASSWORD_MAXSIZE]; + const char* rpath = reportpath(); log_info("Writing reports for turn %d:", turn); report_donations(); @@ -1680,7 +1675,13 @@ int reports(void) for (f = factions; f; f = f->next) { if (f->email && !fval(f, FFL_NPC)) { - int error = write_reports(f); + char* password = NULL; + if (f->lastorders == 0 || f->age <= 1) { + /* neue Parteien, oder solche die noch NIE einen Zug gemacht haben, + * kriegen ein neues Passwort: */ + password = faction_genpassword(f, buffer); + } + int error = write_reports(f, password); if (error) retval = error; if (mailit) diff --git a/src/reports.h b/src/reports.h index fb27f96bc..347bfca15 100644 --- a/src/reports.h +++ b/src/reports.h @@ -46,7 +46,7 @@ extern "C" { const struct unit *u, unsigned int indent, seen_mode mode); int reports(void); - int write_reports(struct faction *f); + int write_reports(struct faction *f, const char *password); int init_reports(void); void reorder_units(struct region * r); diff --git a/src/reports.test.c b/src/reports.test.c index e9b0e3e37..0fe43a488 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -960,14 +960,18 @@ static void test_reports_genpassword(CuTest *tc) { CuAssertIntEquals(tc, 0, f->lastorders); CuAssertIntEquals(tc, 0, f->password_id); f->options = 0; - write_reports(f); + /* writing the report does not change the password */ + write_reports(f, NULL); + CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "changepasswd")); + /* but the main reporting function does */ + reports(); CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd")); CuAssertTrue(tc, f->password_id != 0); test_clear_messagelist(&f->msgs); f->lastorders = 1; f->age = 2; pwid = f->password_id; - write_reports(f); + reports(); CuAssertIntEquals(tc, pwid, f->password_id); CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "changepasswd")); test_teardown();