From 3e1170ffd8adfb1da72d95c3e11feb46ddf88a31 Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Fri, 13 Sep 2024 11:42:47 +0900 Subject: [PATCH] fix: fallback logic for network traversal (#128) --- CHANGELOG.md | 6 +++++- dzgui.sh | 4 ++-- helpers/funcs | 38 +++++++++++++++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ca8908..c62e093 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,12 @@ # Changelog +## [5.4.1-beta.2] 2024-09-12 +### Fixed +- Use fallback logic for modlist queries when user traverses networks + ## [5.4.1-beta.2] 2024-09-10 ### Fixed -- Checkbox toggle signal handling control flow +- Fix signal handling control flow for checkbox toggles ## [5.4.1-beta.1] 2024-09-10 ### Added diff --git a/dzgui.sh b/dzgui.sh index e8ae0de..420b769 100755 --- a/dzgui.sh +++ b/dzgui.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -o pipefail -version=5.4.1-beta.1 +version=5.4.1-beta.3 #CONSTANTS aid=221100 @@ -569,7 +569,7 @@ fetch_helpers_by_sum(){ ["ui.py"]="9cac4d3b87ef292e7d30b25ca86cc438" ["query_v2.py"]="55d339ba02512ac69de288eb3be41067" ["vdf2json.py"]="2f49f6f5d3af919bebaab2e9c220f397" - ["funcs"]="b73289e0aa71a91da539c28707a6405c" + ["funcs"]="4a06a823b6240c518687d2a8ec20e914" ["lan"]="c62e84ddd1457b71a85ad21da662b9af" ) local author="aclist" diff --git a/helpers/funcs b/helpers/funcs index 59bf84e..16030fd 100755 --- a/helpers/funcs +++ b/helpers/funcs @@ -285,7 +285,15 @@ a2s(){ local qport="$2" local mode="$3" logger INFO "Querying '$ip:$qport' with mode '$mode'" - python3 "$query_helper" "$ip" "$qport" "$mode" + local res + res=$(python3 "$query_helper" "$ip" "$qport" "$mode") + if [[ $? -eq 1 ]]; then + res=$(try_fallback "$ip" "$qport" "$mode") + if [[ $? -eq 1 ]]; then + return 1 + fi + fi + printf "%s\n" "$res" } is_in_favs(){ shift @@ -1064,6 +1072,34 @@ update_symlinks(){ legacy_symlinks symlinks } +try_fallback(){ + local ip="$1" + local qport="$2" + local mode="$3" + if [[ $mode != "rules" ]] && [[ $mode != "names" ]]; then + return 1 + fi + [[ -z $api_key ]] && return 1 + local res=$(curl -s "$bm_api" -H "Authorization: Bearer "$api_key"" \ + -G -d "filter[game]=$game" \ + -d "filter[search]=%22${ip}:${qport}%22") + [[ -z $res ]] && return 1 + local len=$(<<< "$res" jq '.data|length') + [[ $len -eq 0 ]] && return 1 + local record=$(<<< "$res" jq -r ' + .data[].attributes + |select(.status != "removed").details') + case "$mode" in + "rules") + <<< "$record" jq '.modIds[]' + ;; + "names") + <<< "$record" jq ' + [.modNames, .modIds] as [$n, $i] + | {names: $n, ids: $i}' + ;; + esac +} try_connect(){ local record="$1" local ip=$(<<< $record awk -F: '{print $1}')