From 47dccc667b2994a7299b59550466a0e9ba751234 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 15 Aug 2015 20:25:36 +0200 Subject: [PATCH] Add a message that contains the password in the first report, so Magellan can pick it up. Fix a bad type conversion when setting skills. --- src/kernel/skills.c | 4 +-- src/laws.c | 5 +++- src/laws.h | 69 +++++++++++++++++++++++---------------------- src/laws.test.c | 28 +++++++++++++++--- src/report.c | 3 -- src/tests.c | 11 ++++++++ src/tests.h | 1 + 7 files changed, 77 insertions(+), 44 deletions(-) diff --git a/src/kernel/skills.c b/src/kernel/skills.c index fede338d7..d3e3f0ba8 100644 --- a/src/kernel/skills.c +++ b/src/kernel/skills.c @@ -206,8 +206,8 @@ int level(int days) void sk_set(skill * sv, int level) { assert(level != 0); - sv->weeks = (unsigned char)skill_weeks(level); - sv->level = (unsigned char)level; + sv->weeks = skill_weeks(level); + sv->level = level; } static int rule_random_progress(void) diff --git a/src/laws.c b/src/laws.c index b60e15ac9..50b7a9a07 100755 --- a/src/laws.c +++ b/src/laws.c @@ -725,11 +725,14 @@ void immigration(void) } } -static void nmr_warnings(void) +void nmr_warnings(void) { faction *f, *fa; #define FRIEND (HELP_GUARD|HELP_MONEY) for (f = factions; f; f = f->next) { + if (f->age <= 1) { + ADDMSG(&f->msgs, msg_message("changepasswd", "value", f->passw)); + } if (!fval(f, FFL_NOIDLEOUT) && turn > f->lastorders) { ADDMSG(&f->msgs, msg_message("nmr_warning", "")); if (turn - f->lastorders == NMRTimeout() - 1) { diff --git a/src/laws.h b/src/laws.h index 987e3d2b0..bd36fce51 100755 --- a/src/laws.h +++ b/src/laws.h @@ -32,6 +32,10 @@ extern "C" { struct order; struct attrib_type; + extern struct attrib_type at_germs; + extern int dropouts[2]; + extern int *age; + int writepasswd(void); void demographics(void); void immigration(void); @@ -50,11 +54,6 @@ extern "C" { /* eressea-specific. put somewhere else, please. */ void processorders(void); - extern struct attrib_type at_germs; - - extern int dropouts[2]; - extern int *age; - void new_units(void); void defaultorders(void); @@ -66,35 +65,37 @@ extern "C" { void sinkships(struct region * r); void do_enter(struct region *r, bool is_final_attempt); - extern int password_cmd(struct unit *u, struct order *ord); - extern int banner_cmd(struct unit *u, struct order *ord); - extern int email_cmd(struct unit *u, struct order *ord); - extern int send_cmd(struct unit *u, struct order *ord); - extern int ally_cmd(struct unit* u, struct order *ord); - extern int prefix_cmd(struct unit *u, struct order *ord); - extern int setstealth_cmd(struct unit *u, struct order *ord); - extern int status_cmd(struct unit *u, struct order *ord); - extern int display_cmd(struct unit *u, struct order *ord); - extern int group_cmd(struct unit *u, struct order *ord); - extern int origin_cmd(struct unit *u, struct order *ord); - extern int quit_cmd(struct unit *u, struct order *ord); - extern int name_cmd(struct unit *u, struct order *ord); - extern int use_cmd(struct unit *u, struct order *ord); - extern int siege_cmd(struct unit *u, struct order *ord); - extern int leave_cmd(struct unit *u, struct order *ord); - extern int pay_cmd(struct unit *u, struct order *ord); - extern int promotion_cmd(struct unit *u, struct order *ord); - extern int renumber_cmd(struct unit *u, struct order *ord); - extern int combatspell_cmd(struct unit *u, struct order *ord); - extern int contact_cmd(struct unit *u, struct order *ord); - extern int guard_on_cmd(struct unit *u, struct order *ord); - extern int guard_off_cmd(struct unit *u, struct order *ord); - extern int reshow_cmd(struct unit *u, struct order *ord); - extern int mail_cmd(struct unit *u, struct order *ord); - extern int reserve_cmd(struct unit *u, struct order *ord); - extern int reserve_self(struct unit *u, struct order *ord); - extern int claim_cmd(struct unit *u, struct order *ord); - extern int follow_cmd(struct unit *u, struct order *ord); + int password_cmd(struct unit *u, struct order *ord); + int banner_cmd(struct unit *u, struct order *ord); + int email_cmd(struct unit *u, struct order *ord); + int send_cmd(struct unit *u, struct order *ord); + int ally_cmd(struct unit* u, struct order *ord); + int prefix_cmd(struct unit *u, struct order *ord); + int setstealth_cmd(struct unit *u, struct order *ord); + int status_cmd(struct unit *u, struct order *ord); + int display_cmd(struct unit *u, struct order *ord); + int group_cmd(struct unit *u, struct order *ord); + int origin_cmd(struct unit *u, struct order *ord); + int quit_cmd(struct unit *u, struct order *ord); + int name_cmd(struct unit *u, struct order *ord); + int use_cmd(struct unit *u, struct order *ord); + int siege_cmd(struct unit *u, struct order *ord); + int leave_cmd(struct unit *u, struct order *ord); + int pay_cmd(struct unit *u, struct order *ord); + int promotion_cmd(struct unit *u, struct order *ord); + int renumber_cmd(struct unit *u, struct order *ord); + int combatspell_cmd(struct unit *u, struct order *ord); + int contact_cmd(struct unit *u, struct order *ord); + int guard_on_cmd(struct unit *u, struct order *ord); + int guard_off_cmd(struct unit *u, struct order *ord); + int reshow_cmd(struct unit *u, struct order *ord); + int mail_cmd(struct unit *u, struct order *ord); + int reserve_cmd(struct unit *u, struct order *ord); + int reserve_self(struct unit *u, struct order *ord); + int claim_cmd(struct unit *u, struct order *ord); + int follow_cmd(struct unit *u, struct order *ord); + + void nmr_warnings(void); bool cansee(const struct faction *f, const struct region *r, const struct unit *u, int modifier); diff --git a/src/laws.test.c b/src/laws.test.c index 0c4881c85..6e6faeadb 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -845,7 +845,7 @@ static void test_long_order_multi_long(CuTest *tc) { update_long_order(u); CuAssertPtrNotNull(tc, u->thisorder); CuAssertPtrNotNull(tc, u->orders); - CuAssertStrEquals(tc, "error52", test_get_messagetype(u->faction->msgs->begin->msg)); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error52")); test_cleanup(); } @@ -860,7 +860,7 @@ static void test_long_order_multi_buy(CuTest *tc) { update_long_order(u); CuAssertPtrEquals(tc, 0, u->thisorder); CuAssertPtrNotNull(tc, u->orders); - CuAssertStrEquals(tc, "error52", test_get_messagetype(u->faction->msgs->begin->msg)); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error52")); test_cleanup(); } @@ -891,7 +891,7 @@ static void test_long_order_buy_cast(CuTest *tc) { update_long_order(u); CuAssertPtrEquals(tc, 0, u->thisorder); CuAssertPtrNotNull(tc, u->orders); - CuAssertStrEquals(tc, "error52", test_get_messagetype(u->faction->msgs->begin->msg)); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error52")); test_cleanup(); } @@ -927,7 +927,7 @@ static void test_ally_cmd_errors(CuTest *tc) { ord = create_order(K_ALLY, u->faction->locale, itoa36(fid)); ally_cmd(u, ord); - CuAssertStrEquals(tc, "error66", test_get_messagetype(u->faction->msgs->begin->msg)); + CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error66")); free_order(ord); test_cleanup(); @@ -974,9 +974,29 @@ static void test_ally_cmd(CuTest *tc) { test_cleanup(); } +void test_nmr_warnings(CuTest *tc) { + faction *f1, *f2; + test_cleanup(); + set_param(&global.parameters, "nmr.timeout", "3"); + f1 = test_create_faction(0); + f2 = test_create_faction(0); + f2->age = 2; + f2->lastorders = 1; + turn = 3; + CuAssertIntEquals(tc, 0, f1->age); + nmr_warnings(); + CuAssertPtrNotNull(tc, f1->msgs); + CuAssertPtrNotNull(tc, test_find_messagetype(f1->msgs, "changepasswd")); + CuAssertPtrNotNull(tc, f2->msgs); + CuAssertPtrNotNull(tc, test_find_messagetype(f2->msgs, "nmr_warning")); + CuAssertPtrNotNull(tc, test_find_messagetype(f2->msgs, "nmr_warning_final")); + test_cleanup(); +} + CuSuite *get_laws_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_nmr_warnings); SUITE_ADD_TEST(suite, test_ally_cmd); SUITE_ADD_TEST(suite, test_ally_cmd_errors); SUITE_ADD_TEST(suite, test_long_order_normal); diff --git a/src/report.c b/src/report.c index b49cdea9b..f5b7e3757 100644 --- a/src/report.c +++ b/src/report.c @@ -2059,9 +2059,6 @@ const char *charset) if (f->age <= 2) { const char *s; - if (f->age <= 1) { - ADDMSG(&f->msgs, msg_message("changepasswd", "value", f->passw)); - } RENDER(f, buf, sizeof(buf), ("newbie_password", "password", f->passw)); newline(out); centre(out, buf, true); diff --git a/src/tests.c b/src/tests.c index 4cb0d61c0..1a61813b5 100644 --- a/src/tests.c +++ b/src/tests.c @@ -244,6 +244,17 @@ const char * test_get_messagetype(const message *msg) { return name; } +struct message * test_find_messagetype(struct message_list *msgs, const char *name) { + struct mlist *ml; + assert(msgs); + for (ml = msgs->begin; ml; ml = ml->next) { + if (strcmp(name, test_get_messagetype(ml->msg)) == 0) { + return ml->msg; + } + } + return 0; +} + const message_type *register_msg(const char *type, int n_param, ...) { char **argv; va_list args; diff --git a/src/tests.h b/src/tests.h index 3da238fdc..7dd1464f3 100644 --- a/src/tests.h +++ b/src/tests.h @@ -41,6 +41,7 @@ extern "C" { int RunAllTests(void); void test_translate_param(const struct locale *lang, param_t param, const char *text); const char * test_get_messagetype(const struct message *msg); + struct message * test_find_messagetype(struct message_list *msgs, const char *name); struct message * test_get_last_message(struct message_list *mlist); const struct message_type *register_msg(const char *type, int n_param, ...);