#!/sbin/runscript
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/games-fps/quake3-bin/files/q3ded.rc,v 1.2 2007/03/07 16:53:48 wolf31o2 Exp $

depend() {
	need net
}

start() {
	ebegin "Starting Quake3 dedicated server"
	screen -A -m -d -S q3ded-bin su - games -c "q3ded-bin ${q3_OPTS}"
	eend $?
}

stop() {
	ebegin "Stopping Quake3 dedicated server"
	local pid=`screen -list | grep q3ded-bin | awk -F . '{print $1}' | sed -e s/.//`
	if [[ -z "${pid}" ]] ; then
		eend 1 "Lost screen session"
	else
		pid=`pstree -p ${pid} | sed -e 's:^.*q3ded-bin::'`
		pid=${pid:1:${#pid}-2}
		if [[ -z "${pid}" ]] ; then
			eend 1 "Lost q3ded-bin session"
		else
			kill ${pid}
			eend $? "Could not kill q3ded-bin"
		fi
	fi
}

status() {
	screen -list | grep q3ded-bin
}
