Merge pull request #826 from ennorehling/develop

cppcheck and password stuff
This commit is contained in:
Enno Rehling 2018-12-09 03:54:06 +01:00 committed by GitHub
commit fdf60c9dd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 157 additions and 121 deletions

View file

@ -2331,7 +2331,7 @@ msgid "curseinfo::magicboost"
msgstr "Der Magier besitzt die Gabe des Chaos. ($int36($id))" msgstr "Der Magier besitzt die Gabe des Chaos. ($int36($id))"
msgid "illegal_password" 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" msgid "curseinfo::sparkle_12"
msgstr "\"Leuchtende Blumen erblühen rund um das Lager von $unit($unit). ($int36($id))\"" msgstr "\"Leuchtende Blumen erblühen rund um das Lager von $unit($unit). ($int36($id))\""

View file

@ -1157,7 +1157,7 @@ static char *cr_output_resource(char *buf, const resource_type *rtype,
assert(rtype); assert(rtype);
name = resourcename(rtype, NMF_PLURAL); name = resourcename(rtype, NMF_PLURAL);
assert(name); assert(name);
buf += sprintf(buf, "RESOURCE %u\n", str_hash(rtype->_name)); buf += sprintf(buf, "RESOURCE %d\n", str_hash(rtype->_name));
tname = LOC(loc, name); tname = LOC(loc, name);
assert(tname); assert(tname);
tname = translate(name, tname); tname = translate(name, tname);

View file

@ -2239,7 +2239,6 @@ static void breed_cmd(unit * u, struct order *ord)
const char *s; const char *s;
param_t p; param_t p;
region *r = u->region; region *r = u->region;
const resource_type *rtype = NULL;
if (r->land == NULL) { if (r->land == NULL) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_onlandonly", "")); ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_onlandonly", ""));
@ -2275,7 +2274,7 @@ static void breed_cmd(unit * u, struct order *ord)
break; break;
default: default:
if (p != P_ANY) { if (p != P_ANY) {
rtype = findresourcetype(s, u->faction->locale); const resource_type *rtype = findresourcetype(s, u->faction->locale);
if (rtype == get_resourcetype(R_SEED) || rtype == get_resourcetype(R_MALLORN_SEED)) { if (rtype == get_resourcetype(R_SEED) || rtype == get_resourcetype(R_MALLORN_SEED)) {
breedtrees(u, m); breedtrees(u, m);
break; break;

View file

@ -874,7 +874,6 @@ static void start_resources(parseinfo *pi, const XML_Char *el, const XML_Char **
} }
static void start_ships(parseinfo *pi, const XML_Char *el, const XML_Char **attr) { static void start_ships(parseinfo *pi, const XML_Char *el, const XML_Char **attr) {
const char *flag_names[] = { "opensea", "fly", "nocoast", "speedy", NULL };
if (xml_strequal(el, "ship")) { if (xml_strequal(el, "ship")) {
const XML_Char *name; const XML_Char *name;
@ -917,10 +916,13 @@ static void start_ships(parseinfo *pi, const XML_Char *el, const XML_Char **attr
else if (xml_strequal(attr[i], "storm")) { else if (xml_strequal(attr[i], "storm")) {
stype->storm = xml_float(attr[i + 1]); stype->storm = xml_float(attr[i + 1]);
} }
else if (!handle_flag(&flags, attr + i, flag_names)) { else {
/* we already handled the name earlier */ const char *flag_names[] = { "opensea", "fly", "nocoast", "speedy", NULL };
if (!xml_strequal(attr[i], "name")) { if (!handle_flag(&flags, attr + i, flag_names)) {
handle_bad_input(pi, el, attr[i]); /* we already handled the name earlier */
if (!xml_strequal(attr[i], "name")) {
handle_bad_input(pi, el, attr[i]);
}
} }
} }
} }
@ -1209,7 +1211,6 @@ static void start_races(parseinfo *pi, const XML_Char *el, const XML_Char **attr
} }
static void start_buildings(parseinfo *pi, const XML_Char *el, const XML_Char **attr) { static void start_buildings(parseinfo *pi, const XML_Char *el, const XML_Char **attr) {
const char *flag_names[] = { "nodestroy", "nobuild", "unique", "decay", "magic", "namechange", "fort", "oneperturn", NULL };
if (xml_strequal(el, "building")) { if (xml_strequal(el, "building")) {
const XML_Char *name; const XML_Char *name;
@ -1245,10 +1246,13 @@ static void start_buildings(parseinfo *pi, const XML_Char *el, const XML_Char **
/* magres is specified in percent! */ /* magres is specified in percent! */
btype->magres = frac_make(xml_int(attr[i + 1]), 100); btype->magres = frac_make(xml_int(attr[i + 1]), 100);
} }
else if (!handle_flag(&flags, attr + i, flag_names)) { else {
/* we already handled the name earlier */ const char *flag_names[] = { "nodestroy", "nobuild", "unique", "decay", "magic", "namechange", "fort", "oneperturn", NULL };
if (!xml_strequal(attr[i], "name")) { if (!handle_flag(&flags, attr + i, flag_names)) {
handle_bad_input(pi, el, attr[i]); /* we already handled the name earlier */
if (!xml_strequal(attr[i], "name")) {
handle_bad_input(pi, el, attr[i]);
}
} }
} }
} }

View file

@ -169,7 +169,6 @@ int give_quota(const unit * src, const unit * dst, const item_type * type,
if (config_changed(&config)) { if (config_changed(&config)) {
divisor = config_get_int("rules.items.give_divisor", divisor); divisor = config_get_int("rules.items.give_divisor", divisor);
} }
assert(divisor <= 0 || divisor >= 1);
if (divisor >= 1) { if (divisor >= 1) {
/* predictable > correct: */ /* predictable > correct: */
return n / divisor; return n / divisor;

View file

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

View file

@ -1032,12 +1032,14 @@ static int add_po_string(const char *msgid, const char *msgstr, const char *msgc
} }
static int include_po(const char *uri) { static int include_po(const char *uri) {
char name[PATH_MAX], lname[8]; char name[PATH_MAX];
const char *filename = uri_to_file(uri, name, sizeof(name)); const char *filename = uri_to_file(uri, name, sizeof(name));
const char *pos = strstr(filename, ".po"); const char *pos = strstr(filename, ".po");
if (pos) { if (pos) {
size_t len; size_t len;
const char *str = --pos; const char *str = --pos;
char lname[8];
while (str > filename && *str != '.') --str; while (str > filename && *str != '.') --str;
len = (size_t)(pos - str); len = (size_t)(pos - str);
if (len < sizeof(lname)) { if (len < sizeof(lname)) {

View file

@ -185,15 +185,15 @@ void at_register(attrib_type * at)
static attrib_type *at_find_key(unsigned int hk) static attrib_type *at_find_key(unsigned int hk)
{ {
const char *translate[3][2] = {
{ "zielregion", "targetregion" }, /* remapping: from 'zielregion, heute targetregion */
{ "verzaubert", "curse" }, /* remapping: früher verzaubert, jetzt curse */
{ NULL, NULL }
};
attrib_type *find = at_hash[hk % MAXATHASH]; attrib_type *find = at_hash[hk % MAXATHASH];
while (find && hk != find->hashkey) while (find && hk != find->hashkey)
find = find->nexthash; find = find->nexthash;
if (!find) { if (!find) {
const char *translate[3][2] = {
{ "zielregion", "targetregion" }, /* remapping: from 'zielregion, heute targetregion */
{ "verzaubert", "curse" }, /* remapping: früher verzaubert, jetzt curse */
{ NULL, NULL }
};
int i = 0; int i = 0;
while (translate[i][0]) { while (translate[i][0]) {
if (__at_hashkey(translate[i][0]) == hk) if (__at_hashkey(translate[i][0]) == hk)

View file

@ -205,6 +205,12 @@ static int unused_faction_id(void)
return id; 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, faction *addfaction(const char *email, const char *password,
const struct race * frace, const struct locale * loc) 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->alliance_joindate = turn;
f->lastorders = turn; f->lastorders = 0;
f->_alive = true; f->_alive = true;
f->password_id = 0; f->password_id = 0;
f->age = 0; f->age = 0;

View file

@ -150,6 +150,7 @@ extern "C" {
const char *faction_getemail(const struct faction *self); const char *faction_getemail(const struct faction *self);
void faction_setemail(struct faction *self, const char *email); void faction_setemail(struct faction *self, const char *email);
void faction_genpassword(struct faction *f);
void faction_setpassword(struct faction *self, const char *pwhash); void faction_setpassword(struct faction *self, const char *pwhash);
const char *faction_getpassword(const struct faction *f); const char *faction_getpassword(const struct faction *f);
bool valid_race(const struct faction *f, const struct race *rc); 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(); test_setup();
rc = rc_get_or_create("human"); rc = rc_get_or_create("human");
lang = test_create_locale(); 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);
CuAssertPtrNotNull(tc, f->name); CuAssertPtrNotNull(tc, f->name);
CuAssertPtrEquals(tc, NULL, (void *)f->units); 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->spellbook);
CuAssertPtrEquals(tc, NULL, (void *)f->origin); CuAssertPtrEquals(tc, NULL, (void *)f->origin);
CuAssertPtrEquals(tc, (void *)factions, (void *)f); 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")); CuAssertTrue(tc, checkpasswd(f, "hurrdurr"));
CuAssertPtrEquals(tc, (void *)lang, (void *)f->locale); CuAssertPtrEquals(tc, (void *)lang, (void *)f->locale);
CuAssertIntEquals(tc, FFL_ISNEW|FFL_PWMSG, f->flags); CuAssertIntEquals(tc, FFL_ISNEW|FFL_PWMSG, f->flags);
CuAssertIntEquals(tc, 0, f->age); CuAssertIntEquals(tc, 0, f->age);
CuAssertTrue(tc, faction_alive(f)); CuAssertTrue(tc, faction_alive(f));
CuAssertIntEquals(tc, M_GRAY, f->magiegebiet); CuAssertIntEquals(tc, M_GRAY, f->magiegebiet);
CuAssertIntEquals(tc, turn, f->lastorders); CuAssertIntEquals(tc, 0, f->lastorders);
CuAssertPtrEquals(tc, f, findfaction(f->no)); CuAssertPtrEquals(tc, f, findfaction(f->no));
test_teardown(); test_teardown();
} }

View file

@ -170,7 +170,6 @@ const char *crescape(const char *str, char *buffer, size_t size) {
int stream_order(struct stream *out, const struct order *ord, const struct locale *lang, bool escape) int stream_order(struct stream *out, const struct order *ord, const struct locale *lang, bool escape)
{ {
const char *text; const char *text;
order_data *od = NULL;
keyword_t kwd = ORD_KEYWORD(ord); keyword_t kwd = ORD_KEYWORD(ord);
if (ord->command & CMD_QUIET) { if (ord->command & CMD_QUIET) {
@ -203,7 +202,7 @@ int stream_order(struct stream *out, const struct order *ord, const struct local
} }
} }
else { else {
od = odata_load(ord->id); order_data *od = odata_load(ord->id);
text = OD_STRING(od); text = OD_STRING(od);
if (text) { if (text) {
char obuf[1024]; char obuf[1024];

View file

@ -181,10 +181,8 @@ struct rawmaterial_type *rmt_get(const struct resource_type *rtype)
struct rawmaterial_type *rmt_create(struct resource_type *rtype) struct rawmaterial_type *rmt_create(struct resource_type *rtype)
{ {
rawmaterial_type *rmtype;
if (!rtype->raw) { if (!rtype->raw) {
rmtype = rtype->raw = malloc(sizeof(rawmaterial_type)); rawmaterial_type *rmtype = rtype->raw = malloc(sizeof(rawmaterial_type));
rmtype->rtype = rtype; rmtype->rtype = rtype;
rmtype->terraform = terraform_default; rmtype->terraform = terraform_default;
rmtype->update = NULL; rmtype->update = NULL;

View file

@ -272,12 +272,11 @@ static void read_owner(gamedata *data, region_owner ** powner)
static void write_owner(gamedata *data, region_owner * owner) static void write_owner(gamedata *data, region_owner * owner)
{ {
if (owner) { if (owner) {
faction *f;
WRITE_INT(data->store, owner->since_turn); WRITE_INT(data->store, owner->since_turn);
if (owner->since_turn >= 0) { if (owner->since_turn >= 0) {
faction *f = owner->last_owner;
WRITE_INT(data->store, owner->morale_turn); WRITE_INT(data->store, owner->morale_turn);
WRITE_INT(data->store, owner->flags); WRITE_INT(data->store, owner->flags);
f = owner->last_owner;
write_faction_reference((f && f->_alive) ? f : NULL, data->store); write_faction_reference((f && f->_alive) ? f : NULL, data->store);
f = owner->owner; f = owner->owner;
write_faction_reference((f && f->_alive) ? f : NULL, data->store); write_faction_reference((f && f->_alive) ? f : NULL, data->store);
@ -887,12 +886,12 @@ int get_spell_level_faction(const spell * sp, void * cbdata)
} }
static char * getpasswd(int fno) { static char * getpasswd(int fno) {
const char *prefix = itoa36(fno);
size_t len = strlen(prefix);
FILE * F = fopen("passwords.txt", "r"); FILE * F = fopen("passwords.txt", "r");
char line[80];
if (F) { if (F) {
const char *prefix = itoa36(fno);
size_t len = strlen(prefix);
while (!feof(F)) { while (!feof(F)) {
char line[80];
fgets(line, sizeof(line), F); fgets(line, sizeof(line), F);
if (line[len] == ':' && strncmp(prefix, line, len) == 0) { if (line[len] == ':' && strncmp(prefix, line, len) == 0) {
size_t slen = strlen(line) - 1; size_t slen = strlen(line) - 1;
@ -1147,7 +1146,7 @@ static int cb_sb_maxlevel(spellbook_entry *sbe, void *cbdata) {
int readgame(const char *filename) int readgame(const char *filename)
{ {
int n, stream_version; int n = -2, stream_version;
char path[PATH_MAX]; char path[PATH_MAX];
gamedata gdata = { 0 }; gamedata gdata = { 0 };
storage store; storage store;
@ -1164,23 +1163,25 @@ int readgame(const char *filename)
return -1; return -1;
} }
sz = fread(&gdata.version, sizeof(int), 1, F); sz = fread(&gdata.version, sizeof(int), 1, F);
sz = fread(&stream_version, sizeof(int), 1, F); if (sz == 1) {
assert((sz == 1 && stream_version == STREAM_VERSION) || !"unsupported data format"); sz = fread(&stream_version, sizeof(int), 1, F);
assert(gdata.version >= MIN_VERSION || !"unsupported data format"); assert((sz == 1 && stream_version == STREAM_VERSION) || !"unsupported data format");
assert(gdata.version <= MAX_VERSION || !"unsupported data format"); assert(gdata.version >= MIN_VERSION || !"unsupported data format");
assert(gdata.version <= MAX_VERSION || !"unsupported data format");
fstream_init(&strm, F); fstream_init(&strm, F);
binstore_init(&store, &strm); binstore_init(&store, &strm);
gdata.store = &store; gdata.store = &store;
if (gdata.version >= BUILDNO_VERSION) { if (gdata.version >= BUILDNO_VERSION) {
int build; int build;
READ_INT(&store, &build); READ_INT(&store, &build);
log_debug("data in %s created with build %d.", filename, build); log_debug("data in %s created with build %d.", filename, build);
}
n = read_game(&gdata);
binstore_done(&store);
fstream_done(&strm);
} }
n = read_game(&gdata);
binstore_done(&store);
fstream_done(&strm);
return n; return n;
} }
@ -1350,8 +1351,6 @@ int read_game(gamedata *data)
int p, nread; int p, nread;
faction *f, **fp; faction *f, **fp;
region *r; region *r;
building **bp;
ship **shp;
unit *u; unit *u;
storage * store = data->store; storage * store = data->store;
const struct building_type *bt_lighthouse = bt_find("lighthouse"); const struct building_type *bt_lighthouse = bt_find("lighthouse");
@ -1407,6 +1406,8 @@ int read_game(gamedata *data)
while (--nread >= 0) { while (--nread >= 0) {
unit **up; unit **up;
building **bp;
ship **shp;
r = read_region(data); r = read_region(data);

View file

@ -776,7 +776,6 @@ void clone_men(const unit * u, unit * dst, int n)
/* "hat attackiert"-status wird uebergeben */ /* "hat attackiert"-status wird uebergeben */
if (dst) { if (dst) {
skill *sv, *sn;
skill_t sk; skill_t sk;
ship *sh; ship *sh;
@ -784,9 +783,8 @@ void clone_men(const unit * u, unit * dst, int n)
for (sk = 0; sk != MAXSKILLS; ++sk) { for (sk = 0; sk != MAXSKILLS; ++sk) {
int weeks, level = 0; int weeks, level = 0;
skill *sv = unit_skill(u, sk);
sv = unit_skill(u, sk); skill *sn = unit_skill(dst, sk);
sn = unit_skill(dst, sk);
if (sv == NULL && sn == NULL) if (sv == NULL && sn == NULL)
continue; continue;

View file

@ -154,8 +154,11 @@ bool IsImmune(const faction * f)
int NMRTimeout(void) int NMRTimeout(void)
{ {
int nmr_timeout = config_get_int("nmr.timeout", 0); static int config, nmr_timeout, ini_timeout;
int ini_timeout = config_get_int("game.maxnmr", 0); 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 (nmr_timeout > 0) {
if (ini_timeout > nmr_timeout) { if (ini_timeout > nmr_timeout) {
return nmr_timeout; return nmr_timeout;
@ -1192,17 +1195,26 @@ void do_enter(struct region *r, bool is_final_attempt)
int dropouts[2]; int dropouts[2];
int *age = NULL; 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 (f->age >= timeout && turn - f->lastorders >= timeout) {
if (rule) { static bool rule_destroy;
unit *u; static int config;
for (u = f->units; u; u = u->nextF) {
if (u->building && building_owner(u->building) == u) { if (config_changed(&config)) {
remove_building(&u->region->buildings, u->building); 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) static void remove_idle_players(void)
@ -1215,8 +1227,7 @@ static void remove_idle_players(void)
for (fp = &factions; *fp;) { for (fp = &factions; *fp;) {
faction *f = *fp; faction *f = *fp;
if (timeout > 0 && turn - f->lastorders >= timeout) { if (timeout > 0 && nmr_death(f, turn, timeout)) {
nmr_death(f);
destroyfaction(fp); destroyfaction(fp);
} else { } else {
if (fval(f, FFL_NOIDLEOUT)) { if (fval(f, FFL_NOIDLEOUT)) {
@ -3388,8 +3399,8 @@ int pay_cmd(unit * u, struct order *ord)
static int reserve_i(unit * u, struct order *ord, int flags) static int reserve_i(unit * u, struct order *ord, int flags)
{ {
char token[128];
if (u->number > 0) { if (u->number > 0) {
char token[128];
int use, count, para; int use, count, para;
const item_type *itype; const item_type *itype;
const char *s; const char *s;

View file

@ -95,6 +95,7 @@ extern "C" {
int claim_cmd(struct unit *u, struct order *ord); int claim_cmd(struct unit *u, struct order *ord);
void nmr_warnings(void); 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, bool cansee(const struct faction * f, const struct region * r,
const struct unit *u, int modifier); const struct unit *u, int modifier);

View file

@ -1334,7 +1334,6 @@ static void do_fumble(castorder * co)
int level = co->level; int level = co->level;
int duration; int duration;
double effect; double effect;
static const race *rc_toad;
static int rc_cache; static int rc_cache;
fumble_f fun; fumble_f fun;
@ -1359,6 +1358,7 @@ static void do_fumble(castorder * co)
* The list of things to happen are attached to a timeout * The list of things to happen are attached to a timeout
* trigger and that's added to the triggerlit of the mage gone toad. * trigger and that's added to the triggerlit of the mage gone toad.
*/ */
static const race *rc_toad;
trigger *trestore = trigger_changerace(mage, u_race(mage), mage->irace); trigger *trestore = trigger_changerace(mage, u_race(mage), mage->irace);
if (chance(0.7)) { if (chance(0.7)) {
const resource_type *rtype = rt_find("toadslime"); const resource_type *rtype = rt_find("toadslime");
@ -2119,10 +2119,9 @@ void add_castorder(spellrank * cll, castorder * co)
void free_castorders(castorder * co) void free_castorders(castorder * co)
{ {
castorder *co2;
while (co) { while (co) {
co2 = co; castorder *co2 = co;
co = co->next; co = co->next;
free_castorder(co2); free_castorder(co2);
free(co2); free(co2);
@ -2202,15 +2201,14 @@ void remove_familiar(unit * mage)
{ {
attrib *a = a_find(mage->attribs, &at_familiar); attrib *a = a_find(mage->attribs, &at_familiar);
attrib *an; attrib *an;
skillmod_data *smd;
if (a != NULL) { if (a != NULL) {
a_remove(&mage->attribs, a); a_remove(&mage->attribs, a);
} }
a = a_find(mage->attribs, &at_skillmod); a = a_find(mage->attribs, &at_skillmod);
while (a && a->type == &at_skillmod) { while (a && a->type == &at_skillmod) {
skillmod_data *smd = (skillmod_data *)a->data.v;
an = a->next; an = a->next;
smd = (skillmod_data *)a->data.v;
if (smd->special == sm_familiar) { if (smd->special == sm_familiar) {
a_remove(&mage->attribs, a); a_remove(&mage->attribs, a);
} }

View file

@ -108,11 +108,11 @@ static const char * valid_keys[] = {
static dictionary *parse_config(const char *filename) static dictionary *parse_config(const char *filename)
{ {
char path[PATH_MAX];
dictionary *d; dictionary *d;
const char *str, *cfgpath = config_get("config.path"); const char *str, *cfgpath = config_get("config.path");
if (cfgpath) { if (cfgpath) {
char path[PATH_MAX];
path_join(cfgpath, filename, path, sizeof(path)); path_join(cfgpath, filename, path, sizeof(path));
log_debug("reading from configuration file %s\n", path); log_debug("reading from configuration file %s\n", path);
d = iniparser_load(path); d = iniparser_load(path);

View file

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

View file

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

View file

@ -948,6 +948,28 @@ static void test_eval_functions(CuTest *tc)
test_teardown(); 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 *get_reports_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
@ -979,5 +1001,6 @@ CuSuite *get_reports_suite(void)
SUITE_ADD_TEST(suite, test_newbie_warning); SUITE_ADD_TEST(suite, test_newbie_warning);
SUITE_ADD_TEST(suite, test_visible_unit); SUITE_ADD_TEST(suite, test_visible_unit);
SUITE_ADD_TEST(suite, test_eval_functions); SUITE_ADD_TEST(suite, test_eval_functions);
SUITE_ADD_TEST(suite, test_reports_genpassword);
return suite; return suite;
} }

View file

@ -94,9 +94,9 @@ skill_t findskill(const char *name)
skill_t get_skill(const char *s, const struct locale * lang) skill_t get_skill(const char *s, const struct locale * lang)
{ {
skill_t result = NOSKILL; skill_t result = NOSKILL;
char buffer[64];
if (s) { if (s) {
char buffer[64];
char * str = transliterate(buffer, sizeof(buffer) - sizeof(int), s); char * str = transliterate(buffer, sizeof(buffer) - sizeof(int), s);
if (str) { if (str) {
int i; int i;

View file

@ -357,8 +357,6 @@ int sp_sleep(struct castorder * co)
const spell * sp = co->sp; const spell * sp = co->sp;
battle *b = fi->side->battle; battle *b = fi->side->battle;
unit *mage = fi->unit; unit *mage = fi->unit;
unit *du;
troop dt;
int force, enemies; int force, enemies;
int k = 0; int k = 0;
message *m; message *m;
@ -374,7 +372,8 @@ int sp_sleep(struct castorder * co)
return 0; return 0;
} }
while (force && enemies) { while (force && enemies) {
dt = select_enemy(fi, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE); unit *du;
troop dt = select_enemy(fi, FIGHT_ROW, BEHIND_ROW, SELECT_ADVANCE);
assert(dt.fighter); assert(dt.fighter);
du = dt.fighter->unit; du = dt.fighter->unit;
if (!is_magic_resistant(mage, du, 0)) { if (!is_magic_resistant(mage, du, 0)) {

View file

@ -217,7 +217,6 @@ int setstealth_cmd(unit * u, struct order *ord)
{ {
char token[64]; char token[64];
const char *s; const char *s;
int level;
init_order_depr(ord); init_order_depr(ord);
s = gettoken(token, sizeof(token)); s = gettoken(token, sizeof(token));
@ -231,7 +230,7 @@ int setstealth_cmd(unit * u, struct order *ord)
if (isdigit(*(const unsigned char *)s)) { if (isdigit(*(const unsigned char *)s)) {
/* Tarnungslevel setzen */ /* Tarnungslevel setzen */
level = atoi((const char *)s); int level = atoi((const char *)s);
if (level > effskill(u, SK_STEALTH, 0)) { if (level > effskill(u, SK_STEALTH, 0)) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_lowstealth", "")); ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_lowstealth", ""));
return 0; return 0;

View file

@ -77,11 +77,12 @@ int *nmrs = NULL;
int update_nmrs(void) int update_nmrs(void)
{ {
int i, newplayers = 0; int newplayers = 0;
faction *f; faction *f;
int timeout = NMRTimeout(); int timeout = NMRTimeout();
if (timeout>0) { if (timeout>0) {
int i;
if (nmrs == NULL) { if (nmrs == NULL) {
nmrs = malloc(sizeof(int) * (timeout + 1)); nmrs = malloc(sizeof(int) * (timeout + 1));
} }

View file

@ -4,21 +4,23 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
char key[4]; char key[4];
char code[4]; char code[4];
char result[4]; char result[4];
int a, i, rot; int a;
for (a = 1; a < argc; ++a) { for (a = 1; a < argc; ++a) {
const char *str = argv[a]; int rot, i;
size_t len = strlen(str); const char *str = argv[a];
str = str + len - 6; size_t len = strlen(str);
memcpy(key, str, 3); str = str + len - 6;
memcpy(code, str + 3, 3); memcpy(key, str, 3);
result[3] = key[3] = code[3] = 0; memcpy(code, str + 3, 3);
rot = atoi(key); result[3] = key[3] = code[3] = 0;
for (i = 0; i != 3; ++i) rot = atoi(key);
result[(i + rot) % 3] = ((code[i] + 10 - key[i]) % 10) + '0'; for (i = 0; i != 3; ++i) {
printf("%s %s\n", argv[a], result); result[(i + rot) % 3] = ((code[i] + 10 - key[i]) % 10) + '0';
} }
return 0; printf("%s %s\n", argv[a], result);
}
return 0;
} }

View file

@ -52,13 +52,13 @@ keyword_t findkeyword(const char *s) {
keyword_t get_keyword(const char *s, const struct locale *lang) { keyword_t get_keyword(const char *s, const struct locale *lang) {
keyword_t result = NOKEYWORD; keyword_t result = NOKEYWORD;
char buffer[64];
assert(lang); assert(lang);
assert(s); assert(s);
while (*s == '@') ++s; while (*s == '@') ++s;
if (*s) { if (*s) {
char buffer[64];
char *str = transliterate(buffer, sizeof(buffer) - sizeof(int), s); char *str = transliterate(buffer, sizeof(buffer) - sizeof(int), s);
if (str) { if (str) {

View file

@ -100,10 +100,10 @@ void init_by_array(unsigned long init_key[], int key_length)
unsigned long genrand_int32(void) unsigned long genrand_int32(void)
{ {
unsigned long y; unsigned long y;
static unsigned long mag01[2]={0x0UL, MATRIX_A};
/* mag01[x] = x * MATRIX_A for x=0,1 */
if (mti >= N) { /* generate N words at one time */ if (mti >= N) { /* generate N words at one time */
static unsigned long mag01[2] = { 0x0UL, MATRIX_A };
/* mag01[x] = x * MATRIX_A for x=0,1 */
int kk; int kk;
if (mti == N+1) /* if init_genrand() has not been called, */ if (mti == N+1) /* if init_genrand() has not been called, */

View file

@ -8,17 +8,13 @@
static void test_rng_round(CuTest * tc) static void test_rng_round(CuTest * tc)
{ {
double f; double f = rng_double();
int i, r; int r = RAND_ROUND(f);
for (i = 0; i < 1000; ++i) { CuAssertTrue(tc, f >= 0);
f = rng_double(); CuAssertTrue(tc, r <= (int)f + 1);
r = RAND_ROUND(f); CuAssertTrue(tc, r >= (int)f);
CuAssertTrue(tc, f >= 0); CuAssertTrue(tc, r == (int)r);
CuAssertTrue(tc, r <= (int)f + 1); CuAssertTrue(tc, r == RAND_ROUND(r));
CuAssertTrue(tc, r >= (int)f);
CuAssertTrue(tc, r == (int)r);
CuAssertTrue(tc, r == RAND_ROUND(r));
}
} }
CuSuite *get_rng_suite(void) CuSuite *get_rng_suite(void)