From 0ca6c8a0fb7b6038d1f40a016e01722f5aee7cbb Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 20 Feb 2021 22:33:15 +0000 Subject: [PATCH] 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 Co-authored-by: DUDU54 <14166148+DUDU54@users.noreply.github.com> --- lgsm/functions/check_system_requirements.sh | 2 +- lgsm/functions/command_send.sh | 41 +++++++++++++++++++++ lgsm/functions/core_functions.sh | 5 +++ lgsm/functions/core_getopt.sh | 8 +++- lgsm/functions/core_messages.sh | 13 +++++++ linuxgsm.sh | 1 + 6 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 lgsm/functions/command_send.sh diff --git a/lgsm/functions/check_system_requirements.sh b/lgsm/functions/check_system_requirements.sh index 758d558a6..2922361f0 100755 --- a/lgsm/functions/check_system_requirements.sh +++ b/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 diff --git a/lgsm/functions/command_send.sh b/lgsm/functions/command_send.sh new file mode 100644 index 000000000..4b653c0be --- /dev/null +++ b/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 diff --git a/lgsm/functions/core_functions.sh b/lgsm/functions/core_functions.sh index 3f598f2f7..be613a45a 100755 --- a/lgsm/functions/core_functions.sh +++ b/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(){ diff --git a/lgsm/functions/core_getopt.sh b/lgsm/functions/core_getopt.sh index b0986024a..904bad37d 100755 --- a/lgsm/functions/core_getopt.sh +++ b/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. diff --git a/lgsm/functions/core_messages.sh b/lgsm/functions/core_messages.sh index 388a64a9d..a56ade188 100755 --- a/lgsm/functions/core_messages.sh +++ b/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 ################################## diff --git a/linuxgsm.sh b/linuxgsm.sh index 5dbe611df..059ac9da2 100755 --- a/linuxgsm.sh +++ b/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