Sfoglia il codice sorgente

Merged feature/mtaserver into develop

Daniel Gibbs 9 anni fa
parent
commit
ec3272f322

+ 180 - 0
MultiTheftAuto/mtaserver

@@ -0,0 +1,180 @@
+#!/bin/bash
+# Multi Theft Auto
+# Server Management Script
+# Author: Daniel Gibbs
+# Website: https://gameservermanagers.com
+if [ -f ".dev-debug" ]; then
+	exec 5>dev-debug.log
+	BASH_XTRACEFD="5"
+	set -x
+fi
+
+version="170103"
+
+##########################
+######## Settings ########
+##########################
+
+#### Server Settings ####
+
+## Server Start Settings | https://github.com/GameServerManagers/LinuxGSM/wiki/Start-Parameters
+# None Available
+
+## Server Start Command | https://github.com/GameServerManagers/LinuxGSM/wiki/Start-Parameters#additional-parameters
+# Edit with care
+fn_parms(){
+parms=" "
+}
+
+#### LinuxGSM Settings ####
+
+## Notification Alerts
+# (on|off)
+# Email Alerts | https://github.com/GameServerManagers/LinuxGSM/wiki/Email
+emailalert="off"
+email="email@example.com"
+emailfrom=""
+
+# Pushbullet Alerts | https://github.com/GameServerManagers/LinuxGSM/wiki/Pushbullet
+pushbulletalert="off"
+pushbullettoken="accesstoken"
+channeltag=""
+
+## Backup | https://github.com/GameServerManagers/LinuxGSM/wiki/Backup
+maxbackups="4"
+maxbackupdays="30"
+stoponbackup="on"
+
+## Logging | https://github.com/GameServerManagers/LinuxGSM/wiki/Logging
+consolelogging="on"
+logdays="7"
+
+#### LinuxGSM Advanced Settings ####
+
+# Github Branch Select
+# Allows for the use of different function files
+# from a different repo and/or branch.
+githubuser="dgibbs64"
+githubrepo="linuxgsm"
+githubbranch="master"
+
+## LinuxGSM Server Details
+# Do not edit
+gamename="Multi Theft Auto"
+engine="renderware"
+
+## Service Name | https://github.com/GameServerManagers/LinuxGSM/wiki/Multiple-Servers
+servicename="mta-server"
+
+#### Directories ####
+# Edit with care
+
+## Work Directories
+rootdir="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"
+selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
+lockselfname=".${servicename}.lock"
+lgsmdir="${rootdir}/lgsm"
+functionsdir="${lgsmdir}/functions"
+libdir="${lgsmdir}/lib"
+tmpdir="${lgsmdir}/tmp"
+filesdir="${rootdir}/serverfiles"
+
+## Server Specific Directories
+systemdir="${filesdir}"
+resourcesdir="${systemdir}/mods/deathmatch/resources"
+executabledir="${systemdir}"
+executable="./mta-server64"
+servercfg="mtaserver.conf"
+servercfgdir="${systemdir}/mods/deathmatch"
+servercfgfullpath="${servercfgdir}/${servercfg}"
+
+## Backup Directory
+backupdir="${rootdir}/backups"
+
+## Logging Directories
+gamelogdir="${filesdir}/mods/deathmatch/logs"
+scriptlogdir="${rootdir}/log/script"
+consolelogdir="${rootdir}/log/console"
+scriptlog="${scriptlogdir}/${servicename}-script.log"
+consolelog="${consolelogdir}/${servicename}-console.log"
+emaillog="${scriptlogdir}/${servicename}-email.log"
+
+## Logs Naming
+scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log"
+consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log"
+
+########################
+######## Script ########
+###### Do not edit #####
+########################
+
+# Fetches core_dl for file downloads
+fn_fetch_core_dl(){
+github_file_url_dir="lgsm/functions"
+github_file_url_name="${functionfile}"
+filedir="${functionsdir}"
+filename="${github_file_url_name}"
+githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
+# If the file is missing, then download
+if [ ! -f "${filedir}/${filename}" ]; then
+	if [ ! -d "${filedir}" ]; then
+		mkdir -p "${filedir}"
+	fi
+	echo -e "    fetching ${filename}...\c"
+	# Check curl exists and use available path
+	curlpaths="$(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl)"
+	for curlcmd in ${curlpaths}
+	do
+		if [ -x "${curlcmd}" ]; then
+			break
+		fi
+	done
+	# If curl exists download file
+	if [ "$(basename ${curlcmd})" == "curl" ]; then
+		curlfetch=$(${curlcmd} -s --fail -o "${filedir}/${filename}" "${githuburl}" 2>&1)
+		if [ $? -ne 0 ]; then
+			echo -e "\e[0;31mFAIL\e[0m\n"
+			echo "${curlfetch}"
+			echo -e "${githuburl}\n"
+			exit 1
+		else
+			echo -e "\e[0;32mOK\e[0m"
+		fi
+	else
+		echo -e "\e[0;31mFAIL\e[0m\n"
+		echo "Curl is not installed!"
+		echo -e ""
+		exit 1
+	fi
+	chmod +x "${filedir}/${filename}"
+fi
+source "${filedir}/${filename}"
+}
+
+core_dl.sh(){
+# Functions are defined in core_functions.sh.
+functionfile="${FUNCNAME}"
+fn_fetch_core_dl
+}
+
+core_functions.sh(){
+# Functions are defined in core_functions.sh.
+functionfile="${FUNCNAME}"
+fn_fetch_core_dl
+}
+
+# Prevent from running this script as root.
+if [ "$(whoami)" = "root" ]; then
+	if [ ! -f "${functionsdir}/core_functions.sh" ]||[ ! -f "${functionsdir}/check_root.sh" ]||[ ! -f "${functionsdir}/core_messages.sh" ]||[ ! -f "${functionsdir}/core_exit.sh" ]; then
+		echo "[ FAIL ] Do NOT run this script as root!"
+		exit 1
+	else
+		core_functions.sh
+		check_root.sh
+	fi
+fi
+
+core_dl.sh
+core_functions.sh
+getopt=$1
+core_getopt.sh

