[Guide] Step-by-step Dedicated Server on CentOS6

User avatar
WarStalkeR
Corporal
Posts: 22
Joined: Thu 12 Sep 2013 03:27
Contact:

[Guide] Step-by-step Dedicated Server on CentOS6

Postby WarStalkeR » Sat 19 Apr 2014 11:42

Image

Dear CentOS users, this guide will explain what to do, to make WarGame: Red Dragon Dedicated Server run on CentOS 6 (x86) (*), will help to create easy-to-use control script for it, will help add WarGame: Red Dragon Dedicated Server as service to easily manage it. In addition this tutorial will help to setup right rules for IPtables, to avoid any connectivity problems between dedicated server and clients and still leave your server protected. So let us start.

(*) Edit by Shifu: Doesn't work for Centos 7

1) Installing all required utilities:

Code: Select all

yum install wget p7zip nano

2) Getting libraries in place:

Code: Select all

cd /
mkdir libhelp
cd libhelp
wget http://soon-tm.info/t_stuff/libhelp.7z
7za x libhelp.7z
rm -f libhelp.7z
chmod 755 lib*

3) Preparing dedicated server:

Code: Select all

useradd wargame
cd /opt
wget --no-check-certificate https://link_to_ip_from_eugen/wargame3_server.tar.bz2
tar -xvjf wargame3_server.tar.bz2
rm -f wargame3_server.tar.bz2
cd wargame3_server
ln -sf /libhelp/libssl.so.1.0.0 libssl.so.1.0.0
ln -sf /libhelp/libcrypto.so.1.0.0 libcrypto.so.1.0.0
ln -sf /libhelp/libstdc++.so.6 libstdc++.so.6
touch wargame3-launcher.sh
chmod 755 wargame3-launcher.sh
nano wargame3-launcher.sh
and put there this script (where XXXX is port what you want to use for games, YY.YY.YY.YY is static IP of your server, PPPPPPPP is a desired password and ZZZZ is a port for the WarGame Server Remote Control):

Code: Select all

#!/bin/sh
# No Copyrights (c) 2014 WarStalkeR
# No Right Reserved, do with it what you want :D

cd "$(dirname "$0")"

LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:./ ./wargame3-server +port XXXX +port_mms 10804 +rcon_port ZZZZ +rcon_password PPPPPPPP +ip YY.YY.YY.YY
After creating script wargame3-launcher.sh do:

Code: Select all

cd ..
chown wargame:wargame -R wargame3_server

4) Adding dedicated server as service:

Code: Select all

cd /opt/wargame3_server/
touch wargame3-controlscript.sh
chown wargame:wargame wargame3-controlscript.sh
chmod 755 wargame3-controlscript.sh
nano wargame3-controlscript.sh
And put there this script (in case you used same directory path as I used in this guide):

Code: Select all

#!/bin/sh
# No Copyrights (c) 2014 WarStalkeR
# No Right Reserved, do with it what you want :D
# Allows only one instance of WarGame Server per machine!

COMMANDLINE_PARAMETERS=""
BINARYNAME="wargame3-server"
BINARYEXEC="wargame3-launcher.sh"
BINARYPATH="$(dirname "${D1}")"
cd "${BINARYPATH}"

