From 1c7f3fab4440b0c8bd34a7806ec07a269886681a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 22 Jan 2017 12:38:41 +0100 Subject: [PATCH] emit a password message for newbie factions --- src/kernel/faction.c | 1 + src/kernel/faction.h | 5 +++-- src/laws.c | 1 + src/reports.c | 8 ++++++++ src/reports.test.c | 18 ++++++++++++++++++ 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/kernel/faction.c b/src/kernel/faction.c index e3b80566d..e884a2d9b 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -249,6 +249,7 @@ faction *addfaction(const char *email, const char *password, 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; diff --git a/src/kernel/faction.h b/src/kernel/faction.h index de55ad1fe..b4768e982 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -37,10 +37,11 @@ extern "C" { extern struct attrib_type at_maxmagicians; /* faction flags */ -#define FFL_NEWID (1<<0) /* Die Partei hat bereits einmal ihre no gewechselt */ +#define FFL_NEWID (1<<0) // Die Partei hat bereits einmal ihre no gewechselt #define FFL_ISNEW (1<<1) +#define FFL_PWMSG (1<<2) // received a "new password" message #define FFL_QUIT (1<<3) -#define FFL_CURSED (1<<4) /* you're going to have a bad time */ +#define FFL_CURSED (1<<4) // you're going to have a bad time #define FFL_DEFENDER (1<<10) #define FFL_SELECT (1<<18) /* ehemals f->dh, u->dh, r->dh, etc... */ #define FFL_NOAID (1<<21) /* Hilfsflag Kampf */ diff --git a/src/laws.c b/src/laws.c index 7baadcf29..112d15fd2 100644 --- a/src/laws.c +++ b/src/laws.c @@ -2214,6 +2214,7 @@ int password_cmd(unit * u, struct order *ord) faction_setpassword(u->faction, password_encode(pwbuf, PASSWORD_DEFAULT)); ADDMSG(&u->faction->msgs, msg_message("changepasswd", "value", pwbuf)); + u->faction->flags |= FFL_PWMSG; return 0; } diff --git a/src/reports.c b/src/reports.c index 6d0aaba37..0da8aed94 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1336,6 +1336,14 @@ void prepare_report(report_context *ctx, faction *f) rule_region_owners = config_token("rules.region_owner_pay_building", bt_lighthouse->_name); } + if (f->age<=2) { + if ((f->flags&FFL_PWMSG)==0) { + // TODO: this assumes unencrypted passwords + f->flags |= FFL_PWMSG; + ADDMSG(&f->msgs, msg_message("changepasswd", "value", f->_password)); + } + } + ctx->f = f; ctx->report_time = time(NULL); ctx->addresses = NULL; diff --git a/src/reports.test.c b/src/reports.test.c index c9fe39c19..389d9c130 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -226,6 +226,23 @@ static void test_arg_resources(CuTest *tc) { test_cleanup(); } +static void test_newbie_password_message(CuTest *tc) { + report_context ctx; + faction *f; + test_setup(); + f = test_create_faction(0); + f->age = 5; + CuAssertIntEquals(tc, 0, f->flags&FFL_PWMSG); + prepare_report(&ctx, f); + CuAssertIntEquals(tc, 0, f->flags&FFL_PWMSG); + CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "changepasswd")); + f->age=2; + prepare_report(&ctx, f); + CuAssertIntEquals(tc, FFL_PWMSG, f->flags&FFL_PWMSG); + CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd")); + test_cleanup(); +} + static void test_prepare_travelthru(CuTest *tc) { report_context ctx; faction *f, *f2; @@ -465,6 +482,7 @@ static void test_seen_travelthru(CuTest *tc) { CuSuite *get_reports_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_newbie_password_message); SUITE_ADD_TEST(suite, test_prepare_report); SUITE_ADD_TEST(suite, test_seen_neighbours); SUITE_ADD_TEST(suite, test_seen_travelthru);