Merge branch 'master' into develop

This commit is contained in:
Enno Rehling 2019-05-08 21:09:39 +02:00
commit 7a59a11c20
6 changed files with 97 additions and 46 deletions

View file

@ -1,21 +1,19 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from email.Utils import parseaddr
from email.Parser import Parser
import os import os
import os.path import os.path
import ConfigParser import ConfigParser
from re import compile, IGNORECASE import string
from stat import ST_MTIME
from string import upper, split, replace
import logging import logging
import sys import sys
import subprocess import subprocess
from sys import stdin import time
from time import ctime, sleep, time import socket
from socket import gethostname import rfc822
from rfc822 import parsedate_tz, mktime_tz from stat import ST_MTIME
from email.Utils import parseaddr
from email.Parser import Parser
if 'ERESSEA' in os.environ: if 'ERESSEA' in os.environ:
dir = os.environ['ERESSEA'] dir = os.environ['ERESSEA']
@ -50,7 +48,7 @@ else:
sender = "%s Server <%s>" % (gamename, frommail) sender = "%s Server <%s>" % (gamename, frommail)
config = None config = None
prefix = 'turn-' prefix = 'turn-'
hostname = gethostname() hostname = socket.gethostname()
orderbase = "orders.dir" orderbase = "orders.dir"
sendmail = True sendmail = True
# maximum number of reports per sender: # maximum number of reports per sender:
@ -177,7 +175,7 @@ def available_file(dirname, basename):
return maxdate, filename return maxdate, filename
def formatpar(string, l=76, indent=2): def formatpar(string, l=76, indent=2):
words = split(string) words = string.split(string)
res = "" res = ""
ll = 0 ll = 0
first = 1 first = 1
@ -223,14 +221,13 @@ def write_part(outfile, part):
outfile.write("\n"); outfile.write("\n");
return True return True
def copy_orders(message, filename, sender): def copy_orders(message, filename, sender, mtime):
# print the header first # print the header first
dirname, basename = os.path.split(filename)
if writeheaders: if writeheaders:
from os.path import split header_dir = dirname + '/headers'
dirname, basename = split(filename) if not os.path.exists(header_dir): os.mkdir(header_dir)
dirname = dirname + '/headers' outfile = open(header_dir + '/' + basename, "w")
if not os.path.exists(dirname): os.mkdir(dirname)
outfile = open(dirname + '/' + basename, "w")
for name, value in message.items(): for name, value in message.items():
outfile.write(name + ": " + value + "\n") outfile.write(name + ": " + value + "\n")
outfile.close() outfile.close()
@ -255,6 +252,7 @@ def copy_orders(message, filename, sender):
charset = message.get_content_charset() charset = message.get_content_charset()
logger.error("could not write text/plain message (charset=%s) for %s" % (charset, sender)) logger.error("could not write text/plain message (charset=%s) for %s" % (charset, sender))
outfile.close() outfile.close()
return found return found
# create a file, containing: # create a file, containing:
@ -283,23 +281,31 @@ def accept(game, locale, stream, extend=None):
logger.warning("more than " + str(maxfiles) + " orders from " + email) logger.warning("more than " + str(maxfiles) + " orders from " + email)
return -1 return -1
# copy the orders to the file # copy the orders to the file
text_ok = copy_orders(message, filename, email)
turndate = None
warning, msg, fail = None, "", False
maildate = message.get("Date") maildate = message.get("Date")
if maildate != None: if maildate is None:
turndate = mktime_tz(parsedate_tz(maildate)) turndate = time.time()
else:
turndate = rfc822.mktime_tz(rfc822.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)) os.utime(filename, (turndate, turndate))
logger.debug("mail date is '%s' (%d)" % (maildate, turndate)) logger.debug("mail date is '%s' (%d)" % (maildate, turndate))
if False and turndate < maxdate: if False and turndate < maxdate:
logger.warning("inconsistent message date " + email) logger.warning("inconsistent message date " + email)
warning = " (" + messages["warning-" + locale] + ")" 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: else:
logger.warning("missing message date " + email) logger.warning("missing message date " + email)
warning = " (" + messages["warning-" + locale] + ")" warning = " (" + messages["warning-" + locale] + ")"
msg = msg + formatpar(messages["nodate-" + locale], 76, 2) + "\n" msg = msg + formatpar(messages["nodate-" + locale], 76, 2) + "\n"
print('ACCEPT_MAIL=' + email)
print('ACCEPT_FILE="' + filename + '"')
if not text_ok: if not text_ok:
warning = " (" + messages["error-" + locale] + ")" warning = " (" + messages["error-" + locale] + ")"
msg = msg + formatpar(messages["multipart-" + locale], 76, 2) + "\n" msg = msg + formatpar(messages["multipart-" + locale], 76, 2) + "\n"
@ -340,10 +346,10 @@ logging.basicConfig(level=logging.DEBUG, filename=LOG_FILENAME)
logger = logging logger = logging
delay = None # TODO: parse the turn delay delay = None # TODO: parse the turn delay
locale = sys.argv[2] locale = sys.argv[2]
infile = stdin infile = sys.stdin
if len(sys.argv)>3: if len(sys.argv)>3:
infile = open(sys.argv[3], "r") infile = open(sys.argv[3], "r")
retval = accept(game, locale, infile, delay) retval = accept(game, locale, infile, delay)
if infile!=stdin: if infile!=sys.stdin:
infile.close() infile.close()
sys.exit(retval) sys.exit(retval)