case "$1" in
        start)
                if ( kill -0 $(pidof wargame3-server) 2> /dev/null ); then
                        echo "WarGame Server is already running, try restart or stop."
                        exit 1
                elif [ -e wargame3-server.pid ]; then
                        echo "wargame3-server.pid found, but no server running. Possibly your previously started WarGame Server has crashed."
                        echo "Please view the logfile for details."
                        rm wargame3-server.pid
                fi
                if [ "${UID}" = "0" ]; then
                        echo WARNING! FOR SECURITY REASONS DO NOT RUN THE WarGame Server AS ROOT!
                        c=1
                        while [ "$c" -le 10 ]; do
                                echo -n "!"
                                sleep 1
                                c=$(($c+1))
                        done
                        echo "!"
                fi
                echo "Starting the WarGame Server."
                if [ -e "$BINARYNAME" ]; then
                        if [ ! -x "$BINARYNAME" ]; then
                                echo "${BINARYNAME} is not executable, trying to set it!"
                                chmod 755 "${BINARYNAME}"
                        fi
                        if [ -x "$BINARYNAME" ]; then
                                "./${BINARYEXEC}" > /dev/null &
                                echo $! > wargame3-server.pid
                                echo "WarGame Server has started!"
                        else
                                echo "${BINARNAME} is not exectuable, cannot start WarGame Server!"
                        fi
                else
                        echo "WARNING! Could not find binary! Aborting."
                        exit 5
                fi
        ;;
        stop)
                if ( kill -0 $(pidof wargame3-server) 2> /dev/null ); then
                        echo -n "Stopping the WarGame Server. "
                        if ( kill -SIGINT $(pidof wargame3-server) 2> /dev/null ); then
                                c=1
                                while [ "$c" -le 300 ]; do
                                        if ( kill -0 $(pidof wargame3-server) 2> /dev/null ); then
                                                echo -n "."
                                                sleep 1
                                        else
                                                break
                                        fi
                                        c=$((++c))
                                done
                        fi
                        if ( kill -TERM $(pidof wargame3-server) 2> /dev/null ); then
                                c=1
                                while [ "$c" -le 300 ]; do
                                        if ( kill -0 $(pidof wargame3-server) 2> /dev/null ); then
                                                echo -n "."
                                                sleep 1
                                        else
                                                break
                                        fi
                                        c=$((++c))
                                done
                        fi
                        if ( kill -0 $(pidof wargame3-server) 2> /dev/null ); then
                                echo "WarGame Server is not shutting down correctly! Terminating!"
                                kill -KILL $(pidof wargame3-server)
                        fi
                        sleep 3
                        if [ -e wargame3-server.pid ]; then
                                rm wargame3-server.pid
                        fi
                        echo "Done."
                else
                        echo "WarGame Server is not running."
                        exit 7
                fi
        ;;
        restart)
                if ( kill -0 $(pidof wargame3-server) 2> /dev/null ); then
                        echo -n "Stopping the WarGame Server. "
                        if ( kill -SIGINT $(pidof wargame3-server) 2> /dev/null ); then
                                c=1
                                while [ "$c" -le 300 ]; do
                                        if ( kill -0 $(pidof wargame3-server) 2> /dev/null ); then
                                                echo -n "."
                                                sleep 1
                                        else
                                                break
                                        fi
                                        c=$((++c))
                                done
                        fi
                        if ( kill -TERM $(pidof wargame3-server) 2> /dev/null ); then
                                c=1
                                while [ "$c" -le 300 ]; do
                                        if ( kill -0 $(pidof wargame3-server) 2> /dev/null ); then
                                                echo -n "."
                                                sleep 1
                                        else
                                                break
                                        fi
                                        c=$((++c))
                                done
                        fi
                        if ( kill -0 $(pidof wargame3-server) 2> /dev/null ); then
                                echo "WarGame Server is not shutting down correctly! Terminating!"
                                kill -KILL $(pidof wargame3-server)
                        fi
                        sleep 3
                        if [ -e wargame3-server.pid ]; then
                                rm wargame3-server.pid
                        fi
                        echo "Done."
                else
                        echo "WarGame Server is not running."
                fi
        if ( kill -0 $(pidof wargame3-server) 2> /dev/null ); then
                        echo "WarGame Server is already running, try restart or stop."
                        exit 1
                elif [ -e wargame3-server.pid ]; then
                        echo "wargame3-server.pid found, but no server running. Possibly your previously started WarGame Server has crashed."
                        echo "Please view the logfile for details."
                        rm wargame3-server.pid
                fi
                if [ "${UID}" = "0" ]; then
                        echo WARNING! FOR SECURITY REASONS DO NOT RUN THE WarGame Server AS ROOT!
                        c=1
                        while [ "$c" -le 10 ]; do
                                echo -n "!"
                                sleep 1
                                c=$(($c+1))
                        done
                        echo "!"
                fi
                echo "Starting the WarGame Server."
                if [ -e "$BINARYNAME" ]; then
                        if [ ! -x "$BINARYNAME" ]; then
                                echo "${BINARYNAME} is not executable, trying to set it!"
                                chmod 755 "${BINARYNAME}"
                        fi
                        if [ -x "$BINARYNAME" ]; then
                                "./${BINARYEXEC}" > /dev/null &
                                echo $! > wargame3-server.pid
                                echo "WarGame Server has started!"
                        else
                                echo "${BINARNAME} is not exectuable, cannot start WarGame Server!"
                        fi
                else
                        echo "WARNING! Could not find binary! Aborting."
                        exit 5
                fi
        ;;
        status)
                if ( kill -0 $(pidof wargame3-server) 2> /dev/null ); then
                        echo "WarGame Server is running."
                elif [ -e wargame3-server.pid ]; then
                        echo "WarGame Server seems to be dead."
                else
                        echo "WarGame Server is not running."
                fi
        ;;
        *)
                echo "Usage: ${0} {start|stop|restart|status}"
                exit 2
