Merge pull request #274 from ennorehling/feature/bug-2116-password-message

Bug 2116: Make sure Magellan can read the password from the first report
This commit is contained in:
Enno Rehling 2015-08-15 20:31:05 +02:00
commit 711bd81cc7
7 changed files with 77 additions and 44 deletions

View File

@ -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)

View File

@ -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) {

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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, ...);