Make the reports.lua script not break passwords of
 new players.
This commit is contained in:
Enno Rehling 2020-11-29 17:14:29 +01:00
parent e23d5e6949
commit 0cfdee0218
5 changed files with 22 additions and 14 deletions

View File

@ -1,4 +1,7 @@
dofile('config.lua') dofile('config.lua')
eressea.read_game(get_turn() .. '.dat') eressea.read_game(get_turn() .. '.dat')
init_reports() init_reports()
write_reports() -- do not use write_reports, since it will change passwords
for f in factions() do
write_report(f)
end

View File

@ -366,7 +366,7 @@ static int tolua_write_report(lua_State * L)
{ {
faction *f = (faction *)tolua_tousertype(L, 1, 0); faction *f = (faction *)tolua_tousertype(L, 1, 0);
if (f) { if (f) {
int result = write_reports(f); int result = write_reports(f, NULL);
lua_pushinteger(L, result); lua_pushinteger(L, result);
} }
else { else {

View File

@ -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; bool gotit = false;
struct report_context ctx; struct report_context ctx;
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 }; const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 };
report_type *rtype; report_type *rtype;
char buffer[PASSWORD_MAXSIZE], *password = NULL;
if (noreports) { if (noreports) {
return false; 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); prepare_report(&ctx, f, password);
get_addresses(&ctx); get_addresses(&ctx);
log_debug("Reports for %s", factionname(f)); log_debug("Reports for %s", factionname(f));
@ -1666,7 +1660,8 @@ int reports(void)
FILE *mailit; FILE *mailit;
int retval = 0; int retval = 0;
char path[PATH_MAX]; char path[PATH_MAX];
const char * rpath = reportpath(); char buffer[PASSWORD_MAXSIZE];
const char* rpath = reportpath();
log_info("Writing reports for turn %d:", turn); log_info("Writing reports for turn %d:", turn);
report_donations(); report_donations();
@ -1680,7 +1675,13 @@ int reports(void)
for (f = factions; f; f = f->next) { for (f = factions; f; f = f->next) {
if (f->email && !fval(f, FFL_NPC)) { 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) if (error)
retval = error; retval = error;
if (mailit) if (mailit)

View File

@ -46,7 +46,7 @@ extern "C" {
const struct unit *u, unsigned int indent, seen_mode mode); const struct unit *u, unsigned int indent, seen_mode mode);
int reports(void); int reports(void);
int write_reports(struct faction *f); int write_reports(struct faction *f, const char *password);
int init_reports(void); int init_reports(void);
void reorder_units(struct region * r); void reorder_units(struct region * r);

View File

@ -960,14 +960,18 @@ static void test_reports_genpassword(CuTest *tc) {
CuAssertIntEquals(tc, 0, f->lastorders); CuAssertIntEquals(tc, 0, f->lastorders);
CuAssertIntEquals(tc, 0, f->password_id); CuAssertIntEquals(tc, 0, f->password_id);
f->options = 0; 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")); CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd"));
CuAssertTrue(tc, f->password_id != 0); CuAssertTrue(tc, f->password_id != 0);
test_clear_messagelist(&f->msgs); test_clear_messagelist(&f->msgs);
f->lastorders = 1; f->lastorders = 1;
f->age = 2; f->age = 2;
pwid = f->password_id; pwid = f->password_id;
write_reports(f); reports();
CuAssertIntEquals(tc, pwid, f->password_id); CuAssertIntEquals(tc, pwid, f->password_id);
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "changepasswd")); CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "changepasswd"));
test_teardown(); test_teardown();