1
0
Fork 0
mirror of https://github.com/aclist/dztui.git synced 2024-12-28 21:32:36 +01:00

Update helper files

This commit is contained in:
aclist 2022-09-14 13:22:14 +09:00
parent 88df4de3d7
commit 2b3e393b0d
3 changed files with 63 additions and 10 deletions

View file

@ -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

41
helpers/latlon.c Normal file
View file

@ -0,0 +1,41 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#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;
}

2
helpers/sums.md5 Normal file
View file

@ -0,0 +1,2 @@
27bf17692c785b13ba03109f0b3f9502 ips.csv
17773960242d92331ac4203daf5ca9e2 latlon