From 98be6bb8aeb5db1f7e63e524add0d491eb787ec8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 18:51:20 +0100 Subject: [PATCH] eliminate duplicate password message --- scripts/tests/faction.lua | 2 +- src/kernel/faction.c | 11 +++++------ src/kernel/faction.test.c | 2 +- src/reports.test.c | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/scripts/tests/faction.lua b/scripts/tests/faction.lua index 38fdc4eb7..87a6b5100 100644 --- a/scripts/tests/faction.lua +++ b/scripts/tests/faction.lua @@ -17,7 +17,7 @@ function setup() end function test_faction_flags() - assert_equal(2, f.flags) -- FFL_ISNEW + assert_equal(6, f.flags) -- FFL_ISNEW|FFL_PWMSG f.flags = 42 assert_equal(42, f.flags) end diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 040cd5fb0..b7115c62f 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -247,11 +247,6 @@ faction *addfaction(const char *email, const char *password, log_warning("Invalid email address for faction %s: %s\n", itoa36(f->no), email); } - if (!password) password = itoa36(rng_int()); - faction_setpassword(f, password_encode(password, PASSWORD_DEFAULT)); - ADDMSG(&f->msgs, msg_message("changepasswd", "value", password)); - f->flags |= FFL_PWMSG; - f->alliance_joindate = turn; f->lastorders = turn; f->_alive = true; @@ -260,7 +255,11 @@ faction *addfaction(const char *email, const char *password, f->magiegebiet = 0; f->locale = loc; f->subscription = subscription; - f->flags = FFL_ISNEW; + f->flags = FFL_ISNEW|FFL_PWMSG; + + if (!password) password = itoa36(rng_int()); + faction_setpassword(f, password_encode(password, PASSWORD_DEFAULT)); + ADDMSG(&f->msgs, msg_message("changepasswd", "value", password)); f->options = want(O_REPORT) | want(O_ZUGVORLAGE) | want(O_COMPUTER) | want(O_COMPRESS) | diff --git a/src/kernel/faction.test.c b/src/kernel/faction.test.c index 3bfc36ca8..b18121e2d 100644 --- a/src/kernel/faction.test.c +++ b/src/kernel/faction.test.c @@ -117,7 +117,7 @@ static void test_addfaction(CuTest *tc) { CuAssertTrue(tc, checkpasswd(f, "hurrdurr")); CuAssertPtrEquals(tc, (void *)lang, (void *)f->locale); CuAssertIntEquals(tc, 1234, f->subscription); - CuAssertIntEquals(tc, FFL_ISNEW, f->flags); + CuAssertIntEquals(tc, FFL_ISNEW|FFL_PWMSG, f->flags); CuAssertIntEquals(tc, 0, f->age); CuAssertTrue(tc, faction_alive(f)); CuAssertIntEquals(tc, M_GRAY, f->magiegebiet); diff --git a/src/reports.test.c b/src/reports.test.c index 18ce468bb..e3ca5c89b 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -232,7 +232,7 @@ static void test_newbie_password_message(CuTest *tc) { test_setup(); f = test_create_faction(0); f->age = 5; - CuAssertIntEquals(tc, 0, f->flags&FFL_PWMSG); + f->flags = 0; prepare_report(&ctx, f); CuAssertIntEquals(tc, 0, f->flags&FFL_PWMSG); CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "changepasswd"));