rename [eressea] section to [game]

This commit is contained in:
Enno Rehling 2017-01-20 18:44:58 +01:00 committed by Enno Rehling
parent d7dd281a6a
commit 6d5749308d
5 changed files with 102 additions and 77 deletions

View File

@ -1,8 +1,7 @@
[game] [game]
email = Eressea Server <eressea-server@kn-bremen.de> email = eressea-server@kn-bremen.de
sender = Eressea Server
name = Eressea name = Eressea
[eressea]
base = . base = .
report = reports report = reports
verbose = 0 verbose = 0

View File

@ -27,13 +27,12 @@ if not os.path.isdir(dir):
sys.exit(1) sys.exit(1)
rootdir = dir rootdir = dir
try:
game = int(sys.argv[1]) game = int(sys.argv[1])
except:
game = sys.argv[1]
gamedir = os.path.join(rootdir, "game-%d" % (game, )) gamedir = os.path.join(rootdir, "game-%d" % (game, ))
frommail = 'Eressea Server <eressea-server@eressea.kn-bremen.de>' frommail = 'eressea-server@kn-bremen.de'
gamename = 'Eressea' gamename = 'Eressea'
sender = '%s Server <%s>' % (gamename, frommail)
inifile = os.path.join(gamedir, 'eressea.ini') inifile = os.path.join(gamedir, 'eressea.ini')
if not os.path.exists(inifile): if not os.path.exists(inifile):
print "no such file: " . inifile print "no such file: " . inifile
@ -44,6 +43,10 @@ else:
frommail = config.get('game', 'email') frommail = config.get('game', 'email')
if config.has_option('game', 'name'): if config.has_option('game', 'name'):
gamename = config.get('game', 'name') gamename = config.get('game', 'name')
if config.has_option('game', 'sender'):
sender = config.get('game', 'sender')
else:
sender = "%s Server <%s>" % (gamename, frommail)
config = None config = None
prefix = 'turn-' prefix = 'turn-'
hostname = gethostname() hostname = gethostname()
@ -278,7 +281,7 @@ def copy_orders(message, filename, sender):
# create a file, containing: # create a file, containing:
# game=0 locale=de file=/path/to/filename email=rcpt@domain.to # game=0 locale=de file=/path/to/filename email=rcpt@domain.to
def accept(game, locale, stream, extend=None): def accept(game, locale, stream, extend=None):
global rootdir, orderbase, gamedir, gamename, frommail global rootdir, orderbase, gamedir, gamename, sender
if extend is not None: if extend is not None:
orderbase = orderbase + ".pre-" + extend orderbase = orderbase + ".pre-" + extend
savedir = os.path.join(gamedir, orderbase) savedir = os.path.join(gamedir, orderbase)
@ -288,21 +291,21 @@ def accept(game, locale, stream, extend=None):
if not os.path.exists(savedir): os.mkdir(savedir) if not os.path.exists(savedir): os.mkdir(savedir)
# parse message # parse message
message = Parser().parse(stream) message = Parser().parse(stream)
sender = get_sender(message) email = get_sender(message)
logger = logging.getLogger(sender) logger = logging.getLogger(email)
# write syslog # write syslog
if sender is None or valid_email(sender)==0: if email is None or valid_email(email)==0:
logger.warning("invalid email address: " + str(sender)) logger.warning("invalid email address: " + str(email))
return -1 return -1
logger.info("received orders from " + sender) logger.info("received orders from " + email)
# get an available filename # get an available filename
lock_file(gamedir + "/orders.queue") lock_file(gamedir + "/orders.queue")
maxdate, filename = available_file(savedir, prefix + sender) maxdate, filename = available_file(savedir, prefix + email)
if filename is None: if filename is None:
logger.warning("more than " + str(maxfiles) + " orders from " + sender) 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, sender) text_ok = copy_orders(message, filename, email)
unlock_file(gamedir + "/orders.queue") unlock_file(gamedir + "/orders.queue")
warning, msg, fail = None, "", False warning, msg, fail = None, "", False
@ -312,47 +315,47 @@ def accept(game, locale, stream, extend=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 turndate < maxdate: if turndate < maxdate:
logger.warning("inconsistent message date " + sender) 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] % (ctime(maxdate),ctime(turndate)), 76, 2) + "\n"
else: else:
logger.warning("missing message date " + sender) 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"
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"
logger.warning("rejected - no text/plain in orders from " + sender) logger.warning("rejected - no text/plain in orders from " + email)
os.unlink(filename) os.unlink(filename)
savedir = savedir + "/rejected" savedir = savedir + "/rejected"
if not os.path.exists(savedir): os.mkdir(savedir) if not os.path.exists(savedir): os.mkdir(savedir)
lock_file(gamedir + "/orders.queue") lock_file(gamedir + "/orders.queue")
maxdate, filename = available_file(savedir, prefix + sender) maxdate, filename = available_file(savedir, prefix + email)
store_message(message, filename) store_message(message, filename)
unlock_file(gamedir + "/orders.queue") unlock_file(gamedir + "/orders.queue")
fail = True fail = True
if sendmail and warning is not None: if sendmail and warning is not None:
subject = gamename + " " + messages["subject-"+locale] + warning subject = gamename + " " + messages["subject-"+locale] + warning
mail = "Subject: %s\nFrom: %s\nTo: %s\n\n" % (subject, frommail, sender) + msg mail = "Subject: %s\nFrom: %s\nTo: %s\n\n" % (subject, sender, email) + msg
from smtplib import SMTP from smtplib import SMTP
server = SMTP("localhost") server = SMTP("localhost")
server.sendmail(frommail, sender, mail) server.sendmail(sender, email, mail)
server.close() server.close()
if not sendmail: if not sendmail:
print text_ok, fail, sender print text_ok, fail, email
print filename print filename
if not fail: if not fail:
lock_file(gamedir + "/orders.queue") lock_file(gamedir + "/orders.queue")
queue = open(gamedir + "/orders.queue", "a") queue = open(gamedir + "/orders.queue", "a")
queue.write("email=%s file=%s locale=%s game=%s\n" % (sender, filename, locale, game)) queue.write("email=%s file=%s locale=%s game=%s\n" % (email, filename, locale, game))
queue.close() queue.close()
unlock_file(gamedir + "/orders.queue") unlock_file(gamedir + "/orders.queue")
logger.info("done - accepted orders from " + sender) logger.info("done - accepted orders from " + email)
return 0 return 0

