Tag Archives: Gameserver

Source-Engine Server Part1

Due to I still receive the HLDS maillinglist with a lot of update notification for the valve game servers in the last days, I decided to get back to my root off the “server administration thing” in a small simple game server project, based on my favourite source engine multiplayer game Day of Defeat: Source, but the main parts of the tutorial should also be useful for other source engine based games.

The result of this small tutorial series will be a Day of Defeat: Source Server, with Mani Admin Plugin as ingame administration tool and HLstatsX Community Edition as ranking system.

The server will be installed on a small vserver I got at Strato, based on Debian 5 Lenny, which currently only hosts the Teamspeak 3 server of my WoW guild with an small MySQL Server for the configuration storage. Well due to it’s not a powerful machine it will just host 10 to 12 slots in the end I think. But lets see what I can get out off that little box 🙂

The beginning

In the first step we will install our basic gameserver and join our first game 🙂

To start, we need the hlds update tool. It’s hidden on the steam homepage under tools, due to we are lazy admins, we download it directly to our server (mine is called minerva).

[email protected]:$ wget http://storefront.steampowered.com/download/hldsupdatetool.bin

Due to it is not executable, we give it the executable flag and start it.

[email protected]:$ chmod +x hldsupdatetool.bin && ./hldsupdatetool.bin

After you have accepted the licence with yes, the tool will extract the final steam client, which we will need to install the server.

When you run the tool the first time it will update it self to the latest version. This will probably take some time, due to the valve servers are often really slow. In the second run we let the tool show us the help output, so we see what parameters we need to install the game.

[email protected]:$ ./steam
Checking bootstrapper version ...

Use: steam -command [parameters] [flags]


update: Install or update HLDS

-game - Game name: use 'list' to see available games
-dir - HLDS Install dir
(if dir not specified, will use value from last run of tool)

-verify_all - Verify all HLDS files are up to date
-retry - Automatically retry every 30 seconds if the Steam Network is busy
-remember_password - Remember password (if a username is supplied)

For example: steam -command update -game cstrike -dir /hlds

version: View installed versions

list: View available games

Optional parameters for all commands:

-username - Steam account username (only needed to access limited content)
- Steam account password (only needed to access limited content)

I want to install Day of Defeat: Source in the directory “/srv/dods/” (make sure you have created the target directory before you start the installation or the tool will hang at the beginning), so I need the following command (for the list of other available games use “-command list” as parameter)

[email protected]:$ ./steam update -command update -game dods -dir /srv/dods

In the following process steam will download the dedicated server files you choose. This will take some time, so pick up a cup of coffee and wait 🙂

After that, the server is installed in a very basic setup. Cause it’s not nice when the game runs as root when we start it, we will create a user for that with his home directory set to “/srv/dods”, give him the rights on the server files and just switch to that user.

[email protected]:$ useradd -d /srv/dods srcds && chown -R srcds:root /srv/dods && su srcds

Afterwards we switch to the folder in which the executable of the server is placed:

[email protected]:$ cd /srv/dods/orangebox

The server executable takes a lot of parameters, you can find a list of them in the valve developer wiki. I have choosen the following for the fist start:

[email protected]:$ ./srcds_run -game dod -autoupdate -maxplayers 10 -port 27015 +map dod_avalanche

With these parameters a server listening on port 27015 (Source-Engine games default), with the game Day of Defeat: Source, a maximum capacity of 10 players on the first map dod_avalanche will be started. The parameter “-autoupdate” allows the server to automatically download updates on startup.

Now open your Day of Defeat: Source client with the parameter “-console 1” and connect to your server 🙂

After that worked we stop the running server with “ctrl + c” switch back to root with the “exit” command and build us a small init script to start the server automatically if we have to reboot the whole server.
You can use the following which I found in the srcds.com forums.

# Source Dedicated Server Init Script

# Server options
TITLE='Source Dedicated Server' # Script initialization title
LONGNAME='Day of Defeat Source'        # Full title of game type
NAME='dods'                          # Server handle for the screen session
DAEMON='srcds_run'                # The server daemon
STEAM='/srv/dods/orangebox'        # STEAM to Steam installation

# Game options
IP=''                # IP of the server
PORT='27015'                    # Port number to
MAP='dod_avalanche'                    # Initial map to start
GAME='dod'                        # Game type (tf|cstrike|valve|hl2mp)
SIZE='10'                        # Maximum number of players

# Server options string
OPTS="-game $GAME +hostname \"$CLIENT\" +map $MAP +ip $IP -port $PORT \
-autoupdate +maxplayers $SIZE -pidfile $STEAM/$GAME/$NAME.pid"

# Screen command
INTERFACE="sudo -u $USER /usr/bin/screen -A -m -d -S $NAME"

service_start() {
# Check if the pid files currently exist
if [ ! -f $STEAM/$GAME/$NAME.pid ] && [ ! -f $STEAM/$GAME/$NAME-screen.pid ]; then
if [ -x $STEAM/$DAEMON ]; then
echo "Starting $TITLE - $LONGNAME"
echo "Server IP: $IP"
echo "Server port: $PORT"
echo "Server size: $SIZE players"
# Prevent race condition on SMP kernels
sleep 1
# Find and write current process id of the screen process
ps -ef | grep SCREEN | grep "$NAME" | grep -v grep | awk '{ print $2}' > $STEAM/$GAME/$NAME-screen.pid
echo "$TITLE screen process ID written to $STEAM/$GAME/$NAME-screen.pid"
echo "$TITLE server process ID written to $STEAM/$GAME/$NAME.pid"

echo "$TITLE started."
echo -e "Cannot start $TITLE.  Server is already running."
#exit 1
service_stop() {
if [ -f $STEAM/$GAME/$NAME.pid ] && [ -f $STEAM/$GAME/$NAME-screen.pid ]; then
echo "Stopping $TITLE - $LONGNAME."
# Get the process ID from the pid file we created earlier
for id in `cat $STEAM/$GAME/$NAME-screen.pid`
do kill -9 $id
echo "Killing process ID $id"
echo "Removing $TITLE screen pid file"
rm -rf $STEAM/$GAME/$NAME-screen.pid
# Remove server pid file
echo "Removing $TITLE pid file"
rm -rf $STEAM/$GAME/$NAME.pid
# Wipe all old screen sessions
screen -wipe 1> /dev/null 2> /dev/null
echo "$TITLE stopped."
echo -e "Cannot stop $TITLE.  Server is not running."
#exit 1

case "$1" in
sleep 1
echo "Usage $0 start|stop|restart"

Place that script in “/etc/init.d/”, change the variables to your needs and update your servers init links. In debian for example with

[email protected]:$ update-rc.d dods defaults

You can now start your server with the init-script

[email protected]:$ /etc/init.d/dods start

That was the first part. We have now a small running server. In the next part we will configure the server and install the Mani Admin plugin.