Skip to content

Commit 0ca6c8a

Browse files
dgibbs640DUDDU
andauthored
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 <[email protected]> Co-authored-by: DUDU54 <[email protected]>
1 parent 8db3b6d commit 0ca6c8a

File tree

6 files changed

+68
-2
lines changed

6 files changed

+68
-2
lines changed

lgsm/functions/check_system_requirements.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ if [ "${ramrequirementmb}" ]; then
4949
fn_print_dots "Check RAM"
5050
# Warn the user.
5151
fn_print_warn_nl "Check RAM: ${ramrequirementgb}G required, ${physmemtotal} available"
52-
echo " * ${gamename} server may fail to run or experience poor performance."
52+
echo "* ${gamename} server may fail to run or experience poor performance."
5353
fn_sleep_time
5454
fi
5555
fi

lgsm/functions/command_send.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
# LinuxGSM command_send.sh module
3+
# Author: Daniel Gibbs
4+
# Contributors: http://linuxgsm.com/contrib
5+
# Website: https://linuxgsm.com
6+
# Description: Send command to the server tmux console.
7+
8+
commandname="SEND"
9+
commandaction="Send"
10+
functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
11+
fn_firstcommand_set
12+
13+
check.sh
14+
if [ -z "${userinput2}" ]; then
15+
fn_print_header
16+
fn_print_information_nl "Send a command to the console."
17+
fi
18+
19+
check_status.sh
20+
if [ "${status}" != "0" ]; then
21+
if [ -n "${userinput2}" ]; then
22+
commandtosend="${userinput2}"
23+
else
24+
echo ""
25+
commandtosend=$( fn_prompt_message "send: " )
26+
fi
27+
echo ""
28+
fn_print_dots "Sending command to console: \"${commandtosend}\""
29+
tmux send-keys -t "${servicename}" "${commandtosend}" ENTER
30+
fn_print_ok_nl "Sending command to console: \"${commandtosend}\""
31+
fn_script_log_pass "Command \"${commandtosend}\" sent to console"
32+
else
33+
fn_print_error_nl "Server not running"
34+
fn_script_log_error "Failed to access: Server not running"
35+
if fn_prompt_yn "Do you want to start the server?" Y; then
36+
exitbypass=1
37+
command_start.sh
38+
fi
39+
fi
40+
41+
core_exit.sh

lgsm/functions/core_functions.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ functionfile="${FUNCNAME[0]}"
180180
fn_fetch_function
181181
}
182182

183+
command_send.sh(){
184+
functionfile="${FUNCNAME[0]}"
185+
fn_fetch_function
186+
}
187+
183188
# Checks
184189

185190
check.sh(){

lgsm/functions/core_getopt.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ cmd_test_alert=( "ta;test-alert" "command_test_alert.sh" "Send a test alert." )
2323
cmd_monitor=( "m;monitor" "command_monitor.sh" "Check server status and restart if crashed." )
2424
cmd_skeleton=( "sk;skeleton" "command_skeleton.sh" "Create a skeleton directory." )
2525
cmd_donate=( "do;donate" "command_donate.sh" "Donation options." )
26+
cmd_send=( "sd;send" "command_send.sh" "Send command to game server console." )
2627
# Console servers only.
2728
cmd_console=( "c;console" "command_console.sh" "Access server console." )
2829
cmd_debug=( "d;debug" "command_debug.sh" "Start server directly in your terminal." )
@@ -82,9 +83,14 @@ fi
8283
# Backup.
8384
currentopt+=( "${cmd_backup[@]}" )
8485

85-
# Console & Debug
86+
# Console & Debug.
8687
currentopt+=( "${cmd_console[@]}" "${cmd_debug[@]}" )
8788

89+
# Console send.
90+
if [ "${consoleinteract}" == "yes" ]; then
91+
currentopt+=( "${cmd_send[@]}" )
92+
fi
93+
8894
## Game server exclusive commands.
8995

9096
# FastDL command.

lgsm/functions/core_messages.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,19 @@ fn_prompt_yn(){
359359
done
360360
}
361361

362+
# Prompt for message
363+
fn_prompt_message(){
364+
while true; do
365+
unset prompt
366+
local prompt="$1"
367+
read -e -p "${prompt}" -r answer
368+
if fn_prompt_yn "Continue" Y; then
369+
break;
370+
fi
371+
done
372+
echo "${answer}"
373+
}
374+
362375
# On-Screen End of Line
363376
##################################
364377

linuxgsm.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ configdir="${lgsmdir}/config-lgsm"
4242
configdirserver="${configdir}/${gameservername}"
4343
configdirdefault="${lgsmdir}/config-default"
4444
userinput="${1}"
45+
userinput2="${2}"
4546

4647
## GitHub Branch Select
4748
# Allows for the use of different function files

0 commit comments

Comments
 (0)