Thehotfix.net Logo                            To the forums            

How to setup A CS: Source Dedicated Server (Linux)

 

The purpose of this tutorial is to teach you how to set up a dedicated server (using Steam) for a game or mod based on the Source engine, like Half-Life 2 (HL2) or Counter-Strike:Source (CS:S). I personally prefer Counter-Strike:Source, as it is a realistic and enjoyable First Person Shooter (FPS), so I will focus on setting it up.

Download and setup HLDSUpdatetool

First of all, you will need to download the HLDSUpdatetool, which will work on almost all Linux distributions. Open up a terminal window and enter these commands (replace ‘username‘ with your username - make sure you are logged in as a normal user, not root!):

$ su
Password:
# cd /home/username/
# mkdir srcds_l/
# cd srcds_l/
# wget http://www.steampowered.com/download/hldsupdatetool.bin
# chmod +x hldsupdatetool.bin
# ./hldsupdatetool.bin

Ok, let’s run through what we’ve just done. First of all, we changed user to root. Then, we moved to username’s home directory (where username is the standard user you logged in as). We created a directory called ’srcds_l’, in which the Steam files will reside. Then we moved into that directory, and downloaded the HLDSUpdatetool using wget. Once the download had completed, we gave the file execute permissions using the chmod command, and then we ran it. On the first run, HLDSUpdatetool will ask you to accept a license agreement and, if you type ‘yes’ (which I’m sure you will), it will extract itself.

Note: You may get an error along the lines of: sh: uncompress: command not found when you try to execute ‘hldsupdatetool.bin’. Not to worry - first, find out where your gunzip tool is. Do this by typing /usr/bin/gunzip and /bin/gunzip and seeing which one of the two works. For me, it was /usr/bin/gunzip. Now, type the following command (and replace the gunzip location if it is different):
# ln -s /usr/bin/gunzip /usr/bin/uncompress
Run the HLDSUpdatetool again via ./hldsupdatetool.bin - that should work.

The extraction of hldsupdatetool.bin has given us another application called steam. Now we must update the Steam HLDS Update Tool, which we can do by running:

# ./steam

Good. Now that we have everything up to date, we can begin downloading the game files.

# ./steam -command update -game “Counter-Strike Source” -dir .

What we have done above is told Steam to update the game “Counter-Strike Source” in the current directory, but as it is not in the current directory (because it is not installed yet), Steam will download and install it. This will take quite a while, no matter how fast your broadband connection is - so I advise that after you’ve executed the command, you go grab a coffee and a bite to eat. Seriously, take your time..

Add maps to the server

If you’re reading this line just a few seconds after the last section, go away - it really will take a long time ;)If not, let’s continue. Now we have a fully installed and updated version of Counter-Strike:Source. What do we do now? Well, first of all, let’s add some new maps; this part is always the most interesting.

Head off to FPSBANANA in your favourite web browser to download the maps you want. As an example, I’m going to download the map breakndeath_kontain0rs.

So, we now have our map, compressed as breakndeath_kontain0rs.zip (which we just downloaded from FPSBANANA, right?). We will need to extract the zip before we can do anything else. Make sure the zip is in /home/username and that is your current working directory (type pwd if you are not sure), then do the following:

# unzip -v breakndeath_kontain0rs.zip
# mv breakndeath_kontain0rs.bsp srcds_l/cstrike/maps/

The -v parameter to unzip meant to do it verbosely - that is, to show exactly what was happening. In this case, only one file (the .bsp) was contained within the zip, but with larger maps you will need to move more unzipped files into the appropriate cstrike directory. This will become clear to you once you unzip a larger map, which has not only the bsp, but also several materials or whatnot.

Now, we should add the map to our rotation list. You can do this by editing the file ‘/home/username/srcds_l/cstrike/mapcycle.txt‘ in an editor like kate or gedit. Remove the names of the maps you do not want to be on the rotation, and add the ones you do want there - one per line. Simple.

Configuring the server

It’s time to configure the server. We will be storing some Counter-Strike:Source server and client commands in a file called ‘server.cfg‘, which will be located in /home/username/srcds_l/cstrike/cfg/. With the help of this thread on the Mani-Admin-Plugin Forums, I have composed a sample server.cfg file for you.
Note: You will have to create the file yourself, so open your favourite text editor and copy the commands below into it. Make sure you save the file in the correct directory and with the right name.

