Просмотр исходного кода

Added a way to have multiple configuration in the same directory

Ilija Matoski 11 лет назад
Родитель
Сommit
6bc2132c51
4 измененных файлов с 97 добавлено и 5 удалено
  1. 7 0
      CounterStrikeGlobalOffensive/csgoserver
  2. 5 0
      functions/fn_functions
  3. 5 5
      functions/fn_getopt
  4. 80 0
      functions/fn_select

+ 7 - 0
CounterStrikeGlobalOffensive/csgoserver

@@ -111,5 +111,12 @@ fn_runfunction
 
 fn_functions
 
+# init the getopt function variables
 getopt=$1
+
+# init the select function variables
+usesrvcfg=1
+getsrvcfg=$2
+
+fn_select
 fn_getopt

+ 5 - 0
functions/fn_functions

@@ -268,5 +268,10 @@ functionfile="${FUNCNAME}"
 fn_runfunction
 }
 
+fn_select(){
+functionfile="${FUNCNAME}"
+fn_runfunction
+}
+
 # Calls on-screen messages
 fn_messages

+ 5 - 5
functions/fn_getopt

@@ -42,7 +42,7 @@ case "$getopt" in
 	auto-install)
 		fn_autoinstall;;
 	*)
-	echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install|auto-install}"
+	echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install|auto-install} $appendextra"
 	exit 1;;
 esac
 exit
@@ -67,7 +67,7 @@ case "$getopt" in
 	backup)
 		fn_backup;;
 	*)
-		echo "Usage: $0 {start|stop|restart|backup|monitor|email-test|details|backup}"
+		echo "Usage: $0 {start|stop|restart|backup|monitor|email-test|details|backup} $appendextra"
 		exit 1;;
 esac
 exit
@@ -98,7 +98,7 @@ case "$getopt" in
 	map-compressor)
 		fn_compress_ut99maps;;
 	*)
-	echo "Usage: $0 {start|stop|restart|monitor|email-test|details|backup|console|debug|install|map-compressor}"
+	echo "Usage: $0 {start|stop|restart|monitor|email-test|details|backup|console|debug|install|map-compressor} $appendextra"
 	exit 1;;
 esac
 exit
@@ -143,7 +143,7 @@ case "$getopt" in
 	map-compressor)
 		fn_compress_unreal2maps;;
 	*)
-	echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install|auto-install|map-compressor}"
+	echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install|auto-install|map-compressor} $appendextra"
 	exit 1;;
 esac
 exit
@@ -175,7 +175,7 @@ case "$getopt" in
 	map-compressor)
 		fn_compress_unreal2maps;;
 	*)
-	echo "Usage: $0 {start|stop|restart|monitor|email-test|details|backup|console|debug|install|map-compressor}"
+	echo "Usage: $0 {start|stop|restart|monitor|email-test|details|backup|console|debug|install|map-compressor} $appendextra"
 	exit 1;;
 esac
 exit

+ 80 - 0
functions/fn_select

@@ -0,0 +1,80 @@
+#!/bin/bash
+# LGSM fn_select function
+# Author: Ilija Matoski (ilijamt@gmail.com)
+# Website: https://matoski.com
+# Version: 010316
+
+# Description: Automatically selects a created server from the available ones defined in the root
+# If no server files found <name>.<appid> it will default to the data in the game file
+
+if [ $usesrvcfg -eq 1 ]; then
+
+    if [ -z "$appid" ]; then
+      fn_printwarn "appid not found for $gamename, this is not supported.\n\n"
+      exit
+    fi
+
+    # get all the available configs for the appid
+    cfgs=()
+    filelist=(`find $rootdir -type f -name "*.$appid"`)
+    for file in "${filelist[@]}"; do
+      cfg=${file:${#rootdir}+1}
+      cfg=${cfg:0:${#cfg} - 4}
+      cfgs+=("$cfg")
+    done
+
+    # create the append extra list for the options
+    appendextra=$(printf "|%s" "${cfgs[@]}")
+    appendextra=${appendextra:1}
+    loadcfg=
+    invalidcfg=0
+    reinit=0
+
+    # if we don't have any config files proced as normal so skip the next part
+    if [ ${#cfgs[@]} -eq 1 ]; then
+        # we have only one config file so we load that one only unless the user specifies it manually, then we verify
+        loadcfg="${cfgs[0]}";
+        if [ ! -z "$getsrvcfg" ] && [ ! -f "${getsrvcfg}.${appid}" ]; then
+            invalidcfg=1
+        fi
+    elif [ ${#cfgs[@]} -gt 0 ]; then
+        # we have more than one files available so we continue on the verification if the file is present
+        loadcfg="$getsrvcfg";
+        if [ -z "$getsrvcfg" ] || [ ! -f "${getsrvcfg}.${appid}" ]; then
+            invalidcfg=1
+        fi
+    else
+        # we don't have anything so we need to continue on without touching anything
+        reinit=0
+        loadcfg=
+    fi
+
+    # it's invalid cfg setting
+    if [ $invalidcfg -eq 1 ]; then
+      fn_printwarn "$getsrvcfg configuration file doesn't exist, use one of the available ones ($appendextra)\n"
+      getopt=
+      fn_getopt
+    else
+      if [ ! -z "$loadcfg" ] && [ -f "${getsrvcfg}.${appid}" ]; then
+        # everything OK, load the config file and reinit the variables
+        source "${loadcfg}.${appid}"
+        reinit=1
+      fi
+    fi
+
+    if [ $reinit -eq 1 ]; then
+        case "$appid" in
+            *)
+            lockselfname=".${servicename}.lock"
+            servercfg="${servicename}.cfg"
+            servercfgfullpath="${servercfgdir}/${servercfg}"
+            scriptlog="${scriptlogdir}/${servicename}-script.log"
+            consolelog="${consolelogdir}/${servicename}-console.log"
+            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"
+            ;;
+        esac
+    fi
+
+fi