Update for new AWS image style

Support old minecraft versions
This commit is contained in:
2020-12-07 19:50:30 +00:00
parent 1b6ec8682f
commit 9e0b04afdc
6 changed files with 36 additions and 12 deletions

View File

@@ -3,10 +3,14 @@
# If exists tmux session
# If Responds to queries
SERVER_DIR='/home/ubuntu/minecraft/servers/kincls'
TMUX_NAME='minecraft kincls server'
SERVER_DIR='/home/ubuntu/minecraft'
TMUX_NAME='minecraft server'
LIVE_UNTIL="/home/ubuntu/minecraft/live_until.txt"
json_has() {
cat - | python3 -c "import sys, json; sys.exit(0 if '$1' in json.load(sys.stdin) else 1)"
}
json_parse() {
cat - | python3 -c "import sys, json; print(json.load(sys.stdin)['$1'])"
}
@@ -51,6 +55,16 @@ server_responsive() {
silent_exitcode /usr/local/bin/mcstatus localhost ping
}
get_nplayers() {
json="$(/usr/local/bin/mcstatus localhost json)"
if `echo $json | json_has player_count`; then
echo $json | json_parse player_count
return
fi
status="$(/usr/local/bin/mcstatus localhost status)"
echo "$status" | grep players: | sed 's/.*\([0-9]\+\)\/.*/\1/g'
}
n_logins="$(w -h | wc -l)"
echo "$(date) [$n_logins logins]"
@@ -67,7 +81,7 @@ else
fi
if server_responsive; then
n_players=$(/usr/local/bin/mcstatus localhost json | json_parse player_count)
n_players=$(get_nplayers)
echo "Server responsive. $n_players players online"
if [ "$n_players" -gt 0 ]; then
# Keep alive as players are online