mirror of
https://github.com/aclist/dztui.git
synced 2025-01-01 15:12:05 +01:00
Update helper files
This commit is contained in:
parent
88df4de3d7
commit
2b3e393b0d
3 changed files with 63 additions and 10 deletions
28
dzgui.sh
28
dzgui.sh
|
@ -21,9 +21,12 @@ news_url="https://raw.githubusercontent.com/aclist/dztui/testing/news"
|
||||||
freedesktop_path="$HOME/.local/share/applications"
|
freedesktop_path="$HOME/.local/share/applications"
|
||||||
sd_install_path="$HOME/.local/share/dzgui"
|
sd_install_path="$HOME/.local/share/dzgui"
|
||||||
helpers_path="$sd_install_path/helpers"
|
helpers_path="$sd_install_path/helpers"
|
||||||
geo_file="$HOME/.local/share/dzgui/helpers/ips.csv"
|
geo_file="$sd_install_path/ips.csv"
|
||||||
km_helper="$HOME/.local/share/dzgui/helpers/lat.py"
|
km_helper="$sd_install_path/latlon"
|
||||||
km_helper_url="https://raw.githubusercontent.com/aclist/dztui/testing/helpers/lat.py"
|
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(){
|
update_last_seen(){
|
||||||
mv $config_file ${config_path}dztuirc.old
|
mv $config_file ${config_path}dztuirc.old
|
||||||
|
@ -861,17 +864,20 @@ pagination(){
|
||||||
printf "Players online: %s" "$players_online"
|
printf "Players online: %s" "$players_online"
|
||||||
}
|
}
|
||||||
check_geo_file(){
|
check_geo_file(){
|
||||||
local db_file="https://github.com/aclist/dztui/releases/download/browser/ips.csv.gz"
|
|
||||||
local gzip="$helpers_path/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(){
|
run(){
|
||||||
mkdir -p "$helpers_path"
|
mkdir -p "$helpers_path"
|
||||||
echo "# Fetching geolocation DB"
|
echo "# Fetching new geolocation DB"
|
||||||
curl -Ls "$db_file" > "$gzip"
|
curl -Ls "$db_file" > "$gzip"
|
||||||
echo "# Extracting coordinates"
|
echo "# Extracting coordinates"
|
||||||
gunzip "$gzip"
|
gunzip "$gzip"
|
||||||
echo "# Preparing helper file"
|
echo "# Preparing helper file"
|
||||||
curl -Ls "$km_helper_url" > "$km_helper"
|
curl -Ls "$km_helper_url" > "$km_helper"
|
||||||
|
chmod +x $km_helper
|
||||||
echo "100"
|
echo "100"
|
||||||
}
|
}
|
||||||
run > >(zenity --pulsate --progress --auto-close --width=500 2>/dev/null)
|
run > >(zenity --pulsate --progress --auto-close --width=500 2>/dev/null)
|
||||||
|
@ -900,12 +906,12 @@ get_dist(){
|
||||||
local dist="Unknown"
|
local dist="Unknown"
|
||||||
echo "$dist"
|
echo "$dist"
|
||||||
else
|
else
|
||||||
local dist=$(python "$km_helper" "$local_lat" "$local_lon" "$remote_lat" "$remote_lon")
|
local dist=$($km_helper "$local_lat" "$local_lon" "$remote_lat" "$remote_lon")
|
||||||
printf "%05d %s" "$dist" "km"
|
printf "%05.0f %s" "$dist" "km"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
prepare_filters(){
|
prepare_filters(){
|
||||||
echo "# Preparing list"
|
echo "# Filtering list"
|
||||||
[[ ! "$sels" =~ "Full" ]] && { exclude_full; disabled+=("Full") ; }
|
[[ ! "$sels" =~ "Full" ]] && { exclude_full; disabled+=("Full") ; }
|
||||||
[[ ! "$sels" =~ "Empty" ]] && { exclude_empty; disabled+=("Empty") ; }
|
[[ ! "$sels" =~ "Empty" ]] && { exclude_empty; disabled+=("Empty") ; }
|
||||||
[[ ! "$sels" =~ "Daytime" ]] && { exclude_daytime; disabled+=("Daytime") ; }
|
[[ ! "$sels" =~ "Daytime" ]] && { exclude_daytime; disabled+=("Daytime") ; }
|
||||||
|
@ -968,7 +974,11 @@ server_browser(){
|
||||||
[[ -z $sels ]] && return
|
[[ -z $sels ]] && return
|
||||||
[[ $ret -eq 97 ]] && return
|
[[ $ret -eq 97 ]] && return
|
||||||
#TODO: some error handling here
|
#TODO: some error handling here
|
||||||
|
fetch(){
|
||||||
|
echo "# Getting server list"
|
||||||
curl -Ls "$url" > $file
|
curl -Ls "$url" > $file
|
||||||
|
}
|
||||||
|
fetch > >(zenity --pulsate --progress --auto-close --width=500 2>/dev/null)
|
||||||
response=$(< $file jq -r '.response.servers')
|
response=$(< $file jq -r '.response.servers')
|
||||||
local sel=$(munge_servers)
|
local sel=$(munge_servers)
|
||||||
if [[ -z $sel ]]; then
|
if [[ -z $sel ]]; then
|
||||||
|
|
41
helpers/latlon.c
Normal file
41
helpers/latlon.c
Normal 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
2
helpers/sums.md5
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
27bf17692c785b13ba03109f0b3f9502 ips.csv
|
||||||
|
17773960242d92331ac4203daf5ca9e2 latlon
|
Loading…
Reference in a new issue