+ 9 - 7
lgsm/functions/check.sh

@@ -50,6 +50,14 @@ do
 	fi
 done
 
+local allowed_commands_array=( command_console.sh command_debug.sh command_details.sh command_monitor.sh command_start.sh command_stop.sh )
+for allowed_command in "${allowed_commands_array[@]}"
+do
+	if [ "${allowed_command}" == "${function_selfname}" ]; then
+		check_config.sh
+	fi
+done
+
 local allowed_commands_array=( command_debug.sh command_details.sh command_monitor.sh command_start.sh command_stop.sh )
 for allowed_command in "${allowed_commands_array[@]}"
 do
@@ -68,13 +76,7 @@ do
 	fi
 done
 
-local allowed_commands_array=( command_console.sh command_debug.sh command_details.sh command_monitor.sh command_start.sh command_stop.sh )
-for allowed_command in "${allowed_commands_array[@]}"
-do
-	if [ "${allowed_command}" == "${function_selfname}" ]; then
-		check_config.sh
-	fi
-done
+
 
 local allowed_commands_array=( command_details.sh command_monitor.sh command_start.sh command_stop.sh command_ts3_server_pass.sh command_update.sh command_details.sh command_validate.sh )
 for allowed_command in "${allowed_commands_array[@]}"

+ 4 - 6
lgsm/functions/check_deps.sh

@@ -6,8 +6,6 @@
 
 local commandname="CHECK"
 
