.com.unity Forums
  The Official e-Store of Shrapnel Games

This Month's Specials

Raging Tiger- Save $9.00
winSPMBT: Main Battle Tank- Save $6.00

   







Go Back   .com.unity Forums > Illwinter Game Design > Dominions 2: The Ascension Wars

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old June 15th, 2004, 04:21 PM

guybrush threepwood guybrush threepwood is offline
Corporal
 
Join Date: Mar 2004
Location: Copenhagen, Denmark
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
guybrush threepwood is on a distinguished road
Default Useful linux script when hosting PBEM.

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

Reply With Quote
 

Bookmarks


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 12:28 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2024, Shrapnel Games, Inc. - All Rights Reserved.