esac
exit 0
Now it's time to add service script itself:

Code: Select all

touch /etc/rc.d/init.d/wargame3
chmod 755 /etc/rc.d/init.d/wargame3
nano /etc/rc.d/init.d/wargame3
And put there this script (in case you used same directory path as I used in this guide):

Code: Select all

#!/bin/sh
# chkconfig: 2345 98 8
# description: Start/Stop/Restart/Status the WarGame Server
# install: chkconfig --add wargame3
# uninstall: chkconfig --del wargame3
# author: WarStalkeR

su=/bin/su
user=wargame #user you want to use for Starbound Server
dir=/opt/wargame3_server/ #folder where you installed Starbound
exec=./wargame3-controlscript.sh #name of the control script

case "$1" in
start)
$su - $user -c "cd $dir;$exec start"
;;
stop)
$su - $user -c "cd $dir;$exec stop"
;;
restart)
$su - $user -c "cd $dir;$exec restart"
;;
status)
$su - $user -c "cd $dir;$exec status"
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 2
esac
exit 0
And then run these command:

Code: Select all

chkconfig --add wargame3
And now in order to run WarGame: Red Dragon Dedicated Server all you need to do is:

Code: Select all

service wargame3 start
service wargame3 start - will start the dedicated server software.
service wargame3 stop - will stop the dedicated server software.
service wargame3 restart - will restart the dedicated server software.
service wargame3 status - will show status whether dedicated server software running, stopped or crashed.

5) Adding WarGame: Red Dragon Dedicated Server compatible rules to IPtables:

Code: Select all

iptables -A INPUT -p tcp --sport 513:65535 --dport XXXX -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport XXXX --dport 513:65535 -m state --state ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport 44000:45000 --dport 10804 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --sport 10804 --dport 44000:45000 -m state --state ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport 513:65535 --dport 10280:10820 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --sport 10280:10820 --dport 513:65535 -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --sport 513:65535 --dport ZZZZ -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport ZZZZ --dport 513:65535 -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -p udp --dport XXXX -j ACCEPT
iptables -A OUTPUT -p udp --sport XXXX -j ACCEPT
Where XXXX and ZZZZ are ports that you defined earlier to use for games at your server and for the WarGame Server Remote Control.

6) Enjoy!

P.S. Maybe later I will add feature in to service script that will allow to work with multiple dedicated service configuration files to start all kinds of different game types instantly.
Last edited by WarStalkeR on Tue 26 Aug 2014 14:52, edited 4 times in total.
"Happiness for everybody, freely, and let no one to leave unhappy!" (c) Strugatsky Brothers

bestboy
Staff Sergeant
Posts: 86
Joined: Sat 13 Jul 2013 17:20
Contact:

Re: Step-by-step Dedicated Server on CentOS

Postby bestboy » Sat 19 Apr 2014 12:30

Great stuff.

But out of curiosity, do you happen to know what the various port ranges are for?
WarStalkeR wrote:...
5) Adding WarGame: Red Dragon Dedicated Server compatible rules to IPtables:

Code: Select all

iptables -A INPUT -p tcp --sport 513:65535 --dport XXXX -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport XXXX --dport 513:65535 -m state --state ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport 44000:45000 --dport 10804 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --sport 10804 --dport 44000:45000 -m state --state ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport 513:65535 --dport 10280:10820 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --sport 10280:10820 --dport 513:65535 -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -p udp --dport XXXX -j ACCEPT
iptables -A OUTPUT -p udp --sport XXXX -j ACCEPT
Where XXXX is port that you defined earlier to use for games at your server.

User avatar
WarStalkeR
Corporal
Posts: 22
Joined: Thu 12 Sep 2013 03:27
Contact:

Re: Step-by-step Dedicated Server on CentOS

Postby WarStalkeR » Sun 20 Apr 2014 03:21

bestboy wrote:Great stuff.

But out of curiosity, do you happen to know what the various port ranges are for?
WarStalkeR wrote:...
5) Adding WarGame: Red Dragon Dedicated Server compatible rules to IPtables:

Code: Select all

iptables -A INPUT -p tcp --sport 513:65535 --dport XXXX -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport XXXX --dport 513:65535 -m state --state ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport 44000:45000 --dport 10804 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --sport 10804 --dport 44000:45000 -m state --state ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport 513:65535 --dport 10280:10820 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --sport 10280:10820 --dport 513:65535 -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -p udp --dport XXXX -j ACCEPT
iptables -A OUTPUT -p udp --sport XXXX -j ACCEPT
Where XXXX is port that you defined earlier to use for games at your server.
Thanks. More or less. Beside official information provided by devs, I just disabled IPtables, then started while true; do (netstat -taupen | grep wargame3); sleep 1; done and then the dedicated server itself to scan what port used during different circumstances.

