From 2b3e393b0d5bbb0b17258984552823372a2c5e43 Mon Sep 17 00:00:00 2001 From: aclist Date: Wed, 14 Sep 2022 13:22:14 +0900 Subject: [PATCH] Update helper files --- dzgui.sh | 30 ++++++++++++++++++++---------- helpers/latlon.c | 41 +++++++++++++++++++++++++++++++++++++++++ helpers/sums.md5 | 2 ++ 3 files changed, 63 insertions(+), 10 deletions(-) create mode 100644 helpers/latlon.c create mode 100644 helpers/sums.md5 diff --git a/dzgui.sh b/dzgui.sh index 536162c..1db777e 100755 --- a/dzgui.sh +++ b/dzgui.sh @@ -21,9 +21,12 @@ news_url="https://raw.githubusercontent.com/aclist/dztui/testing/news" freedesktop_path="$HOME/.local/share/applications" sd_install_path="$HOME/.local/share/dzgui" helpers_path="$sd_install_path/helpers" -geo_file="$HOME/.local/share/dzgui/helpers/ips.csv" -km_helper="$HOME/.local/share/dzgui/helpers/lat.py" -km_helper_url="https://raw.githubusercontent.com/aclist/dztui/testing/helpers/lat.py" +geo_file="$sd_install_path/ips.csv" +km_helper="$sd_install_path/latlon" +sums_path="$sd_install_path/sums.md5" +km_helper_url="https://github.com/aclist/dztui/releases/download/browser/latlon" +db_file="https://github.com/aclist/dztui/releases/download/browser/ips.csv.gz" +sums_url="" update_last_seen(){ mv $config_file ${config_path}dztuirc.old @@ -861,17 +864,20 @@ pagination(){ printf "Players online: %s" "$players_online" } check_geo_file(){ - local db_file="https://github.com/aclist/dztui/releases/download/browser/ips.csv.gz" local gzip="$helpers_path/ips.csv.gz" - if [[ ! -f $geo_file ]]; then + curl -Ls "$sums_url" > "$sums_path" + md5sum -c sums.md5 2>/dev/null 1>&2 + local res=$? + if [[ $res -eq 1 ]]; then run(){ mkdir -p "$helpers_path" - echo "# Fetching geolocation DB" + echo "# Fetching new geolocation DB" curl -Ls "$db_file" > "$gzip" echo "# Extracting coordinates" gunzip "$gzip" echo "# Preparing helper file" curl -Ls "$km_helper_url" > "$km_helper" + chmod +x $km_helper echo "100" } run > >(zenity --pulsate --progress --auto-close --width=500 2>/dev/null) @@ -900,12 +906,12 @@ get_dist(){ local dist="Unknown" echo "$dist" else - local dist=$(python "$km_helper" "$local_lat" "$local_lon" "$remote_lat" "$remote_lon") - printf "%05d %s" "$dist" "km" + local dist=$($km_helper "$local_lat" "$local_lon" "$remote_lat" "$remote_lon") + printf "%05.0f %s" "$dist" "km" fi } prepare_filters(){ - echo "# Preparing list" + echo "# Filtering list" [[ ! "$sels" =~ "Full" ]] && { exclude_full; disabled+=("Full") ; } [[ ! "$sels" =~ "Empty" ]] && { exclude_empty; disabled+=("Empty") ; } [[ ! "$sels" =~ "Daytime" ]] && { exclude_daytime; disabled+=("Daytime") ; } @@ -968,7 +974,11 @@ server_browser(){ [[ -z $sels ]] && return [[ $ret -eq 97 ]] && return #TODO: some error handling here - curl -Ls "$url" > $file + fetch(){ + echo "# Getting server list" + curl -Ls "$url" > $file + } + fetch > >(zenity --pulsate --progress --auto-close --width=500 2>/dev/null) response=$(< $file jq -r '.response.servers') local sel=$(munge_servers) if [[ -z $sel ]]; then diff --git a/helpers/latlon.c b/helpers/latlon.c new file mode 100644 index 0000000..8742102 --- /dev/null +++ b/helpers/latlon.c @@ -0,0 +1,41 @@ +#include +#include +#include + +#define R 6371 +#define TO_RAD (3.1415926536 / 180) +double dist(double th1, double ph1, double th2, double ph2) +{ + double dx, dy, dz; + ph1 -= ph2; + ph1 *= TO_RAD, th1 *= TO_RAD, th2 *= TO_RAD; + + dz = sin(th1) - sin(th2); + dx = cos(ph1) * cos(th1) - cos(th2); + dy = sin(ph1) * cos(th1); + return asin(sqrt(dx * dx + dy * dy + dz * dz) / 2) * 2 * R; +} + +int main(int argc, const char * argv[]) +{ + if(argc < 5 || argc > 5){ + return 1; + } + float coords[4]; + for(int i=1;i<5;i++){ + if(atof(argv[i]) == 0){ + return 1; + } + coords[i] = atof(argv[i]); + } + + float coord1 = atof(argv[1]); + float coord2 = atof(argv[2]); + float coord3 = atof(argv[3]); + float coord4 = atof(argv[4]); + + double d = dist(coords[1], coords[2], coords[3], coords[4]); + printf("%.1f\n", d); + + return 0; +} diff --git a/helpers/sums.md5 b/helpers/sums.md5 new file mode 100644 index 0000000..ab94395 --- /dev/null +++ b/helpers/sums.md5 @@ -0,0 +1,2 @@ +27bf17692c785b13ba03109f0b3f9502 ips.csv +17773960242d92331ac4203daf5ca9e2 latlon