scripts

misc scripts and tools
git clone git://git.2f30.org/scripts.git
Log | Files | Refs

q3d (1241B)


      1 #!/bin/sh
      2 #
      3 # Written by z3bra
      4 
      5 base="/opt/ioquake3/"
      6 port="25000"
      7 
      8 green='\e[1;32m'
      9 reset='\e[0m'
     10 red='\e[1;31m'
     11 
     12 function usage() {
     13 cat << EOF
     14     usage: `basename $0` <command>
     15     commands:
     16         ffa|tdm|ctf|duel|df     - Start the corresponding mod
     17         kill|stop <mod>         - Stop the corresponding mod
     18         list                    - List running servers
     19         help                    - Display this help
     20 EOF
     21 }
     22 
     23 conf_path=$HOME/.q3a/baseq3
     24 fifo_path=$HOME/var/q3
     25 
     26 # Spawn the appropriate game type
     27 function spawn() {
     28     socket=$fifo_path/$1.fifo
     29 
     30     ## Options to add when launching server
     31     opt=""
     32     [[ "$1" == "df" ]] && opt="$opt +set fs_game defrag"
     33     opt="$opt +set dedicated 2"
     34     opt="$opt +set fs_basepath $base"
     35     opt="$opt +set net_port $port"
     36     opt="$opt +exec $1.cfg"
     37 
     38     # If a server exists, attach to it.
     39     if [ -S $socket ]; then
     40         dtach -a $socket
     41     # If not, create a background session
     42     else
     43         dtach -n $socket ioq3ded $opt
     44         echo -e "${green}$1 running through ${reset}${socket}"
     45     fi
     46 }
     47 
     48 case $1 in
     49     ffa|tdm|ctf|duel|df) spawn $1;;
     50     kill|stop) wipe q3 $2;;
     51     list)  ls -C --color=auto $fifo_path;;
     52     help) usage;;
     53     *) usage; exit 1;;
     54 esac
     55 
     56 exit 0
     57