First Pair: used to allow to client to request server to establish connection with it.
Second Pair: used to allow your server to establish connection with main Eugen main server.
Third Pair: used to connect server to client server and allow transferring of game information.
Fourth Pair: used to allow client find/ping server via Eugen main server.

The strange phenomena is, that sometime First Pair isn't switched to Third Pair and also used to transfer gaming information, though I don't see any security issue here, I just find it strange.
"Happiness for everybody, freely, and let no one to leave unhappy!" (c) Strugatsky Brothers

User avatar
Shifu
Lieutenant General
Posts: 4106
Joined: Wed 13 Jul 2011 16:06
Location: :noitacoL
Contact:

Re: Step-by-step Dedicated Server on CentOS

Postby Shifu » Sun 20 Apr 2014 16:03

Moved. Great post, thanks!
I'm currently running short on time. Hence, it takes some time until I respond. In urgent cases, consider contacting another mod.
Forum rules | A Forum's guide. | Tech Support Posting instructions & Tech FAQ

Alveuel
Corporal
Posts: 31
Joined: Tue 4 Feb 2014 03:02
Contact:

Re: Step-by-step Dedicated Server on CentOS

Postby Alveuel » Thu 24 Apr 2014 20:11

service wargame3 status - will show status whether dedicated server software running, stopped or crushed.


^Hoping you meant crashed instead of crushed. ;)

Great instructions. I may try to get this working in openSUSE since it appears that other flavors of Linux can run it just fine. 8-)
~Alveuel

User avatar
WarStalkeR
Corporal
Posts: 22
Joined: Thu 12 Sep 2013 03:27
Contact:

Re: Step-by-step Dedicated Server on CentOS

Postby WarStalkeR » Thu 24 Apr 2014 20:51

Alveuel wrote:Hoping you meant crashed instead of crushed. ;)
Thanks for pointing out. Fixed.

Alveuel wrote:Great instructions. I may try to get this working in openSUSE since it appears that other flavors of Linux can run it just fine. 8-)
Remember, Linux is always Linux, and kernel will be the same, so the drivers compatibility too. Thus if something works on one of the distros, will work on the rest too after little voodoo magic spell ;)
"Happiness for everybody, freely, and let no one to leave unhappy!" (c) Strugatsky Brothers

Alveuel
Corporal
Posts: 31
Joined: Tue 4 Feb 2014 03:02
Contact:

Re: Step-by-step Dedicated Server on CentOS

Postby Alveuel » Thu 24 Apr 2014 21:21

WarStalkeR wrote:Remember, Linux is always Linux, and kernel will be the same, so the drivers compatibility too. Thus if something works on one of the distros, will work on the rest too after little voodoo magic spell ;)


Certainly gave me faith that it was possible. That voodoo magic spell can be tough when crossing the major distro lines (debian, redhat, slackware).
~Alveuel

Wookimonsta
Corporal
Posts: 27
Joined: Wed 12 Feb 2014 19:43
Contact:

Re: Step-by-step Dedicated Server on CentOS

Postby Wookimonsta » Mon 28 Apr 2014 19:08

Well I followed the guide, the only thing I didn't do was set up the control script. The server seems to start and I get up to:

Code: Select all

Connection to match making server validated , dedicated server can be used by clients on IP 176.9.48.239:10001
ServerPropertyReporting listening for client !
Using http://87.98.143.182:10280/stats2/ as CouchDB stats source
.

Unfortunately, I cannot see the server in the list.

User avatar
WarStalkeR
Corporal
Posts: 22
Joined: Thu 12 Sep 2013 03:27
Contact:

Re: Step-by-step Dedicated Server on CentOS

Postby WarStalkeR » Fri 2 May 2014 08:52

Wookimonsta wrote:Unfortunately, I cannot see the server in the list.
Check to be sure that you didn't blocked any port WarGame needs.
"Happiness for everybody, freely, and let no one to leave unhappy!" (c) Strugatsky Brothers

Wookimonsta
Corporal
Posts: 27
Joined: Wed 12 Feb 2014 19:43
Contact:

Re: Step-by-step Dedicated Server on CentOS

Postby Wookimonsta » Mon 5 May 2014 16:41

I even opened all ports just for testing purposes.

Who is online

Users browsing this forum: No registered users and 1 guest