Skip to content

Commit 0cfdee0

Browse files
committed
https://bugs.eressea.de/view.php?id=2712
Make the reports.lua script not break passwords of new players.
1 parent e23d5e6 commit 0cfdee0

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

scripts/reports.lua

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
dofile('config.lua')
22
eressea.read_game(get_turn() .. '.dat')
33
init_reports()
4-
write_reports()
4+
-- do not use write_reports, since it will change passwords
5+
for f in factions() do
6+
write_report(f)
7+
end

src/bindings.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ static int tolua_write_report(lua_State * L)
366366
{
367367
faction *f = (faction *)tolua_tousertype(L, 1, 0);
368368
if (f) {
369-
int result = write_reports(f);
369+
int result = write_reports(f, NULL);
370370
lua_pushinteger(L, result);
371371
}
372372
else {

src/reports.c

+10-9
Original file line numberDiff line numberDiff line change
@@ -1569,21 +1569,15 @@ void finish_reports(report_context *ctx) {
15691569
}
15701570
}
15711571

1572-
int write_reports(faction * f)
1572+
int write_reports(faction * f, const char *password)
15731573
{
15741574
bool gotit = false;
15751575
struct report_context ctx;
15761576
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 };
15771577
report_type *rtype;
1578-
char buffer[PASSWORD_MAXSIZE], *password = NULL;
15791578
if (noreports) {
15801579
return false;
15811580
}
1582-
if (f->lastorders == 0 || f->age <= 1) {
1583-
/* neue Parteien, oder solche die noch NIE einen Zug gemacht haben,
1584-
* kriegen ein neues Passwort: */
1585-
password = faction_genpassword(f, buffer);
1586-
}
15871581
prepare_report(&ctx, f, password);
15881582
get_addresses(&ctx);
15891583
log_debug("Reports for %s", factionname(f));
@@ -1666,7 +1660,8 @@ int reports(void)
16661660
FILE *mailit;
16671661
int retval = 0;
16681662
char path[PATH_MAX];
1669-
const char * rpath = reportpath();
1663+
char buffer[PASSWORD_MAXSIZE];
1664+
const char* rpath = reportpath();
16701665

16711666
log_info("Writing reports for turn %d:", turn);
16721667
report_donations();
@@ -1680,7 +1675,13 @@ int reports(void)
16801675

16811676
for (f = factions; f; f = f->next) {
16821677
if (f->email && !fval(f, FFL_NPC)) {
1683-
int error = write_reports(f);
1678+
char* password = NULL;
1679+
if (f->lastorders == 0 || f->age <= 1) {
1680+
/* neue Parteien, oder solche die noch NIE einen Zug gemacht haben,
1681+
* kriegen ein neues Passwort: */
1682+
password = faction_genpassword(f, buffer);
1683+
}
1684+
int error = write_reports(f, password);
16841685
if (error)
16851686
retval = error;
16861687
if (mailit)

src/reports.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ extern "C" {
4646
const struct unit *u, unsigned int indent, seen_mode mode);
4747

4848
int reports(void);
49-
int write_reports(struct faction *f);
49+
int write_reports(struct faction *f, const char *password);
5050
int init_reports(void);
5151
void reorder_units(struct region * r);
5252

src/reports.test.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -960,14 +960,18 @@ static void test_reports_genpassword(CuTest *tc) {
960960
CuAssertIntEquals(tc, 0, f->lastorders);
961961
CuAssertIntEquals(tc, 0, f->password_id);
962962
f->options = 0;
963-
write_reports(f);
963+
/* writing the report does not change the password */
964+
write_reports(f, NULL);
965+
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "changepasswd"));
966+
/* but the main reporting function does */
967+
reports();
964968
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd"));
965969
CuAssertTrue(tc, f->password_id != 0);
966970
test_clear_messagelist(&f->msgs);
967971
f->lastorders = 1;
968972
f->age = 2;
969973
pwid = f->password_id;
970-
write_reports(f);
974+
reports();
971975
CuAssertIntEquals(tc, pwid, f->password_id);
972976
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "changepasswd"));
973977
test_teardown();

0 commit comments

Comments
 (0)