forked from github/server
Make the reports.lua script not break passwords of new players.
This commit is contained in:
parent
e23d5e6949
commit
0cfdee0218
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue