From 20234ca27a842015d6732d92ba2f080ce3e9408e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 11 Dec 2014 12:19:04 +0100 Subject: [PATCH] lock files to prevent accidents. preview will only run if the turn worked out. cannot accidentally run in the game directory. --- process/cron/run-eressea | 6 ++++++ scripts/run-turn.lua | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/process/cron/run-eressea b/process/cron/run-eressea index cc33f8f1e..21de5ee09 100755 --- a/process/cron/run-eressea +++ b/process/cron/run-eressea @@ -13,7 +13,12 @@ if [ -d $REPORTS ]; then fi mkdir $REPORTS $BIN/backup-eressea $GAME +if [ -d test ]; then + touch test/execute.lock +fi +rm -f execute.lock $BIN/run-turn $GAME +touch execute.lock if [ ! -s $ERESSEA/game-$GAME/orders.$TURN ]; then echo "server did not create orders for turn $TURN in game $GAME" exit 2 @@ -31,3 +36,4 @@ $BIN/compress.sh $GAME $TURN $BIN/sendreports.sh $GAME $BIN/backup-eressea $GAME [ $GAME -lt 4 ] && $BIN/send-summary $GAME +rm -f test/execute.lock diff --git a/scripts/run-turn.lua b/scripts/run-turn.lua index 283bdb1d1..46095f216 100644 --- a/scripts/run-turn.lua +++ b/scripts/run-turn.lua @@ -26,6 +26,18 @@ function callbacks(rules, name, ...) end end +local function change_locales(localechange) + for loc, flist in pairs(localechange) do + for index, name in pairs(flist) do + f = get_faction(atoi36(name)) + if f ~= nil and f.locale ~= loc then + print("LOCALECHANGE ", f, f.locale, loc) + f.locale = loc + end + end + end +end + local function dbupdate() update_scores() dbname = config.dbname or 'eressea.db' @@ -141,6 +153,9 @@ function process(rules, orders) process_orders() callbacks(rules, 'update') + local localechange = { de = { 'ii' } } + change_locales(localechange) + write_files(config.locales) file = '' .. get_turn() .. '.dat' @@ -167,6 +182,16 @@ function run_turn(rules) return result end +function file_exists(name) + local f=io.open(name,"r") + if f~=nil then io.close(f) return true else return false end +end + +if file_exists('execute.lock') then + eressea.log.error("Lockfile exists, aborting.") + assert(false) +end + local path = 'scripts' if config.install then path = config.install .. '/' .. path @@ -174,6 +199,12 @@ end package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' require 'eressea' require 'eressea.xmlconf' -- read xml data -local rules = require('eressea.rules') +local rules = {} +if config.rules then + rules = require('eressea.' .. config.rules) + eressea.log.info('loaded ' .. #rules .. ' modules for ' .. config.rules) +else + eressea.log.warning('no rule modules loaded, specify a game in eressea.ini or with -r') +end run_turn(rules)