#!/bin/sh

if [ -x /usr/share/games/game-data-packager-runtime/gdp_launcher_base.py ]; then
  exec /usr/share/games/game-data-packager-runtime/gdp_launcher_base.py --id=mohaa-server "$@"
fi

IOQ3SELF="mohaa-server"
IOQ3GAME="'Medal of Honor: Allied Assault'"
IOQ3BINARY="omohaaded"

BASEPATH="/usr/lib/openmohaa"
ENGINE="$BASEPATH/${IOQ3BINARY}"

GAMEDATAPATH="/usr/share/games/mohaa"
CVARS="$CVARS +set fs_basepath ${GAMEDATAPATH}"

QUIET=0

EXCUSE="\
${IOQ3GAME} server wrapper for Debian\n\
\n\
Usage: ${IOQ3SELF} [OPTION]...\n\
\n\
 -h, --help\t\tDisplay this help\n\
 -q, --quiet\t\tDisable console output\n\
  +<internal command>\tPass commands to the engine\n"

while [ "$1" != "" ]; do
  case "$1" in
    -h|--help)
      echo ${EXCUSE}
      exit 0
      ;;
    -q|--quiet)
      CVARS="$CVARS +set ttycon 0"
      QUIET=1
      ;;
    *)
      break
      ;;
  esac
  shift
done

# sanity check: the engine doesn't cope well with missing data
if test -f $GAMEDATAPATH/main/pak1.pk3; then
  :
else
  echo "${IOQ3GAME} data missing, see /usr/share/doc/openmohaa-server/README.mohaa-data"
  exit 72     # EX_OSFILE
fi

if test "z$QUIET" = z1; then
  exec >/dev/null 2>&1;
fi

exec ${ENGINE} ${CVARS} "$@"

# vim:set sw=2 sts=2 ft=sh:
