From d5b7c3cba616e2453027ec073ec1acfde05f520d Mon Sep 17 00:00:00 2001
From: Marvin Lehmann <marvinlehmann@live.de>
Date: Fri, 11 Nov 2016 18:24:18 +0100
Subject: [PATCH 01/11] Overhauled Don't Starve Together server

WORK IN PROGRESS
- use ip parameter and/or ip from config
- standardize fn_dstconfig() ?
- ..
---
 DontStarveTogether/dstserver        | 35 +++++++++----
 lgsm/functions/command_details.sh   | 15 +++++-
 lgsm/functions/command_install.sh   |  2 +
 lgsm/functions/core_functions.sh    |  5 ++
 lgsm/functions/core_getopt.sh       | 79 +++++++++++++++++++++++++++++
 lgsm/functions/info_config.sh       | 14 ++---
 lgsm/functions/install_config.sh    | 67 ++++++++++++++++++++++--
 lgsm/functions/install_dst_token.sh | 49 ++++++++++++++++++
 8 files changed, 244 insertions(+), 22 deletions(-)
 create mode 100644 lgsm/functions/install_dst_token.sh

diff --git a/DontStarveTogether/dstserver b/DontStarveTogether/dstserver
index 5b9a5c112..0c4b9647a 100644
--- a/DontStarveTogether/dstserver
+++ b/DontStarveTogether/dstserver
@@ -14,7 +14,7 @@ if [ -f ".dev-debug" ]; then
 	set -x
 fi
 
-version="161030"
+version="161111"
 
 ##########################
 ######## Settings ########
@@ -22,15 +22,29 @@ version="161030"
 
 #### Server Settings ####
 
+## Installation Variables
+# Visit the following link for more information:
+# https://github.com/GameServerManagers/LinuxGSM/wiki/Don't-Starve-Together
+sharding="false"
+master="true"
+shard="Master" 
+cluster="Cluster_1"
+cave="false"
+
 ## Server Start Settings | https://github.com/GameServerManagers/LinuxGSM/wiki/Start-Parameters
 ip="0.0.0.0"
+port="11000"
+steamauthenticationport="8768"
+steammasterserverport="27018"
+tickrate="15"
+
+# Edit with care
+persistentstorageroot="${HOME}/.klei"
+confdir="DoNotStarveTogether"
 
 ## Server Start Command | https://github.com/GameServerManagers/LinuxGSM/wiki/Start-Parameters#additional-parameters
-# Edit with care | http://dont-starve-game.wikia.com/wiki/Guides/Don%E2%80%99t_Starve_Together_Dedicated_Servers
-# Overworld: -conf_dir DST_Overworld
-# Cave: -conf_dir DST_Cave
 fn_parms(){
-parms="-console -cluster MyDediServer -shard Master"
+parms="-bind_ip ${ip} -port ${port} -steam_master_server_port ${steammasterserverport} -steam_authentication_port ${steamauthenticationport} -tick ${tickrate} -persistent_storage_root ${persistentstorageroot} -conf_dir ${confdir} -cluster ${cluster} -shard ${shard}"
 # -console -cluster MyDediServer -shard Master
 }
 
@@ -100,11 +114,14 @@ filesdir="${rootdir}/serverfiles"
 systemdir="${filesdir}"
 executabledir="${filesdir}/bin"
 executable="./dontstarve_dedicated_server_nullrenderer"
-servercfg="settings.ini"
-servercfgdefault="settings.ini"
-servercfgdir="${HOME}/.klei/DoNotStarveTogether"
+clustercfg="cluster.ini"
+clustercfgdir="${persistentstorageroot}/${confdir}/${cluster}"
+clustercfgfullpath="${clustercfgdir}/${clustercfg}"
+clustercfgdefault="${clustercfgdir}/cluster.ini"
+servercfg="server.ini"
+servercfgdir="${clustercfgdir}/${shard}"
 servercfgfullpath="${servercfgdir}/${servercfg}"
-servercfgdefault="${servercfgdir}/lgsm-default.ini"
+servercfgdefault="server.ini"
 
 ## Backup Directory
 backupdir="${rootdir}/backups"
diff --git a/lgsm/functions/command_details.sh b/lgsm/functions/command_details.sh
index 4f39fe2ef..f42378504 100644
--- a/lgsm/functions/command_details.sh
+++ b/lgsm/functions/command_details.sh
@@ -152,6 +152,16 @@ fn_details_gameserver(){
 		if [ -n "${tickrate}" ]; then
 			echo -e "${blue}Tick rate:\t${default}${tickrate}"
 		fi
+				
+		# Cluster (Don't Starve Together)
+		if [ -n "${cluster}" ]; then
+			echo -e "${blue}Cluster:\t${default}${cluster}"
+		fi
+		
+		# Shard (Don't Starve Together)
+		if [ -n "${shard}" ]; then
+			echo -e "${blue}Shard:\t${default}${shard}"
+		fi
 
 		# TeamSpeak dbplugin
 		if [ -n "${dbplugin}" ]; then
@@ -355,7 +365,10 @@ fn_details_dontstarve(){
 	echo -e ""
 	{
 		echo -e "DESCRIPTION\tDIRECTION\tPORT\tPROTOCOL"
-		echo -e "> Game\tINBOUND\t${port}\tudp"
+		echo -e "> Game: Server\tINBOUND\t${port}\tudp"
+		echo -e "> Game: Master\tINBOUND\t${masterport}\tudp"
+		echo -e "> Steam: Auth\tINBOUND\t${steamauthenticationport}\tudp"
+		echo -e "> Steam: Master\tINBOUND\t${steammasterserverport}\tudp"
 	} | column -s $'\t' -t
 }
 
diff --git a/lgsm/functions/command_install.sh b/lgsm/functions/command_install.sh
index 43dc9daf5..b415f47a3 100644
--- a/lgsm/functions/command_install.sh
+++ b/lgsm/functions/command_install.sh
@@ -30,6 +30,8 @@ fi
 install_config.sh
 if [ "${gamename}" == "Counter-Strike: Global Offensive" ]||[ "${gamename}" == "Team Fortress 2" ]||[ "${gamename}" == "BrainBread 2" ]; then
 	install_gslt.sh
+elif [ "${gamename}" == "Don't Starve Together" ]; then
+	install_dst_token.sh
 elif [ "${gamename}" == "TeamSpeak 3" ]; then
 	install_ts3db.sh
 fi
diff --git a/lgsm/functions/core_functions.sh b/lgsm/functions/core_functions.sh
index f5ba4ce9e..746027581 100644
--- a/lgsm/functions/core_functions.sh
+++ b/lgsm/functions/core_functions.sh
@@ -475,6 +475,11 @@ functionfile="${FUNCNAME}"
 fn_fetch_function
 }
 
