aboutsummarylogtreecommitdiffstats
path: root/minecraftd.sh
diff options
context:
space:
mode:
authorGordian Edenhofer2016-05-20 11:53:30 +0200
committerGordian Edenhofer2016-05-20 11:53:30 +0200
commit9fafea9acfad5efe2525d3a1171ae0f7d38c0141 (patch)
treeb2b31673c1f0af447ab48cb6cf6430540ad6aaae /minecraftd.sh
parent53bb3e07646e83182bac85584c0ea9a335139e32 (diff)
downloadaur-9fafea9acfad5efe2525d3a1171ae0f7d38c0141.tar.gz
upgpkg: (minecraft-server|spigot) 1.9.4-2
Pause player checking when in idle_server mode as long as someone is connected to the server console. Not only does it make sense for any admin which wants to monitor the console, it also removes annoying list invocations from the console while e.g. typing in it. upgpkg: minecraft-server 1.9.4-2 upgpkg: spigot 1.9.4-2
Diffstat (limited to 'minecraftd.sh')
-rwxr-xr-xminecraftd.sh15
1 files changed, 9 insertions, 6 deletions
diff --git a/minecraftd.sh b/minecraftd.sh
index e0a07aac4d43..3013eed6522c 100755
--- a/minecraftd.sh
+++ b/minecraftd.sh
@@ -78,16 +78,19 @@ idle_server_daemon() {
no_player=0
while true; do
+ echo -e "no_players: ${no_player}s\tcheck_player_time: ${CHECK_PLAYER_TIME}s\tidle_if_time: ${IDLE_IF_TIME}s"
# Retry in ${CHECK_PLAYER_TIME} seconds
sleep ${CHECK_PLAYER_TIME}
screen -S "${SESSION_NAME}" -Q select . > /dev/null
if [[ $? -eq 0 ]]; then
# Game server is up and running
- screen -S "${SESSION_NAME}" -X stuff "`printf \"list\r\"`"
+ if [[ "$(screen -S "${SESSION_NAME}" -ls | sed -n 2p | awk '{ print $2 }')" == "(Attached)" ]]; then
+ # An administrator is connected to the console, pause player checking
+ echo "An admin is connected to the console. Pause player checking."
# The list command prints a line containing the usernames after the last occurrence of ": "
# and since playernames may not contain this string the clean player-list can be easily retrieved.
- if [[ $? -eq 0 && -z $(sleep 0.6; tail -n 1 "${LOGPATH}/latest.log" | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' | sed 's/.*\: //' | tr -d '\n') ]]; then
+ elif [[ -z $(SUDO_CMD="" game_command list; sleep 0.6; tail -n 1 "${LOGPATH}/latest.log" | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' | sed 's/.*\: //' | tr -d '\n') ]]; then
# No player was seen on the server through list
no_player=$(( no_player + CHECK_PLAYER_TIME ))
# Stop the game server if no player was active for at least ${IDLE_IF_TIME}
@@ -103,7 +106,7 @@ idle_server_daemon() {
# Reset timer and give the player 300 seconds to connect after pinging
no_player=$(( IDLE_IF_TIME - 300 ))
# Game server is down, listen on port ${GAME_PORT} for incoming connections
- echo "Netcat is listening on port ${GAME_PORT} for incoming connections..."
+ echo -n "Netcat: "
${NETCAT_CMD} -v -l -p ${GAME_PORT}
[[ $? -eq 0 ]] && echo "Netcat caught an connection. The server is coming up again..."
IDLE_SERVER="false" ${myname} start
@@ -116,7 +119,7 @@ idle_server_daemon() {
# Reset timer and give the player 300 seconds to connect after pinging
no_player=$(( IDLE_IF_TIME - 300 ))
# Game server is down, listen on port ${GAME_PORT} for incoming connections
- echo "Netcat is listening on port ${GAME_PORT} for incoming connections..."
+ echo -n "Netcat: "
${NETCAT_CMD} -v -l -p ${GAME_PORT}
[[ $? -eq 0 ]] && echo "Netcat caught an connection. The server is coming up again..."
IDLE_SERVER="false" ${myname} start
@@ -186,10 +189,10 @@ server_stop() {
${SUDO_CMD} screen -S "${SESSION_NAME}" -Q select . > /dev/null
if [[ $? -eq 0 ]]; then
# Game server is up and running, gracefully stop the server when there are still active players
- ${SUDO_CMD} screen -S "${SESSION_NAME}" -X stuff "`printf \"list\r\"`"
+
# The list command prints a line containing the usernames after the last occurrence of ": "
# and since playernames may not contain this string the clean player-list can be easily retrieved.
- if [[ $? -eq 0 && -z $(sleep 0.6; tail -n 1 "${LOGPATH}/latest.log" | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' | sed 's/.*\: //' | tr -d '\n') ]]; then
+ if [[ -z $(game_command list; sleep 0.6; tail -n 1 "${LOGPATH}/latest.log" | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' | sed 's/.*\: //' | tr -d '\n') ]]; then
# No player was seen on the server through list
echo -en "Server is going down..."
game_command stop