// General Settings
hostname “My AMAZING Dedicated Server” // What your server will be called. Change this!
host_framerate 0
setpause 0
mp_chattime 10
sv_lan 0
sv_secure 1
sv_pausable 0
sv_cheats 0
sv_consistency 1
sv_stats 1
sv_allowdownload 1
sv_allowupload 0
sv_timeout 30
sv_voicecodec vaudio_miles
sv_voiceenable 1
sv_alltalk 1
sv_visiblemaxplayers 14 // maxplayers minus reserved slots

// Ban Settings
exec banned_user.cfg
exec banned_ip.cfg
writeid
writeip

// Contact & Geo Settings
sv_contact my@email.address // Change this!
sv_region 3 // Change this!
// us eastcoast - sv_region 0
// us westcoast - sv_region 1
// south america - sv_region 2
// europe - sv_region 3
// asia - sv_region 4
// australia - sv_region 5
// middle east - sv_region 6
// africa - sv_region 7
// world - sv_region 255

// Rcon Settings
rcon_password “My_Ub3R_l3T-5eRv%r” // Change this!
sv_rcon_banpenalty 15
sv_rcon_maxfailures 4
sv_rcon_minfailures 2
sv_rcon_minfailuretime 30

// Log Settings
sv_log_onefile 0
sv_logfile 1
sv_logbans 1
sv_logecho 1
mp_logdetail 3
log on

// Teamplay Settings
mp_spawnprotectiontime 0
mp_autokick 0
mp_autoteambalance 0
mp_fadetoblack 0
mp_forcecamera 0
mp_forcerespawn 1
mp_teamplay 0

// Game Settings
mp_fraglimit 0
mp_maxrounds 0
mp_winlimit 0
mp_timelimit 15
mp_startmoney 800
mp_roundtime 2.5
// mp_allowNPCs 1
mp_autocrosshair 0
mp_buytime 0.75
mp_c4timer 30
mp_falldamage 1
mp_flashlight 1
mp_footsteps 1
mp_freezetime 2
mp_friendlyfire 1
mp_tkpunish 0
mp_hostagepenalty 4
mp_limitteams 2
mp_playerid 0
sv_footsteps 1

// Performance Settings
mp_weaponstay 0
mp_decals 200
decalfrequency 10
breakable_multiplayer 1

// Spectator Settings
mp_allowspectators 1
sv_specaccelerate 5
sv_specnoclip 1
sv_specspeed 3

// Physics Settings
sv_gravity 800
sv_friction 4
sv_airaccelerate 10
sv_stopspeed 75
sv_stepsize 18
sv_maxspeed 320

// Rate Settings
sv_minrate 0
sv_maxrate 0
sv_minupdaterate 10
sv_maxupdaterate 60
sv_unlag 1
sv_maxunlag 1

// Ammo Settings
ammo_338mag_max 30
ammo_357sig_max 50
ammo_45acp_max 100
ammo_50AE_max 35
ammo_556mm_box_max 200
ammo_556mm_max 90
ammo_57mm_max 100
ammo_762mm_max 90
ammo_9mm_max 120
ammo_buckshot_max 40
ammo_flashbang_max 1
ammo_hegrenade_max 1
ammo_smokegrenade_max 1

// Mani Mod
exec mani_server.cfg
ma_war 0

// Announce Execution
say Public Mode CFG executed

Setting up Mani-Admin-Plugin

Now we have the server correctly setup, we can start adding some plugins. One of the all-time favourites is the Mani-Admin-Plugin, which makes administering a server extremely easy, and
adds extra functionality which is otherwise unavailable. I will take you through the installation steps, and then feel free to explore everything it has to offer.