+install_dst_token.sh(){
+functionfile="${FUNCNAME}"
+fn_fetch_function
+}
+
 install_gsquery.sh(){
 functionfile="${FUNCNAME}"
 fn_fetch_function
diff --git a/lgsm/functions/core_getopt.sh b/lgsm/functions/core_getopt.sh
index d629e3711..2a553b582 100644
--- a/lgsm/functions/core_getopt.sh
+++ b/lgsm/functions/core_getopt.sh
@@ -337,6 +337,83 @@ case "${getopt}" in
 	esac
 }
 
+fn_getopt_dstserver(){
+case "${getopt}" in
+	st|start)
+		command_start.sh;;
+	sp|stop)
+		command_stop.sh;;
+	r|restart)
+		command_restart.sh;;
+	u|update)
+		command_update.sh;;
+	fu|force-update|update-restart)
+		forceupdate=1;
+		command_update.sh;;
+	uf|update-functions)
+		command_update_functions.sh;;
+	v|validate)
+		command_validate.sh;;
+	m|monitor)
+		command_monitor.sh;;
+	ta|test-alert)
+		command_test_alert.sh;;
+	dt|details)
+		command_details.sh;;
+	pd|postdetails)
+		command_postdetails.sh;;
+	b|backup)
+		command_backup.sh;;
+	c|console)
+		command_console.sh;;
+	d|debug)
+		command_debug.sh;;
+	dev|dev-debug)
+		command_dev_debug.sh;;
+	i|install)
+		command_install.sh;;
+	ai|auto-install)
+		fn_autoinstall;;
+	ct|cluster-token)
+		install_dst_token.sh;;
+	dd|detect-deps)
+		command_dev_detect_deps.sh;;
+	dg|detect-glibc)
+		command_dev_detect_glibc.sh;;
+	dl|detect-ldd)
+		command_dev_detect_ldd.sh;;
+	*)
+	if [ -n "${getopt}" ]; then
+		echo -e "${red}Unknown command${default}: $0 ${getopt}"
+		exitcode=2
+	fi
+	echo "Usage: $0 [option]"
+	echo "${gamename} - Linux Game Server Manager - Version ${version}"
+	echo "https://gameservermanagers.com/${selfname}"
+	echo -e ""
+	echo -e "${lightyellow}Commands${default}"
+	{
+		echo -e "${blue}start\t${default}st |Start the server."
+		echo -e "${blue}stop\t${default}sp |Stop the server."
+		echo -e "${blue}restart\t${default}r  |Restart the server."
+		echo -e "${blue}update\t${default}u  |Checks and applies updates from SteamCMD."
+		echo -e "${blue}force-update\t${default}fu |Bypasses the check and applies updates from SteamCMD."
+		echo -e "${blue}update-functions\t${default}uf |Removes all functions so latest can be downloaded."
+		echo -e "${blue}validate\t${default}v  |Validate server files with SteamCMD."
+		echo -e "${blue}monitor\t${default}m  |Checks that the server is running."
+		echo -e "${blue}test-alert\t${default}ta |Sends test alert."
+		echo -e "${blue}details\t${default}dt |Displays useful information about the server."
+		echo -e "${blue}postdetails\t${default}pd |Post stripped details to pastebin (for support)"
+		echo -e "${blue}backup\t${default}b  |Create archive of the server."
+		echo -e "${blue}console\t${default}c  |Console allows you to access the live view of a server."
+		echo -e "${blue}debug\t${default}d  |See the output of the server directly to your terminal."
+		echo -e "${blue}install\t${default}i  |Install the server."
+		echo -e "${blue}auto-install\t${default}ai |Install the server, without prompts."
+		echo -e "${blue}cluster-token\t${default}ct |Configure cluster token."
+	} | column -s $'\t' -t
+	esac
+}
+
 fn_getopt_gmodserver(){
 case "${getopt}" in
 	st|start)
@@ -628,6 +705,8 @@ elif [ "${engine}" == "lwjgl2" ]; then
 	fn_getopt_minecraft
 elif [ "${gamename}" == "TeamSpeak 3" ]; then
 	fn_getopt_teamspeak3
+elif [ "${gamename}" == "Don't Starve Together" ]; then
+	fn_getopt_dstserver
 elif [ "${gamename}" == "Garry's Mod" ]; then
 	fn_getopt_gmodserver
 elif [ "${engine}" == "unreal2" ]; then