View file

@ -1,17 +1,17 @@
#!/bin/bash #!/bin/bash
( (
[ "$PREVIEW" != "yes" ] && exit [ "$PREVIEW" != "yes" ] && exit
[ -z ${ERESSEA} ] && ERESSEA=$HOME/eressea [ -z "${ERESSEA}" ] && ERESSEA="$HOME/eressea"
branch="develop" branch="develop"
if [ -e ${ERESSEA}/build/.preview ]; then if [ -e "${ERESSEA}/build/.preview" ]; then
branch=`cat ${ERESSEA}/build/.preview` branch=$(cat "${ERESSEA}/build/.preview")
fi fi
SRC=${ERESSEA}/git SRC="${ERESSEA}/git"
${SRC}/s/preview build ${branch} || exit $? "${SRC}/s/preview" build "$branch" || exit $?
for game in 2 3 4 ; do for game in "$@" ; do
${SRC}/s/preview -g ${game} run && \ "${SRC}/s/preview" -g "$game" run && \
${SRC}/s/preview -g ${game} send "${SRC}/s/preview" -g "$game" send
done done
) | tee -a $HOME/log/preview.cron.log ) | tee -a "$HOME/log/preview.cron.log"

View file

@ -1,8 +1,25 @@
#!/bin/sh #!/bin/sh
SCRIPT=$(readlink -f $0) # example: orders-accept 2 de < mail.txt
cd $(dirname $SCRIPT)
lockfile -r3 -l120 orders.queue.lock game="$1"
python accept-orders.py "$@"
rm -f orders.queue.lock
[ -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" "$@")"
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

View file

@ -6,7 +6,7 @@ cd Debug
make clean make clean
../../coverity/bin/cov-build --dir cov-int make eressea ../../coverity/bin/cov-build --dir cov-int make eressea
tar czf eressea.tgz cov-int tar czf eressea.tgz cov-int
curl --form token=IISXKH3A1ngZGfFmBz_aSA \ curl -k --form token=IISXKH3A1ngZGfFmBz_aSA \
--form email=enno.rehling@gmail.com \ --form email=enno.rehling@gmail.com \
--form file=@eressea.tgz \ --form file=@eressea.tgz \
--form version="$VERSION" \ --form version="$VERSION" \

View file

@ -42,7 +42,8 @@
#define FAMILIAR_FIXMAGE_VERSION 364 /* familiar links are fixed */ #define FAMILIAR_FIXMAGE_VERSION 364 /* familiar links are fixed */
#define FAMILIAR_FIXSPELLBOOK_VERSION 365 /* familiar spells are fixed */ #define FAMILIAR_FIXSPELLBOOK_VERSION 365 /* familiar spells are fixed */
#define FIX_STARTLEVEL_VERSION 366 /* fixing resource startlevels */ #define FIX_STARTLEVEL_VERSION 366 /* fixing resource startlevels */
#define FIX_CLONES_VERSION 367 /* dissolve clones */ #define FIX_RES_BASE_VERSION 367 /* fixing resource base */
#define FIX_CLONES_VERSION 368 /* dissolve clones */
#define RELEASE_VERSION FIX_CLONES_VERSION /* current datafile */ #define RELEASE_VERSION FIX_CLONES_VERSION /* current datafile */
#define MIN_VERSION UIDHASH_VERSION /* minimal datafile we support */ #define MIN_VERSION UIDHASH_VERSION /* minimal datafile we support */

View file

@ -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; struct terrain_production *p;
for (p = r->terrain->production; p->type; ++p) { for (p = r->terrain->production; p->type; ++p) {
char *end; 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) static region *readregion(gamedata *data, int x, int y)
{ {
region *r; region *r;
@ -803,9 +824,15 @@ static region *readregion(gamedata *data, int x, int y)
} }
read_attribs(data, &r->attribs, r); read_attribs(data, &r->attribs, r);
if (r->resources && data->version < FIX_STARTLEVEL_VERSION) { if (r->resources) {
/* we had some badly made rawmaterials before this */ if (data->version < FIX_STARTLEVEL_VERSION) {
fix_baselevel(r); /* 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; return r;
} }