From 90cd77c586e4e7d08c9e43224940ff969b5185a8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 26 Apr 2019 18:56:38 +0200 Subject: [PATCH 01/10] preview gets games as arguments, game 4 is over --- process/cron/preview.cron | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/process/cron/preview.cron b/process/cron/preview.cron index eb39fd8f8..63fe2ca76 100755 --- a/process/cron/preview.cron +++ b/process/cron/preview.cron @@ -1,17 +1,17 @@ #!/bin/bash ( [ "$PREVIEW" != "yes" ] && exit -[ -z ${ERESSEA} ] && ERESSEA=$HOME/eressea +[ -z "${ERESSEA}" ] && ERESSEA="$HOME/eressea" branch="develop" -if [ -e ${ERESSEA}/build/.preview ]; then - branch=`cat ${ERESSEA}/build/.preview` +if [ -e "${ERESSEA}/build/.preview" ]; then + branch=$(cat "${ERESSEA}/build/.preview") fi -SRC=${ERESSEA}/git -${SRC}/s/preview build ${branch} || exit $? -for game in 2 3 4 ; do - ${SRC}/s/preview -g ${game} run && \ - ${SRC}/s/preview -g ${game} send +SRC="${ERESSEA}/git" +"${SRC}/s/preview" build "$branch" || exit $? +for game in "$@" ; do + "${SRC}/s/preview" -g "$game" run && \ + "${SRC}/s/preview" -g "$game" send done -) | tee -a $HOME/log/preview.cron.log +) | tee -a "$HOME/log/preview.cron.log" From 8c0fc4bd918610edabded2bb2da3c92f164aeaa2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 30 Apr 2019 18:56:37 +0200 Subject: [PATCH 02/10] 2577: Fix resource values, again. --- src/kernel/gamedata.h | 3 ++- src/kernel/save.c | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/kernel/gamedata.h b/src/kernel/gamedata.h index 986b13d1d..64732b7fc 100644 --- a/src/kernel/gamedata.h +++ b/src/kernel/gamedata.h @@ -42,8 +42,9 @@ #define FAMILIAR_FIXMAGE_VERSION 364 /* familiar links are fixed */ #define FAMILIAR_FIXSPELLBOOK_VERSION 365 /* familiar spells are fixed */ #define FIX_STARTLEVEL_VERSION 366 /* fixing resource startlevels */ +#define FIX_RES_BASE_VERSION 367 /* fixing resource base */ -#define RELEASE_VERSION FIX_STARTLEVEL_VERSION /* current datafile */ +#define RELEASE_VERSION FIX_RES_BASE_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 */ diff --git a/src/kernel/save.c b/src/kernel/save.c index 0b3ade593..f5e66162b 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -613,7 +613,7 @@ static void read_regioninfo(gamedata *data, const region *r, char *info, size_t } } -static void fix_baselevel(region *r) { +static void fix_resource_levels(region *r) { struct terrain_production *p; for (p = r->terrain->production; p->type; ++p) { char *end; @@ -634,6 +634,27 @@ static void fix_baselevel(region *r) { } } +static void fix_resource_bases(region *r) { + struct terrain_production *p; + for (p = r->terrain->production; p->type; ++p) { + char *end; + long base = (int)strtol(p->base, &end, 10); + if (*end == '\0') { + rawmaterial *res; + for (res = r->resources; res; res = res->next) { + if (p->type == res->rtype) { + if (base != res->base) { + log_debug("setting resource base for %s in %s to %d", + res->rtype->_name, regionname(r, NULL), base); + res->base = base; + } + } + } + } + + } +} + static region *readregion(gamedata *data, int x, int y) { region *r; @@ -803,9 +824,15 @@ static region *readregion(gamedata *data, int x, int y) } read_attribs(data, &r->attribs, r); - if (r->resources && data->version < FIX_STARTLEVEL_VERSION) { - /* we had some badly made rawmaterials before this */ - fix_baselevel(r); + if (r->resources) { + if (data->version < FIX_STARTLEVEL_VERSION) { + /* we had some badly made rawmaterials before this */ + fix_resource_levels(r); + } + if (data->version < FIX_RES_BASE_VERSION) { + /* we had some badly made rawmaterials before this */ + fix_resource_bases(r); + } } return r; } From 5cde26e25ea7eecb90ca2806285f47c28703f27e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 26 Apr 2019 18:56:38 +0200 Subject: [PATCH 03/10] preview gets games as arguments, game 4 is over --- process/cron/preview.cron | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/process/cron/preview.cron b/process/cron/preview.cron index eb39fd8f8..63fe2ca76 100755 --- a/process/cron/preview.cron +++ b/process/cron/preview.cron @@ -1,17 +1,17 @@ #!/bin/bash ( [ "$PREVIEW" != "yes" ] && exit -[ -z ${ERESSEA} ] && ERESSEA=$HOME/eressea +[ -z "${ERESSEA}" ] && ERESSEA="$HOME/eressea" branch="develop" -if [ -e ${ERESSEA}/build/.preview ]; then - branch=`cat ${ERESSEA}/build/.preview` +if [ -e "${ERESSEA}/build/.preview" ]; then + branch=$(cat "${ERESSEA}/build/.preview") fi -SRC=${ERESSEA}/git -${SRC}/s/preview build ${branch} || exit $? -for game in 2 3 4 ; do - ${SRC}/s/preview -g ${game} run && \ - ${SRC}/s/preview -g ${game} send +SRC="${ERESSEA}/git" +"${SRC}/s/preview" build "$branch" || exit $? +for game in "$@" ; do + "${SRC}/s/preview" -g "$game" run && \ + "${SRC}/s/preview" -g "$game" send done -) | tee -a $HOME/log/preview.cron.log +) | tee -a "$HOME/log/preview.cron.log" From 505ad39ddfdf3927f0962300807cfc1a52ad66de Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 30 Apr 2019 19:00:03 +0200 Subject: [PATCH 04/10] coverity cert hack --- s/coverity | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/s/coverity b/s/coverity index 3d218adb7..01bb2a042 100755 --- a/s/coverity +++ b/s/coverity @@ -6,7 +6,7 @@ cd Debug make clean ../../coverity/bin/cov-build --dir cov-int make eressea tar czf eressea.tgz cov-int -curl --form token=IISXKH3A1ngZGfFmBz_aSA \ +curl -k --form token=IISXKH3A1ngZGfFmBz_aSA \ --form email=enno.rehling@gmail.com \ --form file=@eressea.tgz \ --form version="$VERSION" \ From b20e6972a5e968dccfc034a1768e94cbc2bc5ead Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 4 May 2019 16:21:03 +0200 Subject: [PATCH 05/10] write accepted orders to database --- process/accept-orders.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/process/accept-orders.py b/process/accept-orders.py index 237184861..08f4e27de 100755 --- a/process/accept-orders.py +++ b/process/accept-orders.py @@ -57,6 +57,9 @@ sendmail = True maxfiles = 30 # write headers to file? writeheaders = True +# write received files to datrabase? +tooldir = os.path.join(rootdir, orderbase) +writedb = os.path.exists(tooldir) # reject all html email? rejecthtml = True @@ -225,16 +228,20 @@ def write_part(outfile, part): def copy_orders(message, filename, sender): # print the header first + dirname, basename = split(filename) if writeheaders: - from os.path import split - dirname, basename = split(filename) - dirname = dirname + '/headers' - if not os.path.exists(dirname): os.mkdir(dirname) - outfile = open(dirname + '/' + basename, "w") + header_dir = dirname + '/headers' + if not os.path.exists(header_dir): os.mkdir(header_dir) + outfile = open(header_dir + '/' + basename, "w") for name, value in message.items(): outfile.write(name + ": " + value + "\n") outfile.close() + if writedb: + cli = os.path.join(tooldir, 'cli.php'); + dbname = os.path.join(dirname, 'orders.db') + subprocess.call(['php', cli, '-d', dbname, 'insert', basename]) + found = False outfile = open(filename, "w") if message.is_multipart(): From 11b628d092a78c823bad1d82ecf08506bf727946 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 4 May 2019 17:37:11 +0200 Subject: [PATCH 06/10] use the orders databse script if it exists --- process/accept-orders.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/process/accept-orders.py b/process/accept-orders.py index 08f4e27de..31b8f3abd 100755 --- a/process/accept-orders.py +++ b/process/accept-orders.py @@ -13,7 +13,7 @@ import logging import sys import subprocess from sys import stdin -from time import ctime, sleep, time +import time from socket import gethostname from rfc822 import parsedate_tz, mktime_tz @@ -58,7 +58,7 @@ maxfiles = 30 # write headers to file? writeheaders = True # write received files to datrabase? -tooldir = os.path.join(rootdir, orderbase) +tooldir = os.path.join(rootdir, 'orders-php') writedb = os.path.exists(tooldir) # reject all html email? rejecthtml = True @@ -226,9 +226,9 @@ def write_part(outfile, part): outfile.write("\n"); return True -def copy_orders(message, filename, sender): - # print the header first - dirname, basename = split(filename) +def copy_orders(message, filename, sender, mtime): + # print the header first + dirname, basename = os.path.split(filename) if writeheaders: header_dir = dirname + '/headers' if not os.path.exists(header_dir): os.mkdir(header_dir) @@ -238,9 +238,11 @@ def copy_orders(message, filename, sender): outfile.close() if writedb: + dirname, basename = os.path.split(filename) cli = os.path.join(tooldir, 'cli.php'); dbname = os.path.join(dirname, 'orders.db') - subprocess.call(['php', cli, '-d', dbname, 'insert', basename]) + datestr = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(mtime)) + subprocess.call(['php', cli, '-d', dbname, 'insert', basename, sender, datestr]) found = False outfile = open(filename, "w") @@ -290,18 +292,23 @@ def accept(game, locale, stream, extend=None): logger.warning("more than " + str(maxfiles) + " orders from " + email) return -1 # copy the orders to the file - text_ok = copy_orders(message, filename, email) - - warning, msg, fail = None, "", False + + turndate = None maildate = message.get("Date") - if maildate != None: + if maildate is None: + turndate = time.time() + else: turndate = mktime_tz(parsedate_tz(maildate)) + + text_ok = copy_orders(message, filename, email, turndate) + warning, msg, fail = None, "", False + if not maildate is None: os.utime(filename, (turndate, turndate)) logger.debug("mail date is '%s' (%d)" % (maildate, turndate)) if False and turndate < maxdate: logger.warning("inconsistent message date " + email) warning = " (" + messages["warning-" + locale] + ")" - msg = msg + formatpar(messages["maildate-" + locale] % (ctime(maxdate),ctime(turndate)), 76, 2) + "\n" + msg = msg + formatpar(messages["maildate-" + locale] % (time.ctime(maxdate), time.ctime(turndate)), 76, 2) + "\n" else: logger.warning("missing message date " + email) warning = " (" + messages["warning-" + locale] + ")" From 305098c32c768bc9afd34a7ffd2b0a86b9eaf8f2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 7 May 2019 19:46:22 +0200 Subject: [PATCH 07/10] do not pollute global namespace with import statements --- process/accept-orders.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/process/accept-orders.py b/process/accept-orders.py index 31b8f3abd..b0acbe0e1 100755 --- a/process/accept-orders.py +++ b/process/accept-orders.py @@ -1,21 +1,19 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from email.Utils import parseaddr -from email.Parser import Parser import os import os.path import ConfigParser -from re import compile, IGNORECASE -from stat import ST_MTIME -from string import upper, split, replace +import string import logging import sys import subprocess -from sys import stdin import time -from socket import gethostname -from rfc822 import parsedate_tz, mktime_tz +import socket +import rfc822 +from stat import ST_MTIME +from email.Utils import parseaddr +from email.Parser import Parser if 'ERESSEA' in os.environ: dir = os.environ['ERESSEA'] @@ -50,14 +48,14 @@ else: sender = "%s Server <%s>" % (gamename, frommail) config = None prefix = 'turn-' -hostname = gethostname() +hostname = socket.gethostname() orderbase = "orders.dir" sendmail = True # maximum number of reports per sender: maxfiles = 30 # write headers to file? writeheaders = True -# write received files to datrabase? +# write received files to database? tooldir = os.path.join(rootdir, 'orders-php') writedb = os.path.exists(tooldir) # reject all html email? @@ -180,7 +178,7 @@ def available_file(dirname, basename): return maxdate, filename def formatpar(string, l=76, indent=2): - words = split(string) + words = string.split(string) res = "" ll = 0 first = 1 @@ -298,7 +296,7 @@ def accept(game, locale, stream, extend=None): if maildate is None: turndate = time.time() else: - turndate = mktime_tz(parsedate_tz(maildate)) + turndate = rfc822.mktime_tz(rfc822.parsedate_tz(maildate)) text_ok = copy_orders(message, filename, email, turndate) warning, msg, fail = None, "", False @@ -354,10 +352,10 @@ logging.basicConfig(level=logging.DEBUG, filename=LOG_FILENAME) logger = logging delay = None # TODO: parse the turn delay locale = sys.argv[2] -infile = stdin +infile = sys.stdin if len(sys.argv)>3: infile = open(sys.argv[3], "r") retval = accept(game, locale, infile, delay) -if infile!=stdin: +if infile!=sys.stdin: infile.close() sys.exit(retval) From 32da0028c1b6721029b7186b5d51a5ad97548616 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 7 May 2019 21:45:10 +0200 Subject: [PATCH 08/10] write to database after the file is created and dated --- process/accept-orders.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/process/accept-orders.py b/process/accept-orders.py index b0acbe0e1..8dd088c40 100755 --- a/process/accept-orders.py +++ b/process/accept-orders.py @@ -235,13 +235,6 @@ def copy_orders(message, filename, sender, mtime): outfile.write(name + ": " + value + "\n") outfile.close() - if writedb: - dirname, basename = os.path.split(filename) - cli = os.path.join(tooldir, 'cli.php'); - dbname = os.path.join(dirname, 'orders.db') - datestr = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(mtime)) - subprocess.call(['php', cli, '-d', dbname, 'insert', basename, sender, datestr]) - found = False outfile = open(filename, "w") if message.is_multipart(): @@ -262,6 +255,7 @@ def copy_orders(message, filename, sender, mtime): charset = message.get_content_charset() logger.error("could not write text/plain message (charset=%s) for %s" % (charset, sender)) outfile.close() + return found # create a file, containing: @@ -312,6 +306,12 @@ def accept(game, locale, stream, extend=None): warning = " (" + messages["warning-" + locale] + ")" msg = msg + formatpar(messages["nodate-" + locale], 76, 2) + "\n" + if writedb: + dirname, basename = os.path.split(filename) + cli = os.path.join(tooldir, 'cli.php'); + dbname = os.path.join(dirname, 'orders.db') + subprocess.call(['php', cli, '-d', dbname, 'insert', basename, email]) + if not text_ok: warning = " (" + messages["error-" + locale] + ")" msg = msg + formatpar(messages["multipart-" + locale], 76, 2) + "\n" From 85a7066ecc7a250931c4cfc784742f9ba55a1c74 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 8 May 2019 18:23:19 +0200 Subject: [PATCH 09/10] move php calls from python to shell script --- process/accept-orders.py | 10 ++-------- process/orders-accept | 27 ++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/process/accept-orders.py b/process/accept-orders.py index 8dd088c40..5a7124d43 100755 --- a/process/accept-orders.py +++ b/process/accept-orders.py @@ -55,9 +55,6 @@ sendmail = True maxfiles = 30 # write headers to file? writeheaders = True -# write received files to database? -tooldir = os.path.join(rootdir, 'orders-php') -writedb = os.path.exists(tooldir) # reject all html email? rejecthtml = True @@ -306,11 +303,8 @@ def accept(game, locale, stream, extend=None): warning = " (" + messages["warning-" + locale] + ")" msg = msg + formatpar(messages["nodate-" + locale], 76, 2) + "\n" - if writedb: - dirname, basename = os.path.split(filename) - cli = os.path.join(tooldir, 'cli.php'); - dbname = os.path.join(dirname, 'orders.db') - subprocess.call(['php', cli, '-d', dbname, 'insert', basename, email]) + print('ACCEPT_MAIL=' + email) + print('ACCEPT_FILE="' + filename + '"') if not text_ok: warning = " (" + messages["error-" + locale] + ")" diff --git a/process/orders-accept b/process/orders-accept index 33b3d5ecc..0873352e0 100755 --- a/process/orders-accept +++ b/process/orders-accept @@ -1,8 +1,25 @@ #!/bin/sh -SCRIPT=$(readlink -f $0) -cd $(dirname $SCRIPT) +# example: orders-accept 2 de < mail.txt -lockfile -r3 -l120 orders.queue.lock -python accept-orders.py "$@" -rm -f orders.queue.lock +game="$1" +[ -z "$ERESSEA" ] && ERESSEA="$HOME/eressea" +SCRIPT=$(readlink -f "$0") +BIN=$(dirname "$SCRIPT") + +LOCKFILE="$ERESSEA/game-$game/orders.queue.lock" +set -e +trap 'rm -f "$LOCKFILE"' EXIT + +cd "$ERESSEA/game-$game" +mkdir -p orders.dir +cd orders.dir +lockfile -r3 -l120 "$LOCKFILE" +eval "$(python "$BIN/accept-orders.py" "$@")" +filename=$(basename "$ACCEPT_FILE") +email="$ACCEPT_MAIL" +if [ -d "$ERESSEA/orders-php" ] +then + php "$ERESSEA/orders-php/cli.php" insert "$filename" "$email" +fi +rm -f "$LOCKFILE" From ef90806ca0060c930b0167d45c9d5d28fca477be Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 8 May 2019 21:08:14 +0200 Subject: [PATCH 10/10] hold lockfile only during python script --- process/orders-accept | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/process/orders-accept b/process/orders-accept index 0873352e0..99398e64f 100755 --- a/process/orders-accept +++ b/process/orders-accept @@ -16,10 +16,10 @@ mkdir -p orders.dir cd orders.dir lockfile -r3 -l120 "$LOCKFILE" eval "$(python "$BIN/accept-orders.py" "$@")" +rm -f "$LOCKFILE" filename=$(basename "$ACCEPT_FILE") email="$ACCEPT_MAIL" if [ -d "$ERESSEA/orders-php" ] then php "$ERESSEA/orders-php/cli.php" insert "$filename" "$email" fi -rm -f "$LOCKFILE"