lock files to prevent accidents.

preview will only run if the turn worked out.
cannot accidentally run in the game directory.
This commit is contained in:
Enno Rehling 2014-12-11 12:19:04 +01:00
parent c76ff2b9c7
commit 20234ca27a
2 changed files with 38 additions and 1 deletions

View File

@ -13,7 +13,12 @@ if [ -d $REPORTS ]; then
fi fi
mkdir $REPORTS mkdir $REPORTS
$BIN/backup-eressea $GAME $BIN/backup-eressea $GAME
if [ -d test ]; then
touch test/execute.lock
fi
rm -f execute.lock
$BIN/run-turn $GAME $BIN/run-turn $GAME
touch execute.lock
if [ ! -s $ERESSEA/game-$GAME/orders.$TURN ]; then if [ ! -s $ERESSEA/game-$GAME/orders.$TURN ]; then
echo "server did not create orders for turn $TURN in game $GAME" echo "server did not create orders for turn $TURN in game $GAME"
exit 2 exit 2
@ -31,3 +36,4 @@ $BIN/compress.sh $GAME $TURN
$BIN/sendreports.sh $GAME $BIN/sendreports.sh $GAME
$BIN/backup-eressea $GAME $BIN/backup-eressea $GAME
[ $GAME -lt 4 ] && $BIN/send-summary $GAME [ $GAME -lt 4 ] && $BIN/send-summary $GAME
rm -f test/execute.lock

View File

@ -26,6 +26,18 @@ function callbacks(rules, name, ...)
end end
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() local function dbupdate()
update_scores() update_scores()
dbname = config.dbname or 'eressea.db' dbname = config.dbname or 'eressea.db'
@ -141,6 +153,9 @@ function process(rules, orders)
process_orders() process_orders()
callbacks(rules, 'update') callbacks(rules, 'update')
local localechange = { de = { 'ii' } }
change_locales(localechange)
write_files(config.locales) write_files(config.locales)
file = '' .. get_turn() .. '.dat' file = '' .. get_turn() .. '.dat'
@ -167,6 +182,16 @@ function run_turn(rules)
return result return result
end 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' local path = 'scripts'
if config.install then if config.install then
path = config.install .. '/' .. path path = config.install .. '/' .. path
@ -174,6 +199,12 @@ end
package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua' package.path = package.path .. ';' .. path .. '/?.lua;' .. path .. '/?/init.lua'
require 'eressea' require 'eressea'
require 'eressea.xmlconf' -- read xml data 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) run_turn(rules)