4
0

check_players_online.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. #!/bin/bash
  2. # LinuxGSM check_players_online.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Queries the server with gamedig and sets ${playersonline} to the
  7. # current player count when players are connected (empty otherwise).
  8. # Used by the stoponlyifnoplayers feature to postpone stop/restart.
  9. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  10. playersonline=""
  11. if [ "${stoponlyifnoplayers}" == "on" ]; then
  12. if [ "${querymode}" == "2" ] || [ "${querymode}" == "3" ]; then
  13. querysucceeded="0"
  14. for queryip in "${queryips[@]}"; do
  15. query_gamedig.sh
  16. if [ "${querystatus}" == "0" ]; then
  17. querysucceeded="1"
  18. if [ -n "${gdplayers}" ] && [ "${gdplayers}" -ne 0 ]; then
  19. playersonline="${gdplayers}"
  20. break
  21. fi
  22. fi
  23. done
  24. # The query failed for every configured IP, so the player count could not be
  25. # determined. Fail open (proceed as if empty) rather than block the server
  26. # indefinitely, but warn clearly since the safety check did not actually run.
  27. if [ "${querysucceeded}" == "0" ]; then
  28. fn_print_warn_nl "Unable to determine player count: stoponlyifnoplayers check skipped"
  29. fn_script_log_warn "Unable to determine player count via gamedig: stoponlyifnoplayers check skipped"
  30. fi
  31. fi
  32. fi