Bladeren bron

feat(send): new command send (#3288)

The send command will appear for any game servers that support sending commands within the console i.e interactive console.

Note: This is not rcon support

Co-authored-by: Daniel Gibbs <me@danielgibbs.co.uk>
Co-authored-by: DUDU54 <14166148+DUDU54@users.noreply.github.com>
Daniel Gibbs 5 jaren geleden
bovenliggende
commit
0ca6c8a0fb

+ 1 - 1
lgsm/functions/check_system_requirements.sh

@@ -49,7 +49,7 @@ if [ "${ramrequirementmb}" ]; then
 		fn_print_dots "Check RAM"
 		# Warn the user.
 		fn_print_warn_nl "Check RAM: ${ramrequirementgb}G required, ${physmemtotal} available"
-		echo  "	* ${gamename} server may fail to run or experience poor performance."
+		echo "* ${gamename} server may fail to run or experience poor performance."
 		fn_sleep_time
 	fi
 fi

+ 41 - 0
lgsm/functions/command_send.sh

@@ -0,0 +1,41 @@
+#!/bin/bash
+# LinuxGSM command_send.sh module
+# Author: Daniel Gibbs
+# Contributors: http://linuxgsm.com/contrib
+# Website: https://linuxgsm.com
+# Description: Send command to the server tmux console.
+
+commandname="SEND"
+commandaction="Send"
+functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
+fn_firstcommand_set
+
+check.sh
+if [ -z "${userinput2}" ]; then
+	fn_print_header
+	fn_print_information_nl "Send a command to the console."
+fi
+
+check_status.sh
+if [ "${status}" != "0" ]; then
+	if [ -n "${userinput2}" ]; then
+		commandtosend="${userinput2}"
+	else
+		echo ""
+		commandtosend=$( fn_prompt_message "send: " )
+	fi
+	echo ""
+	fn_print_dots "Sending command to console: \"${commandtosend}\""
+	tmux send-keys -t "${servicename}" "${commandtosend}" ENTER
+	fn_print_ok_nl "Sending command to console: \"${commandtosend}\""
+	fn_script_log_pass "Command \"${commandtosend}\" sent to console"
+else
+	fn_print_error_nl "Server not running"
+	fn_script_log_error "Failed to access: Server not running"
+	if fn_prompt_yn "Do you want to start the server?" Y; then
+		exitbypass=1
+		command_start.sh
+	fi
+fi
+
+core_exit.sh

+ 5 - 0
lgsm/functions/core_functions.sh

@@ -180,6 +180,11 @@ functionfile="${FUNCNAME[0]}"
 fn_fetch_function
 }
 
+command_send.sh(){
+functionfile="${FUNCNAME[0]}"
+fn_fetch_function
+}
+
 # Checks
 
 check.sh(){

+ 7 - 1
lgsm/functions/core_getopt.sh

@@ -23,6 +23,7 @@ cmd_test_alert=( "ta;test-alert" "command_test_alert.sh" "Send a test alert." )
 cmd_monitor=( "m;monitor" "command_monitor.sh" "Check server status and restart if crashed." )
 cmd_skeleton=( "sk;skeleton" "command_skeleton.sh" "Create a skeleton directory." )
 cmd_donate=( "do;donate" "command_donate.sh" "Donation options." )
+cmd_send=( "sd;send" "command_send.sh" "Send command to game server console." )
 # Console servers only.
 cmd_console=( "c;console" "command_console.sh" "Access server console." )
 cmd_debug=( "d;debug" "command_debug.sh" "Start server directly in your terminal." )
@@ -82,9 +83,14 @@ fi
 # Backup.
 currentopt+=( "${cmd_backup[@]}" )
 
-# Console & Debug
+# Console & Debug.
 currentopt+=( "${cmd_console[@]}" "${cmd_debug[@]}" )
 
+# Console send.
+if [ "${consoleinteract}" == "yes" ]; then
+	currentopt+=( "${cmd_send[@]}" )
+fi
+
 ## Game server exclusive commands.
 
 # FastDL command.

+ 13 - 0
lgsm/functions/core_messages.sh

@@ -359,6 +359,19 @@ fn_prompt_yn(){
 	done
 }
 
+# Prompt for message
+fn_prompt_message(){
+	while true; do
+		unset prompt
+		local prompt="$1"
+		read -e -p  "${prompt}" -r answer
+		if fn_prompt_yn "Continue" Y; then
+			break;
+		fi
+	done
+	echo "${answer}"
+}
+
 # On-Screen End of Line
 ##################################
 

+ 1 - 0
linuxgsm.sh

@@ -42,6 +42,7 @@ configdir="${lgsmdir}/config-lgsm"
 configdirserver="${configdir}/${gameservername}"
 configdirdefault="${lgsmdir}/config-default"
 userinput="${1}"
+userinput2="${2}"
 
 ## GitHub Branch Select
 # Allows for the use of different function files