forked from github/server
Merge branch 'master' into develop
This commit is contained in:
commit
e47da17cc6
|
@ -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))\""
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -205,6 +205,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)
|
||||
{
|
||||
|
@ -219,7 +225,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;
|
||||
|
|
|
@ -150,6 +150,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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
33
src/laws.c
33
src/laws.c
|
@ -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)) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -1607,6 +1607,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));
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue