Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2003:
[Freeciv-Dev] civserver overwrites old savegames (PR#3516)
Home

[Freeciv-Dev] civserver overwrites old savegames (PR#3516)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: admerik@xxxxxxxxxxxx
Subject: [Freeciv-Dev] civserver overwrites old savegames (PR#3516)
From: "Reinier Post" <rp@xxxxxxxxxx>
Date: Thu, 27 Feb 2003 09:26:36 -0800
Reply-to: rt@xxxxxxxxxxxxxx

On Thu, Feb 27, 2003 at 02:49:37AM -0800, ChrisK@xxxxxxxx wrote:
> On Wed, Feb 26, 2003 at 11:15:39PM -0800, Raimar Falke wrote:
> > On Wed, Feb 26, 2003 at 07:07:01PM -0800, Alan Horkan wrote:
> > > 
> > > I am not sure but i get the feeling that civserver overwrote one of my
> > > save games* with the current game, which is not exactly running the games
> > > in parallel but if i can verify this problem i will bring it up properly
> > > onlist.
> 
> Yes, it does, as long as you don't use the 'set savename' option. It's
> a feature, not a bug.

Attached is the wrapper I use to avoid this.  It creates a new
subdirectory and starts civserver in it.  The method it uses to
find a civserver binary is probably wrong.

#!/bin/sh
#
# cs - start a civserver
#
# this script differs from 'ser' in two ways:
#
# - it uses $FREECIV_PATH or its default to locate a civserver binary
# - it uses separate working directories to store the game data
#
# $Id: cs,v 1.10 2002/11/06 13:39:31 gamecvs Exp $

# if a working directory is supplied in $CSDIR, it will use that

#exec > /tmp/cs.$$.log 2>&1; set -x  # temporary, I hope - rp
  # problem: this will leave civserver.out empty

# remember the default location of civserver

# find civserver in $PATH; don't use which, it's poisoned on Solaris
#
for d in `echo "$PATH" | sed 's/:/  /g'`
do
  if [ -x $d/civserver ]
  then
    if expr X"$d" : X/ >/dev/null  # it's an absolute path
    then
      civserver=$d/civserver
    else
      civserver=`/bin/pwd`/$d/civserver
    fi
  fi
done

PATH=/bin:/usr/bin; export PATH
me=`basename $0`

#--- config ---#
#

playground=$HOME/.freeciv/games
cwd=`/bin/pwd`
default_freeciv_path=$cwd/data:$cwd/share/freeciv:$HOME/.freeciv:$HOME/.freeciv/data:$HOME/.freeciv/share
  # we should use what Freeciv uses, I suppose

Die()
{
  echo "$me: fatal error: $@" 1>&2
  exit 1
}

Remark()
{
  echo "$me: $@" 1>&2
}

newsubdir=`dirname $0`/newsubdir
civpath2server=`dirname $0`/civpath2server

[ -x $newsubdir ]  || Die "cannot find required executable '$newsubdir'"
[ -x $civpath2server ]  || Die "cannot find required executable 
'$civpath2server'"
[ -d $playground ] || mkdir -p "$playground" ||
  Die "cannot cd to working directory '$playground'"


#--- set $FREECIV_PATH if not set yet ---#
#

[ X != X"$FREECIV_PATH" ] || FREECIV_PATH=$default_freeciv_path
export FREECIV_PATH

civserver=`$civpath2server` ||
    Die "cannot find a civserver binary along \$FREECIV_PATH '$FREECIV_PATH'"

Remark "using binary '$civserver'"


#--- create a separate working directory for this game and run it there ---#
#

(cd $playground || Die "cannot cd to $playground/")
[ $? -eq 0 ] || exit $?

if [ X != X"$CSDIR" ]
then
  # use $CSDIR
  [ -d "$CSDIR" ] || Die "working dir $CSDIR is not a directory"
  [ -w "$CSDIR" ] || Die "working dir $CSDIR is not writable"
  d="$CSDIR"
else
  d=`$newsubdir $playground`
  [ $? = 0 ] && [ X != X"$d" ] || Die "cannot create working directory '$d'"
fi

Remark "using directory '$d'"

cd $d || Die "cannot cd to '$d'"

env > $d/env
echo $civserver "$@" > $d/cmdline

$civserver "$@"
exit $?
#!/bin/sh
#
# newsubdir - creates a new subdir in the given dir, and returns its name
#
# $Id: newsubdir,v 1.2 2001/08/14 18:59:51 gamecvs Exp $

# the subdir is created so we have the effect of 'locking'
# (although it isn't perfect)

PATH=/bin:/usr/bin:/usr/ucb; export PATH

me=`basename $0`

Die()
{
  echo "$me: fatal error: $@" 1>&2
  exit 1
}

d=$1

[ X != X"$d" ] || Die "supply a directory as argument"
[ -d $d ]      || Die "argument must be an existing directory"
cd $d          || Die "cannot cd to $d"


nextdir="`ls -t | grep '^[0-9][0-9]*$' | sort -n | tail -1`"
case "$nextdir" in
"")
  nextdir=0
  ;;
*)
  nextdir=`expr "$nextdir" + 1`
 ;;
esac

while :
do
  mkdir $nextdir 2>/dev/null && break  # success
  [ -d $nextdir ]            || Die "cannot create subdir '$d/$nextdir'"
  nextdir=`expr "$nextdir" + 1`
done

echo "$d/$nextdir"

[Prev in Thread] Current Thread [Next in Thread]