-
-
 fn_deps_detector(){
 	# Checks if dependency is missing
 	if [ "${tmuxcheck}" == "1" ]; then
@@ -158,8 +156,8 @@ if [ -n "$(command -v dpkg-query)" ]; then
 		fi
 	fi
 
-	# All servers except ts3,mumble and minecraft servers require libstdc++6 and lib32gcc1
-	if [ "${gamename}" != "TeamSpeak 3" ]&&[ "${gamename}" != "Mumble" ]&&[ "${engine}" != "lwjgl2" ]; then
+	# All servers except ts3,mumble,multitheftauto and minecraft servers require libstdc++6 and lib32gcc1
+	if [ "${gamename}" != "TeamSpeak 3" ]&&[ "${gamename}" != "Mumble" ]&&[ "${engine}" != "lwjgl2" ]&&[ "${engine}" != "renderware" ]; then
 		if [ "${arch}" == "x86_64" ]; then
 			array_deps_required+=( lib32gcc1 libstdc++6:i386 )
 		else
@@ -241,8 +239,8 @@ elif [ -n "$(command -v yum)" ]; then
 		fi
 	fi
 
-	# All servers except ts3,mumble and minecraft servers require glibc.i686 and libstdc++.i686
-	if [ "${gamename}" != "TeamSpeak 3" ]&&[ "${gamename}" != "Mumble" ]&&[ "${engine}" != "lwjgl2" ]; then
+	# All servers except ts3,mumble,multitheftauto and minecraft servers require glibc.i686 and libstdc++.i686
+	if [ "${gamename}" != "TeamSpeak 3" ]&&[ "${gamename}" != "Mumble" ]&&[ "${engine}" != "lwjgl2" ]&&[ "${engine}" != "renderware" ]; then
 		array_deps_required+=( glibc.i686 libstdc++.i686 )
 	fi
 

+ 23 - 4
lgsm/functions/command_details.sh

@@ -168,6 +168,11 @@ fn_details_gameserver(){
 			echo -e "${blue}dbplugin:\t${default}${dbplugin}"
 		fi
 
+		# ASE (Multi Theft Auto)
+		if [ -n "${ase}" ]; then
+			echo -e "${blue}ASE:\t${default}${ase}"
+		fi
+
 		# Online status
 		if [ "${status}" == "0" ]; then
 			echo -e "${blue}Status:\t${red}OFFLINE${default}"
@@ -310,7 +315,7 @@ fn_details_ports(){
 
 	parmslocation="${red}UNKNOWN${default}"
 	# engines/games that require editing in the config file
-	local ports_edit_array=( "avalanche" "dontstarve" "idtech2" "idtech3" "idtech3_ql" "lwjgl2" "projectzomboid" "quake" "refractor" "seriousengine35" "teeworlds" "terraria" "unreal" "unreal2" "unreal3" "TeamSpeak 3" "Mumble" "7 Days To Die" )
+	local ports_edit_array=( "avalanche" "dontstarve" "idtech2" "idtech3" "idtech3_ql" "lwjgl2" "projectzomboid" "quake" "refractor" "realvirtuality" "renderware" "seriousengine35" "teeworlds" "terraria" "unreal" "unreal2" "unreal3" "TeamSpeak 3" "Mumble" "7 Days To Die" )
 	for port_edit in "${ports_edit_array[@]}"
 	do
 		if [ "${engine}" == "${port_edit}" ]||[ "${gamename}" == "${port_edit}" ]; then
@@ -726,6 +731,18 @@ fn_details_wolfensteinenemyterritory(){
 	} | column -s $'\t' -t
 }
 
+fn_details_mta(){
+	echo -e "netstat -atunp | grep mta-server64"
+	echo -e ""
+	{
+		echo -e "DESCRIPTION\tDIRECTION\tPORT\tPROTOCOL"
+		echo -e "> Game\tOUTBOUND\t${port}\tudp"
+		echo -e "> HTTP Server\tINBOUND\t${httpport}\ttcp"
+		if [ "${ase}" == "Enabled" ]; then
+			echo -e "> ASE Game_Monitor\tOUTBOUND\t$((${port} + 123))\tudp"
+		fi
+	} | column -s $'\t' -t
+}
 
 # Run checks and gathers details to display.
 
@@ -742,7 +759,7 @@ fn_display_details() {
 	fn_details_script
 	fn_details_backup
 	# Some game servers do not have parms.
-	if [ "${gamename}" != "TeamSpeak 3" ]&&[ "${engine}" != "avalanche" ]&&[ "${engine}" != "dontstarve" ]&&[ "${engine}" != "projectzomboid" ]; then
+	if [ "${gamename}" != "TeamSpeak 3" ]&&[ "${engine}" != "avalanche" ]&&[ "${engine}" != "dontstarve" ]&&[ "${engine}" != "projectzomboid" ]&&[ "${engine}" != "renderware" ]; then
 		fn_parms
 		fn_details_commandlineparms
 	fi
@@ -793,6 +810,8 @@ fn_display_details() {
 		fn_details_cod4
 	elif [ "${gamename}" == "Call of Duty: World at War" ]; then
 		fn_details_codwaw
+	elif [ "${gamename}" == "Factorio" ]; then
+		fn_details_factorio    
 	elif [ "${gamename}" == "Hurtworld" ]; then
 		fn_details_hurtworld
 	elif [ "${gamename}" == "QuakeWorld" ]; then
@@ -805,14 +824,14 @@ fn_display_details() {
 		fn_details_quakelive
 	elif [ "${gamename}" == "TeamSpeak 3" ]; then
 		fn_details_teamspeak3
+	elif [ "${gamename}" == "Multi Theft Auto" ]; then
+		fn_details_mta    
 	elif [ "${gamename}" == "Mumble" ]; then
 		fn_details_mumble
 	elif [ "${gamename}" == "Rust" ]; then
 		fn_details_rust
 	elif [ "${gamename}" == "Wolfenstein: Enemy Territory" ]; then
 		fn_details_wolfensteinenemyterritory
-	elif [ "${gamename}" == "Factorio" ]; then
-		fn_details_factorio
 	else
 		fn_print_error_nl "Unable to detect server engine."
 	fi

+ 3 - 1
lgsm/functions/command_install.sh

@@ -18,7 +18,7 @@ check_deps.sh
 if [ "${gamename}" == "Unreal Tournament 2004" ]; then
 	install_server_files.sh
 	install_ut2k4_key.sh
-elif [ "${gamename}" == "Battlefield: 1942" ]||[ "${gamename}" == "Call of Duty" ]||[ "${gamename}" == "Call of Duty: United Offensive" ]||[ "${gamename}" == "Call of Duty 2" ]||[ "${gamename}" == "Call of Duty 4" ]||[ "${gamename}" == "Call of Duty: World at War" ]||[ "${gamename}" == "Factorio" ]||[ "${gamename}" == "Minecraft" ]||[ "${gamename}" == "Quake 2" ]||[ "${gamename}" == "Quake 3: Arena" ]||[ "${gamename}" == "QuakeWorld" ]||[ "${gamename}" == "Unreal Tournament 99" ]||[ "${gamename}" == "Unreal Tournament" ]||[ "${gamename}" == "Unreal Tournament 3" ]||[ "${gamename}" == "TeamSpeak 3" ]||[ "${gamename}" == "Mumble" ]||[ "${gamename}" == "Wolfenstein: Enemy Territory" ]; then
+elif [ "${gamename}" == "Battlefield: 1942" ]||[ "${gamename}" == "Call of Duty" ]||[ "${gamename}" == "Call of Duty: United Offensive" ]||[ "${gamename}" == "Call of Duty 2" ]||[ "${gamename}" == "Call of Duty 4" ]||[ "${gamename}" == "Call of Duty: World at War" ]||[ "${gamename}" == "Factorio" ]||[ "${gamename}" == "Minecraft" ]||[ "${gamename}" == "Multi Theft Auto" ]||[ "${gamename}" == "Quake 2" ]||[ "${gamename}" == "Quake 3: Arena" ]||[ "${gamename}" == "QuakeWorld" ]||[ "${gamename}" == "Unreal Tournament 99" ]||[ "${gamename}" == "Unreal Tournament" ]||[ "${gamename}" == "Unreal Tournament 3" ]||[ "${gamename}" == "TeamSpeak 3" ]||[ "${gamename}" == "Mumble" ]||[ "${gamename}" == "Wolfenstein: Enemy Territory" ]; then
 	installer=1
 	install_server_files.sh
 elif [ -n "${appid}" ]; then
@@ -34,6 +34,8 @@ elif [ "${gamename}" == "Don't Starve Together" ]; then
 	install_dst_token.sh
 elif [ "${gamename}" == "TeamSpeak 3" ]; then
 	install_ts3db.sh
+elif [ "${gamename}" == "Multi Theft Auto" ]; then
+	command_install_resources_mta.sh
 fi
 
 fix.sh

+ 31 - 0
lgsm/functions/command_install_resources_mta.sh

@@ -0,0 +1,31 @@
+#!/bin/bash
+# LGSM command_install_resources_mta.sh function
+# Author: Daniel Gibbs
+# Website: https://gameservermanagers.com
+# Description: Installs the default resources for Multi Theft Auto.
+
+local commandname="DEFAULT_RESOURCES"
+local commandaction="Default Resources"
+local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
+
+fn_install_resources(){
+	echo ""
+	echo "Installing Default Resources"
+	echo "================================="
+	fileurl="http://mirror.mtasa.com/mtasa/resources/mtasa-resources-latest.zip"; filedir="${tmpdir}"; filename="multitheftauto_resources.zip"; executecmd="noexecute" run="norun"; force="noforce"; md5="nomd5"
+	fn_fetch_file "${fileurl}" "${filedir}" "${filename}" "${executecmd}" "${run}" "${force}" "${md5}"
+	fn_dl_extract "${filedir}" "${filename}" "${resourcesdir}"
+	echo "Default Resources Installed."
+}
+
+fn_print_header
+
+fn_print_warning_nl "Installing the default resources with existing resources may cause issues."
+while true; do
+	read -e -i "y" -p "Do you want to install MTA default resources? [Y/n]" yn
+	case $yn in
+	[Yy]* ) fn_install_resources && break;;
+	[Nn]* ) break;;
+	* ) echo "Please answer yes or no.";;
+	esac
+done

+ 30 - 0
lgsm/functions/command_stop.sh

@@ -190,6 +190,34 @@ fn_stop_graceful_minecraft(){
 	fn_stop_tmux
 }
 
+# Attempts graceful of mta using rcon 'quit' command.
+fn_stop_graceful_mta(){
+	fn_print_dots "Graceful: console quit"
+	fn_script_log_info "Graceful: console quit"
+	# sends quit
+	tmux send -t "${servicename}" quit ENTER > /dev/null 2>&1
+	# waits up to 120 seconds giving the server time to shutdown gracefuly, we need a long wait time here as resources are stopped individually and process their own shutdowns
+	for seconds in {1..120}; do
+		check_status.sh
+		if [ "${status}" == "0" ]; then
+			fn_print_ok "Graceful: console quit: ${seconds}: "
+			fn_print_ok_eol_nl
+			fn_script_log_pass "Graceful: console quit: OK: ${seconds} seconds"
+			break
+		fi
+		sleep 1
+		fn_print_dots "Graceful: console quit: ${seconds}"
+	done
+	check_status.sh
+	if [ "${status}" != "0" ]; then
+		fn_print_error "Graceful: console quit: "
+		fn_print_fail_eol_nl
+		fn_script_log_error "Graceful: console quit: FAIL"
+	fi
+	sleep 1
+	fn_stop_tmux
+}
+
 fn_stop_graceful_select(){
 	if [ "${gamename}" == "7 Days To Die" ]; then
 		fn_stop_graceful_sdtd
@@ -201,6 +229,8 @@ fn_stop_graceful_select(){
 		fn_stop_graceful_goldsource
 	elif [ "${engine}" == "lwjgl2" ]; then
 		fn_stop_graceful_minecraft
+	elif [ "${engine}" == "renderware" ]; then
+		fn_stop_graceful_mta
 	else
 		fn_stop_tmux
 	fi

+ 3 - 1
lgsm/functions/command_update.sh

@@ -20,7 +20,9 @@ elif [ "${engine}" == "lwjgl2" ]; then
 elif [ "${gamename}" == "Mumble" ]; then
 	update_mumble.sh
 elif [ "${gamename}" == "Factorio" ]; then
-        update_factorio.sh
+  update_factorio.sh
+elif [ "${gamename}" == "Multi Theft Auto" ]; then
+	update_mta.sh
 else
 	update_steamcmd.sh
 fi

+ 15 - 0
lgsm/functions/core_functions.sh

@@ -182,6 +182,11 @@ functionfile="${FUNCNAME}"
 fn_fetch_function
 }
 
+command_install_resources_mta.sh(){
+functionfile="${FUNCNAME}"
+fn_fetch_function
+}
+
 command_mods_install.sh(){
 functionfile="${FUNCNAME}"
 fn_fetch_function
@@ -400,6 +405,11 @@ functionfile="${FUNCNAME}"
 fn_fetch_function
 }
 
+fix_mta.sh(){
+functionfile="${FUNCNAME}"
+fn_fetch_function
+}
+
 # Info
 
 info_config.sh(){
@@ -483,6 +493,11 @@ functionfile="${FUNCNAME}"
 fn_fetch_function
 }
 
+update_mta.sh(){
+functionfile="${FUNCNAME}"
+fn_fetch_function
+}
+
 update_factorio.sh(){
 functionfile="${FUNCNAME}"
 fn_fetch_function

+ 80 - 3
lgsm/functions/core_getopt.sh

@@ -351,6 +351,80 @@ case "${getopt}" in
 	esac
 }
 
+fn_getopt_mta(){
+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;;
+	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;;
+	ir|install-default-resources)
+		command_install_resources_mta.sh;;
+	ai|auto-install)
+		fn_autoinstall;;
+	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 linux.mtasa.com."
+		echo -e "${blue}force-update\t${default}fu |Bypasses the check and applies updates from linux.mtasa.com."
+		echo -e "${blue}update-functions\t${default}uf |Removes all functions so latest can be downloaded."
+		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 infomation 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}install-default-resources\t${default}ir |Install the MTA default resources."
+	} | column -s $'\t' -t
+	esac
+}
+
 fn_getopt_mumble(){
 case "${getopt}" in
 	st|start)
