Hi there,
I just made a somewhat useful script for my own purposes and thought I would share it here.
The script (which is a simple bash script) is invoked as:
dom2-host-game my-game-name
The script then carefully checks (using output from dom2 --verify) whether all .2h files are alright, that there are no stale turns, etc. If everything is fine, it then hosts.
Let me know if anyone finds it useful :-)
Install by putting the following inside ~/bin/dom2-host-game (you might need to change the variable DOMINIONS2EXECUTABLE):
code:
#!/bin/bash
DOMINIONS2SAVEDIR=$HOME/dominions2
DOMINIONS2EXECUTABLE=/usr/local/bin/dom2
HOSTFLAGS="--host -xxx --statfile"
#could add --scoredump, but scoredump outputs info even though statistics on other nations is off!!!
if [ $# -ne 1 ]; then
echo Usage: $0 gamename
exit 1
fi
GAMENAME=$1
GAMEDIR="$DOMINIONS2SAVEDIR/$GAMENAME"
if [ ! -d "$GAMEDIR" ]; then
echo Game \"$GAMENAME\" does not appear to exist in $DOMINIONS2SAVEDIR
exit 1
fi
OK=1;
for nationtrn in $GAMEDIR/*.trn; do
nationname=`basename $nationtrn .trn`
file_2h=$GAMEDIR/$nationname.2h
if [ ! -f $file_2h ]; then
echo missing .2h file for $nationname
OK=0
fi
done
if [ $OK -eq 0 ]; then
exit 1
fi
#remove old .chk files
rm -f $GAMEDIR/*.chk
#invoke dom2 -verify to produce new .chk files.
$DOMINIONS2EXECUTABLE --verify $GAMENAME
if [ ! $? ]; then
echo Errors when invoking \"dom2 --verify $GAMENAME\"
exit 1
fi
# A non-existing ftherlnd.chk file means something was wrong with the ftherlnd file.
if [ ! -f $GAMEDIR/ftherlnd.chk ]; then
echo Something is wrong with the ftherlnd file.
exit 1
fi
#ftherlnd defines turn number and game number:
FATHERGAMENUMBER=`grep gamenbr $GAMEDIR/ftherlnd.chk|sed 's/ *//'|cut -d ' ' -f 2`
FATHERTURNNUMBER=`grep turnnbr $GAMEDIR/ftherlnd.chk|sed 's/ *//'|cut -d ' ' -f 2`
#Now, let us check all the chk files.
OK=1;
for nationtrn in $GAMEDIR/*.trn; do
nationname=`basename $nationtrn .trn`
file_chk=$GAMEDIR/$nationname.chk
GREPCHK=`/bin/grep '2h file is OK!' $file_chk`
if [ "$GREPCHK" != "2h file is OK!" ]; then
echo Something is wrong with $nationname.2h
OK=0
else
GAMENUMBER=`grep gamenbr $file_chk|sed 's/ *//'|cut -d ' ' -f 2`
TURNNUMBER=`grep turnnbr $file_chk|sed 's/ *//'|cut -d ' ' -f 2`
if [ "$GAMENUMBER" != "$FATHERGAMENUMBER" ]; then
echo $nationname.2h file appears to belong to a different game!
OK=0
else
if [ "$TURNNUMBER" != "$FATHERTURNNUMBER" ]; then
echo $nationname.2h file appears to be from a wrong turn. Maybe $nationname did not play their turn yet.
OK=0
fi
fi
fi
done
if [ $OK -eq 0 ]; then
exit 1
fi
$DOMINIONS2EXECUTABLE $HOSTFLAGS $GAMENAME
if [ $? ]; then
echo Hosted $GAMENAME succesfully.
exit 0
fi