1
0
Fork 0
mirror of https://github.com/aclist/dztui.git synced 2024-12-29 13:52:03 +01:00

Recent connect history

This commit is contained in:
aclist 2022-11-22 04:54:23 +09:00
parent f9c00f3522
commit 7ad6c13b52
2 changed files with 115 additions and 39 deletions

View file

@ -5,6 +5,15 @@
- Custom query API - Custom query API
- Standardize dialogs - Standardize dialogs
## [3.1.0-rc.10] 2022-11-21
### Added
- Recent connect history
- Force refresh local mods
### Changed
- More verbose messages regarding automod installation
### Dropped
- Headless mode
## [3.1.0-rc.10] 2022-11-09 ## [3.1.0-rc.10] 2022-11-09
### Changed ### Changed
- More verbose logs - More verbose logs

139
dzgui.sh
View file

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
set -o pipefail set -o pipefail
version=3.1.0-rc.10 version=3.1.0-rc.11
aid=221100 aid=221100
game="dayz" game="dayz"
@ -10,6 +10,7 @@ api="https://api.battlemetrics.com/servers"
sd_res="--width=1280 --height=800" sd_res="--width=1280 --height=800"
config_path="$HOME/.config/dztui/" config_path="$HOME/.config/dztui/"
config_file="${config_path}dztuirc" config_file="${config_path}dztuirc"
hist_file="${config_path}/history"
tmp=/tmp/dzgui.tmp tmp=/tmp/dzgui.tmp
fifo=/tmp/table.tmp fifo=/tmp/table.tmp
separator="%%" separator="%%"
@ -97,8 +98,9 @@ items=(
" Server browser" " Server browser"
" My servers" " My servers"
" Quick connect to favorite server" " Quick connect to favorite server"
"[Manage servers]"
" Connect by IP" " Connect by IP"
" History (last 10 connected)"
"[Manage servers]"
" Add server by ID" " Add server by ID"
" Add favorite server" " Add favorite server"
" Delete server" " Delete server"
@ -527,7 +529,6 @@ symlinks(){
passed_mod_check(){ passed_mod_check(){
echo "[DZGUI] Passed mod check" echo "[DZGUI] Passed mod check"
echo "# Preparing symlinks" echo "# Preparing symlinks"
stale_symlinks
legacy_symlinks legacy_symlinks
symlinks symlinks
echo "100" echo "100"
@ -551,6 +552,7 @@ auto_mod_install(){
echo "# Downloaded $((${#modids[@]}-missing)) of ${#modids[@]} mods" echo "# Downloaded $((${#modids[@]}-missing)) of ${#modids[@]} mods"
done | zenity --pulsate --progress --title="DZG Watcher" --auto-close --no-cancel --width=500 2>/dev/null done | zenity --pulsate --progress --title="DZG Watcher" --auto-close --no-cancel --width=500 2>/dev/null
compare compare
[[ $force_update -eq 1 ]] && { unset force_update; return; }
if [[ -z $diff ]]; then if [[ -z $diff ]]; then
check_timestamps check_timestamps
passed_mod_check > >(zenity --pulsate --progress --title=DZGUI --auto-close --width=500 2>/dev/null) passed_mod_check > >(zenity --pulsate --progress --title=DZGUI --auto-close --width=500 2>/dev/null)
@ -609,6 +611,7 @@ check_timestamps(){
fi fi
} }
merge_modlists(){ merge_modlists(){
[[ $force_update -eq 1 ]] && echo "# Checking mod versions"
check_timestamps check_timestamps
if [[ -z "$diff" ]] && [[ ${#needs_update[@]} -gt 0 ]]; then if [[ -z "$diff" ]] && [[ ${#needs_update[@]} -gt 0 ]]; then
diff=$(printf "%s\n" "${needs_update[@]}") diff=$(printf "%s\n" "${needs_update[@]}")
@ -619,6 +622,15 @@ merge_modlists(){
else else
diff="$(echo -e "$diff\n${needs_update[@]}")" diff="$(echo -e "$diff\n${needs_update[@]}")"
fi fi
[[ $force_update -eq 1 ]] && echo "100"
}
update_history(){
[[ -n $(grep "$ip" $hist_file) ]] && return
if [[ -f $hist_file ]]; then
old=$(tail -n9 "$hist_file")
old="$old\n"
fi
echo -e "${old}${ip}" > "$hist_file"
} }
connect(){ connect(){
#TODO: sanitize/validate input #TODO: sanitize/validate input
@ -642,7 +654,7 @@ connect(){
rc=$? rc=$?
[[ $rc -eq 1 ]] && return [[ $rc -eq 1 ]] && return
compare compare
merge_modlists [[ $auto_install -eq 2 ]] && merge_modlists
if [[ -n $diff ]]; then if [[ -n $diff ]]; then
if [[ $auto_install -eq 1 ]]; then if [[ $auto_install -eq 1 ]]; then
headless_mod_install "$diff" headless_mod_install "$diff"
@ -655,6 +667,7 @@ connect(){
fi fi
else else
passed_mod_check > >(zenity --pulsate --progress --auto-close --width=500 2>/dev/null) passed_mod_check > >(zenity --pulsate --progress --auto-close --width=500 2>/dev/null)
update_history
launch launch
fi fi
} }
@ -700,6 +713,41 @@ prepare_ip_list(){
echo "$time" echo "$time"
done done
} }
history_table(){
for i in $(cat $hist_file); do
echo "# Getting metadata for $i"
local meta_file=$(mktemp)
source $config_file
local url="https://api.steampowered.com/IGameServersService/GetServerList/v1/?filter=\appid\221100\gameaddr\\$i&key=$steam_api"
curl -Ls "$url" > $meta_file
json=$(mktemp)
< $meta_file jq '.response' > $json
res=$(< $meta_file jq -er '.response.servers[]' 2>/dev/null)
prepare_ip_list "$meta_file" >> /tmp/dz.hist
sleep 1s
done > >(zenity --pulsate --progress --auto-close --width=500 2>/dev/null)
while true; do
sel=$(cat /tmp/dz.hist | zenity --width 1200 --height 800 --list --column=Name --column=IP --column=Players --column=Gametime --print-column=2 --separator=%% 2>/dev/null)
if [[ $? -eq 1 ]]; then
return_from_table=1
rm /tmp/dz.hist
return
fi
if [[ -z $sel ]]; then
echo "No selection"
else
local gameport="$(echo "$sel" | awk -F: '{print $2}')"
local ip="$(echo "$sel" | awk -F: '{print $1}')"
local addr=$(< $json jq -r --arg gameport $gameport '.servers[]|select(.gameport == ($gameport|tonumber)).addr')
local qport=$(echo "$addr" | awk -F: '{print $2}')
local sa_ip=$(echo "$ip:$gameport%%$qport")
qport_list="$sa_ip"
connect "$sel" "ip"
fi
done
rm /tmp/dz.hist
}
ip_table(){ ip_table(){
while true; do while true; do
@ -1065,8 +1113,11 @@ toggle_headless(){
} }
console_dl(){ console_dl(){
readarray -t modids <<< "$@" readarray -t modids <<< "$@"
steam steam://open/console 2>/dev/null 1>&2 steam steam://open/console 2>/dev/null 1>&2 &&
sleep 1s sleep 1s
#https://github.com/jordansissel/xdotool/issues/67
local wid=$(xdotool search --sync --onlyvisible --desktop "$(xdotool get_desktop)" --name Steam)
xdotool windowactivate $wid
for i in "${modids[@]}"; do for i in "${modids[@]}"; do
xdotool type --delay 15 "workshop_download_item $aid $i" xdotool type --delay 15 "workshop_download_item $aid $i"
sleep 0.2s sleep 0.2s
@ -1082,6 +1133,7 @@ find_default_path(){
if [[ -d "$HOME/.local/share/Steam" ]]; then if [[ -d "$HOME/.local/share/Steam" ]]; then
default_steam_path="$HOME/.local/share/Steam" default_steam_path="$HOME/.local/share/Steam"
else else
# ubuntu .steam
default_steam_path=$(find / -type d \( -path "/proc" -o -path "*/timeshift" -o -path \ default_steam_path=$(find / -type d \( -path "/proc" -o -path "*/timeshift" -o -path \
"/tmp" -o -path "/usr" -o -path "/boot" -o -path "/run" -o -path "/proc" -o -path "/root" \ "/tmp" -o -path "/usr" -o -path "/boot" -o -path "/run" -o -path "/proc" -o -path "/root" \
-o -path "/sys" -o -path "/etc" -o -path "/var" -o -path "/lost+found" \) -prune \ -o -path "/sys" -o -path "/etc" -o -path "/var" -o -path "/lost+found" \) -prune \
@ -1096,12 +1148,19 @@ find_default_path(){
source $config_file source $config_file
} }
popup(){ popup(){
[[ $1 -eq 100 ]] && zenity --info --text="This feature requires xdotool" --title=DZGUI --width=500 pop(){
[[ $1 -eq 200 ]] && zenity --info --text="This feature is not supported on Gaming Mode" --title=DZGUI --width=500 zenity --info --text="$1" --title=DZGUI --width=500 2>/dev/null
[[ $1 -eq 300 ]] && zenity --info --text="\nThe Steam console will now open and briefly issue commands to\ndownload the workshop files, then return to the download progress page.\n\nEnsure that the Steam console has keyboard and mouse focus\n(keep hands off keyboard) while the commands are being issued.\n\nIt will only take a few seconds to queue the downloads, but if a\npopup or notification window steals focus, it could obstruct\nthe process." --title=DZGUI --width=500 2>/dev/null }
case "$1" in
100) pop "This feature requires xdotool.";;
200) pop "This feature is not supported on Gaming Mode.";;
300) pop "\nThe Steam console will now open and briefly issue commands to\ndownload the workshop files, then return to the download progress page.\n\nEnsure that the Steam console has keyboard and mouse focus\n(keep hands off keyboard) while the commands are being issued.\n\nDepending on the number if mods, it may take some time to queue the downloads,\nbut if a popup or notification window steals focus, it could obstruct\nthe process." ;;
400) pop "Automod install enabled. Auto-downloaded mods will not appear\nin your Steam Workshop subscriptions, but DZGUI will\ntrack the version number of downloaded mods internally\nand trigger an update if necessary." ;;
500) pop "Automod install disabled.\nSwitched to manual mode." ;;
esac
} }
requires_xdo(){ requires_xdo(){
zenity --info --text="This feature requires xdojool" --title=DZGUI --width=500 zenity --info --text="This feature requires xdotool" --title=DZGUI --width=500
} }
toggle_console_dl(){ toggle_console_dl(){
[[ $is_steam_deck -eq 1 ]] && test_display_mode [[ $is_steam_deck -eq 1 ]] && test_display_mode
@ -1111,14 +1170,22 @@ toggle_console_dl(){
local nr=$(awk '/auto_install=/ {print NR}' ${config_path}dztuirc.old) local nr=$(awk '/auto_install=/ {print NR}' ${config_path}dztuirc.old)
if [[ $auto_install == "2" ]]; then if [[ $auto_install == "2" ]]; then
auto_install="0" auto_install="0"
popup 500
else else
auto_install="2" auto_install="2"
popup 400
fi fi
local flip_state="auto_install=\"$auto_install\"" local flip_state="auto_install=\"$auto_install\""
awk -v "var=$flip_state" -v "nr=$nr" 'NR==nr {$0=var}{print}' ${config_path}dztuirc.old > $config_file awk -v "var=$flip_state" -v "nr=$nr" 'NR==nr {$0=var}{print}' ${config_path}dztuirc.old > $config_file
printf "[DZGUI] Set mod install to '$auto_install'\n" printf "[DZGUI] Set mod install to '$auto_install'\n"
source $config_file source $config_file
} }
force_update_mods(){
if [[ -f $version_file ]]; then
awk '{OFS="\t"}{$2="000"}1' $version_file > /tmp/versions
mv /tmp/versions $version_file
fi
}
options_menu(){ options_menu(){
case "$auto_install" in case "$auto_install" in
0) auto_hr="OFF"; headless_hr="OFF" ;; 0) auto_hr="OFF"; headless_hr="OFF" ;;
@ -1130,8 +1197,9 @@ options_menu(){
"Toggle debug mode" "Toggle debug mode"
"Generate debug log" "Generate debug log"
"Toggle auto mod install [$auto_hr]" "Toggle auto mod install [$auto_hr]"
"Toggle headless mod install [$headless_hr]" "Force update local mods"
"Set auto-mod staging directory [$staging_dir]" # "Toggle headless mod install [$headless_hr]"
# "Set auto-mod staging directory [$staging_dir]"
) )
debug_sel=$(zenity --list --width=1280 --height=800 --column="Options" --title="DZGUI" --hide-header "${debug_list[@]}" 2>/dev/null) debug_sel=$(zenity --list --width=1280 --height=800 --column="Options" --title="DZGUI" --hide-header "${debug_list[@]}" 2>/dev/null)
if [[ $debug_sel == "${debug_list[0]}" ]]; then if [[ $debug_sel == "${debug_list[0]}" ]]; then
@ -1149,9 +1217,10 @@ options_menu(){
elif [[ $debug_sel == "${debug_list[3]}" ]]; then elif [[ $debug_sel == "${debug_list[3]}" ]]; then
toggle_console_dl toggle_console_dl
elif [[ $debug_sel == "${debug_list[4]}" ]]; then elif [[ $debug_sel == "${debug_list[4]}" ]]; then
toggle_headless force_update=1
elif [[ $debug_sel == "${debug_list[5]}" ]]; then force_update_mods
file_picker merge_modlists > >(zenity --pulsate --progress --auto-close --title=DZGUI --width=500 2>/dev/null)
auto_mod_install
fi fi
} }
query_and_connect(){ query_and_connect(){
@ -1440,13 +1509,12 @@ mods_disk_size(){
printf "%s mods | " $(ls -1 "$game_dir" | wc -l) printf "%s mods | " $(ls -1 "$game_dir" | wc -l)
printf "Location: %s/steamapps/workshop/content/221100" "$steam_path" printf "Location: %s/steamapps/workshop/content/221100" "$steam_path"
} }
main_menu(){ main_menu(){
print_news print_news
set_mode set_mode
if [[ -n $fav ]]; then # if [[ -n $fav ]]; then
items[7]=" Change favorite server" # items[8]=" Change favorite server"
fi # fi
while true; do while true; do
set_header ${FUNCNAME[0]} set_header ${FUNCNAME[0]}
rc=$? rc=$?
@ -1462,35 +1530,37 @@ main_menu(){
elif [[ $sel == "${items[3]}" ]]; then elif [[ $sel == "${items[3]}" ]]; then
connect_to_fav connect_to_fav
elif [[ $sel == "${items[4]}" ]]; then elif [[ $sel == "${items[4]}" ]]; then
:
elif [[ $sel == "${items[5]}" ]]; then
connect_by_ip connect_by_ip
elif [[ $sel == "${items[5]}" ]]; then
history_table
elif [[ $sel == "${items[6]}" ]]; then elif [[ $sel == "${items[6]}" ]]; then
add_by_id :
elif [[ $sel == "${items[7]}" ]]; then elif [[ $sel == "${items[7]}" ]]; then
add_by_fav add_by_id
elif [[ $sel == "${items[8]}" ]]; then elif [[ $sel == "${items[8]}" ]]; then
add_by_fav
elif [[ $sel == "${items[9]}" ]]; then
delete=1 delete=1
query_and_connect query_and_connect
elif [[ $sel == "${items[9]}" ]]; then
:
elif [[ $sel == "${items[10]}" ]]; then elif [[ $sel == "${items[10]}" ]]; then
:
elif [[ $sel == "${items[11]}" ]]; then
list_mods | sed 's/\t/\n/g' | zenity --list --column="Mod" --column="Symlink" \ list_mods | sed 's/\t/\n/g' | zenity --list --column="Mod" --column="Symlink" \
--title="DZGUI" $sd_res --text="$(mods_disk_size)" \ --title="DZGUI" $sd_res --text="$(mods_disk_size)" \
--print-column="" 2>/dev/null --print-column="" 2>/dev/null
elif [[ $sel == "${items[11]}" ]]; then
changelog | zenity --text-info $sd_res --title="DZGUI" 2>/dev/null
elif [[ $sel == "${items[12]}" ]]; then elif [[ $sel == "${items[12]}" ]]; then
changelog | zenity --text-info $sd_res --title="DZGUI" 2>/dev/null
elif [[ $sel == "${items[13]}" ]]; then
options_menu options_menu
main_menu main_menu
return return
elif [[ $sel == "${items[13]}" ]]; then
:
elif [[ $sel == "${items[14]}" ]]; then elif [[ $sel == "${items[14]}" ]]; then
help_file :
elif [[ $sel == "${items[15]}" ]]; then elif [[ $sel == "${items[15]}" ]]; then
report_bug help_file
elif [[ $sel == "${items[16]}" ]]; then elif [[ $sel == "${items[16]}" ]]; then
report_bug
elif [[ $sel == "${items[17]}" ]]; then
forum forum
else else
warn "This feature is not yet implemented." warn "This feature is not yet implemented."
@ -1550,9 +1620,6 @@ create_array(){
time=$(echo "$line" | awk -F'\t' '{print $4}') time=$(echo "$line" | awk -F'\t' '{print $4}')
stat=$(echo "$line" | awk -F'\t' '{print $5}') stat=$(echo "$line" | awk -F'\t' '{print $5}')
#yad only
#[[ $stat == "online" ]] && stat="<span color='#77ff33'>online</span>" || :
#TODO: probe offline return codes #TODO: probe offline return codes
id=$(echo "$line" | awk -F'\t' '{print $6}') id=$(echo "$line" | awk -F'\t' '{print $6}')
tc=$(awk 'END{print NR}' $tmp) tc=$(awk 'END{print NR}' $tmp)
@ -1714,7 +1781,7 @@ toggle_debug(){
setup(){ setup(){
if [[ -n $fav ]]; then if [[ -n $fav ]]; then
set_fav set_fav
items[7]=" Change favorite server" items[8]=" Change favorite server"
fi fi
} }
check_map_count(){ check_map_count(){
@ -1749,7 +1816,7 @@ while true; do
zenity --info --title="DZGUI" --text="Added "$fav_id" to:\n${config_path}dztuirc\nIf errors occurred, you can restore the file:\n${config_path}dztuirc.old" 2>/dev/null zenity --info --title="DZGUI" --text="Added "$fav_id" to:\n${config_path}dztuirc\nIf errors occurred, you can restore the file:\n${config_path}dztuirc.old" 2>/dev/null
source $config_file source $config_file
set_fav set_fav
items[7]=" Change favorite server" items[8]=" Change favorite server"
return return
fi fi
fi fi
@ -1826,6 +1893,7 @@ initial_setup(){
find_default_path find_default_path
fetch_scmd_helper fetch_scmd_helper
run_varcheck run_varcheck
stale_symlinks
init_items init_items
setup setup
deprecation_warning deprecation_warning
@ -1840,4 +1908,3 @@ main(){
} }
main main
#trap cleanup EXIT