@@ -790,10 +864,13 @@ elif [ "${gamename}" == "Garry's Mod" ]; then
 # Minecraft
 elif [ "${engine}" == "lwjgl2" ]; then
 	fn_getopt_minecraft
+# Multi Theft Auto
+elif [ "${gamename}" == "Multi Theft Auto" ]; then
+	fn_getopt_mta
 # Mumble
 elif [ "${gamename}" == "Mumble" ]; then
 	fn_getopt_mumble
-# Teamspeak 3	
+# Teamspeak 3
 elif [ "${gamename}" == "TeamSpeak 3" ]; then
 	fn_getopt_teamspeak3
 # Unreal 2 Engine
@@ -803,14 +880,14 @@ elif [ "${engine}" == "unreal2" ]; then
 	else
 		fn_getopt_unreal2
 	fi
-# Unreal Engine	
+# Unreal Engine
 elif [ "${engine}" == "unreal" ]; then
 	fn_getopt_unreal
 # Generic
 elif [ "${gamename}" == "Battlefield: 1942" ]||[ "${gamename}" == "Call of Duty" ]||[ "${gamename}" == "Call of Duty: United Offensive" ]||[ "${gamename}" == "Call of Duty 2" ]||[ "${gamename}" == "Call of Duty 4" ]||[ "${gamename}" == "Call of Duty: World at War" ]||[ "${gamename}" == "QuakeWorld" ]||[ "${gamename}" == "Quake 2" ]||[ "${gamename}" == "Quake 3: Arena" ]||[ "${gamename}" == "Wolfenstein: Enemy Territory" ]; then
 	fn_getopt_generic_no_update
 elif  [ "${gamename}" == "Factorio" ]; then
