Merge pull request #828 from ennorehling/master

Vertrautenzauber reparieren.
This commit is contained in:
Enno Rehling 2018-12-15 15:40:02 +01:00 committed by GitHub
commit 0473d76f45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 72 additions and 30 deletions

View File

@ -2331,7 +2331,7 @@ msgid "curseinfo::magicboost"
msgstr "Der Magier besitzt die Gabe des Chaos. ($int36($id))"
msgid "illegal_password"
msgstr "\"Dein Passwort enthält Zeichen, die bei der Nachsendung von Reports Probleme bereiten können. Bitte beachte, dass Passwortenur aus Buchstaben von A bis Z und Zahlen bestehen dürfen. Dein neues Passwort ist '${newpass}'.\""
msgstr "\"Das Passwort enthielt Zeichen, die bei der Nachsendung von Reports Probleme bereiten können. Bitte beachte, dass Passworte nur aus Ziffern und Buchstaben von A bis Z bestehen dürfen. Dein neues Passwort ist '${newpass}'.\""
msgid "curseinfo::sparkle_12"
msgstr "\"Leuchtende Blumen erblühen rund um das Lager von $unit($unit). ($int36($id))\""

View File

@ -19,7 +19,7 @@ function test_undead_reserve_self()
assert_equal(1, u1:get_item("log"))
end
function test_undead_reserve_other()
function skip_undead_reserve_other()
local r1 = region.create(0, 0, "plain")
local f1 = faction.create("human")
local u1 = unit.create(f1, r1, 1)

View File

