From 770f969afc3bd8b20ad73ea4a509f92bf1166fd4 Mon Sep 17 00:00:00 2001 From: DUDU54 <14166148+DUDU54@users.noreply.github.com> Date: Sat, 20 Feb 2021 14:04:49 +0100 Subject: [PATCH] add send command to console (#2350) * add send command Added a function to send command directly to the console If the user don't provide a command right after the "send" argument, he will be prompt to enter a command * updates to messages converted spaces to tabs * minor * minor * messages only display if manual entry * updated description * send will not show if not supported * corrected if changed to ! * ui updates * ui changes * Update core_getopt.sh Co-authored-by: Daniel Gibbs Co-authored-by: Frisasky --- lgsm/functions/command_send.sh | 38 ++++++++++++++++++++++++++++++++ lgsm/functions/core_functions.sh | 5 +++++ lgsm/functions/core_getopt.sh | 6 +++++ lgsm/functions/core_messages.sh | 14 ++++++++++++ linuxgsm.sh | 1 + 5 files changed, 64 insertions(+) create mode 100644 lgsm/functions/command_send.sh diff --git a/lgsm/functions/command_send.sh b/lgsm/functions/command_send.sh new file mode 100644 index 000000000..959c331a2 --- /dev/null +++ b/lgsm/functions/command_send.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# LinuxGSM command_send.sh function +# Author: Duval Lucas +# Website: https://linuxgsm.com +# Description: Send command to the server tmux console. + +local commandname="SEND" +local commandaction="Send" +local function_selfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" + +check.sh +if [ -z "${userinput2}" ]; then + fn_print_header + fn_print_information_nl "Send allows a command to be sent to the console." +fi + +check_status.sh +if [ "${status}" != "0" ]; then + if [ -n "${userinput2}" ]; then + command_to_send="${userinput2}" + else + echo "" + command_to_send=$( fn_prompt_message "send: " ) + fi + fn_print_dots "Sending command to console: \"${command_to_send}\"" + tmux send-keys -t "${servicename}" "${command_to_send}" ENTER + fn_print_ok_nl "Sending command to console: \"${command_to_send}\"" + fn_script_log_pass "Command \"${command_to_send}\" 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..f1701897d 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}" +fn_fetch_function +} + # Checks check.sh(){ diff --git a/lgsm/functions/core_getopt.sh b/lgsm/functions/core_getopt.sh index b0986024a..bf22b260f 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 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." ) @@ -85,6 +86,11 @@ currentopt+=( "${cmd_backup[@]}" ) # Console & Debug currentopt+=( "${cmd_console[@]}" "${cmd_debug[@]}" ) +# Exclude game servers that dont support send +if [ "${shortname}" != "rust" ]||[ "${shortname}" != "hw" ]||[ "${shortname}" != "ark" ]||[ "${shortname}" != "ts3" ]; 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..a7f12a362 100755 --- a/lgsm/functions/core_messages.sh +++ b/lgsm/functions/core_messages.sh @@ -359,6 +359,20 @@ fn_prompt_yn(){ done } +# Prompt for message +fn_prompt_message(){ + local prompt="$1" + + while true; do + read -e -p "${prompt}" -r answer + if fn_prompt_yn "\"${answer}\", is this correct ?" 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