Skip to content

Commit

Permalink
https://bugs.eressea.de/view.php?id=2712
Browse files Browse the repository at this point in the history
Make the reports.lua script not break passwords of
 new players.
  • Loading branch information
ennorehling committed Dec 6, 2020
1 parent e23d5e6 commit 0cfdee0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
5 changes: 4 additions & 1 deletion scripts/reports.lua
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 10 additions & 9 deletions src/reports.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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();
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/reports.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 6 additions & 2 deletions src/reports.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 0cfdee0

Please sign in to comment.