Merge branch 'develop' of github.com:ennorehling/eressea into develop

This commit is contained in:
Enno Rehling 2019-09-23 20:44:59 +02:00
commit a2ece4e749
9 changed files with 106 additions and 46 deletions

View File

@ -5291,6 +5291,7 @@
<message name="pest" section="events"> <message name="pest" section="events">
<type> <type>
<arg name="dead" type="int"/> <arg name="dead" type="int"/>
<arg name="peasants" type="resource"/>
</type> </type>
</message> </message>
<message name="error131" section="errors"> <message name="error131" section="errors">

View File

@ -2370,7 +2370,7 @@ msgid "sp_confusion_effect_0"
msgstr "\"$unit($mage) stimmt einen seltsamen Gesang an. Ein plötzlicher Tumult entsteht, der sich jedoch schnell wieder legt.\"" msgstr "\"$unit($mage) stimmt einen seltsamen Gesang an. Ein plötzlicher Tumult entsteht, der sich jedoch schnell wieder legt.\""
msgid "pest" msgid "pest"
msgstr "\"Hier wütete die Pest, und $int($dead) Bauern starben.\"" msgstr "\"Hier wütete die Pest, und $int($dead) $resource($peasants,$dead) $if($eq($dead,1), \"starb\", \"starben\").\""
msgid "wormhole_exit" msgid "wormhole_exit"
msgstr "\"$unit($unit) reist durch ein Wurmloch nach $region($region).\"" msgstr "\"$unit($unit) reist durch ein Wurmloch nach $region($region).\""

View File

@ -2370,7 +2370,7 @@ msgid "sp_confusion_effect_0"
msgstr "\"$unit($mage) intones a mysterious chant. There is a sudden hubbub, but order is restored quickly.\"" msgstr "\"$unit($mage) intones a mysterious chant. There is a sudden hubbub, but order is restored quickly.\""
msgid "pest" msgid "pest"
msgstr "\"The region is visited by the plague and $int($dead) peasants died.\"" msgstr "\"The region is visited by the plague and $int($dead) $resource($$peasants,$dead) died.\""
msgid "wormhole_exit" msgid "wormhole_exit"
msgstr "\"$unit($unit) travels through a wormhole to $region($region).\"" msgstr "\"$unit($unit) travels through a wormhole to $region($region).\""

View File

@ -571,7 +571,7 @@ msgid "balloon"
msgstr "Ballon" msgstr "Ballon"
msgid "nr_schemes_template" msgid "nr_schemes_template"
msgstr "Schemen der Regionen {0} sind erkennbar." msgstr "Schemen von {0} sind erkennbar."
msgid "list_two" msgid "list_two"
msgstr "{0} und {1}" msgstr "{0} und {1}"

View File

@ -85,3 +85,30 @@ function test_recruit_in_desert()
assert_equal('winter', get_season(get_turn())) assert_equal('winter', get_season(get_turn()))
assert_equal(2, u.number) assert_equal(2, u.number)
end end
function test_ride_through_mountain()
local r1 = region.create(1, 0, "plain")
local r2 = region.create(2, 0, "mountain")
local r3 = region.create(3, 0, "plain")
local f = faction.create("insect")
local u = unit.create(f, r1, 1)
u.name="Hercules"
u:add_order('NACH O O')
u:add_item('horse', 1)
u:set_skill('riding', 1, true)
process_orders()
assert_equal(r3, u.region)
end
function test_ride_from_mountain()
local r1 = region.create(1, 0, "mountain")
local r2 = region.create(2, 0, "plain")
local r3 = region.create(3, 0, "plain")
local f = faction.create("insect")
local u = unit.create(f, r1, 1)
u:add_order('NACH O O')
u:add_item('horse', 1)
u:set_skill('riding', 1, true)
process_orders()
assert_equal(r2, u.region)
end

View File

@ -2181,6 +2181,21 @@ int email_cmd(unit * u, struct order *ord)
return 0; return 0;
} }
bool password_wellformed(const char *password)
{
unsigned char *c = (unsigned char *)password;
int i;
if (!password || password[0]=='\0') {
return false;
}
for (i = 0; c[i] && i != PASSWORD_MAXSIZE; ++i) {
if (!isalnum(c[i])) {
return false;
}
}
return true;
}
int password_cmd(unit * u, struct order *ord) int password_cmd(unit * u, struct order *ord)
{ {
char pwbuf[PASSWORD_MAXSIZE + 1]; char pwbuf[PASSWORD_MAXSIZE + 1];
@ -2194,19 +2209,11 @@ int password_cmd(unit * u, struct order *ord)
pwbuf[PASSWORD_MAXSIZE - 1] = '\0'; pwbuf[PASSWORD_MAXSIZE - 1] = '\0';
} }
if (s && *s) { if (!s || !password_wellformed(s)) {
unsigned char *c = (unsigned char *)pwbuf; if (s) {
int i, r = 0;
for (i = 0; c[i] && i != PASSWORD_MAXSIZE; ++i) {
if (!isalnum(c[i])) {
c[i] = 'X';
++r;
}
}
if (r != 0) {
cmistake(u, ord, 283, MSG_EVENT); cmistake(u, ord, 283, MSG_EVENT);
} }
password_generate(pwbuf, PASSWORD_MAXSIZE);
} }
faction_setpassword(u->faction, password_hash(pwbuf, PASSWORD_DEFAULT)); faction_setpassword(u->faction, password_hash(pwbuf, PASSWORD_DEFAULT));
ADDMSG(&u->faction->msgs, msg_message("changepasswd", "value", pwbuf)); ADDMSG(&u->faction->msgs, msg_message("changepasswd", "value", pwbuf));