diff --git a/lgsm/functions/info_config.sh b/lgsm/functions/info_config.sh
index 46e7445a6..4e8fca918 100644
--- a/lgsm/functions/info_config.sh
+++ b/lgsm/functions/info_config.sh
@@ -81,7 +81,7 @@ fn_info_config_cod(){
 }
 
 fn_info_config_dontstarve(){
-	if [ ! -f "${servercfgfullpath}" ]; then
+	if [ ! -f "${clustercfgfullpath}" ]; then
 		servername="${unavailable}"
 		serverpassword="${unavailable}"
 		slots="${zero}"
@@ -89,12 +89,12 @@ fn_info_config_dontstarve(){
 		tickrate="${zero}"
 		port="${zero}"
 	else
-		servername=$(grep "default_server_name" "${servercfgfullpath}" | sed -e 's/^[ \t]*//g' -e '/^#/d' -e 's/default_server_name//g' | tr -d '=\";,:' | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//')
-		serverpassword=$(grep "server_password" "${servercfgfullpath}" | sed -e 's/^[ \t]*//g' -e '/^#/d' -e 's/server_password//g' | tr -d '=\";,:' | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//')
-		slots=$(grep "max_players" "${servercfgfullpath}" | grep -v "#" | tr -cd '[:digit:]')
-		gamemode=$(grep "game_mode" "${servercfgfullpath}" | sed -e 's/^[ \t]*//g' -e '/^#/d' -e 's/game_mode//g' | tr -d '=\";,:' | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//')
-		tickrate=$(grep "tick_rate" "${servercfgfullpath}" | grep -v "#" | tr -cd '[:digit:]')
-		port=$(grep "server_port" "${servercfgfullpath}" | grep -v "#" | tr -cd '[:digit:]')
+		servername=$(grep "cluster_name" "${clustercfgfullpath}" | sed -e 's/^[ \t]*//g' -e '/^#/d' -e 's/cluster_name//g' | tr -d '=\";,:' | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//')
+		serverpassword=$(grep "cluster_password" "${clustercfgfullpath}" | sed -e 's/^[ \t]*//g' -e '/^#/d' -e 's/cluster_password//g' | tr -d '=\";,:' | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//')
+		slots=$(grep "max_players" "${clustercfgfullpath}" | grep -v "#" | tr -cd '[:digit:]')
+		gamemode=$(grep "game_mode" "${clustercfgfullpath}" | sed -e 's/^[ \t]*//g' -e '/^#/d' -e 's/game_mode//g' | tr -d '=\";,:' | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//')
+		tickrate=$(grep "tick_rate" "${clustercfgfullpath}" | grep -v "#" | tr -cd '[:digit:]')
+		port=$(grep "master_port" "${clustercfgfullpath}" | grep -v "#" | tr -cd '[:digit:]')
 
 		# Not Set
 		servername=${servername:-"NOT SET"}
diff --git a/lgsm/functions/install_config.sh b/lgsm/functions/install_config.sh
index 543315458..adfad2e90 100644
--- a/lgsm/functions/install_config.sh
+++ b/lgsm/functions/install_config.sh
@@ -10,11 +10,11 @@ local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
 
 fn_fetch_default_config(){
 	mkdir -pv "${lgsmdir}/default-configs"
-	githuburl="https://github.com/GameServerManagers/Game-Server-Configs/master"
+	githuburl="https://github.com/GameServerManagers/Game-Server-Configs/dstserver"
 
 	for config in "${array_configs[@]}"
 	do
-		fileurl="https://raw.githubusercontent.com/GameServerManagers/Game-Server-Configs/master/${gamedirname}/${config}"; filedir="${lgsmdir}/default-configs"; filename="${config}";  executecmd="noexecute" run="norun"; force="noforce"
+		fileurl="https://raw.githubusercontent.com/GameServerManagers/Game-Server-Configs/dstserver/${gamedirname}/${config}"; filedir="${lgsmdir}/default-configs"; filename="${config}";  executecmd="noexecute" run="norun"; force="noforce"
 		fn_fetch_file "${fileurl}" "${filedir}" "${filename}" "${executecmd}" "${run}" "${force}" "${md5}"
 	done
 }
@@ -65,6 +65,64 @@ fn_default_config_remote(){
 	sleep 1
 }
 
+fn_dstconfig(){
+	## cluster.ini
+	# this config shouldn't be overridden
+	if [ ! -s "${clustercfgfullpath}" ]; then
+		echo "copying ${clustercfg} config file."
+		fn_script_log_info "copying ${clustercfg} config file."
+		cp -v "${lgsmdir}/default-configs/${clustercfgdefault}" "${clustercfgfullpath}"
+		sleep 1
+		echo "changing server name."
+		fn_script_log_info "changing server name."
+		sed -i "s/SERVERNAME/LinuxGSM/g" "${clustercfgfullpath}"
+		sleep 1
+		echo "changing shard mode."
+		fn_script_log_info "changing shard mode."
+		sed -i "s/USESHARDING/${sharding}/g" "${clustercfgfullpath}"
+		sleep 1
+		echo "randomizing cluster key."
+		fn_script_log_info "randomizing cluster key."
+		randomkey=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
+		sed -i "s/CLUSTERKEY/${randomkey}/g" "${clustercfgfullpath}"
+		sleep 1
+	else	
+		echo "${clustercfg} already exists."
+		fn_script_log_info "${clustercfg} already exists."
+	fi
+	
+	## server.ini
+	echo "copying ${servercfg} config file."
+	fn_script_log_info "copying ${servercfg} config file."
+	cp -v "${lgsmdir}/default-configs/${servercfgdefault}" "${servercfgfullpath}"
+	sleep 1
+	# removing unnecessary options (dependent on sharding & shard type)
+	if [ "sharding" == "false" ]; then 
+		sed -i "s/ISMASTER//g" "${servercfgfullpath}"
+		sed -d "/SHARDNAME/d" "${servercfgfullpath}"
+	elif [ "master" == "true" ];
+		sed -d "/SHARDNAME/d" "${servercfgfullpath}"
+	fi
+	# configure settings
+	echo "changing shard name."
+	fn_script_log_info "changing shard name."
+	sed -i "s/SHARDNAME/${shard}/g" "${servercfgfullpath}"
+	sleep 1
+	echo "changing master setting."
+	fn_script_log_info "changing master setting."
+	sed -i "s/ISMASTER/${master}/g" "${servercfgfullpath}"
+	sleep 1
+	
+	## worldgenoverride.lua
+	if [ "${cave}" == "true" ]; then
+		echo "defining ${shard} as cave in ${servercfgdir}/worldgenoverride.lua."
+		fn_script_log_info "defining ${shard} as cave in ${servercfgdir}/worldgenoverride.lua."
+		echo 'return { override_enabled = true, preset = "DST_CAVE", }' > "${servercfgdir}/worldgenoverride.lua"
+	fi
+	sleep 1
+	echo ""
+}
+
 echo ""
 echo "Downloading ${gamename} Config"
 echo "================================="
@@ -175,10 +233,9 @@ elif [ "${gamename}" == "Deathmatch Classic" ]; then
 	fn_set_config_vars
 elif [ "${gamename}" == "Don't Starve Together" ]; then
 	gamedirname="DontStarveTogether"
-	array_configs+=( Settings.ini )
+	array_configs+=( cluster.ini server.ini )
 	fn_fetch_default_config
-	fn_default_config_remote
-	fn_set_config_vars
+	fn_dstconfig
 elif [ "${gamename}" == "Double Action: Boogaloo" ]; then
 	gamedirname="DoubleActionBoogaloo"
 	array_configs+=( server.cfg )
diff --git a/lgsm/functions/install_dst_token.sh b/lgsm/functions/install_dst_token.sh
new file mode 100644
index 000000000..2e9713e71
--- /dev/null
+++ b/lgsm/functions/install_dst_token.sh
@@ -0,0 +1,49 @@
+#!/bin/bash
+# LGSM install_dst_token.sh function
+# Author: Daniel Gibbs & Marvin Lehmann (marvinl97)
+# Website: https://gameservermanagers.com
+# Description: Configures Don't Starve Together cluster with given token.
+
+local commandname="INSTALL"
+local commandaction="Install"
+local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
+
+echo ""
+echo "Enter ${gamename} Cluster Token"
+echo "================================="
+sleep 1
+echo "A cluster token is required to run this server!"
+echo "Follow the instructions in this link to obtain this key:"
+echo "https://gameservermanagers.com/dst-auth-token"
+echo ""
+if [ -z "${autoinstall}" ]; then
+	overwritetoken="true"
+	if [ -s "${clustercfgdir}/cluster_token.txt" ]; then
+		echo "The cluster token is already set. Do you want to overwrite it?"
+		fn_script_log_info "Don't Starve Together cluster token is already set"
+		while true; do
+			read -e -i "n" -p "Continue? [Y/n]" yn
+			case $yn in
+			[Yy]* ) overwritetoken="true"; break;;
+			[Nn]* ) overwritetoken="false"; break;;
+			* ) echo "Please answer yes or no.";;
+			esac
+		done
+	fi	
+	if [ "${overwritetoken}" == "true" ]; then
+		echo "Once you have the cluster token, enter it below"
+		echo -n "Cluster Token: "
+		read token
+		mkdir -pv "${clustercfgdir}"
+		echo "${token}" > "${clustercfgdir}/cluster_token.txt"
+		if [ -f "${clustercfgdir}/cluster_token.txt" ]; then
+			echo "Don't Starve Together cluster token created"
+			fn_script_log_info "Don't Starve Together cluster token created"
+		fi
+		unset overwritetoken
+	fi
+else
+	echo "You can add your cluster token using the following command"
+	echo "./${selfname} cluster-token"
+fi
+echo ""

From 4ab4218fbceb79f3a2097cb929d6469d6bbd1436 Mon Sep 17 00:00:00 2001
From: Marvin Lehmann <marvinlehmann@live.de>
Date: Fri, 11 Nov 2016 19:04:14 +0100
Subject: [PATCH 02/11] Added missing "then"

---
 lgsm/functions/install_config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lgsm/functions/install_config.sh b/lgsm/functions/install_config.sh
index adfad2e90..d751fb3a1 100644
--- a/lgsm/functions/install_config.sh
+++ b/lgsm/functions/install_config.sh
@@ -100,7 +100,7 @@ fn_dstconfig(){
 	if [ "sharding" == "false" ]; then 
 		sed -i "s/ISMASTER//g" "${servercfgfullpath}"
 		sed -d "/SHARDNAME/d" "${servercfgfullpath}"
-	elif [ "master" == "true" ];
+	elif [ "master" == "true" ]; then
 		sed -d "/SHARDNAME/d" "${servercfgfullpath}"
 	fi
 	# configure settings

From 316509f3aa7b1e109cba704c3fbba96bfd1521cf Mon Sep 17 00:00:00 2001
From: Marvin Lehmann <marvinlehmann@live.de>
Date: Fri, 11 Nov 2016 19:04:52 +0100
Subject: [PATCH 03/11] Switched to dstserver-new branch

---
 DontStarveTogether/dstserver | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/DontStarveTogether/dstserver b/DontStarveTogether/dstserver
index 0c4b9647a..6b65cacf7 100644
--- a/DontStarveTogether/dstserver
+++ b/DontStarveTogether/dstserver
@@ -87,7 +87,7 @@ branch=""
 # from a different repo and/or branch.
 githubuser="GameServerManagers"
 githubrepo="LinuxGSM"
-githubbranch="master"
+githubbranch="dstserver-new"
 
 ## LinuxGSM Server Details
 # Do not edit

From 8a21bfe48d3e3b405fa766e8f5b79035286c81d6 Mon Sep 17 00:00:00 2001
From: Marvin Lehmann <marvinlehmann@live.de>
Date: Fri, 11 Nov 2016 21:15:23 +0100
Subject: [PATCH 04/11] Fixes and improvements

- moved tick_rate to config
- corrected config info (port -> masterport)
- corrected default cluster.ini path
- added missing $ for variables
---
 DontStarveTogether/dstserver     | 5 ++---
 lgsm/functions/info_config.sh    | 6 +++---
 lgsm/functions/install_config.sh | 9 +++++----
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/DontStarveTogether/dstserver b/DontStarveTogether/dstserver
index 6b65cacf7..859dbbe8f 100644
--- a/DontStarveTogether/dstserver
+++ b/DontStarveTogether/dstserver
@@ -36,7 +36,6 @@ ip="0.0.0.0"
 port="11000"
 steamauthenticationport="8768"
 steammasterserverport="27018"
-tickrate="15"
 
 # Edit with care
 persistentstorageroot="${HOME}/.klei"
@@ -44,7 +43,7 @@ confdir="DoNotStarveTogether"
 
 ## Server Start Command | https://github.com/GameServerManagers/LinuxGSM/wiki/Start-Parameters#additional-parameters
 fn_parms(){
-parms="-bind_ip ${ip} -port ${port} -steam_master_server_port ${steammasterserverport} -steam_authentication_port ${steamauthenticationport} -tick ${tickrate} -persistent_storage_root ${persistentstorageroot} -conf_dir ${confdir} -cluster ${cluster} -shard ${shard}"
+parms="-bind_ip ${ip} -port ${port} -steam_master_server_port ${steammasterserverport} -steam_authentication_port ${steamauthenticationport} -persistent_storage_root ${persistentstorageroot} -conf_dir ${confdir} -cluster ${cluster} -shard ${shard}"
 # -console -cluster MyDediServer -shard Master
 }
 
@@ -117,7 +116,7 @@ executable="./dontstarve_dedicated_server_nullrenderer"
 clustercfg="cluster.ini"
 clustercfgdir="${persistentstorageroot}/${confdir}/${cluster}"
 clustercfgfullpath="${clustercfgdir}/${clustercfg}"
-clustercfgdefault="${clustercfgdir}/cluster.ini"
+clustercfgdefault="cluster.ini"
 servercfg="server.ini"
 servercfgdir="${clustercfgdir}/${shard}"
 servercfgfullpath="${servercfgdir}/${servercfg}"
diff --git a/lgsm/functions/info_config.sh b/lgsm/functions/info_config.sh
index 4e8fca918..99e2038fa 100644
--- a/lgsm/functions/info_config.sh
+++ b/lgsm/functions/info_config.sh
@@ -87,14 +87,14 @@ fn_info_config_dontstarve(){
 		slots="${zero}"
 		gamemode="${unavailable}"
 		tickrate="${zero}"
-		port="${zero}"
+		masterport="${zero}"
 	else
 		servername=$(grep "cluster_name" "${clustercfgfullpath}" | sed -e 's/^[ \t]*//g' -e '/^#/d' -e 's/cluster_name//g' | tr -d '=\";,:' | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//')
 		serverpassword=$(grep "cluster_password" "${clustercfgfullpath}" | sed -e 's/^[ \t]*//g' -e '/^#/d' -e 's/cluster_password//g' | tr -d '=\";,:' | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//')
 		slots=$(grep "max_players" "${clustercfgfullpath}" | grep -v "#" | tr -cd '[:digit:]')
 		gamemode=$(grep "game_mode" "${clustercfgfullpath}" | sed -e 's/^[ \t]*//g' -e '/^#/d' -e 's/game_mode//g' | tr -d '=\";,:' | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//')
 		tickrate=$(grep "tick_rate" "${clustercfgfullpath}" | grep -v "#" | tr -cd '[:digit:]')
-		port=$(grep "master_port" "${clustercfgfullpath}" | grep -v "#" | tr -cd '[:digit:]')
+		masterport=$(grep "master_port" "${clustercfgfullpath}" | grep -v "#" | tr -cd '[:digit:]')
 
 		# Not Set
 		servername=${servername:-"NOT SET"}
@@ -102,7 +102,7 @@ fn_info_config_dontstarve(){
 		slots=${slots:-"0"}
 		gamemode=${gamemode:-"NOT SET"}
 		tickrate=${tickrate:-"0"}
-		port=${port:-"0"}
+		masterport=${masterport:-"0"}
 	fi
 }
 
diff --git a/lgsm/functions/install_config.sh b/lgsm/functions/install_config.sh
index d751fb3a1..a77ef5d2d 100644
--- a/lgsm/functions/install_config.sh
+++ b/lgsm/functions/install_config.sh
@@ -97,11 +97,11 @@ fn_dstconfig(){
 	cp -v "${lgsmdir}/default-configs/${servercfgdefault}" "${servercfgfullpath}"
 	sleep 1
 	# removing unnecessary options (dependent on sharding & shard type)
-	if [ "sharding" == "false" ]; then 
+	if [ "${sharding}" == "false" ]; then 
 		sed -i "s/ISMASTER//g" "${servercfgfullpath}"
-		sed -d "/SHARDNAME/d" "${servercfgfullpath}"
-	elif [ "master" == "true" ]; then
-		sed -d "/SHARDNAME/d" "${servercfgfullpath}"
+		sed -i "/SHARDNAME/d" "${servercfgfullpath}"
+	elif [ "${master}" == "true" ]; then
+		sed -i "/SHARDNAME/d" "${servercfgfullpath}"
 	fi
 	# configure settings
 	echo "changing shard name."
@@ -233,6 +233,7 @@ elif [ "${gamename}" == "Deathmatch Classic" ]; then
 	fn_set_config_vars
 elif [ "${gamename}" == "Don't Starve Together" ]; then
 	gamedirname="DontStarveTogether"
+	fn_check_cfgdir
 	array_configs+=( cluster.ini server.ini )
 	fn_fetch_default_config
 	fn_dstconfig

From 904cd4cbec73a3ed32b9fd3ad6855dac0718acfa Mon Sep 17 00:00:00 2001
From: Marvin Lehmann <marvinlehmann@live.de>
Date: Fri, 18 Nov 2016 12:41:44 +0100
Subject: [PATCH 05/11] Switched config branch and removed token message after
 install

---
 lgsm/functions/install_complete.sh | 6 ------
 lgsm/functions/install_config.sh   | 5 +++--
 2 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/lgsm/functions/install_complete.sh b/lgsm/functions/install_complete.sh
index af522d2ee..4a38d79b4 100644
--- a/lgsm/functions/install_complete.sh
+++ b/lgsm/functions/install_complete.sh
@@ -8,12 +8,6 @@ local commandname="INSTALL"
 local commandaction="Install"
 local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
 
-if [ "${gamename}" == "Don't Starve Together" ]; then
-  echo ""
-  echo "An Authentication Token is required to run this server!"
-  echo "Follow the instructions in this link to obtain this key"
-  echo "  https://gameservermanagers.com/dst-auth-token"
-fi
 echo "================================="
 echo "Install Complete!"
 fn_script_log_info "Install Complete!"
diff --git a/lgsm/functions/install_config.sh b/lgsm/functions/install_config.sh
index a77ef5d2d..9b0e5fc21 100644
--- a/lgsm/functions/install_config.sh
+++ b/lgsm/functions/install_config.sh
@@ -10,11 +10,11 @@ local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
 
 fn_fetch_default_config(){
 	mkdir -pv "${lgsmdir}/default-configs"
-	githuburl="https://github.com/GameServerManagers/Game-Server-Configs/dstserver"
+	githuburl="https://github.com/GameServerManagers/Game-Server-Configs/master"
 
 	for config in "${array_configs[@]}"
 	do
-		fileurl="https://raw.githubusercontent.com/GameServerManagers/Game-Server-Configs/dstserver/${gamedirname}/${config}"; filedir="${lgsmdir}/default-configs"; filename="${config}";  executecmd="noexecute" run="norun"; force="noforce"
+		fileurl="https://raw.githubusercontent.com/GameServerManagers/Game-Server-Configs/master/${gamedirname}/${config}"; filedir="${lgsmdir}/default-configs"; filename="${config}";  executecmd="noexecute" run="norun"; force="noforce"
 		fn_fetch_file "${fileurl}" "${filedir}" "${filename}" "${executecmd}" "${run}" "${force}" "${md5}"
 	done
 }
@@ -65,6 +65,7 @@ fn_default_config_remote(){
 	sleep 1
 }
 
+# this should be somehow standardized
 fn_dstconfig(){
 	## cluster.ini
 	# this config shouldn't be overridden

From 62b7f98807346439ec0c99a399e8c11065fae2d2 Mon Sep 17 00:00:00 2001
From: Marvin Lehmann <marvinlehmann@live.de>
Date: Sun, 20 Nov 2016 01:14:07 +0100
Subject: [PATCH 06/11] Standardized DST config function partly

and cleaned up dstserver script
---
 DontStarveTogether/dstserver     |  7 ++-----
 lgsm/functions/install_config.sh | 29 +++++++++++------------------
 2 files changed, 13 insertions(+), 23 deletions(-)

diff --git a/DontStarveTogether/dstserver b/DontStarveTogether/dstserver
index 859dbbe8f..af9f2595a 100644
--- a/DontStarveTogether/dstserver
+++ b/DontStarveTogether/dstserver
@@ -14,7 +14,7 @@ if [ -f ".dev-debug" ]; then
 	set -x
 fi
 
-version="161111"
+version="161120"
 
 ##########################
 ######## Settings ########
@@ -22,9 +22,7 @@ version="161111"
 
 #### Server Settings ####
 
-## Installation Variables
-# Visit the following link for more information:
-# https://github.com/GameServerManagers/LinuxGSM/wiki/Don't-Starve-Together
+## Installation Variables | https://github.com/GameServerManagers/LinuxGSM/wiki/Don't-Starve-Together
 sharding="false"
 master="true"
 shard="Master" 
@@ -44,7 +42,6 @@ confdir="DoNotStarveTogether"
 ## Server Start Command | https://github.com/GameServerManagers/LinuxGSM/wiki/Start-Parameters#additional-parameters
 fn_parms(){
 parms="-bind_ip ${ip} -port ${port} -steam_master_server_port ${steammasterserverport} -steam_authentication_port ${steamauthenticationport} -persistent_storage_root ${persistentstorageroot} -conf_dir ${confdir} -cluster ${cluster} -shard ${shard}"
-# -console -cluster MyDediServer -shard Master
 }
 
 #### LinuxGSM Settings ####
diff --git a/lgsm/functions/install_config.sh b/lgsm/functions/install_config.sh
index 9b0e5fc21..1a9bb69b3 100644
--- a/lgsm/functions/install_config.sh
+++ b/lgsm/functions/install_config.sh
@@ -55,9 +55,10 @@ fn_default_config_remote(){
 		fn_script_log_info "copying ${servercfg} config file."
 		if [ "${config}" == "${servercfgdefault}" ]; then
 			cp -v "${lgsmdir}/default-configs/${config}" "${servercfgfullpath}"
-		elif [ "${config}" == "${networkcfgdefault}" ]; then
-			# ARMA 3
+		elif [ "${gamename}" == "ARMA 3" ]&&[ "${config}" == "${networkcfgdefault}" ]; then
 			cp -v "${lgsmdir}/default-configs/${config}" "${networkcfgfullpath}"
+		elif [ "${gamename}" == "Don't Starve Together" ]&&[ "${config}" == "${clustercfgdefault}" ]; then
+			cp -nv "${lgsmdir}/default-configs/${clustercfgdefault}" "${clustercfgfullpath}"
 		else
 			cp -v "${lgsmdir}/default-configs/${config}" "${servercfgdir}/${config}"
 		fi
@@ -65,15 +66,10 @@ fn_default_config_remote(){
 	sleep 1
 }
 
-# this should be somehow standardized
-fn_dstconfig(){
+# Changes some variables within the default Don't Starve Together configs
+fn_set_dst_config_vars(){
 	## cluster.ini
-	# this config shouldn't be overridden
-	if [ ! -s "${clustercfgfullpath}" ]; then
-		echo "copying ${clustercfg} config file."
-		fn_script_log_info "copying ${clustercfg} config file."
-		cp -v "${lgsmdir}/default-configs/${clustercfgdefault}" "${clustercfgfullpath}"
-		sleep 1
+	if grep -Fq "SERVERNAME" "${clustercfgfullpath}"; then
 		echo "changing server name."
 		fn_script_log_info "changing server name."
 		sed -i "s/SERVERNAME/LinuxGSM/g" "${clustercfgfullpath}"
@@ -88,15 +84,11 @@ fn_dstconfig(){
 		sed -i "s/CLUSTERKEY/${randomkey}/g" "${clustercfgfullpath}"
 		sleep 1
 	else	
-		echo "${clustercfg} already exists."
-		fn_script_log_info "${clustercfg} already exists."
+		echo "${clustercfg} is already configured."
+		fn_script_log_info "${clustercfg} is already configured."
 	fi
 	
 	## server.ini
-	echo "copying ${servercfg} config file."
-	fn_script_log_info "copying ${servercfg} config file."
-	cp -v "${lgsmdir}/default-configs/${servercfgdefault}" "${servercfgfullpath}"
-	sleep 1
 	# removing unnecessary options (dependent on sharding & shard type)
 	if [ "${sharding}" == "false" ]; then 
 		sed -i "s/ISMASTER//g" "${servercfgfullpath}"
@@ -104,7 +96,7 @@ fn_dstconfig(){
 	elif [ "${master}" == "true" ]; then
 		sed -i "/SHARDNAME/d" "${servercfgfullpath}"
 	fi
-	# configure settings
+	
 	echo "changing shard name."
 	fn_script_log_info "changing shard name."
 	sed -i "s/SHARDNAME/${shard}/g" "${servercfgfullpath}"
@@ -237,7 +229,8 @@ elif [ "${gamename}" == "Don't Starve Together" ]; then
 	fn_check_cfgdir
 	array_configs+=( cluster.ini server.ini )
 	fn_fetch_default_config
-	fn_dstconfig
+	fn_default_config_remote
+	fn_set_dst_config_vars
 elif [ "${gamename}" == "Double Action: Boogaloo" ]; then
 	gamedirname="DoubleActionBoogaloo"
 	array_configs+=( server.cfg )

From 4e694069954c67218c3674113f153ac81c3b47e5 Mon Sep 17 00:00:00 2001
From: Marvin Lehmann <marvinlehmann@live.de>
Date: Sun, 20 Nov 2016 11:57:02 +0100
Subject: [PATCH 07/11] Display correct config name when copying

---
 lgsm/functions/install_config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lgsm/functions/install_config.sh b/lgsm/functions/install_config.sh
index 1a9bb69b3..16b2882ee 100644
--- a/lgsm/functions/install_config.sh
+++ b/lgsm/functions/install_config.sh
@@ -51,7 +51,7 @@ fn_default_config_remote(){
 	for config in "${array_configs[@]}"
 	do
 		# every config is copied
-		echo "copying ${servercfg} config file."
+		echo "copying ${config} config file."
 		fn_script_log_info "copying ${servercfg} config file."
 		if [ "${config}" == "${servercfgdefault}" ]; then
 			cp -v "${lgsmdir}/default-configs/${config}" "${servercfgfullpath}"

From 9823aed3dfce3d87991ff70b88fafd8a3c5fb257 Mon Sep 17 00:00:00 2001
From: Marvin Lehmann <marvinlehmann@live.de>
Date: Sun, 20 Nov 2016 23:48:09 +0100
Subject: [PATCH 08/11] Move parameter variables to configs

Setting variables in configs is preferred.
---
 DontStarveTogether/dstserver  | 10 ++--------
 lgsm/functions/info_config.sh | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/DontStarveTogether/dstserver b/DontStarveTogether/dstserver
index af9f2595a..c89ad92f6 100644
--- a/DontStarveTogether/dstserver
+++ b/DontStarveTogether/dstserver
@@ -29,19 +29,13 @@ shard="Master"
 cluster="Cluster_1"
 cave="false"
 
-## Server Start Settings | https://github.com/GameServerManagers/LinuxGSM/wiki/Start-Parameters
-ip="0.0.0.0"
-port="11000"
-steamauthenticationport="8768"
-steammasterserverport="27018"
-
 # Edit with care
 persistentstorageroot="${HOME}/.klei"
 confdir="DoNotStarveTogether"
 
 ## Server Start Command | https://github.com/GameServerManagers/LinuxGSM/wiki/Start-Parameters#additional-parameters
 fn_parms(){
-parms="-bind_ip ${ip} -port ${port} -steam_master_server_port ${steammasterserverport} -steam_authentication_port ${steamauthenticationport} -persistent_storage_root ${persistentstorageroot} -conf_dir ${confdir} -cluster ${cluster} -shard ${shard}"
+parms="-persistent_storage_root ${persistentstorageroot} -conf_dir ${confdir} -cluster ${cluster} -shard ${shard}"
 }
 
 #### LinuxGSM Settings ####
@@ -91,7 +85,7 @@ gamename="Don't Starve Together"
 engine="dontstarve"
 
 ## Service Name | https://github.com/GameServerManagers/LinuxGSM/wiki/Multiple-Servers
-servicename="dst-server"
+servicename="dst-server-${shard}"
 
 #### Directories ####
 # Edit with care
diff --git a/lgsm/functions/info_config.sh b/lgsm/functions/info_config.sh
index 99e2038fa..3bd3ebd04 100644
--- a/lgsm/functions/info_config.sh
+++ b/lgsm/functions/info_config.sh
@@ -95,6 +95,10 @@ fn_info_config_dontstarve(){
 		gamemode=$(grep "game_mode" "${clustercfgfullpath}" | sed -e 's/^[ \t]*//g' -e '/^#/d' -e 's/game_mode//g' | tr -d '=\";,:' | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//')
 		tickrate=$(grep "tick_rate" "${clustercfgfullpath}" | grep -v "#" | tr -cd '[:digit:]')
 		masterport=$(grep "master_port" "${clustercfgfullpath}" | grep -v "#" | tr -cd '[:digit:]')
+		
+		ip=$(grep "bind_ip" "${clustercfgfullpath}" | sed -e 's/^[ \t]*//g' -e '/^#/d' -e 's/bind_ip//g' | tr -d '=\";,:' | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//')
+		ipsetinconfig=1
+		ipinconfigvar="bind_ip"
 
 		# Not Set
 		servername=${servername:-"NOT SET"}
@@ -104,6 +108,21 @@ fn_info_config_dontstarve(){
 		tickrate=${tickrate:-"0"}
 		masterport=${masterport:-"0"}
 	fi
+	
+	if [ ! -f "${servercfgfullpath}" ]; then
+		port="${zero}"
+		steamauthenticationport="${zero}"
+		steammasterserverport="${zero}"
+	else
+		port=$(grep "server_port" "${servercfgfullpath}" | grep -v "#" | tr -cd '[:digit:]')
+		steamauthenticationport=$(grep "authentication_port" "${servercfgfullpath}" | grep -v "#" | tr -cd '[:digit:]')
+		steammasterserverport=$(grep "master_server_port" "${servercfgfullpath}" | grep -v "#" | tr -cd '[:digit:]')
+		
+		# Not Set
+		port=${port:-"0"}
+		steamauthenticationport=${steamauthenticationport:-"0"}
+		steammasterserverport=${steammasterserverport:-"0"}
+	fi
 }
 
 fn_info_config_minecraft(){

From 6c43ad882f71e5181904c2b976ca283b4535b6ef Mon Sep 17 00:00:00 2001
From: Marvin Lehmann <marvinlehmann@live.de>
Date: Mon, 21 Nov 2016 00:09:35 +0100
Subject: [PATCH 09/11] Made server_port grep more unique

master_server_port was also grep'd before
---
 lgsm/functions/info_config.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lgsm/functions/info_config.sh b/lgsm/functions/info_config.sh
index 3bd3ebd04..e083e622a 100644
--- a/lgsm/functions/info_config.sh
+++ b/lgsm/functions/info_config.sh
@@ -114,7 +114,7 @@ fn_info_config_dontstarve(){
 		steamauthenticationport="${zero}"
 		steammasterserverport="${zero}"
 	else
-		port=$(grep "server_port" "${servercfgfullpath}" | grep -v "#" | tr -cd '[:digit:]')
+		port=$(grep "server_port" "${servercfgfullpath}" | grep "^server_port" | grep -v "#" | tr -cd '[:digit:]')
 		steamauthenticationport=$(grep "authentication_port" "${servercfgfullpath}" | grep -v "#" | tr -cd '[:digit:]')
 		steammasterserverport=$(grep "master_server_port" "${servercfgfullpath}" | grep -v "#" | tr -cd '[:digit:]')
 		

From 23cf50932127c5a6137aa56193664b4f7f1ae3a0 Mon Sep 17 00:00:00 2001
From: Marvin Lehmann <marvinlehmann@live.de>
Date: Fri, 25 Nov 2016 00:57:43 +0100
Subject: [PATCH 10/11] Changing branch var to develop

---
 DontStarveTogether/dstserver | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/DontStarveTogether/dstserver b/DontStarveTogether/dstserver
index 1dd527100..24de569f5 100644
--- a/DontStarveTogether/dstserver
+++ b/DontStarveTogether/dstserver
@@ -79,7 +79,7 @@ branch=""
 # from a different repo and/or branch.
 githubuser="GameServerManagers"
 githubrepo="LinuxGSM"
-githubbranch="dstserver-new"
+githubbranch="develop"
 
 ## LinuxGSM Server Details
 # Do not edit
@@ -204,4 +204,4 @@ fi
 core_dl.sh
 core_functions.sh
 getopt=$1
-core_getopt.sh
\ No newline at end of file
+core_getopt.sh

From bde68d9cdd90279b7adf9e7046a7528aa56f19c8 Mon Sep 17 00:00:00 2001
From: Daniel Gibbs <me@danielgibbs.co.uk>
Date: Fri, 25 Nov 2016 10:29:54 +0000
Subject: [PATCH 11/11] corrected github branch

---
 DontStarveTogether/dstserver | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/DontStarveTogether/dstserver b/DontStarveTogether/dstserver
index 24de569f5..643026c1a 100644
--- a/DontStarveTogether/dstserver
+++ b/DontStarveTogether/dstserver
@@ -25,7 +25,7 @@ version="161118"
 ## Installation Variables | https://github.com/GameServerManagers/LinuxGSM/wiki/Don't-Starve-Together
 sharding="false"
 master="true"
-shard="Master" 
+shard="Master"
 cluster="Cluster_1"
 cave="false"
 
@@ -79,7 +79,7 @@ branch=""
 # from a different repo and/or branch.
 githubuser="GameServerManagers"
 githubrepo="LinuxGSM"
-githubbranch="develop"
+githubbranch="master"
 
 ## LinuxGSM Server Details
 # Do not edit