Still as root in a terminal, copy and paste the following commands (Note: There may be a newer version of the Mani-Admin-Plugin for Counter-Strike:Source available. Check the Mani-Admin-Plugin websitefor the latest version of Mani and supply the link to the zip to wget:

# cd /home/username/
# wget http://link/to/mani_admin_plugin_v1_1_0zh_cssource.zip
# unzip mani_admin_plugin_v1_1_0zh_cssource.zip
# mkdir srcds_l/cstrike/addons/
# cp -r cstrike/addons/* srcds_l/cstrike/addons/
# cp -r cstrike/cfg/* srcds_l/cstrike/cfg/
# cp -r cstrike/materials/* srcds_l/cstrike/materials/
# cp -r cstrike/sound/* srcds_l/cstrike/sound/
# rm -rf cstrike/

We have just copied all the Mani-Admin-Plugin files into their respective directories within the Counter-Strike:Source directory, and the Plugin is correctly installed (thanks to our server.cfg). You can read up on all the advantages and extra tweaking settings here: Mani-Admin-Plugin Documentation. The Installation -> Configuration section will be particularly helpful, and I advise you read it with patience and care.

Setting up HLStatsX

To setup HLStatsX, we will need the following applications as well: Apache, Perl V5 or above (with the DBI and Msql-Mysql Modules), PHP V4 or above, and MySQL V3.23 or above. I suggest that you install those packages manually instead of using an all-in-one like XAMPP in this case, because it may make things a bit more complicated in the long run. If you have a package manager, install Apache2, Perl, PHP and MySQL from the repositories - if not you will have to compile them from source. An alternative is to use an external webhosting service to host HLStatsX for you - this is a good idea if you are already paying for webhosting, because you will not have to worry about installing the dependencies (there should be a simple interface to do this, or it will come with the package). Contact your webhost first to make sure you are allowed to install it.

Now that you (hopefully) have those installed - or are connected to your webhost via SSH - we need to add some Perl Modules to the system. Here is how we will do it:

# cpan (You will need to answer the questions - the defaults are usually fine)
cpan>install DBI
cpan>install DBD::mysql
cpan>quit

Great! Now we can get on with installing HLStatsX itself. First, download the latest version from here - it is currently at version 1.00 Final, so that is what I will be using.

# cd /home/username/
# wget http://www.hlstatsx.com/downloads/HLstatsX_V1.00.zip
# mkdir HLStatsX/
# mv HLstatsX_V1.00.zip HLStatsX/
# cd HLStatsX/
# unzip HLstatsX_V1.00.zip

And from here, I pass you on to United Admins - their HLStatsX installation guide will take you through the remaining steps!

Getting it online

If you are behind a router, you will have a few problems getting the server online. So, you will need to forward the following ports from the router to your server using a DMZ - make sure your server has a static IP address!

[UDP] 1200 (Used for Steam’s Friends service)
[UDP] 27000 to 27015 inclusive
[TCP] 27030 to 27039 inclusive

These are all Steam related ports

[UDP] 27015 and 27020 (Default dedicated server port, also used for HLTV)
[TCP] 27015 (For RCON access)

These ports are used by the dedicated server itself

The required ports were found here. You will also need port 27011 outbound allowed (configure your firewall), because this will allow you to connect to the master servers.

All we have to do now is run the server. The Command Line Interface (CLI) is less CPU intensive, and so the server will run more efficiently if we are not running an X server. So, let’s get complex. Open up a terminal (like aterm or konsole), and switch to root via the command su (or for sudo users, a simple workaround is sudo bash). Now, type in the command runlevel. You should see output similar to the following:
  N 5

In this case, my runlevel is 5. Yours will be the digit that appears in the result. However, sometimes this command may not be installed on your system, so we will have to discover your runlevel via another method. Here is what you will have to do (still as root in the terminal):
# less /etc/inittab
One of the first lines in that file will be something like the following:
id:5:initdefault:
The key section here is the 5 between id: and initdefault:, because that tells us what runlevel init boots into when the computers starts.

Well, now that we know what runlevel we are on, we can successfully switch to a runlevel which we are not on. You have the following runlevels to choose from: 2, 3, 4, 5 - minus the one we just discovered is your default one. In my case, the relevant runlevels are 2, 3, and 4, because I am already running on 5. All it takes to switch to another runlevel is:
# telinit 3
You will need to replace 3 with whatever runlevel you have chosen. I have decided to go to runlevel 3. Note that your graphical runlevel is usually 5, and the command line one is usually 3 (by default).

In your new runlevel, log in as a standard user (that is, non-root). Now we can move on to the next step. You can read more about init and runlevels here, and by viewing the init man page (man 8 init).

Right, now we have done pretty much everything. All we need to do is start the server (you may need to do it as root - if so, append ’sudo’ in front of the second command below)! Find out what your IP address is (using the ifconfig command), and replace 192.168.1.100 with it below:

# cd /home/username/srcds_l/
# ./srcds_run -console -game cstrike +map cs_italy +ip 192.168.1.100 +maxplayers 16 -autoupdate

And you’re done! :D

Note: This setup is not secure enough to be allowed online, especially if it is not behind a hardware firewall. Please take appropriate measures to secure your server before allowing others to play.

 

Thanks to http://wolphination.com/linux/2006/03/29/how-to-setup-a-cssource-dedicated-server/ for this how-to!!