View File

@ -48,6 +48,7 @@ extern "C" {
void sinkships(struct region * r); void sinkships(struct region * r);
void do_enter(struct region *r, bool is_final_attempt); void do_enter(struct region *r, bool is_final_attempt);
bool long_order_allowed(const struct unit *u); bool long_order_allowed(const struct unit *u);
bool password_wellformed(const char *password);
int password_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 banner_cmd(struct unit *u, struct order *ord);

View File

@ -49,37 +49,6 @@ static void test_new_building_can_be_renamed(CuTest * tc)
test_teardown(); test_teardown();
} }
static void test_password_cmd(CuTest * tc)
{
unit *u;
faction * f;
test_setup();
u = test_create_unit(f = test_create_faction(NULL), test_create_plain(0, 0));
u->thisorder = create_order(K_PASSWORD, f->locale, "abcdefgh");
password_cmd(u, u->thisorder);
CuAssertPtrNotNull(tc, faction_getpassword(f));
CuAssertTrue(tc, checkpasswd(f, "abcdefgh"));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd"));
free_order(u->thisorder);
u->thisorder = create_order(K_PASSWORD, f->locale, "abc*de*");
password_cmd(u, u->thisorder);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error283"));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd"));
CuAssertTrue(tc, !checkpasswd(f, "abc*de*"));
CuAssertTrue(tc, checkpasswd(f, "abcXdeX"));
free_order(u->thisorder);
u->thisorder = create_order(K_PASSWORD, f->locale, "1234567890123456789012345678901234567890");
password_cmd(u, u->thisorder);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error321"));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd"));
CuAssertTrue(tc, checkpasswd(f, "1234567890123456789012345678901"));
test_teardown();
}
static void test_rename_building(CuTest * tc) static void test_rename_building(CuTest * tc)
{ {
region *r; region *r;
@ -1949,6 +1918,60 @@ static void test_long_order_on_ocean(CuTest *tc) {
test_teardown(); test_teardown();
} }
static void test_password_cmd(CuTest *tc) {
unit *u;
message *msg;
faction * f;
CuAssertTrue(tc, password_wellformed("PASSword"));
CuAssertTrue(tc, password_wellformed("1234567"));
CuAssertTrue(tc, !password_wellformed("$password"));
CuAssertTrue(tc, !password_wellformed("no space"));
test_setup();
mt_create_error(283);
mt_create_error(321);
mt_create_va(mt_new("changepasswd", NULL), "value:string", MT_NEW_END);
u = test_create_unit(f = test_create_faction(NULL), test_create_plain(0, 0));
u->thisorder = create_order(K_PASSWORD, f->locale, "password1234", NULL);
password_cmd(u, u->thisorder);
CuAssertTrue(tc, checkpasswd(f, "password1234"));
CuAssertPtrNotNull(tc, msg = test_find_messagetype(f->msgs, "changepasswd"));
free_order(u->thisorder);
test_clear_messages(f);
u->thisorder = create_order(K_PASSWORD, f->locale, "bad-password", NULL);
password_cmd(u, u->thisorder);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error283"));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd"));
CuAssertTrue(tc, !checkpasswd(f, "password1234"));
free_order(u->thisorder);
test_clear_messages(f);
u->thisorder = create_order(K_PASSWORD, f->locale, "''", NULL);
password_cmd(u, u->thisorder);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error283"));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd"));
free_order(u->thisorder);
test_clear_messages(f);
u->thisorder = create_order(K_PASSWORD, f->locale, NULL);
password_cmd(u, u->thisorder);
CuAssertTrue(tc, !checkpasswd(f, "password1234"));
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error283"));
CuAssertPtrNotNull(tc, msg = test_find_messagetype(f->msgs, "changepasswd"));
free_order(u->thisorder);
test_clear_messages(f);
u->thisorder = create_order(K_PASSWORD, f->locale, "1234567890123456789012345678901234567890");
password_cmd(u, u->thisorder);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error321"));
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd"));
CuAssertTrue(tc, checkpasswd(f, "1234567890123456789012345678901"));
test_teardown();
}
static void test_peasant_migration(CuTest *tc) { static void test_peasant_migration(CuTest *tc) {
region *r1, *r2; region *r1, *r2;
int rmax; int rmax;

View File

@ -587,7 +587,8 @@ void plagues(region * r)
} }
if (dead > 0) { if (dead > 0) {
ADDMSG(&r->msgs, msg_message("pest", "dead", dead)); ADDMSG(&r->msgs, msg_message("pest", "peasants dead",
get_resourcetype(R_PEASANT), dead));
deathcounts(r, dead); deathcounts(r, dead);
rsetpeasants(r, peasants - dead); rsetpeasants(r, peasants - dead);
} }