summarylogtreecommitdiffstats
path: root/minecraftd.sh
diff options
context:
space:
mode:
Diffstat (limited to 'minecraftd.sh')
-rwxr-xr-xminecraftd.sh6
1 files changed, 4 insertions, 2 deletions
diff --git a/minecraftd.sh b/minecraftd.sh
index cd64a693f526..3563ce7f944a 100755
--- a/minecraftd.sh
+++ b/minecraftd.sh
@@ -82,14 +82,16 @@ game_command() {
# Check whether there are player on the server through list
is_player_online() {
response="$(sleep_time=0.6 return_stdout=true game_command list)"
+ # Delete leading line and free response string from fancy characters
+ response="$(echo "${response}" | sed -r -e '$!d' -e 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?[JKmsuG]//g')"
# 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 easily be retrieved.
# Otherwiese check the first digit after the last occurrence of "There are". If it is 0 then there
# are no players on the server. Should this test fail as well. Assume that a player is online.
- if [[ $(echo "${response}" | grep ":" | sed -r -e '$!d' -e 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?[JKmsuG]//g' -e 's/.*\: //' | tr -d '\n' | wc -c) -le 1 ]]; then
+ if [[ $(echo "${response}" | grep ":" | sed -e 's/.*\: //' | tr -d '\n' | wc -c) -le 1 ]]; then
# No player is online
return 0
- elif [[ $(echo "${response}" | grep "There are" | sed -r -e '$!d' -e 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?[JKmsuG]//g' -e 's/.*\: //' -e 's/^([^.]+).*$/\1/; s/^[^0-9]*([0-9]+).*$/\1/' | tr -d '\n') -eq 0 ]]; then
+ elif [[ "x$(echo "${response}" | grep "There are" | sed -r -e 's/.*\: //' -e 's/^([^.]+).*$/\1/; s/^[^0-9]*([0-9]+).*$/\1/' | tr -d '\n')" == "x0" ]]; then
# No player is online
return 0
else