From f6f802bbc30ac24ecadaec8c86838c924f40bed4 Mon Sep 17 00:00:00 2001 From: Jared Ballou Date: Tue, 19 Jan 2016 00:57:58 -0500 Subject: [PATCH] Added CS:GO as another test of gamedata loader. Moved the config portion and gamedata loader to game_settings.sh. --- Insurgency/insserver | 200 +++----------------------------- functions/game_settings.sh | 144 +++++++++++++++++++++++ games/_default | 14 +++ games/_srcds | 50 +++++--- games/csgoserver | 39 +++++++ games/{insurgency => insserver} | 10 +- 6 files changed, 258 insertions(+), 199 deletions(-) create mode 100644 functions/game_settings.sh create mode 100644 games/csgoserver rename games/{insurgency => insserver} (59%) diff --git a/Insurgency/insserver b/Insurgency/insserver index db442e532..b3f12cc1a 100755 --- a/Insurgency/insserver +++ b/Insurgency/insserver @@ -6,29 +6,35 @@ version="180116" +# File fetching settings +# Github Branch Select +# Allows for the use of different function files +# from a different repo and/or branch. +githubuser="jaredballou" +githubrepo="linuxgsm" +githubbranch="master" + #### Variables #### # The name of this script file, used to show the LGSM link properly selfname=$(basename $(readlink -f "${BASH_SOURCE[0]}")) +# Name of this service (for symlinked instances) +servicename="$(basename $0)" + # Directories # Script root rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" - # LGSM Support Files lgsmdir="${rootdir}/lgsm" - # Temporary path to store and manipulate settings settingsdir="${lgsmdir}/settings.tmp" - # Supported Game Data gamesdir="${lgsmdir}/games" - # Config path for local instances scriptcfgdir="${lgsmdir}/cfg/servers" - # Debugging, if debugflag exists send output to $debuglog debugflag="${lgsmdir}/.dev-debug" debuglog="${lgsmdir}/dev-debug.log" @@ -38,138 +44,8 @@ if [ -f "${debugflag}" ]; then set -x fi -# Settings to get before config parsing begins -engine="source" -# Game name for file paths -game="insurgency" -# Name for subdirectory in GitHub repo -gamename="Insurgency" -# Name of this service (for symlinked instances) -servicename="$(basename $0)" - -# File fetching settings -# Github Branch Select -# Allows for the use of different function files -# from a different repo and/or branch. -githubuser="jaredballou" -githubrepo="linuxgsm" -githubbranch="master" - #ipaddr=$(ip addr show $(ip route | grep '^default' | awk '{print $NF}') | grep 'inet ' | awk '{print $2}' | cut -f1 -d'/') -# Config files -cfg_file_default="${scriptcfgdir}/_default.cfg" -cfg_file_common="${scriptcfgdir}/_common.cfg" -cfg_file_instance="${scriptcfgdir}/${servicename}.cfg" - -# Config file headers -cfg_header_all="# Your settings for all servers go in _common.cfg\n# Server-specific settings go into \$SERVER.cfg" -cfg_header_default="# Default config - Changes will be overwritten by updates.\n${cfg_header_all}" -cfg_header_common="# Common config - Will not be overwritten by script.\n${cfg_header_all}" -cfg_header_instance="# Instance Config for ${servicename} - Will not be overwritten by script.\n${cfg_header_all}" - -# If default config does not exist, create it. This should come from Git, and will be overwritten by updates. -# Rather than try to wget it from Github or other fancy ways to get it, the simplest way to ensure it works is to simply create it here. -fn_update_config() -{ - key=$1 - val=$2 - cfg_file=${3:-$cfg_file_default} - comment=${4:-""} - # Put " # " at beginning of comment if not empty - if [ "${comment}" != "" ] - then - comment=" # ${comment}" - fi - - # Line to be put in - data="${key}=\"${val}\"${comment}" - - # Get current key/value pair from file - exists=$(grep "^${key}=" $cfg_file) - - # Check if key exists in config - if [ "${exists}" != "" ]; then - # If the line isn't the same as the parsed data line, replace it - if [ "${exists}" != "${data}" ]; then - echo "Updating ${data} in ${cfg_file}" - sed -e "s/^${key}=.*\$/${data}/g" -i $cfg_file - fi - else - # If value does not exist, append to file - echo "Adding ${data} to ${cfg_file}" - echo -ne "${data}\n" >> $cfg_file - fi -} -fn_create_config(){ - cfg_type=${1:-default} - cfg_file="cfg_file_${cfg_type}" - cfg_header="cfg_header_${cfg_type}" - - cfg_dir=$(dirname ${!cfg_file}) - #If config directory does not exist, create it - if [ ! -e $cfg_dir ]; then mkdir -p $cfg_dir; fi - - # Create file header if needed - if [ ! -e ${!cfg_file} ]; then - echo "Creating ${cfg_type} config at ${!cfg_file}" - echo -ne "${!cfg_header}\n\n" > ${!cfg_file} - fi - - # Default config values - if [ "${cfg_type}" == "default" ]; then - fn_update_config "appid" "237410" - fn_update_config "beta" "" "${!cfg_file}" "To enable beta, use \"-beta beta\"" - fn_update_config "clientport" "27005" - fn_update_config "defaultmap" "ministry" - fn_update_config "defaultmode" "checkpoint" - fn_update_config "email" "email@example.com" - fn_update_config "emailnotification" "off" "$cfg_file_default" "(on|off)" - fn_update_config "ip" "0.0.0.0" - fn_update_config "lgsm_version" $version - fn_update_config "logdays" "7" - fn_update_config "mapcyclefile" "mapcycle.txt" - fn_update_config "maxplayers" "64" - fn_update_config "playlist" "custom" - fn_update_config "port" "27015" - fn_update_config "sourcetvport" "27020" - fn_update_config "srcds_parms" "" "$cfg_file_default" "Put the parameters that start with \"-\" first, then \"+\" parameters after" - fn_update_config "steampass" "" - fn_update_config "steamuser" "anonymous" - fn_update_config "updateonstart" "off" - fi -} - -fn_settings_flush(){ - if [ -e $settingsdir ]; then - rm -rf $settingsdir > /dev/null - fi - mkdir -p $settingsdir -} -fn_settings_import(){ - import="${gamesdir}/${1}" - if [ ! -e $import ]; then - fn_getgithubfile "games/${1}" - fi - source $import -} - -fn_set_game_params(){ - param_set=$1 - param_name=$2 - param_value=$3 - param_comment=$4 - fn_update_config "${param_name}" "${param_value}" "${settingsdir}/${param_set}" "${param_comment}" -} -fn_get_game_params(){ - param_set=$1 - param_name=$2 - param_default=$3 -} - - - - ##### Script ##### # Do not edit @@ -237,24 +113,6 @@ fn_getgithubfile(){ fi } -# Flush old setings buffer -fn_settings_flush - -# Import this game's settings -fn_settings_import $game - -# New method is to always run this function, it will overwrite defaults with whatever the new script values are -fn_create_config default - -# Load defaults -source $cfg_file_default - -# Load sitewide common settings (so that Git updates can safely overwrite default.cfg) -if [ ! -f $cfg_file_common ]; then fn_create_config common; else source $cfg_file_common; fi - -# Load instance specific settings -if [ ! -f $cfg_file_instance ]; then fn_create_config instance; else source $cfg_file_instance; fi - #### Advanced Variables #### # Directories lockselfname=".${servicename}.lock" @@ -283,41 +141,21 @@ emaillog="${scriptlogdir}/${servicename}-email.log" scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log" consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log" - - - - -# Set the paramaters to send to srcds -# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server -fn_parms(){ -#TODO: Put in some conditional logic to handle generating the parm string so we can make this a little less game specific -parms="${parms} -game ${game}" -parms="${parms} -strictportbind" -parms="${parms} -ip ${ip}" -parms="${parms} -port ${port}" -parms="${parms} -maxplayers ${maxplayers}" -parms="${parms} ${srcds_parms}" -parms="${parms} +clientport ${clientport}" -parms="${parms} +tv_port ${sourcetvport}" -parms="${parms} +sv_playlist ${playlist}" -parms="${parms} +mapcyclefile ${mapcyclefile}" -parms="${parms} +servercfgfile ${servercfg}" -parms="${parms} +map ${defaultmap} ${defaultmode}" -} - # fn_runfunction fn_runfunction(){ + scriptfile=${1:-$functionfile} + functionfile=$scriptfile fn_getgithubfile "functions/${functionfile}" 1 } # core_functions.sh -core_functions.sh(){ - # Functions are defined in core_functions.sh. - functionfile="${FUNCNAME}" - fn_runfunction -} +#core_functions.sh(){ +# # Functions are defined in core_functions.sh. +# fn_runfunction "${FUNCNAME}" +#} -core_functions.sh +fn_runfunction game_settings.sh +fn_runfunction core_functions.sh getopt=$1 core_getopt.sh diff --git a/functions/game_settings.sh b/functions/game_settings.sh new file mode 100644 index 000000000..fd95bbce6 --- /dev/null +++ b/functions/game_settings.sh @@ -0,0 +1,144 @@ +#!/bin/bash +# LGSM game_settings.sh function +# Author: Jared Ballou +# Website: http://gameservermanagers.com +lgsm_version="180116" + +function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))" +local modulename="Settings" + +# Config files +cfg_file_default="${scriptcfgdir}/_default.cfg" +cfg_file_common="${scriptcfgdir}/_common.cfg" +cfg_file_instance="${scriptcfgdir}/${servicename}.cfg" + +# Config file headers +cfg_header_all="# Your settings for all servers go in _common.cfg\n# Server-specific settings go into \$SERVER.cfg" +cfg_header_default="# Default config - Changes will be overwritten by updates.\n${cfg_header_all}" +cfg_header_common="# Common config - Will not be overwritten by script.\n${cfg_header_all}" +cfg_header_instance="# Instance Config for ${servicename} - Will not be overwritten by script.\n${cfg_header_all}" + + +# If default config does not exist, create it. This should come from Git, and will be overwritten by updates. +# Rather than try to wget it from Github or other fancy ways to get it, the simplest way to ensure it works is to simply create it here. +fn_update_config() +{ + key=$1 + val=$2 + cfg_file=${3:-$cfg_file_default} + comment=${4:-""} + + # Get current key/value pair from file + exists=$(grep "^${key}=" $cfg_file 2>/dev/null) + exists_comment=$(echo $(echo $exists | cut -d'#' -f2-)) + case "${val}" in + ""|"--UNSET--") + if [ "${exists}" != "" ]; then + echo "Removing ${key} from ${cfg_file}" + sed "/${key}=.*/d" -i $cfg_file + fi + return + ;; + "--EMPTY--") + val="" + ;; + esac + # Put " # " at beginning of comment if not empty + if [ "${comment}" != "" ] + then + comment=" # ${comment}" + else + if [ "${exists_comment}" != "" ]; then + comment=" # ${exists_comment}" + fi + fi + + # Line to be put in + data="${key}=\"${val}\"${comment}" + + # Check if key exists in config + if [ "${exists}" != "" ]; then + # If the line isn't the same as the parsed data line, replace it + if [ "${exists}" != "${data}" ]; then + #echo "Updating ${data} in ${cfg_file}" + sed -e "s/^${key}=.*\$/${data}/g" -i $cfg_file + #sed "/${key}=.*/${data}/" -i $cfg_file + fi + else + # If value does not exist, append to file + #echo "Adding ${data} to ${cfg_file}" + echo -ne "${data}\n" >> $cfg_file + fi +} + +fn_create_config(){ + cfg_type=${1:-default} + cfg_force=$2 + cfg_file="cfg_file_${cfg_type}" + cfg_header="cfg_header_${cfg_type}" + + cfg_dir=$(dirname ${!cfg_file}) + #If config directory does not exist, create it + if [ ! -e $cfg_dir ]; then mkdir -p $cfg_dir; fi + + # Create file header if needed + if [ ! -e ${!cfg_file} ] || [ "${cfg_force}" != "" ]; then + echo "Creating ${cfg_type} config at ${!cfg_file}" + echo -ne "${!cfg_header}\n\n" > ${!cfg_file} + # Dump in defaults for this game + if [ "${cfg_type}" == "default" ]; then + cat ${settingsdir}/settings >> ${!cfg_file} + fi + fi +} + +fn_flush_game_settings(){ + if [ -e $settingsdir ]; then + rm -rf $settingsdir > /dev/null + fi + mkdir -p $settingsdir +} + +fn_import_game_settings(){ + import="${gamesdir}/${1}" + if [ ! -e $import ]; then + fn_getgithubfile "games/${1}" + fi + source $import +} + +fn_set_game_params(){ + param_set=$1 + param_name=$2 + param_value=$3 + param_comment=$4 + fn_update_config "${param_name}" "${param_value}" "${settingsdir}/${param_set}" "${param_comment}" +} + + +fn_get_game_params(){ + param_set=$1 + param_name=$2 + param_default=$3 +} + +# Flush old setings buffer +fn_flush_game_settings + +# Import this game's settings +fn_import_game_settings $selfname + +# New method is to always run this function, it will overwrite defaults with whatever the new script values are +fn_create_config default + +# Load defaults +source $cfg_file_default + +# Load sitewide common settings (so that Git updates can safely overwrite default.cfg) +if [ ! -f $cfg_file_common ]; then fn_create_config common; else source $cfg_file_common; fi + +# Load instance specific settings +if [ ! -f $cfg_file_instance ]; then fn_create_config instance; else source $cfg_file_instance; fi + + + diff --git a/games/_default b/games/_default index 9c62574d9..94e2b7de6 100644 --- a/games/_default +++ b/games/_default @@ -2,9 +2,23 @@ # _default # Base defaults for all games +# Set the default settings for the script fn_set_game_params settings "email" "email@example.com" "Email address for notification" fn_set_game_params settings "emailnotification" "off" "Email notification (on|off)" fn_set_game_params settings "ip" "0.0.0.0" "IP Address to bind for server" fn_set_game_params settings "lgsm_version" "${version}" "Version of LGSM that created this config" fn_set_game_params settings "logdays" "7" "Number of days to retain logs" fn_set_game_params settings "updateonstart" "off" "Update game on start" + + + +fn_set_game_params settings "lockselfname" ".\${servicename}.lock" "LGSM Lock File" +fn_set_game_params settings "filesdir" "\${rootdir}/serverfiles" "Server Files Directory" +fn_set_game_params settings "backupdir" "\${lgsmdir}/backups" "Backup Directory" +fn_set_game_params settings "scriptlogdir" "\${lgsmdir}/log/script" "Script Log Dir" +fn_set_game_params settings "consolelogdir" "\${lgsmdir}/log/console" "Console Log Dir" +fn_set_game_params settings "scriptlog" "\${scriptlogdir}/\${servicename}-script.log" "Script Log" +fn_set_game_params settings "consolelog" "\${consolelogdir}/\${servicename}-console.log" "Console Log" +fn_set_game_params settings "emaillog" "\${scriptlogdir}/\${servicename}-email.log" "Email Log" +fn_set_game_params settings "scriptlogdate" "\${scriptlogdir}/\${servicename}-script-\$(date '+%d-%m-%Y-%H-%M-%S').log" "Script Log Rotation Filename" +fn_set_game_params settings "consolelogdate" "\${consolelogdir}/\${servicename}-console-\$(date '+%d-%m-%Y-%H-%M-%S').log" "Console Log Rotation Filename" diff --git a/games/_srcds b/games/_srcds index 361f3120f..25115cee8 100644 --- a/games/_srcds +++ b/games/_srcds @@ -2,31 +2,51 @@ # _srcds # Base SRCDS Game -fn_settings_import _default +# Import default settings +fn_import_game_settings _default -fn_set_game_params params "" "\${params_minus} \${params_plus}" -fn_set_game_params params_minus "-game" "\${game}" -fn_set_game_params params_minus "-strictportbind" "" -fn_set_game_params params_minus "-ip" "\${ip}" -fn_set_game_params params_minus "-port" "\${port}" -fn_set_game_params params_minus "-maxplayers" "\${maxplayers}" +# This is the way we create a script that collates and parses the parameters +fn_parms(){ + parms="$(echo $(sed -e 's/=\"/ /g' -e 's/\"$//g' ${settingsdir}/parms_minus)) ${srcds_parms} $(echo $(sed -e 's/=\"/ /g' -e 's/\"$//g' ${settingsdir}/parms_plus))" +} +# The parms that start with - go first +fn_set_game_params parms_minus "-game" "\${game}" +fn_set_game_params parms_minus "-strictportbind" "--EMPTY--" +fn_set_game_params parms_minus "-ip" "\${ip}" +fn_set_game_params parms_minus "-port" "\${port}" +fn_set_game_params parms_minus "-maxplayers" "\${maxplayers}" -fn_set_game_params params_plus "+clientport" "\${clientport}" -fn_set_game_params params_plus "+tv_port" "\${sourcetvport}" -fn_set_game_params params_plus "+mapcyclefile" "\${mapcyclefile}" -fn_set_game_params params_plus "+servercfgfile" "\${servercfg}" -fn_set_game_params params_plus "+map" "\${defaultmap}" +# Then the parms that start with + +fn_set_game_params parms_plus "+clientport" "\${clientport}" +fn_set_game_params parms_plus "+tv_port" "\${sourcetvport}" +fn_set_game_params parms_plus "+mapcyclefile" "\${mapcyclefile}" +fn_set_game_params parms_plus "+servercfgfile" "\${servercfg}" +fn_set_game_params parms_plus "+map" "\${defaultmap}" +# And the settings for defaults fn_set_game_params settings "appid" "204" "Steam App ID" fn_set_game_params settings "clientport" "27005" "Client Port" fn_set_game_params settings "defaultmap" "dm_lockdown" "Default map to load" +fn_set_game_params settings "engine" "source" "Game Engine" fn_set_game_params settings "game" "hl2mp" "Name of game to pass to srcds" +fn_set_game_params settings "gamename" "HalfLife2Deathmatch" "Name for subdirectory in GitHub repo" fn_set_game_params settings "mapcyclefile" "mapcycle.txt" "Map Cycle File" fn_set_game_params settings "maxplayers" "64" "Maximum player count" fn_set_game_params settings "playlist" "custom" "Playlist" fn_set_game_params settings "port" "27015" "Port to bind for server" -fn_set_game_params settings "servercfg" "${instance}.cfg" "Server Config file" +fn_set_game_params settings "servercfg" "${selfname}.cfg" "Server Config file" fn_set_game_params settings "sourcetvport" "27020" "SourceTV Port" -fn_set_game_params settings "srcds_parms" "" "Additional SRCDS Parameters. Put the parameters that start with \"-\" first, then \"+\" parameters after" -fn_set_game_params settings "steampass" "" "Steam Password" +fn_set_game_params settings "srcds_parms" "--EMPTY--" "Additional SRCDS Parameters. Put the parameters that start with \"-\" first, then \"+\" parameters after" +fn_set_game_params settings "steampass" "--EMPTY--" "Steam Password" fn_set_game_params settings "steamuser" "anonymous" "Steam Username" + + +fn_set_game_params settings "systemdir" "\${filesdir}/\${game}" +fn_set_game_params settings "gamelogdir" "\${systemdir}/logs" +fn_set_game_params settings "executabledir" "\${filesdir}" +fn_set_game_params settings "executable" "./srcds_linux" +fn_set_game_params settings "servercfg" "\${servicename}.cfg" +fn_set_game_params settings "servercfgdir" "\${systemdir}/cfg" +fn_set_game_params settings "servercfgfullpath" "\${servercfgdir}/\${servercfg}" +fn_set_game_params settings "servercfgdefault" "\${servercfgdir}/lgsm-default.cfg" + diff --git a/games/csgoserver b/games/csgoserver new file mode 100644 index 000000000..afe9dab63 --- /dev/null +++ b/games/csgoserver @@ -0,0 +1,39 @@ +# Game Settings File +# csgoserver +# Counter-Strike: Global Offensive Dedicated Server + +# Import SRCDS +fn_import_game_settings _srcds + +# Add playlist parameter +fn_set_game_params parms_plus "+sv_playlist" "\${playlist}" + +# Override some server settings +fn_set_game_params settings "appid" "740" +fn_set_game_params settings "defaultmap" "de_dust2" +fn_set_game_params settings "game" "csgo" +fn_set_game_params settings "mapcyclefile" "--UNSET--" +fn_set_game_params settings "gamename" "Counter Strike: Global Offensive" +fn_set_game_params settings "mapgroup" "random_classic" "Map Group. See https://developer.valvesoftware.com/wiki/Counter-Strike:_Global_Offensive_Dedicated_Servers#Starting_the_Server" +fn_set_game_params settings "tickrate" "64" "Server Tick Rate" +fn_set_game_params settings "gametype" "0" "Game Type. Set to: Arms Race 1 Classic Casual 0 Classic Competitive 0 Demolition 1 Deathmatch 1" +fn_set_game_params settings "gamemode" "0" "Game Mode. Set to: Arms Race 0 Classic Casual 0 Classic Competitive 1 Demolition 1 Deathmatch 2" +fn_set_game_params settings "gslt" "--EMPTY--" "Required: Game Server Login Token. GSLT is required for running a public server. More info: http://gameservermanagers.com/gslt" +fn_set_game_params settings "authkey" "--EMPTY--" "Optional key for Workshop Content. See https://developer.valvesoftware.com/wiki/CSGO_Workshop_For_Server_Operators - To get an authkey visit - http://steamcommunity.com/dev/apikey" +fn_set_game_params settings "ws_collection_id" "--EMPTY--" "Workshop Collection ID" +fn_set_game_params settings "ws_start_map" "--EMPTY--" "Workshop Start Map" + + +# The parms that start with - go first +fn_set_game_params parms_minus "-usercon" "--EMPTY--" +fn_set_game_params parms_minus "-tickrate" "\${tickrate}" +fn_set_game_params parms_minus "-maxplayers_override" "\${maxplayers}" +fn_set_game_params parms_minus "-authkey" "\${authkey}" + +# Then the parms that start with + +fn_set_game_params parms_plus "+sv_setsteamaccount" "\${gslt}" +fn_set_game_params parms_plus "+mapgroup" "\${mapgroup}" +fn_set_game_params parms_plus "+game_mode" "\${gamemode}" +fn_set_game_params parms_plus "+game_type" "\${gametype}" +fn_set_game_params parms_plus "+host_workshop_collection" "\${ws_collection_id}" +fn_set_game_params parms_plus "+workshop_start_map" "\${ws_start_map}" diff --git a/games/insurgency b/games/insserver similarity index 59% rename from games/insurgency rename to games/insserver index 44d5fd76a..c2dde4f3b 100644 --- a/games/insurgency +++ b/games/insserver @@ -1,13 +1,17 @@ # Game Settings File -# insurgency +# insserver # Insurgency Dedicated Server -fn_settings_import _srcds +# Import SRCDS +fn_import_game_settings _srcds -fn_set_game_params params_plus "+sv_playlist" "\${playlist}" +# Add playlist parameter +fn_set_game_params parms_plus "+sv_playlist" "\${playlist}" +# Override some server settings fn_set_game_params settings "appid" "237410" fn_set_game_params settings "defaultmap" "ministry checkpoint" fn_set_game_params settings "game" "insurgency" fn_set_game_params settings "mapcyclefile" "mapcycle.txt" fn_set_game_params settings "playlist" "custom" "Server Playlist" +fn_set_game_params settings "gamename" "Insurgency"