.com.unity Forums

.com.unity Forums (http://forum.shrapnelgames.com/index.php)
-   Dominions 2: The Ascension Wars (http://forum.shrapnelgames.com/forumdisplay.php?f=55)
-   -   Useful linux script when hosting PBEM. (http://forum.shrapnelgames.com/showthread.php?t=19375)

guybrush threepwood June 15th, 2004 04:21 PM

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=&quot;--host -xxx --statfile&quot;
#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=&quot;$DOMINIONS2SAVEDIR/$GAMENAME&quot;

if [ ! -d &quot;$GAMEDIR&quot; ]; then
echo Game \&quot;$GAMENAME\&quot; 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 \&quot;dom2 --verify $GAMENAME\&quot;
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 [ &quot;$GREPCHK&quot; != &quot;2h file is OK!&quot; ]; 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 [ &quot;$GAMENUMBER&quot; != &quot;$FATHERGAMENUMBER&quot; ]; then
echo $nationname.2h file appears to belong to a different game!
OK=0
else
if [ &quot;$TURNNUMBER&quot; != &quot;$FATHERTURNNUMBER&quot; ]; 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">

Gandalf Parker June 16th, 2004 02:28 AM

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

guybrush threepwood June 16th, 2004 08:38 AM

Re: Useful linux script when hosting PBEM.
 
Quote:

Originally posted by Gandalf Parker:
Nice script. Id have to force a text mode but other than that it looks good.

<font size="2" face="sans-serif, arial, verdana">I would like that very much also. But how can I do that? It seems to me that I can only run text-only mode when running a tcpserver (I would be glad to be corrected on this).

Quote:


Care to work on a project to create a linux web-page game-signup and starter? http://forum.shrapnelgames.com/images/icons/icon7.gif

<font size="2" face="sans-serif, arial, verdana">I might be interested, but is that not exactly what Mose Hansen's server is already?

Cheers,
Thomas

Gandalf Parker June 16th, 2004 03:18 PM

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.