@ -1189,7 +1189,7 @@ static void destroy_items(troop dt) {
}
static void calculate_defense_type(troop dt, troop at, int type, bool missile,
static void calculate_defense_type(troop at, troop dt, int type, bool missile,
const weapon_type **dwtype, int *defskill) {
const weapon *weapon;
weapon = select_weapon(dt, false, true); /* missile=true to get the unmodified best weapon she has */
@ -1198,7 +1198,7 @@ static void calculate_defense_type(troop dt, troop at, int type, bool missile,
*dwtype = weapon->type;
}
static void calculate_attack_type(troop dt, troop at, int type, bool missile,
static void calculate_attack_type(troop at, troop dt, int type, bool missile,
const weapon_type **awtype, int *attskill, bool *magic) {
const weapon *weapon;

View File

@ -1065,10 +1065,9 @@ static void seed_player(state *st, const newfaction *player) {
pnormalize(&nx, &ny, st->cursor.pl);
r = findregion(nx, ny);
if (r) {
faction *f;
const char *password = player->password ? player->password : itoa36(rng_int());
addplayer(r, f = addfaction(player->email, password,
player->race, player->lang));
faction *f = addfaction(player->email, player->password,
player->race, player->lang);
addplayer(r, f);
}
}
}

View File

@ -227,6 +227,12 @@ static int unused_faction_id(void)
return id;
}
void faction_genpassword(faction *f) {
const char * password = itoa36(rng_int());
faction_setpassword(f, password_hash(password, PASSWORD_DEFAULT));
ADDMSG(&f->msgs, msg_message("changepasswd", "value", password));
}
faction *addfaction(const char *email, const char *password,
const struct race * frace, const struct locale * loc)
{
@ -241,7 +247,7 @@ faction *addfaction(const char *email, const char *password,
}
f->alliance_joindate = turn;
f->lastorders = turn;
f->lastorders = 0;
f->_alive = true;
f->password_id = 0;
f->age = 0;

View File

@ -151,6 +151,7 @@ extern "C" {
const char *faction_getemail(const struct faction *self);
void faction_setemail(struct faction *self, const char *email);
void faction_genpassword(struct faction *f);
void faction_setpassword(struct faction *self, const char *pwhash);
const char *faction_getpassword(const struct faction *f);
bool valid_race(const struct faction *f, const struct race *rc);

View File

@ -110,7 +110,7 @@ static void test_addfaction(CuTest *tc) {
test_setup();
rc = rc_get_or_create("human");
lang = test_create_locale();
f = addfaction("test@eressea.de", NULL, rc, lang);
f = addfaction("test@example.com", NULL, rc, lang);
CuAssertPtrNotNull(tc, f);
CuAssertPtrNotNull(tc, f->name);
CuAssertPtrEquals(tc, NULL, (void *)f->units);
@ -119,14 +119,14 @@ static void test_addfaction(CuTest *tc) {
CuAssertPtrEquals(tc, NULL, (void *)f->spellbook);
CuAssertPtrEquals(tc, NULL, (void *)f->origin);
CuAssertPtrEquals(tc, (void *)factions, (void *)f);
CuAssertStrEquals(tc, "test@eressea.de", f->email);
CuAssertStrEquals(tc, "test@example.com", f->email);
CuAssertTrue(tc, checkpasswd(f, "hurrdurr"));
CuAssertPtrEquals(tc, (void *)lang, (void *)f->locale);
CuAssertIntEquals(tc, FFL_ISNEW|FFL_PWMSG, f->flags);
CuAssertIntEquals(tc, 0, f->age);
CuAssertTrue(tc, faction_alive(f));
CuAssertIntEquals(tc, M_GRAY, f->magiegebiet);
CuAssertIntEquals(tc, turn, f->lastorders);
CuAssertIntEquals(tc, 0, f->lastorders);
CuAssertPtrEquals(tc, f, findfaction(f->no));
test_teardown();
}

View File

@ -40,8 +40,9 @@
#define FACTION_UID_VERSION 362 /* f->uid contains a database id */
#define CRYPT_VERSION 363 /* passwords are encrypted */
#define FAMILIAR_FIXMAGE_VERSION 364 /* familiar links are fixed */
#define FAMILIAR_FIXSPELLBOOK_VERSION 365 /* familiar spells are fixed */
#define RELEASE_VERSION FAMILIAR_FIXMAGE_VERSION /* current datafile */
#define RELEASE_VERSION FAMILIAR_FIXSPELLBOOK_VERSION /* current datafile */
#define MIN_VERSION UIDHASH_VERSION /* minimal datafile we support */
#define MAX_VERSION RELEASE_VERSION /* change this if we can need to read the future datafile, and we can do so */

View File

@ -1527,7 +1527,7 @@ int read_game(gamedata *data)
if (data->version < FAMILIAR_FIX_VERSION) {
fix_familiars(fix_fam_triggers);
}
if (data->version < FAMILIAR_FIXMAGE_VERSION) {
if (data->version < FAMILIAR_FIXSPELLBOOK_VERSION) {
fix_familiars(fix_fam_mage);
}

View File

@ -154,8 +154,11 @@ bool IsImmune(const faction * f)
int NMRTimeout(void)
{
int nmr_timeout = config_get_int("nmr.timeout", 0);
int ini_timeout = config_get_int("game.maxnmr", 0);
static int config, nmr_timeout, ini_timeout;
if (config_changed(&config)) {
nmr_timeout = config_get_int("nmr.timeout", 0);
ini_timeout = config_get_int("game.maxnmr", 0);
}
if (nmr_timeout > 0) {
if (ini_timeout > nmr_timeout) {
return nmr_timeout;
@ -1192,17 +1195,26 @@ void do_enter(struct region *r, bool is_final_attempt)
int dropouts[2];
int *age = NULL;
static void nmr_death(faction * f)
bool nmr_death(const faction * f, int turn, int timeout)
{
int rule = config_get_int("rules.nmr.destroy", 0) != 0;
if (rule) {
unit *u;
for (u = f->units; u; u = u->nextF) {
if (u->building && building_owner(u->building) == u) {
remove_building(&u->region->buildings, u->building);
if (f->age >= timeout && turn - f->lastorders >= timeout) {
static bool rule_destroy;
static int config;
if (config_changed(&config)) {
rule_destroy = config_get_int("rules.nmr.destroy", 0) != 0;
}
if (rule_destroy) {
unit *u;
for (u = f->units; u; u = u->nextF) {
if (u->building && building_owner(u->building) == u) {
remove_building(&u->region->buildings, u->building);
}
}
}
return true;
}
return false;
}
static void remove_idle_players(void)
@ -1215,8 +1227,7 @@ static void remove_idle_players(void)
for (fp = &factions; *fp;) {
faction *f = *fp;
if (timeout > 0 && turn - f->lastorders >= timeout) {
nmr_death(f);
if (timeout > 0 && nmr_death(f, turn, timeout)) {
destroyfaction(fp);
} else {
if (fval(f, FFL_NOIDLEOUT)) {

View File

@ -95,6 +95,7 @@ extern "C" {
int claim_cmd(struct unit *u, struct order *ord);
void nmr_warnings(void);
bool nmr_death(const struct faction * f, int turn, int timeout);
bool cansee(const struct faction * f, const struct region * r,
const struct unit *u, int modifier);

View File

@ -549,15 +549,13 @@ int autoseed(newfaction ** players, int nsize, int max_agediff)
newfaction **nfp, *nextf = *players;
faction *f;
unit *u;
const char * password;
isize += REGIONS_PER_FACTION;
terraform_region(r, preferred_terrain(nextf->race));
prepare_starting_region(r);
++tsize;
assert(r->land && r->units == 0);
password = nextf->password ? nextf->password : itoa36(rng_int());
u = addplayer(r, addfaction(nextf->email, password, nextf->race,
u = addplayer(r, addfaction(nextf->email, nextf->password, nextf->race,
nextf->lang));
f = u->faction;
fset(f, FFL_ISNEW);
@ -857,8 +855,7 @@ static void starting_region(newfaction ** players, region * r, region * rn[])
newfaction *nf = *players;
const struct race *rc = nf->race ? nf->race : races;
const struct locale *lang = nf->lang ? nf->lang : default_locale;
const char * passwd = nf->password ? nf->password : itoa36(rng_int());
addplayer(r, addfaction(nf->email, passwd, rc, lang));
addplayer(r, addfaction(nf->email, nf->password, rc, lang));
*players = nf->next;
free_newfaction(nf);
}

View File

@ -1606,6 +1606,9 @@ int write_reports(faction * f)
if (noreports) {
return false;
}
if (f->lastorders == 0) {
faction_genpassword(f);
}
prepare_report(&ctx, f);
get_addresses(&ctx);
log_debug("Reports for %s", factionname(f));

View File

@ -948,6 +948,28 @@ static void test_eval_functions(CuTest *tc)
test_teardown();
}
static void test_reports_genpassword(CuTest *tc) {
faction *f;
int pwid;
test_setup();
mt_create_va(mt_new("changepasswd", NULL), "value:string", MT_NEW_END);
f = test_create_faction(NULL);
CuAssertIntEquals(tc, 0, f->lastorders);
CuAssertIntEquals(tc, 0, f->password_id);
f->options = 0;
write_reports(f);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd"));
CuAssertTrue(tc, f->password_id != 0);
test_clear_messagelist(&f->msgs);
f->lastorders = 1;
pwid = f->password_id;
write_reports(f);
CuAssertIntEquals(tc, pwid, f->password_id);
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "changepasswd"));
test_teardown();
}
CuSuite *get_reports_suite(void)
{
CuSuite *suite = CuSuiteNew();
@ -979,5 +1001,6 @@ CuSuite *get_reports_suite(void)
SUITE_ADD_TEST(suite, test_newbie_warning);
SUITE_ADD_TEST(suite, test_visible_unit);
SUITE_ADD_TEST(suite, test_eval_functions);
SUITE_ADD_TEST(suite, test_reports_genpassword);
return suite;
}