View File

@ -2,7 +2,9 @@
# -*- coding: iso-8859-1 -*- # -*- coding: iso-8859-1 -*-
from os import unlink, symlink, rename, popen, tmpfile from os import unlink, symlink, rename, popen, tmpfile
from os.path import exists import os
import os.path
import ConfigParser
from re import compile, IGNORECASE from re import compile, IGNORECASE
from string import split, join, upper, strip from string import split, join, upper, strip
from sys import argv, exit from sys import argv, exit
@ -14,9 +16,8 @@ from epasswd import EPasswd
def pwd_get_email(faction, pwd, pwdfile=None): def pwd_get_email(faction, pwd, pwdfile=None):
return None return None
def splitfilename(filename): def split_filename(filename):
from os.path import split return os.path.split(filename)
return split(filename)
def unlock_file(filename): def unlock_file(filename):
try: try:
@ -28,7 +29,7 @@ def unlock_file(filename):
def lock_file(filename): def lock_file(filename):
i = 0 i = 0
wait = 1 wait = 1
if not exists(filename): if not os.path.exists(filename):
file=open(filename, "w") file=open(filename, "w")
file.close() file.close()
while True: while True:
@ -62,17 +63,47 @@ messages = {
"error-en": "Error", "error-en": "Error",
} }
game = int(sys.argv[1])
echeck_cmd = "/home/eressea/echeck/echeck.sh"
maxlines = 25
# base directory for all your games: # base directory for all your games:
rootdir = "/home/eressea/eressea" install_dir = "/home/eressea/eressea"
frommail = "Eressea Server <eressea-server@eressea.kn-bremen.de>" if 'ERESSEA' in os.environ:
orderbase = "orders.dir" install_dir = os.environ['ERESSEA']
sendmail = True elif 'HOME' in os.environ:
maxlines = 25 install_dir = os.path.join(os.environ['HOME'], '/eressea')
echeck_cmd = "/home/eressea/echeck/echeck.sh" if not os.path.isdir(install_dir):
print "please set the ERESSEA environment variable to the install path"
sys.exit(1)
game_dir = os.path.join(install_dir, "game-%d" % (game, ))
frommail = 'eressea-server@kn-bremen.de'
gamename = 'Eressea'
sender = '%s Server <%s>' % (gamename, frommail)
inifile = os.path.join(gamedir, 'eressea.ini')
if not os.path.exists(inifile):
print "no such file: " . inifile
else:
config = ConfigParser.ConfigParser()
config.read(inifile)
if config.has_option('game', 'email'):
frommail = config.get('game', 'email')
if config.has_option('game', 'name'):
gamename = config.get('game', 'name')
if config.has_option('game', 'sender'):
sender = config.get('game', 'sender')
else:
sender = "%s Server <%s>" % (gamename, frommail)
config = None
queue_file = os.path.join(game_dir, "orders.queue")
if not os.path.exists(queue_file):
exit(0)
# regular expression that finds the start of a faction # regular expression that finds the start of a faction
fact_re = compile("^\s*(eressea|vinyambar|partei|faction)\s+([a-zA-Z0-9]+)\s+\"?([^\"]*)\"?", IGNORECASE) fact_re = compile("^\s*(eressea|partei|faction)\s+([a-zA-Z0-9]+)\s+\"?([^\"]*)\"?", IGNORECASE)
def check_pwd(filename, email, pw_data): def check_pwd(filename, email, pw_data):
results = [] results = []
@ -98,7 +129,7 @@ def check_pwd(filename, email, pw_data):
return results return results
def echeck(filename, locale, rules): def echeck(filename, locale, rules):
dirname, filename = splitfilename(filename) dirname, filename = split_filename(filename)
stream = popen("%s %s %s %s %s" % (echeck_cmd, locale, filename, dirname, rules), 'r') stream = popen("%s %s %s %s %s" % (echeck_cmd, locale, filename, dirname, rules), 'r')
lines = stream.readlines() lines = stream.readlines()
if len(lines)==0: if len(lines)==0:
@ -111,14 +142,6 @@ def echeck(filename, locale, rules):
stream.close() stream.close()
return mail return mail
## the main body of the script
game = int(argv[1])
basedir = rootdir + "/game-%d" % (game, )
queuename = basedir + "/orders.queue"
if not exists(queuename):
exit(0)
# parse the queue file - # parse the queue file -
#print "connecting to SMTP..." #print "connecting to SMTP..."
from smtplib import SMTP from smtplib import SMTP
@ -127,16 +150,17 @@ try:
except: except:
print "could not connect to SMTP server" print "could not connect to SMTP server"
exit(0) exit(0)
#print "reading password file..." #print "reading password file..."
pw_data = EPasswd(basedir + "/passwd") pw_data = EPasswd(os.path.join(game_dir,"passwd"))
#print "reading orders.queue..." #print "reading orders.queue..."
# move the queue file to a save space while locking it: # move the queue file to a save space while locking it:
try: try:
lock_file(queuename) lock_file(queue_file)
except: except:
exit(0) exit(0)
queuefile = open(queuename, "r") queuefile = open(queue_file, "r")
lines = queuefile.readlines() lines = queuefile.readlines()
queuefile.close() queuefile.close()
@ -154,9 +178,9 @@ tmpfile.close()
openlog("orders") openlog("orders")
unlink(queuename) unlink(queue_file)
try: try:
unlock_file(queuename) unlock_file(queue_file)
except: except:
pass pass
@ -170,15 +194,15 @@ for line in lines:
email = dict["email"] email = dict["email"]
locale = dict["locale"] locale = dict["locale"]
game = int(dict["game"]) game = int(dict["game"])
file = dict["file"] infile = dict["file"]
gamename='[E%d]' % game gamename='[E%d]' % game
rules='e%d' % game rules='e%d' % game
warning = "" warning = ""
failed = True failed = True
results = check_pwd(file, email, pw_data) results = check_pwd(infile, email, pw_data)
logfile = open(basedir+"/zug.log", "a") logfile = open(os.path.join(game_dir, "zug.log"), "a")
dirname, filename = splitfilename(file) dirname, filename = split_filename(infile)
msg = messages["validate-"+locale] + " " + filename + "\n\n" msg = messages["validate-"+locale] + " " + infilename + "\n\n"
for faction, game_email, success, pwd in results: for faction, game_email, success, pwd in results:
msg = msg + messages["faction-"+locale] + " " + faction + "\n" msg = msg + messages["faction-"+locale] + " " + faction + "\n"
if success: failed = False if success: failed = False
@ -189,25 +213,24 @@ for line in lines:
if failed: if failed:
warning = " (" + messages["warning-" + locale] + ")" warning = " (" + messages["warning-" + locale] + ")"
syslog("failed - no valid password in " + file) syslog("failed - no valid password in " + infile)
else: else:
result = echeck(file, locale, rules) result = None
if email=='eressea': if os.path.exists(echeck_cmd):
print result result = echeck(infile, locale, rules)
continue if result is None:
elif result is None:
# echeck did not finish # echeck did not finish
msg = msg + "Echeck was killed. Your turn was accepted, but could not be verified.\n" msg = msg + "Echeck is broken. Your turn was accepted, but could not be verified.\n"
warning = " (" + messages["warning-" + locale] + ")" warning = " (" + messages["warning-" + locale] + ")"
syslog("process - echeck got killed, " + file) syslog("process - echeck broken, " + infile)
else: else:
msg = msg + result msg = msg + result
syslog("process - checked orders in " + file) syslog("process - checked orders in " + infile)
subject = gamename + " " + messages["subject-" + locale] + warning subject = gamename + " " + messages["subject-" + locale] + warning
msg = "Subject: %s\nFrom: %s\nTo: %s\nContent-Type: text/plain; charset=utf-8\n\n" % (subject, frommail, email) + msg msg = "Subject: %s\nFrom: %s\nTo: %s\nContent-Type: text/plain; charset=utf-8\n\n" % (subject, sender, email) + msg
try: try:
server.sendmail(frommail, email, msg) server.sendmail(sender, email, msg)
except: except:
syslog("failed - cannot send to " + email) syslog("failed - cannot send to " + email)