-	fn_getopt_generic_update_no_steam	
+	fn_getopt_generic_update_no_steam
 else
 	fn_getopt_generic
 fi

+ 10 - 0
lgsm/functions/fix.sh

@@ -17,6 +17,14 @@ fn_fix_msg_start(){
 	sleep 1
 }
 
+fn_fix_msg_start_nl(){
+	fn_print_dots "Applying ${fixname} fix: ${gamename}"
+	sleep 1
+	fn_print_info "Applying ${fixname} fix: ${gamename}"
+	fn_script_log_info "Applying ${fixname} fix: ${gamename}"
+	sleep 1
+}
+
 fn_fix_msg_end(){
 	if [ $? -ne 0 ]; then
 		fn_print_error_nl "Applying ${fixname} fix: ${gamename}"
@@ -47,6 +55,8 @@ if [ "${function_selfname}" != "command_install.sh" ]; then
 		fix_ins.sh
 	elif [ "${gamename}" == "Rust" ]; then
 		fix_rust.sh
+	elif [ "${gamename}" == "Multi Theft Auto" ]; then
+		fix_mta.sh
 	fi
 fi
 

+ 3 - 3
lgsm/functions/fix_glibc.sh

@@ -46,8 +46,6 @@ do
 	fi
 done
 
-export LD_LIBRARY_PATH=:"${libdir}"
-
 ## amd64
 
 # libm.so.6
@@ -66,4 +64,6 @@ do
 	if [ "${gamename}" == "${libc_server}" ]; then
 		fn_fetch_file_github "lgsm/lib/ubuntu12.04/amd64" "libc.so.6" "${lgsmdir}/lib" "noexecutecmd" "norun" "noforce" "nomd5"
 	fi
-done
+done
+
+export LD_LIBRARY_PATH=:"${libdir}"

+ 20 - 0
lgsm/functions/fix_mta.sh

@@ -0,0 +1,20 @@
+#!/bin/bash
+# LGSM fix_mta.sh function
+# Author: Daniel Gibbs
+# Contributor: ChaosMTA
+# Website: https://gameservermanagers.com
+# Description: Installs the libmysqlclient for database functions on the server
+local commandname="FIX"
+local commandaction="Fix"
+local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
+
+if [ ! -f "${lgsmdir}/lib/libmysqlclient.so.16" ]; then
+	fixname="libmysqlclient16"
+	fn_fix_msg_start_nl
+	sleep 1
+	fileurl="https://nightly.mtasa.com/files/modules/64/libmysqlclient.so.16"; filedir="${lgsmdir}/lib"; filename="libmysqlclient.so.16"; executecmd="executecmd" run="norun"; force="noforce"; md5="6c188e0f8fb5d7a29f4bc413b9fed6c2"
+	fn_fetch_file "${fileurl}" "${filedir}" "${filename}" "${executecmd}" "${run}" "${force}" "${md5}"
+	fn_fix_msg_end
+fi
+
+export LD_LIBRARY_PATH=:"${libdir}"

+ 39 - 0
lgsm/functions/info_config.sh

@@ -603,6 +603,43 @@ fn_info_config_sdtd(){
 	fi
 }
 
+fn_info_config_mta(){
+	if [ ! -f "${servercfgfullpath}" ]; then
+		ip="${zero}"
+		port="${unavailable}"
+		httpport="${unavailable}"
+		ase="${unavailable}"
+		servername="${unavailable}"
+		serverpassword="${unavailable}"
+		maxplayers="${zero}"
+	else
+		port=$(grep -m 1 "serverport" "${servercfgfullpath}" | sed -e 's/^[ \t]*//g' -e '/^\//d' -e 's/<serverport>//g' | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//' | cut -f1 -d "<" | tr -cd '[:digit:]')
+		httpport=$(grep -m 1 "httpport" "${servercfgfullpath}" | sed -e 's/^[ \t]*//g' -e '/^\//d' -e 's/<httpport>//g' | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//' | cut -f1 -d "<" | tr -cd '[:digit:]')
+		ase=$(grep -m 1 "ase" "${servercfgfullpath}" | sed -e 's/^[ \t]*//g' -e '/^\//d' -e 's/<ase>//g' | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//' | cut -f1 -d "<" | tr -cd '[:digit:]')
+		servername=$(grep -m 1 "servername" "${servercfgfullpath}" | sed -e 's/^[ \t]*//g' -e '/^\//d' -e 's/<servername>//g' | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//' | cut -f1 -d "<")
+		serverpassword=$(grep -m 1 "password" "${servercfgfullpath}" | sed -e 's/^[ \t]*//g' -e '/^\//d' -e 's/<password>//g' | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//' | cut -f1 -d "<")
+		maxplayers=$(grep -m 1 "maxplayers" "${servercfgfullpath}" | sed -e 's/^[ \t]*//g' -e '/^\//d' -e 's/<maxplayers>//g' | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//' | cut -f1 -d "<" | tr -cd '[:digit:]')
+
+		if [ "${ase}" == "1" ]; then
+			ase="Enabled"
+		else
+			ase="Disabled"
+		fi
+
+		ip=$(grep -m 1 "serverip" "${servercfgfullpath}" | sed -e 's/^[ \t]*//g' -e '/^\//d' -e 's/<serverip>//g' | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//' | cut -f1 -d "<" | tr -cd '[:digit:]')
+		ipsetinconfig=1
+		ipinconfigvar="serverip"
+
+		# Not Set
+		port=${port:-"22003"}
+		httpport=${httpport:-"22005"}
+		ase=${ase:-"Disabled"}
+		servername=${servername:-"NOT SET"}
+		serverpassword=${serverpassword:-"NOT SET"}
+		maxplayers=${maxplayers:-"0"}
+	fi
+}
+
 # Just Cause 2
 if [ "${engine}" == "avalanche" ]; then
 	fn_info_config_avalanche
@@ -676,4 +713,6 @@ elif [ "${gamename}" == "7 Days To Die" ]; then
 	fn_info_config_sdtd
 elif [ "${gamename}" == "Wolfenstein: Enemy Territory" ]; then
 	fn_info_config_wolfensteinenemyterritory
+elif [ "${gamename}" == "Multi Theft Auto" ]; then
+	fn_info_config_mta
 fi

+ 3 - 0
lgsm/functions/info_glibc.sh

@@ -134,6 +134,9 @@ elif [ "${engine}" == "refractor" ]; then
 elif [ "${gamename}" == "Wolfenstein: Enemy Territory" ]; then
 	glibcrequired="2.2.4"
 	glibcfix="no"
+elif [ "${gamename}" == "Multi Theft Auto" ]; then
+	glibcrequired="NOT REQUIRED"
+	glibcfix="no"
 else
 	glibcrequired="UNKNOWN"
 	glibcfix="no"

+ 9 - 3
lgsm/functions/install_config.sh

@@ -34,13 +34,13 @@ fn_default_config_remote(){
 		echo "copying ${config} config file."
 		fn_script_log_info "copying ${servercfg} config file."
 		if [ "${config}" == "${servercfgdefault}" ]; then
-			cp -v "${lgsmdir}/default-configs/${config}" "${servercfgfullpath}"
+			cp -nv "${lgsmdir}/default-configs/${config}" "${servercfgfullpath}"
 		elif [ "${gamename}" == "ARMA 3" ]&&[ "${config}" == "${networkcfgdefault}" ]; then
-			cp -v "${lgsmdir}/default-configs/${config}" "${networkcfgfullpath}"
+			cp -nv "${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}"
+			cp -nv "${lgsmdir}/default-configs/${config}" "${servercfgdir}/${config}"
 		fi
 	done
 	sleep 1
@@ -361,6 +361,12 @@ elif [ "${gamename}" == "No More Room in Hell" ]; then
 	fn_fetch_default_config
 	fn_default_config_remote
 	fn_set_config_vars
+elif [ "${gamename}" == "Multi Theft Auto" ]; then
+	gamedirname="MultiTheftAuto"
+	fn_check_cfgdir
+	array_configs+=( acl.xml mtaserver.conf vehiclecolors.conf )
+	fn_fetch_default_config
+	fn_default_config_remote
 elif [ "${gamename}" == "Mumble" ]; then
 	gamedirname="Mumble"
 	array_configs+=( murmur.ini )

+ 37 - 0
lgsm/functions/install_mta_resources.sh

@@ -0,0 +1,37 @@
+#!/bin/bash
+# LGSM install_mta_resources.sh function
+# Author: Daniel Gibbs
+# Contributor: ChaosMTA
+# Website: https://gameservermanagers.com
+# Description: Installs the libmysqlclient for database functions on the server and optionally installs default resources required to run the server
+
+local commandname="INSTALL"
+local commandaction="Install"
+local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
+
+fn_install_libmysqlclient16(){
+	echo ""
+	echo "Checking if libmysqlclient16 is installed"
+	echo "================================="
+	sleep 1
+	if [ ! -f /usr/lib/libmysqlclient.so.16 ]; then
+		fn_print_warn_nl "libmysqlclient16 not installed. Installing.."
+		sleep 1
+		sudo -v > /dev/null 2>&1
+		if [ $? -eq 0 ]; then
+    	fileurl="https://nightly.mtasa.com/files/modules/64/libmysqlclient.so.16"; filedir="${tmpdir}"; filename="libmysqlclient.so.16"; executecmd="executecmd" run="norun"; force="noforce"; md5="6c188e0f8fb5d7a29f4bc413b9fed6c2"
+    	fn_fetch_file "${fileurl}" "${filedir}" "${filename}" "${executecmd}" "${run}" "${force}" "${md5}"
+			sudo mv ${tmpdir}/${filename} /usr/lib/${filename}
+		else
+			fn_print_fail_nl "Failed to install libmysqlclient16, $(whoami) does not have sudo access. Download it manually and place it in /usr/lib"
+			sleep 1
+		fi
+	else
+  	echo "libmysqlclient16 already installed."
+	fi
+}
+
+fn_install_libmysqlclient16
+
+fn_print_information_nl "Server is inoperable by default without resources, you can install default ones by running the command install-default-resources"
+echo ""

+ 2 - 0
lgsm/functions/install_server_files.sh

@@ -129,6 +129,8 @@ elif [ "${gamename}" == "Minecraft" ]; then
 	update_minecraft.sh
 elif [ "${gamename}" == "Mumble" ]; then
 	update_mumble.sh
+elif [ "${gamename}" == "Multi Theft Auto" ]; then
+	update_mta.sh
 elif [ "${gamename}" == "Factorio" ]; then
   update_factorio.sh
   install_factorio_save.sh

+ 155 - 0
lgsm/functions/update_mta.sh

@@ -0,0 +1,155 @@
+#!/bin/bash
+# LGSM update_mta.sh function
+# Author: Daniel Gibbs
+# Website: https://gameservermanagers.com
+# Description: Handles updating of Multi Theft Auto servers.
+
+local commandname="UPDATE"
+local commandaction="Update"
+local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
+
+fn_update_mta_dl(){
+	fn_fetch_file "http://linux.mtasa.com/dl/${numversion}/multitheftauto_linux_x64-${fullversion}.tar.gz" "${tmpdir}" "multitheftauto_linux_x64-${fullversion}.tar.gz"
+  mkdir "${tmpdir}/multitheftauto_linux_x64-${fullversion}"
+	fn_dl_extract "${tmpdir}" "multitheftauto_linux_x64-${fullversion}.tar.gz" "${tmpdir}/multitheftauto_linux_x64-${fullversion}"
+	echo -e "copying to ${filesdir}...\c"
+	fn_script_log "Copying to ${filesdir}"
+	cp -R "${tmpdir}/multitheftauto_linux_x64-${fullversion}/multitheftauto_linux_x64-${fullversion}/"* "${filesdir}"
+	local exitcode=$?
+	if [ "${exitcode}" == "0" ]; then
+		fn_print_ok_eol_nl
+	else
+		fn_print_fail_eol_nl
+	fi
+}
+
+fn_update_mta_currentbuild(){
+	# Gets current build info
+	# Checks if current build info is available. If it fails, then a server restart will be forced to generate logs.
+	if [ ! -f "${consolelogdir}/${servicename}-console.log" ]; then
+		fn_print_error "Checking for update: linux.mtasa.com"
+		sleep 1
+		fn_print_error_nl "Checking for update: linux.mtasa.com: No logs with server version found"
+		fn_script_log_error "Checking for update: linux.mtasa.com: No logs with server version found"
+		sleep 1
+		fn_print_info_nl "Checking for update: linux.mtasa.com: Forcing server restart"
+		fn_script_log_info "Checking for update: linux.mtasa.com: Forcing server restart"
+		sleep 1
+		exitbypass=1
+		command_stop.sh
+		exitbypass=1
+		command_start.sh
+		sleep 1
+		# Check again and exit on failure.
+		if [ ! -f "${consolelogdir}/${servicename}-console.log" ]; then
+			fn_print_fail_nl "Checking for update: linux.mtasa.com: Still No logs with server version found"
+			fn_script_log_fatal "Checking for update: linux.mtasa.com: Still No logs with server version found"
+			core_exit.sh
+		fi
+	fi
+
+	# Get current build from logs
+	currentbuild=$(awk -F"= Multi Theft Auto: San Andreas v" '{print $2}' "${consolelogdir}"/"${servicename}"-console.log | awk '{print $1}')
+	if [ -z "${currentbuild}" ]; then
+		fn_print_error_nl "Checking for update: linux.mtasa.com: Current build version not found"
+		fn_script_log_error "Checking for update: linux.mtasa.com: Current build version not found"
+		sleep 1
+		fn_print_info_nl "Checking for update: linux.mtasa.com: Forcing server restart"
+		fn_script_log_info "Checking for update: linux.mtasa.com: Forcing server restart"
+		exitbypass=1
+		command_stop.sh
+		exitbypass=1
+		command_start.sh
+		currentbuild=$(awk -F"= Multi Theft Auto: San Andreas v" '{print $2}' "${consolelogdir}"/"${servicename}"-console.log | awk '{print $1}')
+		if [ -z "${currentbuild}" ]; then
+			fn_print_fail_nl "Checking for update: linux.mtasa.com: Current build version still not found"
+			fn_script_log_fatal "Checking for update: linux.mtasa.com: Current build version still not found"
+			core_exit.sh
+		fi
+	fi
+}
+
+fn_mta_get_availablebuild()
+{
+	fn_fetch_file "https://raw.githubusercontent.com/multitheftauto/mtasa-blue/master/Server/version.h" "${tmpdir}" "version.h" # we need to find latest stable version here
+	local majorversion="$(cat ${tmpdir}/version.h | grep "#define MTASA_VERSION_MAJOR" | awk '{ print $3 }' | sed 's/\r//g')"
+	local minorversion="$(cat ${tmpdir}/version.h | grep "#define MTASA_VERSION_MINOR" | awk '{ print $3 }' | sed 's/\r//g')"
+	local maintenanceversion="$(cat ${tmpdir}/version.h | grep "#define MTASA_VERSION_MAINTENANCE" | awk '{ print $3 }' | sed 's/\r//g')"
+	numversion="${majorversion}${minorversion}${maintenanceversion}"
+	fullversion="${majorversion}.${minorversion}.${maintenanceversion}"
+	rm -f "${tmpdir}/version.h"
+}
+
+fn_update_mta_compare(){
+	# Removes dots so if can compare version numbers
+	currentbuilddigit=$(echo "${currentbuild}"|tr -cd '[:digit:]')
+	if [ "${currentbuilddigit}" -ne "${numversion}" ]||[ "${forceupdate}" == "1" ]; then
+		if [ "${forceupdate}" == "1" ]; then
+			# forceupdate bypasses checks, useful for small build changes
+			mta_update_string="forced"
+		else
+			mta_update_string="available"
+		fi
+		echo -e "\n"
+		echo -e "Update ${mta_update_string}:"
+		sleep 1
+		echo -e "	Current build: ${red}${currentbuild} ${default}"
+		echo -e "	Available build: ${green}${fullversion} ${default}"
+		echo -e ""
+		sleep 1
+		echo ""
+		echo -en "Applying update.\r"
+		sleep 1
+		echo -en "Applying update..\r"
+		sleep 1
+		echo -en "Applying update...\r"
+		sleep 1
+		echo -en "\n"
+		fn_script_log "Update ${mta_update_string}"
+		fn_script_log "Current build: ${currentbuild}"
+		fn_script_log "Available build: ${fullversion}"
+		fn_script_log "${currentbuild} > ${fullversion}"
+
+		unset updateonstart
+
+		check_status.sh
+		if [ "${status}" == "0" ]; then
+			fn_update_mta_dl
+			exitbypass=1
+			command_start.sh
+			exitbypass=1
+			command_stop.sh
+		else
+			exitbypass=1
+			command_stop.sh
+			fn_update_mta_dl
+			exitbypass=1
+			command_start.sh
+		fi
+		alert="update"
+		alert.sh
+	else
+		echo -e "\n"
+		echo -e "No update available:"
+		echo -e "	Current version: ${green}${currentbuild}${default}"
+		echo -e "	Available version: ${green}${fullversion}${default}"
+		echo -e ""
+		fn_print_ok_nl "No update available"
+		fn_script_log_info "Current build: ${currentbuild}"
+		fn_script_log_info "Available build: ${fullversion}"
+	fi
+}
+
+
+if [ "${installer}" == "1" ]; then
+	fn_mta_get_availablebuild
+	fn_update_mta_dl
+else
+	# Checks for server update from linux.mtasa.com using the github repo.
+	fn_print_dots "Checking for update: linux.mtasa.com"
+	fn_script_log_info "Checking for update: linux.mtasa.com"
+	sleep 1
+	fn_update_mta_currentbuild
+	fn_mta_get_availablebuild
+	fn_update_mta_compare
+fi