![]() |
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): </font><blockquote><font size="1" face="sans-serif, arial, verdana">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">#!/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</pre><hr /></blockquote><font size="2" face="sans-serif, arial, verdana"> |
Re: Useful linux script when hosting PBEM.
Nice script. Id have to force a text mode but other than that it looks good.
Care to work on a project to create a linux web-page game-signup and starter? http://forum.shrapnelgames.com/images/icons/icon7.gif |
Re: Useful linux script when hosting PBEM.
Quote:
Quote:
Cheers, Thomas |
Re: Useful linux script when hosting PBEM.
Yes text mode applies to server. Its just my own quirk. I tend to seperate my stuff between GUI stuff (which I run on Windows XP) and server stuff (which I run on a pretty bare linux).
As to the game server thing, yes its what Mosehanson has done (and very well) but Im still interested in doing one of my own. His kindof came from a programmer side. Top down. Answers all done in modules of a single programming code. System level answers were chosen Last, if at all. Im more SysAdmin than programmer. Id like to do one system-up with programming answers chosen Last, if at all. Cant hurt to have 2 Versions. 3 actually if anyone tackles doing a Windows Version. [ June 16, 2004, 14:19: Message edited by: Gandalf Parker ] |
All times are GMT -4. The time now is 05:58 PM. |
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2025, Shrapnel Games, Inc. - All Rights Reserved.