View File

@ -94,8 +94,8 @@ touch eressea.ini
} }
ini_start ini_start
ini_sec eressea ini_sec game
ini_add eressea locales de,en ini_add game locales de,en
ini_sec lua ini_sec lua
ini_add lua install $SOURCE ini_add lua install $SOURCE
ini_add lua paths $SOURCE/scripts:$SOURCE/lunit ini_add lua paths $SOURCE/scripts:$SOURCE/lunit

View File

@ -54,23 +54,23 @@ static void load_inifile(dictionary * d)
assert(d); assert(d);
str = iniparser_getstring(d, "eressea:base", basedir); str = iniparser_getstring(d, "game:base", basedir);
if (str != basedir) { if (str != basedir) {
set_basepath(str); set_basepath(str);
} }
str = iniparser_getstring(d, "eressea:report", reportdir); str = iniparser_getstring(d, "game:report", reportdir);
if (str != reportdir) { if (str != reportdir) {
set_reportpath(str); set_reportpath(str);
} }
str = iniparser_getstring(d, "eressea:data", datadir); str = iniparser_getstring(d, "game:data", datadir);
if (str != datadir) { if (str != datadir) {
set_datapath(str); set_datapath(str);
} }
lomem = iniparser_getint(d, "eressea:lomem", lomem) ? 1 : 0; lomem = iniparser_getint(d, "game:lomem", lomem) ? 1 : 0;
verbosity = iniparser_getint(d, "eressea:verbose", 2); verbosity = iniparser_getint(d, "game:verbose", 2);
str = iniparser_getstring(d, "eressea:locales", "de,en"); str = iniparser_getstring(d, "game:locales", "de,en");
make_locales(str); make_locales(str);
if (global.inifile) iniparser_freedict(global.inifile); if (global.inifile) iniparser_freedict(global.inifile);
@ -84,7 +84,7 @@ static void parse_config(const char *filename)
load_inifile(d); load_inifile(d);
log_debug("reading from configuration file %s\n", filename); log_debug("reading from configuration file %s\n", filename);
memdebug = iniparser_getint(d, "eressea:memcheck", memdebug); memdebug = iniparser_getint(d, "game:memcheck", memdebug);
#ifdef USE_CURSES #ifdef USE_CURSES
/* only one value in the [editor] section */ /* only one value in the [editor] section */
force_color = iniparser_getint(d, "editor:color", force_color); force_color = iniparser_getint(d, "editor:color", force_color);