Răsfoiți Sursa

Merge pull request #351 from dgibbs64/development

Development
Daniel Gibbs 11 ani în urmă
părinte
comite
7c643b3d3b

+ 12 - 1
7DaysToDie/sdtdserver

@@ -17,7 +17,18 @@ steamuser="username"
 steampass="password"
 
 # Start Variables
-ip="0.0.0.0"
+ip="0.0.0.0"  # can leave to answer on any IP
+
+# Mod Variables
+
+# If you are using or want to use Alloc's Server Fixes,
+# uncomment the variable below
+# *****Note: It has happened where the core gets updated, but
+# Alloc's fixes weren't updated yet. If this happens
+# you may need to comment out or set to false temporarily
+# until Alloc's patch is updated.  Please see 7 Days To Die
+# forum for details.  Many people use this patch.
+allocsfixes=true  # set to true if you want installed, false or comment if not
 
 # http://7daystodie.gamepedia.com/Server
 fn_parms(){

BIN
NS2Combat/dependencies/libc.so.6


BIN
NS2Combat/dependencies/libm.so.6


BIN
NS2Combat/dependencies/libstdc++.so.6


+ 103 - 0
NS2Combat/ns2cserver

@@ -0,0 +1,103 @@
+#!/bin/bash
+# NS2: Combat
+# Server Management Script
+# Author: Daniel Gibbs
+# Website: http://danielgibbs.co.uk
+# Version: 210115
+
+#### Variables ####
+
+# Notification Email
+# (on|off)
+emailnotification="off"
+email="email@example.com"
+
+# Steam login
+steamuser="username"
+steampass="password"
+
+# Start Variables
+defaultmap="co_core"
+port="27015"
+maxplayers="24"
+ip="0.0.0.0"
+servername="NS2C Server"
+webadminuser="admin"
+webadminpass="admin"
+webadminport="8080"
+configpath="server1"
+modstorage="server1/Workshop"
+mods=""
+password=""
+# Add the following line to the parms if you want a private server. Ensuring
+# that the password variable above is not left empty.
+# -password \"${password}\"
+
+# http://wiki.unknownworlds.com/ns2/Dedicated_Server
+fn_parms(){
+parms="-name \"${servername}\" -port ${port} -webadmin -webdomain ${ip} -webuser ${webadminuser} -webpassword \"${webadminpass}\" -webport ${webadminport} -map ${defaultmap} -limit ${maxplayers} -config_path \"${rootdir}/${configpath}\" -modstorage \"${rootdir}/${modstorage}\" -mods \"${mods}\""
+}
+
+#### Advanced Variables ####
+
+# Steam
+appid="313900"
+
+# Server Details
+servicename="ns2c-server"
+gamename="NS2: Combat"
+engine="spark"
+
+# Directories
+rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+selfname="$(basename $0)"
+lockselfname=".${servicename}.lock"
+filesdir="${rootdir}/serverfiles"
+systemdir="${filesdir}"
+executabledir="${filesdir}/ia32"
+executable="./ns2combatserver_linux32"
+backupdir="${rootdir}/backups"
+
+# Logging
+logdays="7"
+gamelogdir="${systemdir}/logs"
+scriptlogdir="${rootdir}/log/script"
+consolelogdir="${rootdir}/log/console"
+
+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"
+
+##### Script #####
+# Do not edit
+
+fn_runfunction(){
+# Functions are downloaded and run with this function
+if [ ! -f "${rootdir}/functions/${functionfile}" ]; then
+	cd "${rootdir}"
+	if [ ! -d "functions" ]; then
+		mkdir functions
+	fi
+	cd functions
+	echo -e "loading ${functionfile}...\c"
+	wget -N --no-check-certificate /dev/null https://raw.githubusercontent.com/dgibbs64/linuxgsm/master/functions/${functionfile} 2>&1 | grep -F HTTP | cut -c45-
+	chmod +x "${functionfile}"
+	cd "${rootdir}"
+	sleep 1
+fi
+source "${rootdir}/functions/${functionfile}"
+}
+
+fn_functions(){
+# Functions are defined in fn_functions.
+functionfile="${FUNCNAME}"
+fn_runfunction
+}
+
+fn_functions
+
+getopt=$1
+fn_getopt

+ 99 - 18
functions/fn_stop

@@ -8,6 +8,27 @@
 
 local modulename="Stopping"
 
+sdtd_telnet(){
+    sdtdshutdown=$( expect -c '
+    proc abort {} {
+        puts "Timeout or EOF\n"
+        exit 1
+    }
+    spawn telnet '"${telnetip}"' '"${telnetport}"'
+    expect {
+        "password:"     { send "'"${telnetpass}"'\r" }
+        default         abort
+    }
+    expect {
+        "session."  { send "shutdown\r" }
+        default         abort
+    }
+    expect { eof }
+    puts "Completed.\n"
+    ')
+}
+
+
 fn_stop_teamspeak3(){
 fn_check_root
 fn_check_systemdir
@@ -16,12 +37,12 @@ fn_scriptlog "${servername}"
 sleep 1
 fn_check_ts3status
 if [ "${ts3status}" = "No server running (ts3server.pid is missing)" ];then
-	fn_printfail "${servername} is already stopped"
-	fn_scriptlog "${servername} is already stopped"
+    fn_printfail "${servername} is already stopped"
+    fn_scriptlog "${servername} is already stopped"
 else
-	${filesdir}/ts3server_startscript.sh stop inifile=${ini} > /dev/null 2>&1
-	fn_printok "${servername}"
-	fn_scriptlog "Stopped ${servername}"
+    ${filesdir}/ts3server_startscript.sh stop inifile=${ini} > /dev/null 2>&1
+    fn_printok "${servername}"
+    fn_scriptlog "Stopped ${servername}"
 fi
 # Remove lock file
 rm -f "${rootdir}/${lockselfname}"
@@ -37,23 +58,83 @@ fn_printdots "${servername}"
 fn_scriptlog "${servername}"
 sleep 1
 fn_check_tmux
-pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:")
-if [ "${pid}" == "0" ]; then
-	fn_printfail "${servername} is already stopped"
-	fn_scriptlog "${servername} is already stopped"
+
+if [ "${gamename}" == "7 Days To Die" ] ; then
+    # if game is 7 Days To Die, we need special, graceful shutdown via telnet connection.
+    # Set below variable to be called for expect to operate correctly..
+    fn_printdots "Attempting graceful shutdown via telnet"
+    fn_scriptlog "Attempting graceful shutdown via telnet"
+    sleep 1
+
+
+    telnetip=127.0.0.1
+    sdtd_telnet
+
+    # If failed using localhost will use servers ip
+    refused=$(echo -en "\n ${sdtdshutdown}"| grep "Timeout or EOF")
+    if [ -n "${refused}" ]; then
+        fn_check_ip
+        telnetip=${ip}
+        fn_printwarn "Attempting graceful shutdown via telnet: localhost failed"
+        fn_scriptlog "Warning! Attempting graceful shutdown failed using localhost"
+        sleep 5
+        echo -en "\n"
+        fn_printdots "Attempting graceful shutdown via telnet: using ${telnetip}"
+        fn_scriptlog "Attempting graceful shutdown via telnet using ${telnetip}"
+        sdtd_telnet
+        sleep 1
+    fi
+
+    refused=$(echo -en "\n ${sdtdshutdown}"| grep "Timeout or EOF")
+    completed=$(echo -en "\n ${sdtdshutdown}"| grep "Completed.")
+    if [ -n "${refused}" ]; then
+        fn_printfail "Attempting graceful shutdown via telnet"
+         fn_scriptlog "Attempting graceful shutdown failed"
+         fn_scriptlog "${refused}"
+    elif [ -n "${completed}" ]; then
+        fn_printok "Attempting graceful shutdown via telnet"
+        fn_scriptlog "Attempting graceful shutdown succeeded"
+    else
+         fn_printfail "Attempting graceful shutdown via telnet: Unknown error"
+         fn_scriptlog "Attempting graceful shutdown failed"
+         fn_scriptlog "Unknown error"
+    fi
+    sleep 1
+    echo -en "\n\n"
+    echo -en "Telnet output:"
+    echo -en "\n ${sdtdshutdown}"
+    echo -en "\n\n"
+    sleep 1
+    fn_printdots "${servername}"
+    fn_scriptlog "${servername}"
+    sleep 5
+    pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:")
+    if [ "${pid}" == "0" ]; then
+        fn_printok "${servername} is already stopped using graceful shutdown"
+        fn_scriptlog "${servername} is already stopped using graceful shutdown"
+    else
+        tmux kill-session -t ${servicename}
+        fn_printok "${servername}"
+        fn_scriptlog "Stopped ${servername}"
+    fi
+
 else
-	tmux kill-session -t ${servicename}
-	fn_printok "${servername}"
-	fn_scriptlog "Stopped ${servername}"
+    pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -Ec "^${servicename}:")
+    if [ "${pid}" == "0" ]; then
+        fn_printfail "${servername} is already stopped"
+        fn_scriptlog "${servername} is already stopped"
+    else
+        tmux kill-session -t ${servicename}
+        fn_printok "${servername}"
+        fn_scriptlog "Stopped ${servername}"
+    fi
 fi
-# Remove lock file
-rm -f "${rootdir}/${lockselfname}"
-sleep 1
-echo -en "\n"
+    sleep 1
+    echo -en "\n"
 }
 
 if [ "${gamename}" == "Teamspeak 3" ]; then
-	fn_stop_teamspeak3
+    fn_stop_teamspeak3
 else
-	fn_stop_tmux
+    fn_stop_tmux
 fi

+ 4 - 5
functions/fn_validate

@@ -26,14 +26,13 @@ cd "steamcmd"
 fn_scriptlog "Checking complete"
 }
 
-
 fn_check_root
 fn_check_systemdir
 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
 if [ "${tmuxwc}" -eq 1 ]; then
-	fn_stop
-	fn_validation
-	fn_start
+    fn_stop
+    fn_validation
+    fn_start
 else
-	fn_validation
+    fn_validation
 fi