From 2f35feee3e096829a61371c998d9df41fd11358f Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Mon, 25 Sep 2017 09:32:15 +0200 Subject: [PATCH 1/2] minor, obvious fixes --- conf/eressea.ini | 2 +- process/send-bz2-report | 2 +- process/sendreport.sh | 2 -- s/install | 2 +- s/setup | 50 +++++++++++++++++++++-------------------- scripts/run-turn.lua | 2 +- src/gmtool.c | 2 +- 7 files changed, 31 insertions(+), 31 deletions(-) diff --git a/conf/eressea.ini b/conf/eressea.ini index c745631ad..aed9c219c 100644 --- a/conf/eressea.ini +++ b/conf/eressea.ini @@ -1,5 +1,5 @@ [game] -email = eressea-server@kn-bremen.de +email = eressea-server@example.com sender = Eressea Server name = Eressea report = reports diff --git a/process/send-bz2-report b/process/send-bz2-report index f4b2ad6ea..2282a9f24 100755 --- a/process/send-bz2-report +++ b/process/send-bz2-report @@ -16,7 +16,7 @@ then shift fi -if [ "$1" == "-Lde" ] +if [ "$1" == "-Len" ] then TEMPLATE=report-mail.en.txt shift diff --git a/process/sendreport.sh b/process/sendreport.sh index 93d52f0b4..be643ef56 100755 --- a/process/sendreport.sh +++ b/process/sendreport.sh @@ -1,7 +1,5 @@ #!/bin/bash -## this script takes a backup of a turn. -## usage: backup.sh if [ -z $ERESSEA ]; then echo "You have to define the \$ERESSEA environment variable to run $0" diff --git a/s/install b/s/install index 5115ca8ee..cf72362c8 100755 --- a/s/install +++ b/s/install @@ -10,7 +10,7 @@ done if [ "$FORCE" != "yes" ] ; then BRANCH=$(git status -s -b | head -1 | cut -d\ -f 2 | sed 's/\..*//') if [ "$BRANCH" != "master" ] ; then - echo "you should only install stable versions from the master branch" + echo "You should only install stable versions from the master branch. Use -f to override." exit fi fi diff --git a/s/setup b/s/setup index adf4e0b85..77097d024 100755 --- a/s/setup +++ b/s/setup @@ -11,9 +11,9 @@ done ERESSEA=$(dirname $ROOT) function abort() { -echo $1 -[ -z $2 ] && exit -1 -exit $2 # otherwise + echo $1 + [ -z $2 ] && exit -1 + exit $2 # otherwise } function usage() { @@ -63,34 +63,36 @@ if [ -d $dir ] ; then [ $force -eq 1 ] || abort "$dir directory exists. Use -f to force" fi mkdir -p $dir -cd $dir || abort "could not chdir to game-$game" +cd $dir || abort "could not chdir to $dir" mkdir -p data reports function ini_sec() { -if [ $edit -eq 1 ]; then -$INIFILE eressea.ini add $1 -else -echo "[$1]" >> eressea.ini -fi + if [ $edit -eq 1 ]; then + $INIFILE eressea.ini add $1 + else + echo "[$1]" >> eressea.ini + fi } + function ini_add() { -if [ $edit -eq 1 ]; then -$INIFILE eressea.ini add $1:$2 $3 -else -echo "$2 = $3" >> eressea.ini -fi + if [ $edit -eq 1 ]; then + $INIFILE eressea.ini add $1:$2 $3 + else + echo "$2 = $3" >> eressea.ini + fi } + function ini_start() { -if [ -e eressea.ini ]; then -if [ ! -e $INIFILE ] && [ $edit -eq 1 ]; then -abort "missing editor for eressea.ini. use -n to create new file." -fi -rm -f eressea.ini -edit=0 -else -edit=0 -fi -touch eressea.ini + if [ -e eressea.ini ]; then + if [ ! -e $INIFILE ] && [ $edit -eq 1 ]; then + abort "missing editor for eressea.ini. use -n to create new file." + fi + rm -f eressea.ini + edit=0 + else + edit=0 + fi + touch eressea.ini } ini_start diff --git a/scripts/run-turn.lua b/scripts/run-turn.lua index 83d4045ac..34c1ea4fb 100644 --- a/scripts/run-turn.lua +++ b/scripts/run-turn.lua @@ -29,7 +29,7 @@ local function dbupdate() update_scores() if config.dbname then dbname = config.basepath..'/'..config.dbname - edb = db.open(dbame) + edb = db.open(dbname) if edb~=nil then edb:update_factions() edb:update_scores() diff --git a/src/gmtool.c b/src/gmtool.c index db556bb0a..30d80ba4a 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -859,7 +859,7 @@ static void select_regions(state * st, int selectmode) static void loaddata(state *st) { char datafile[MAX_PATH]; - askstring(st->wnd_status->handle, "save as:", datafile, sizeof(datafile)); + askstring(st->wnd_status->handle, "load from:", datafile, sizeof(datafile)); if (strlen(datafile) > 0) { readgame(datafile); st->modified = 0; From 0aa5a64c632537dae8b682b07b3a9db9ee9748d8 Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Tue, 14 Nov 2017 16:20:31 +0100 Subject: [PATCH 2/2] allow empty faction email --- src/creport.c | 6 +++--- src/json.c | 2 +- src/kernel/faction.c | 11 ++++++++--- src/kernel/faction.test.c | 31 +++++++++++++++++++++---------- src/kernel/save.c | 10 ++++++---- src/laws.c | 8 ++++---- src/modules/autoseed.c | 7 +++++-- src/monsters.c | 2 +- src/report.c | 21 +++++++++++++-------- src/reports.c | 8 ++++++-- src/sqlite.c | 5 +++-- src/util/goodies.c | 10 +++------- src/util/goodies.h | 2 +- 13 files changed, 75 insertions(+), 48 deletions(-) diff --git a/src/creport.c b/src/creport.c index 15e1791f6..9ef2b1e65 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1055,8 +1055,8 @@ static void cr_find_address(FILE * F, const faction * uf, selist * addresses) if (uf != f) { fprintf(F, "PARTEI %d\n", f->no); fprintf(F, "\"%s\";Parteiname\n", f->name); - if (f->email) - fprintf(F, "\"%s\";email\n", f->email); + if (strcmp(faction_getemail(f), "") != 0) + fprintf(F, "\"%s\";email\n", faction_getemail(f)); if (f->banner) fprintf(F, "\"%s\";banner\n", f->banner); fprintf(F, "\"%s\";locale\n", locale_name(f->locale)); @@ -1604,7 +1604,7 @@ report_computer(const char *filename, report_context * ctx, const char *bom) } fprintf(F, "\"%s\";Parteiname\n", f->name); - fprintf(F, "\"%s\";email\n", f->email); + fprintf(F, "\"%s\";email\n", faction_getemail(f)); if (f->banner) fprintf(F, "\"%s\";banner\n", f->banner); print_items(F, f->items, f->locale); diff --git a/src/json.c b/src/json.c index e6eacced9..127d74f70 100644 --- a/src/json.c +++ b/src/json.c @@ -102,7 +102,7 @@ int json_export(stream * out, int flags) { cJSON *data; cJSON_AddItemToObject(json, itoa36(f->no), data = cJSON_CreateObject()); cJSON_AddStringToObject(data, "name", f->name); - cJSON_AddStringToObject(data, "email", f->email); + cJSON_AddStringToObject(data, "email", faction_getemail(f)); cJSON_AddNumberToObject(data, "score", (double)f->score); } } diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 98e49bd84..00b62627f 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -229,8 +229,11 @@ faction *addfaction(const char *email, const char *password, faction *f = calloc(sizeof(faction), 1); char buf[128]; - if (set_email(&f->email, email) != 0) { - log_warning("Invalid email address for faction %s: %s\n", itoa36(f->no), email); + if (check_email(email) == 0) { + faction_setemail(f, email); + } else { + log_warning("Invalid email address for faction %s: %s\n", itoa36(f->no), email?email:""); + faction_setemail(f, NULL); } f->alliance_joindate = turn; @@ -544,6 +547,8 @@ void faction_setemail(faction * self, const char *email) free(self->email); if (email) self->email = strdup(email); + else + self->email = NULL; } const char *faction_getbanner(const faction * self) @@ -797,7 +802,7 @@ int writepasswd(void) for (f = factions; f; f = f->next) { fprintf(F, "%s:%s:%s:%d\n", - itoa36(f->no), f->email, f->_password, f->subscription); + itoa36(f->no), faction_getemail(f), f->_password, f->subscription); } fclose(F); return 0; diff --git a/src/kernel/faction.test.c b/src/kernel/faction.test.c index 7901cd96f..251f11bb9 100644 --- a/src/kernel/faction.test.c +++ b/src/kernel/faction.test.c @@ -225,17 +225,28 @@ static void test_valid_race(CuTest *tc) { } static void test_set_email(CuTest *tc) { - char * email = NULL; + faction *f; + char email[10]; test_setup(); - CuAssertIntEquals(tc, 0, set_email(&email, "enno@eressea.de")); - CuAssertStrEquals(tc, "enno@eressea.de", email); - CuAssertIntEquals(tc, 0, set_email(&email, "bugs@eressea.de")); - CuAssertStrEquals(tc, "bugs@eressea.de", email); - CuAssertIntEquals(tc, -1, set_email(&email, "bad@@eressea.de")); - CuAssertIntEquals(tc, -1, set_email(&email, "eressea.de")); - CuAssertIntEquals(tc, -1, set_email(&email, "eressea@")); - CuAssertStrEquals(tc, "bugs@eressea.de", email); - free(email); + CuAssertIntEquals(tc, 0, check_email("enno@eressea.de")); + CuAssertIntEquals(tc, 0, check_email("bugs@eressea.de")); + CuAssertIntEquals(tc, -1, check_email("bad@@eressea.de")); + CuAssertIntEquals(tc, -1, check_email("eressea.de")); + CuAssertIntEquals(tc, -1, check_email("eressea@")); + CuAssertIntEquals(tc, -1, check_email("")); + CuAssertIntEquals(tc, -1, check_email(NULL)); + f = test_create_faction(0); + + sprintf(email, "enno"); + faction_setemail(f, email); + email[0] = 0; + CuAssertStrEquals(tc, "enno", f->email); + CuAssertStrEquals(tc, "enno", faction_getemail(f)); + faction_setemail(f, "bugs@eressea.de"); + CuAssertStrEquals(tc, "bugs@eressea.de", f->email); + faction_setemail(f, NULL); + CuAssertPtrEquals(tc, 0, f->email); + CuAssertStrEquals(tc, "", faction_getemail(f)); test_cleanup(); } diff --git a/src/kernel/save.c b/src/kernel/save.c index aa09a27be..5617bc252 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1067,9 +1067,11 @@ faction *read_faction(gamedata * data) log_debug(" - Lese Partei %s (%s)", f->name, itoa36(f->no)); READ_STR(data->store, name, sizeof(name)); - if (set_email(&f->email, name) != 0) { - log_warning("Invalid email address for faction %s: %s", itoa36(f->no), name); - set_email(&f->email, ""); + if (check_email(name) == 0) { + faction_setemail(f, name); + } else { + log_warning("Invalid email address for faction %s: %s", itoa36(f->no), name); + faction_setemail(f, NULL); } read_password(data, f); @@ -1168,7 +1170,7 @@ void write_faction(gamedata *data, const faction * f) WRITE_STR(data->store, f->name); WRITE_STR(data->store, f->banner); - WRITE_STR(data->store, f->email); + WRITE_STR(data->store, f->email?f->email:""); write_password(data, f); WRITE_TOK(data->store, locale_name(f->locale)); WRITE_INT(data->store, f->lastorders); diff --git a/src/laws.c b/src/laws.c index 1f3633d14..215dbf0ec 100644 --- a/src/laws.c +++ b/src/laws.c @@ -2126,13 +2126,13 @@ int email_cmd(unit * u, struct order *ord) } else { faction *f = u->faction; - if (set_email(&f->email, s) != 0) { + if (check_email(s) == 0) { + faction_setemail(f, s); + ADDMSG(&f->msgs, msg_message("changemail", "value", faction_getemail(f))); + } else { log_error("Invalid email address for faction %s: %s\n", itoa36(f->no), s); ADDMSG(&f->msgs, msg_message("changemail_invalid", "value", s)); } - else { - ADDMSG(&f->msgs, msg_message("changemail", "value", f->email)); - } } return 0; } diff --git a/src/modules/autoseed.c b/src/modules/autoseed.c index 52a5344cc..fd9ef2f19 100644 --- a/src/modules/autoseed.c +++ b/src/modules/autoseed.c @@ -171,7 +171,7 @@ newfaction *read_newfactions(const char *filename) sz += strlcat(password, itoa36(rng_int()), sizeof(password)); } for (f = factions; f; f = f->next) { - if (strcmp(f->email, email) == 0 && f->age < MINAGE_MULTI) { + if (strcmp(faction_getemail(f), email) == 0 && f->age < MINAGE_MULTI) { log_warning("email %s already in use by %s", email, factionname(f)); break; } @@ -188,7 +188,9 @@ newfaction *read_newfactions(const char *filename) continue; } nf = calloc(sizeof(newfaction), 1); - if (set_email(&nf->email, email) != 0) { + if (check_email(email) == 0) { + nf->email = strdup(email); + } else { log_error("Invalid email address for subscription %s: %s\n", itoa36(subscription), email); free(nf); continue; @@ -619,6 +621,7 @@ int autoseed(newfaction ** players, int nsize, int max_agediff) while (*nfp) { newfaction *nf = *nfp; if (strcmp(nextf->email, nf->email) == 0) { + log_warning("Duplicate email %s\n", nf->email?nf->email:""); *nfp = nf->next; free_newfaction(nf); } diff --git a/src/monsters.c b/src/monsters.c index 115759d29..6c0304f55 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -1132,7 +1132,7 @@ faction *get_or_create_monsters(void) if (!f) { const race *rc = rc_get_or_create("dragon"); const char *email = config_get("monster.email"); - f = addfaction(email ? email : NULL, NULL, rc, default_locale, 0); + f = addfaction(email, NULL, rc, default_locale, 0); renumber_faction(f, MONSTER_ID); faction_setname(f, "Monster"); fset(f, FFL_NPC | FFL_NOIDLEOUT); diff --git a/src/report.c b/src/report.c index 4e5eef98b..f99d6db12 100644 --- a/src/report.c +++ b/src/report.c @@ -1753,7 +1753,7 @@ static void list_address(struct stream *out, const faction * uf, selist * seenfa char buf[8192]; char label = '-'; - sprintf(buf, "%s: %s; %s", factionname(f), f->email, + sprintf(buf, "%s: %s; %s", factionname(f), faction_getemail(f), f->banner ? f->banner : ""); if (uf == f) label = '*'; @@ -2078,7 +2078,7 @@ report_plaintext(const char *filename, report_context * ctx, newline(out); sprintf(buf, "%s, %s/%s (%s)", factionname(f), LOC(f->locale, rc_name_s(f->race, NAME_PLURAL)), - LOC(f->locale, mkname("school", magic_school[f->magiegebiet])), f->email); + LOC(f->locale, mkname("school", magic_school[f->magiegebiet])), faction_getemail(f)); centre(out, buf, true); if (f_get_alliance(f)) { centre(out, alliancename(f->alliance), true); @@ -2088,12 +2088,17 @@ report_plaintext(const char *filename, report_context * ctx, const char *email; const char *subject; email = config_get("game.email"); - subject = get_mailcmd(f->locale); - m = msg_message("newbie_info_game", "email subject", email, subject); - if (m) { - nr_render(m, f->locale, buf, sizeof(buf), f); - msg_release(m); - centre(out, buf, true); + if (!email) + log_error("game.email not set"); + else { + subject = get_mailcmd(f->locale); + + m = msg_message("newbie_info_game", "email subject", email, subject); + if (m) { + nr_render(m, f->locale, buf, sizeof(buf), f); + msg_release(m); + centre(out, buf, true); + } } if ((f->options & want(O_COMPUTER)) == 0) { const char *s; diff --git a/src/reports.c b/src/reports.c index 1591de637..b474f32ed 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1560,8 +1560,12 @@ static void write_script(FILE * F, const faction * f) { report_type *rtype; char buf[1024]; - - fprintf(F, "faction=%s:email=%s:lang=%s", itoa36(f->no), f->email, + + if (check_email(faction_getemail(f)) != 0) { + return; + } + + fprintf(F, "faction=%s:email=%s:lang=%s", itoa36(f->no), faction_getemail(f), locale_name(f->locale)); if (f->options & (1 << O_BZIP2)) fputs(":compression=bz2", F); diff --git a/src/sqlite.c b/src/sqlite.c index edb5bfc62..970032f35 100644 --- a/src/sqlite.c +++ b/src/sqlite.c @@ -144,7 +144,8 @@ static bool db_faction_cb(void *el, void *arg) { struct cb_data *cb = (struct cb_data *)arg; const faction *f = cb->f; - if (f->no == df->no || strcmp(f->email, df->email) == 0 || strcmp(f->name, df->name) == 0) { + /* FIXME comparing name and email is inaccurate ... */ + if (f->no == df->no || strcmp(faction_getemail(f), df->email?df->email:"") == 0 || strcmp(f->name, df->name) == 0) { cb->dbf = df; } if (f->subscription == df->uid) { @@ -172,7 +173,7 @@ int db_update_factions(sqlite3 * db, bool force, int game_id) { log_warning("faction %s(%d) not found in database, but matches %d\n", itoa36(f->no), f->subscription, dbf->uid); f->subscription = dbf->uid; } - update = (dbf->no != f->no) || (strcmp(f->email, dbf->email) != 0) || (strcmp(f->name, dbf->name) != 0); + update = (dbf->no != f->no) || (strcmp(faction_getemail(f), dbf->email?dbf->email:"") != 0) || (strcmp(f->name, dbf->name) != 0); } else { f->subscription = insert_faction(db, game_id, f); diff --git a/src/util/goodies.c b/src/util/goodies.c index 0794240d5..fcfaa1013 100644 --- a/src/util/goodies.c +++ b/src/util/goodies.c @@ -109,17 +109,13 @@ static int spc_email_isvalid(const char *address) return (count >= 1); } -int set_email(char **pemail, const char *newmail) +int check_email(const char *newmail) { if (newmail && *newmail) { if (spc_email_isvalid(newmail) <= 0) return -1; - } - if (*pemail) - free(*pemail); - *pemail = 0; - if (newmail) { - *pemail = strdup(newmail); + } else { + return -1; } return 0; } diff --git a/src/util/goodies.h b/src/util/goodies.h index c619c4958..bb3a372f6 100644 --- a/src/util/goodies.h +++ b/src/util/goodies.h @@ -23,7 +23,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif - int set_email(char **pemail, const char *newmail); + int check_email(const char *newmail); int *intlist_init(void); int *intlist_add(int *i_p, int i);