From 9e77ca2dd15b64437b94fcdeaacba47613c218e2 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 27 Apr 2022 00:52:38 +0200 Subject: [PATCH] refactor: move steammaster check to info_game (#3821) --- lgsm/functions/info_distro.sh | 55 --------------------------------- lgsm/functions/info_game.sh | 57 +++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 55 deletions(-) diff --git a/lgsm/functions/info_distro.sh b/lgsm/functions/info_distro.sh index 148e2df48..f747b0d1b 100755 --- a/lgsm/functions/info_distro.sh +++ b/lgsm/functions/info_distro.sh @@ -267,61 +267,6 @@ fi netint=$(${ipcommand} -o addr | grep "${ip}" | awk '{print $2}') netlink=$(${ethtoolcommand} "${netint}" 2>/dev/null| grep Speed | awk '{print $2}') -# External IP address -if [ -z "${extip}" ]; then - extip="$(curl --connect-timeout 10 -s https://api.ipify.org 2>/dev/null)" - exitcode=$? - # Should ifconfig.co return an error will use last known IP. - if [ ${exitcode} -eq 0 ]; then - if [[ "${extip}" != *"DOCTYPE"* ]]; then - echo -e "${extip}" > "${tmpdir}/extip.txt" - else - if [ -f "${tmpdir}/extip.txt" ]; then - extip="$(cat "${tmpdir}/extip.txt")" - else - fn_print_error_nl "Unable to get external IP" - fi - fi - else - if [ -f "${tmpdir}/extip.txt" ]; then - extip="$(cat "${tmpdir}/extip.txt")" - else - fn_print_error_nl "Unable to get external IP" - fi - fi -fi - -# Alert IP address -if [ "${displayip}" ]; then - alertip="${displayip}" -elif [ "${extip}" ]; then - alertip="${extip}" -else - alertip="${ip}" -fi - -# Steam Master Server - checks if detected by master server. -if [ -z "${displaymasterserver}" ]; then - if [ "$(command -v jq 2>/dev/null)" ]; then - if [ "${ip}" ]&&[ "${port}" ]; then - if [ "${steammaster}" == "true" ]||[ "${commandname}" == "DEV-QUERY-RAW" ]; then - # Will query server IP addresses first. - for queryip in "${queryips[@]}"; do - masterserver="$(curl --connect-timeout 10 -m 3 -s "https://api.steampowered.com/ISteamApps/GetServersAtAddress/v0001?addr=${queryip}&format=json" | jq --arg port "${port}" --arg queryport "${queryport}" '.response.servers[] | select((.gameport == ($port|tonumber) or (.gameport == ($queryport|tonumber)))) | .addr' | wc -l 2>/dev/null)" - done - # Should that not work it will try the external IP. - if [ "${masterserver}" == "0" ]; then - masterserver="$(curl --connect-timeout 10 -m 3 -s "https://api.steampowered.com/ISteamApps/GetServersAtAddress/v0001?addr=${extip}&format=json" | jq --arg port "${port}" --arg queryport "${queryport}" '.response.servers[] | select((.gameport == ($port|tonumber) or (.gameport == ($queryport|tonumber)))) | .addr' | wc -l 2>/dev/null)" - fi - if [ "${masterserver}" == "0" ]; then - displaymasterserver="false" - else - displaymasterserver="true" - fi - fi - fi - fi -fi # Sets the SteamCMD glibc requirement if the game server requirement is less or not required. if [ "${appid}" ]; then if [ "${glibc}" = "null" ]||[ -z "${glibc}" ]||[ "$(printf '%s\n'${glibc}'\n' "2.14" | sort -V | head -n 1)" != "2.14" ]; then diff --git a/lgsm/functions/info_game.sh b/lgsm/functions/info_game.sh index b2f5b7a24..3b6910802 100644 --- a/lgsm/functions/info_game.sh +++ b/lgsm/functions/info_game.sh @@ -2441,3 +2441,60 @@ elif [ "${engine}" == "source" ]||[ "${engine}" == "goldsrc" ]; then elif [ "${engine}" == "unreal2" ]; then fn_info_game_unreal2 fi + +# External IP address +if [ -z "${extip}" ]; then + extip="$(curl --connect-timeout 10 -s https://api.ipify.org 2>/dev/null)" + exitcode=$? + # Should ifconfig.co return an error will use last known IP. + if [ ${exitcode} -eq 0 ]; then + if [[ "${extip}" != *"DOCTYPE"* ]]; then + echo -e "${extip}" > "${tmpdir}/extip.txt" + else + if [ -f "${tmpdir}/extip.txt" ]; then + extip="$(cat "${tmpdir}/extip.txt")" + else + fn_print_error_nl "Unable to get external IP" + fi + fi + else + if [ -f "${tmpdir}/extip.txt" ]; then + extip="$(cat "${tmpdir}/extip.txt")" + else + fn_print_error_nl "Unable to get external IP" + fi + fi +fi + +# Alert IP address +if [ "${displayip}" ]; then + alertip="${displayip}" +elif [ "${extip}" ]; then + alertip="${extip}" +else + alertip="${ip}" +fi + +# Steam Master Server - checks if detected by master server. +# Checked after config init, as the queryport is needed +if [ -z "${displaymasterserver}" ]; then + if [ "$(command -v jq 2>/dev/null)" ]; then + if [ "${ip}" ]&&[ "${port}" ]; then + if [ "${steammaster}" == "true" ]||[ "${commandname}" == "DEV-QUERY-RAW" ]; then + # Will query server IP addresses first. + for queryip in "${queryips[@]}"; do + masterserver="$(curl --connect-timeout 10 -m 3 -s "https://api.steampowered.com/ISteamApps/GetServersAtAddress/v0001?addr=${queryip}&format=json" | jq --arg port "${port}" --arg queryport "${queryport}" '.response.servers[] | select((.gameport == ($port|tonumber) or (.gameport == ($queryport|tonumber)))) | .addr' | wc -l 2>/dev/null)" + done + # Should that not work it will try the external IP. + if [ "${masterserver}" == "0" ]; then + masterserver="$(curl --connect-timeout 10 -m 3 -s "https://api.steampowered.com/ISteamApps/GetServersAtAddress/v0001?addr=${extip}&format=json" | jq --arg port "${port}" --arg queryport "${queryport}" '.response.servers[] | select((.gameport == ($port|tonumber) or (.gameport == ($queryport|tonumber)))) | .addr' | wc -l 2>/dev/null)" + fi + if [ "${masterserver}" == "0" ]; then + displaymasterserver="false" + else + displaymasterserver="true" + fi + fi + fi + fi +fi