Setting up an UFO2000 server

From UFOpaedia
Jump to: navigation, search

In principle, for playing online, you do need an online server. Usually the public ufo2000.net server should do just fine. But maybe you want to set up a private server or a backup server.

How to get the binary and what it brings with it

In order to run your own server, you can either use the supplied precompiled ufo2000.exe from the project page, or for linux, you will need to compile it yourself. Don't worry, the latter is no big deal. You should have a look at the compilation page, then. The server brings a status-page with it, a tiny webserver, that only shows, who is logged on. If you use the standard port for it, the url is http://servername:2000.

Starting and stopping

You should have either the ufo2000-srv.exe (Windows) or the ufo2000-srv (Linux). You can either start it manually (stopping with CTRL+C) or let it be done by an init-script/the systems service-manager. For the moment, it is not recommended, to use the demonized-mode, as there have been reports of problems with that. On piece of advice at this point: If you choose to run the server on a regular basis, e. g. on a root-server, you really should not run the server as root. Better use an init-script, running it as a limited user. That way, it's far less dangerous, running the ufo2000-server. There are no known security issues, but usually the problems are the not known ones... If somebody may find any, the service run as root is a big security risk. So keep that in mind, when running ufo2000 servers, or any other gaming server for that matter.

If you want the server to be a backup-server, don't forget to add it to backup servers list!

Example init-script

Heres an example for an init-script for starting the server on system start with Linux via V-Init:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          UFO2000 server management
# Required-Start:
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Controls the UFO2000 server
# Description:       Nothing further
### END INIT INFO
# Author: 7Saturn <[email protected]>

# Aktionen

COMMANDLINE_PARAMETERS="" #any command line parameters you want to pass here
D1=$(readlink -f "$0")
BINARYPATH="/path-to/ufo2000server"
PIDFILE="ufo2000.pid"
SERVERUSER = "ufo2000"
cd "${BINARYPATH}"
LIBRARYPATH="$(pwd)"
BINARYNAME="ufo2000-srv"

case "$1" in
	start)
		if [ -e $PIDFILE ]; then
			if ( kill -0 $(cat $PIDFILE) 2> /dev/null ); then
				echo "UFO2000 server already running, maybe try restart or stop!"
				exit 1
			else
				echo "$PIDFILE found, but UFO2000 server doesn't run any more. Possibly crashed."
				rm $PIDFILE
			fi
		fi
		if [ "${UID}" = "0" ]; then
			echo "Warning! It's not recommended, to run the server as root!"
		fi
		echo "Running UFO2000 server..."
		if [ -e "$BINARYNAME" ]; then
			if [ ! -x "$BINARYNAME" ]; then
				echo "${BINARYNAME} is not executable, trying to change rights..."
				chmod u+x "${BINARYNAME}"
			fi
			if [ -x "$BINARYNAME" ]; then
				export LD_LIBRARY_PATH="${LIBRARYPATH}:${LD_LIBRARY_PATH}"					
				sudo -u $SERVERUSER "./${BINARYNAME}" ${COMMANDLINE_PARAMETERS} > /dev/null 2>&1 & 
				echo $! > $PIDFILE
				sudo chgrp $SERVERUSER $PIDFILE
				sudo chown $SERVERUSER $PIDFILE
				echo "UFO2000 server started."
			else
				echo "${BINARNAME} is not executable, UFO2000 server was NOT started!"
			fi
		else
			echo "Server binary not found, aborting!"
			exit 5
		fi
	;;
	stop)
		if [ -e $PIDFILE ]; then
			echo -n "Stopping UFO2000 server."
			if ( kill -TERM $(cat $PIDFILE) 2> /dev/null ); then
				c=1
				while [ "$c" -le 300 ]; do
					if ( kill -0 $(cat $PIDFILE) 2> /dev/null ); then
						echo -n "."
						sleep 1
					else
						break
					fi
					c=$((++c)) 
				done
			fi
			if ( kill -0 $(cat $PIDFILE) 2> /dev/null ); then
				echo "Server couldn't cleanly stopped, killing process..."
				kill -KILL $(cat $PIDFILE)
			else
				echo " server stopped."
			fi
			rm $PIDFILE
		else
			echo "UFO2000 server not running ($PIDFILE missing)."
			exit 7
		fi
	;;
	restart)
		echo "Trying to start UFO2000 server..."
		$D1 stop && $D1 start || exit 1
	;;
	status)
		if [ -e $PIDFILE ]; then
			if ( kill -0 $(cat $PIDFILE) 2> /dev/null ); then
				echo "UFO2000 server running."
			else
				echo "UFO2000 server seems to have crashed."
			fi
		else
			echo "UFO2000 server isn't running ($PIDFILE missing)."
		fi
	;;
	*)
		echo "Usuage: ${0} {start|stop|restart|status}"
		exit 2
esac
exit 0

Using the init-script

  • Add the necessary additional user, dedicated to the ufo2000 service, e. g. ufo2000. The user doesn't need to be able to log in on that machine, it won't need to be part of additional groups for special permissions and it doesn't necessarily need a homefolder. It will only need the permissions to read and write inside the ufo2000 server folder.
  • Adapt SERVERUSER = ""-line with the username, it should be run by. Do not use root for that.
  • It should be placed in the folder /etc/init.d/.
  • It has to be executable: sudo chmod 755 /etc/init.d/<scriptname>.
  • To register it as a script to be run, the command is: sudo update-rc.d <scriptname> defaults.
  • To remove it, use sudo update-rc.d -f <scriptname> remove.

After that, the script can be used manually with sudo service <scriptname> {start|stop|restart|status}, but usually is run by the system itself during bootup.

Ports and routers

When running, the server automatically opens up a tiny web server, showing the current players on the server. You can reach it via http://<server-adress>:2000. The Port 2000 (TCP) is also the port, where the server listens for connections of the game. If you run it behind a NAT (e. g. used by most home routers), you will also need to forward that port to the computer, running the service.

Configuration

The file ufo2000-srv.conf contains a few options for configuration:

daemonize               = 0
tcp_port                = 2000
players_count_limit     = 32
connections_count_limit = 64
login_time_limit        = 10000
username_size_limit     = 25
packet_size_limit       = 65536

Most of it should be rather self explaining. As said before, for the moment better not use the deamonize-option.

Stats and passwords

Stats

There is a function for recording of results of all played games. These results are saved in the file ufo2000.db. To query this file, e. g. with a php-script, you need access to it, provided by php. You will need to install php for use with an apache server. Usually, this is already the case. You will also need the pdo drivers for the query itself. On Ubuntu 14.04 you can install the required files with this:

sudo apt-get install php5-sqlite sqlite

From that on, you can build your own server stats-page.

Passwords

All users connecting to the server, will have the opportunity to choose a password, when connecting the first time with a certain user name. This password will remain! It's saved as a MD5-hash, and can only be changed by manipulating the database-table ufo2000_users. You can either delete a user completely, or let him give you a new password-hash. The user has no way of changing it himself and you won't have any means of recovering a lost password, as there are only hashes in the table.

Logs

The file ufo2000-srv.log contains server logs. If you experience problems, first look there, to further isolate the problem.