Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add send command to console #2350

38 changes: 38 additions & 0 deletions lgsm/functions/command_send.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions lgsm/functions/core_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ functionfile="${FUNCNAME}"
fn_fetch_function
}

command_send.sh(){
functionfile="${FUNCNAME}"
fn_fetch_function
}

# Checks

check.sh(){
Expand Down
6 changes: 6 additions & 0 deletions lgsm/functions/core_getopt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ cmd_update_linuxgsm=( "ul;update-lgsm;uf;update-functions" "command_update_linux
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_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." )
Expand Down Expand Up @@ -82,6 +83,11 @@ if [ "${shortname}" != "ts3" ]; then
currentopt+=( "${cmd_console[@]}" "${cmd_debug[@]}" )
fi

# 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.
Expand Down
14 changes: 14 additions & 0 deletions lgsm/functions/core_messages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,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
##################################

Expand Down
1 change: 1 addition & 0 deletions linuxgsm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down