From db6772098a8eaefd5e0621cca20504c2b91e7f6e Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Sat, 17 Jan 2026 21:13:46 +0000 Subject: [PATCH 01/32] initial, untested consolidation of some functions across netplay scripts --- .../script/netplay/easy-netplay_client.sh | 79 +------- .../netplay/easy-netplay_client_pokemon.sh | 125 +----------- .../easy-netplay_client_pokemon_GBA.sh | 52 +---- .../script/netplay/easy-netplay_server.sh | 28 +-- .../netplay/easy-netplay_server_pokemon.sh | 171 +--------------- .../easy-netplay_server_pokemon_GBA.sh | 98 +-------- .../script/netplay/netplay_common.sh | 191 ++++++++++++++++++ .../script/netplay/standard-netplay.sh | 6 +- 8 files changed, 205 insertions(+), 545 deletions(-) create mode 100644 static/build/.tmp_update/script/netplay/netplay_common.sh diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh index 7c2286d6eb..e67459ef5b 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh @@ -14,7 +14,9 @@ export LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/p export hostip="192.168.100.100" # This should be the default unless the user has changed it.. logfile=easy_netplay +# Source scripts . $sysdir/script/log.sh +. $sysdir/script/netplay/netplay_common.sh program=$(basename "$0" .sh) ########## @@ -338,53 +340,7 @@ sync_file() { } -checksum_func() { - local_file_size=$(stat -c%s "$file_path") - local func_file_path="$1" - local CRC="$2" - ########################## File checksum check : same_chksum = 0 different, 1 identical , 2 unknown - - if [ "$CRC" != "0" ]; then # file_checksum=0 means skip the difference check = always replace - local_file_checksum=$(xcrc "$func_file_path") - - if [ "$local_file_size" -gt "$MAX_FILE_CHKSUM_SIZE" ]; then - log "File size too big for checksum: it would be too long" - same_chksum=2 - else - if [ "$CRC" == "$local_file_checksum" ]; then - same_chksum=1 - else - same_chksum=0 - fi - fi - else - log "Skipping checksum check." - same_chksum=1 # fake same size for skipping - fi -} - -checksize_func() { - - local func_file_path="$1" - local filesize_tocheck="$2" - local_file_size=$(stat -c%s "$func_file_path") - - ########################## File size check same_size = 0 different, 1 identical , 2 unknown - - if echo "$filesize_tocheck" | grep -q "^[0-9][0-9]*$"; then # check if the remote file size is a numeric value - if [ "$filesize_tocheck" -eq "$local_file_size" ]; then - log "Same size as remote" - same_size=1 - else - log "Files size are different" - same_size=0 - fi - else - log "Impossible to get file size : wrong parameter." - same_size=2 - fi -} # Start retroarch with -C in client mode if everything's gone to plan start_retroarch() { @@ -421,33 +377,6 @@ start_retroarch() { ########### # URL encode helper -url_encode() { - encoded_str=$(echo "$*" | awk ' - BEGIN { - split ("1 2 3 4 5 6 7 8 9 A B C D E F", hextab, " ") - hextab [0] = 0 - for ( i=1; i<=255; ++i ) ord [ sprintf ("%c", i) "" ] = i + 0 - } - { - encoded = "" - for ( i=1; i<=length ($0); ++i ) { - c = substr ($0, i, 1) - if ( c ~ /[a-zA-Z0-9.-]/ ) { - encoded = encoded c # safe character - } else if ( c == " " ) { - encoded = encoded "%20" # special handling - } else { - # unsafe character, encode it as a two-digit hex-number - lo = ord [c] % 16 - hi = int (ord [c] / 16); - encoded = encoded "%" hextab [hi] hextab [lo] - } - } - print encoded - } -') - echo "$encoded_str" -} wifi_disabled() { [ $(/customer/app/jsonval wifi) -eq 0 ] @@ -494,10 +423,6 @@ stripped_game_name() { game_name=$(awk -F'/' '/\[rom\]:/ {print $NF}' /mnt/SDCARD/RetroArch/retroarch.cookie.client | sed 's/\(.*\)\..*/\1/') } -is_running() { - process_name="$1" - pgrep "$process_name" >/dev/null -} cleanup() { build_infoPanel_and_log "Cleanup" "Cleaning up after netplay session..." diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh index 995e92d92d..14001ec462 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh @@ -15,9 +15,10 @@ client_rom_filename_NoExt="${client_rom_filename%.*}" SaveFromGambatte=0 -## Source global utils logfile=pokemon_link +# Source scripts . $sysdir/script/log.sh +. $sysdir/script/netplay/netplay_common.sh program=$(basename "$0" .sh) export CurDate=$(date +%Y%m%d_%H%M%S) @@ -120,31 +121,6 @@ backup_and_send_save() { } # Wait for the host to tell us it's ready, this happens just before it starts its RA session and we look in /tmp for a file indicator (file removed in host script cleanup) -wait_for_host() { - - local counter=0 - - build_infoPanel_and_log "Ready" "Waiting for host to ready up" - while true; do - sync - check_stop - for file in /tmp/host_ready; do - if [ -f "$file" ]; then - build_infoPanel_and_log "Message from host" "Setup complete" - rm /tmp/host_ready # be ready for the second use of host_ready flag - break 2 - fi - done - - sleep 1 - counter=$((counter + 1)) - - if [ $counter -ge 25 ]; then - build_infoPanel_and_log "Error" "The host didn't ready up, cannot continue..." - notify_stop - fi - done -} # Start retroarch with -C in client mode if everything's gone to plan start_retroarch() { @@ -264,40 +240,8 @@ cleanup() { ########### # URL encode helper -url_encode() { - encoded_str=$(echo "$*" | awk ' - BEGIN { - split ("1 2 3 4 5 6 7 8 9 A B C D E F", hextab, " ") - hextab [0] = 0 - for ( i=1; i<=255; ++i ) ord [ sprintf ("%c", i) "" ] = i + 0 - } - { - encoded = "" - for ( i=1; i<=length ($0); ++i ) { - c = substr ($0, i, 1) - if ( c ~ /[a-zA-Z0-9.-]/ ) { - encoded = encoded c # safe character - } else if ( c == " " ) { - encoded = encoded "%20" # special handling - } else { - # unsafe character, encode it as a two-digit hex-number - lo = ord [c] % 16 - hi = int (ord [c] / 16); - encoded = encoded "%" hextab [hi] hextab [lo] - } - } - print encoded - } -') - echo "$encoded_str" -} # Use the safe word -notify_stop() { - notify_peer "stop_now" - sleep 2 - cleanup -} # Check stop, if the client tells us to stop we will. check_stop() { @@ -647,22 +591,7 @@ create_cookie_info() { } # This will restore the users original ftp state -restore_ftp() { - log "Restoring original FTP server" - killall -9 tcpsvd - if flag_enabled ftpState; then - if flag_enabled authftpState; then - bftpd -d -c /mnt/SDCARD/.tmp_update/config/bftpdauth.conf & - else - bftpd -d -c /mnt/SDCARD/.tmp_update/config/bftpd.conf & - fi - fi -} -flag_enabled() { - flag="$1" - [ -f "$sysdir/config/.$flag" ] -} build_infoPanel_and_log() { local title="$1" @@ -717,58 +646,8 @@ stripped_game_names() { game_name_client="\n Client (me): \n$client_rom_trimmed" } -checksum_func() { - local_file_size=$(stat -c%s "$file_path") - local func_file_path="$1" - local CRC="$2" - - ########################## File checksum check : same_chksum = 0 different, 1 identical , 2 unknown - - if [ "$CRC" != "0" ]; then # file_checksum=0 means skip the difference check = always replace - local_file_checksum=$(xcrc "$func_file_path") - - if [ "$local_file_size" -gt "$MAX_FILE_CHKSUM_SIZE" ]; then - log "File size too big for checksum: it would be too long" - same_chksum=2 - else - if [ "$CRC" == "$local_file_checksum" ]; then - same_chksum=1 - else - same_chksum=0 - fi - fi - else - log "Skipping checksum check." - same_chksum=1 # fake same size for skipping - fi -} -checksize_func() { - local func_file_path="$1" - local filesize_tocheck="$2" - local_file_size=$(stat -c%s "$func_file_path") - - ########################## File size check same_size = 0 different, 1 identical , 2 unknown - - if echo "$filesize_tocheck" | grep -q "^[0-9][0-9]*$"; then # check if the remote file size is a numeric value - if [ "$filesize_tocheck" -eq "$local_file_size" ]; then - log "Same size as remote" - same_size=1 - else - log "Files size are different" - same_size=0 - fi - else - log "Impossible to get file size : wrong parameter." - same_size=2 - fi -} - -is_running() { - process_name="$1" - pgrep "$process_name" >/dev/null -} ######### ##Main.## diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh index afb9ff5c43..e6c3ddc198 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh @@ -13,9 +13,10 @@ client_rom_filename=$(basename "$client_rom") client_rom_filename_NoExt="${client_rom_filename%.*}" netplaycore="/mnt/SDCARD/RetroArch/.retroarch/cores/gpsp_libretro.so" -## Source global utils logfile=pokemon_link +# Source scripts . $sysdir/script/log.sh +. $sysdir/script/netplay/netplay_common.sh log "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* Easy Netplay Pokemon Client GBA -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" @@ -24,31 +25,6 @@ log "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* Easy Netplay Pokemon Client GBA -* ########## # Wait for the host to tell us it's ready, this happens just before it starts its RA session and we look in /tmp for a file indicator (file removed in host script cleanup) -wait_for_host() { - - local counter=0 - - build_infoPanel_and_log "Ready" "Waiting for host to ready up" - while true; do - sync - check_stop - for file in /tmp/host_ready; do - if [ -f "$file" ]; then - build_infoPanel_and_log "Message from host" "Setup complete" - rm /tmp/host_ready # be ready for the second use of host_ready flag - break 2 - fi - done - - sleep 1 - counter=$((counter + 1)) - - if [ $counter -ge 25 ]; then - build_infoPanel_and_log "Error" "The host didn't ready up, cannot continue..." - notify_stop - fi - done -} # Start retroarch with -C in client mode if everything's gone to plan start_retroarch() { @@ -112,11 +88,6 @@ cleanup() { ########### # Use the safe word -notify_stop() { - notify_peer "stop_now" - sleep 2 - cleanup -} # Check stop, if the client tells us to stop we will. check_stop() { @@ -157,22 +128,7 @@ start_ftp() { } # This will restore the users original ftp state -restore_ftp() { - log "Restoring original FTP server" - killall -9 tcpsvd - if flag_enabled ftpState; then - if flag_enabled authftpState; then - bftpd -d -c /mnt/SDCARD/.tmp_update/config/bftpdauth.conf & - else - bftpd -d -c /mnt/SDCARD/.tmp_update/config/bftpd.conf & - fi - fi -} -flag_enabled() { - flag="$1" - [ -f "$sysdir/config/.$flag" ] -} build_infoPanel_and_log() { local title="$1" @@ -218,10 +174,6 @@ stripped_game_names() { game_name_client="Client (me): \n$client_rom_trimmed" } -is_running() { - process_name="$1" - pgrep "$process_name" >/dev/null -} ######### ##Main.## diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh index 1ec4255326..0ae4439cbc 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh @@ -12,7 +12,9 @@ miyoodir=/mnt/SDCARD/miyoo export LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/parasyte" logfile=easy_netplay +# Source scripts . $sysdir/script/log.sh +. $sysdir/script/netplay/netplay_common.sh program=$(basename "$0" .sh) ########## @@ -162,35 +164,9 @@ build_infoPanel_and_log() { sync } -restore_ftp() { - log "Restoring original FTP server" - killall -9 tcpsvd - if flag_enabled ftpState; then - if flag_enabled authftpState; then - bftpd -d -c /mnt/SDCARD/.tmp_update/config/bftpdauth.conf & - else - bftpd -d -c /mnt/SDCARD/.tmp_update/config/bftpd.conf & - fi - fi -} -flag_enabled() { - flag="$1" - [ -f "$sysdir/config/.$flag" ] -} -udhcpc_control() { - if pgrep udhcpc >/dev/null; then - killall -9 udhcpc - fi - sleep 1 - udhcpc -i wlan0 -s /etc/init.d/udhcpc.script >/dev/null 2>&1 & -} -is_running() { - process_name="$1" - pgrep "$process_name" >/dev/null -} ######### ##Main.## diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh index b7f4f8a538..859bc12981 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh @@ -7,7 +7,9 @@ miyoodir=/mnt/SDCARD/miyoo LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/parasyte" logfile=pokemon_link +# Source scripts . $sysdir/script/log.sh +. $sysdir/script/netplay/netplay_common.sh program=$(basename "$0" .sh) rm /tmp/stop_now @@ -113,57 +115,6 @@ create_cookie_info() { } # Wait for a hit on the sta list for someone joining the hotspot -wait_for_client() { - check_stop - build_infoPanel_and_log "Hotspot" "Waiting for a client to connect..." - - client_ip="" - client_mac="" - counter=0 - - killall -9 wpa_supplicant - killall -9 udhcpc - - sleep 1 - - while true; do - sta_list=$($sysdir/bin/hostapd_cli all_sta 2>/dev/null) - $sysdir/bin/hostapd_cli all_sta flush - - if [ $? -ne 0 ]; then - build_infoPanel_and_log "Hotspot" "Hostapd hook failing, retrying." - counter=$((counter + 1)) - fi - - if [ ! -z "$sta_list" ]; then - client_mac=$(echo "$sta_list" | awk 'NR==2{print $1; exit}') - client_ip=$(arp -an | awk '/'"$client_mac"'/ {gsub(/[\(\)]/,""); print $2}') - - if [ ! -z "$client_ip" ]; then - case "$client_ip" in - 192.168.100.*) - log "$sta_list" - log "A client has connected. IP: $client_ip" - build_infoPanel_and_log "Hotspot" "A client has connected! \n IP: $client_ip" - break - ;; - esac - fi - fi - - sleep 1 - counter=$((counter + 1)) - - if [ $counter -ge 30 ]; then - log "No client has connected" - build_infoPanel_and_log "Hotspot error" "No client has connected. Exiting..." - cleanup - fi - done - - sleep 1 - log "$client_ip has joined the hotspot" -} # Backup the save we're going to use before we do anythign else host_save_backup() { @@ -303,16 +254,6 @@ client_rom_rename() { } # Tell the client we're ready to accept connections -ready_up() { - check_stop - ping -c 5 $client_ip >/dev/null 2>&1 - if [ $? -eq 0 ]; then - notify_peer "host_ready" - else - build_infoPanel_and_log "Error" "No connectivity to $client_ip, \n is the client still connected?" - notify_stop - fi -} # We'll start Retroarch in host mode with -H with the core and rom paths loaded in. start_retroarch() { @@ -433,40 +374,8 @@ cleanup() { ########### # URL encode helper -url_encode() { - encoded_str=$(echo "$*" | awk ' - BEGIN { - split ("1 2 3 4 5 6 7 8 9 A B C D E F", hextab, " ") - hextab [0] = 0 - for ( i=1; i<=255; ++i ) ord [ sprintf ("%c", i) "" ] = i + 0 - } - { - encoded = "" - for ( i=1; i<=length ($0); ++i ) { - c = substr ($0, i, 1) - if ( c ~ /[a-zA-Z0-9.-]/ ) { - encoded = encoded c # safe character - } else if ( c == " " ) { - encoded = encoded "%20" # special handling - } else { - # unsafe character, encode it as a two-digit hex-number - lo = ord [c] % 16 - hi = int (ord [c] / 16); - encoded = encoded "%" hextab [hi] hextab [lo] - } - } - print encoded - } -') - echo "$encoded_str" -} # Use the safe word -notify_stop() { - notify_peer "stop_now" - sleep 2 - cleanup -} # Check stop, if the client tells us to stop we will. check_stop() { @@ -821,53 +730,7 @@ sync_file() { } -checksum_func() { - local_file_size=$(stat -c%s "$file_path") - local func_file_path="$1" - local CRC="$2" - - ########################## File checksum check : same_chksum = 0 different, 1 identical , 2 unknown - if [ "$CRC" != "0" ]; then # file_checksum=0 means skip the difference check = always replace - local_file_checksum=$(xcrc "$func_file_path") - - if [ "$local_file_size" -gt "$MAX_FILE_CHKSUM_SIZE" ]; then - log "File size too big for checksum: it would be too long" - same_chksum=2 - else - if [ "$CRC" == "$local_file_checksum" ]; then - same_chksum=1 - else - same_chksum=0 - fi - fi - else - log "Skipping checksum check." - same_chksum=1 # fake same size for skipping - fi -} - -checksize_func() { - - local func_file_path="$1" - local filesize_tocheck="$2" - local_file_size=$(stat -c%s "$func_file_path") - - ########################## File size check same_size = 0 different, 1 identical , 2 unknown - - if echo "$filesize_tocheck" | grep -q "^[0-9][0-9]*$"; then # check if the remote file size is a numeric value - if [ "$filesize_tocheck" -eq "$local_file_size" ]; then - log "Same size as remote" - same_size=1 - else - log "Files size are different" - same_size=0 - fi - else - log "Impossible to get file size : wrong parameter." - same_size=2 - fi -} unpack_rom() { file="$1" @@ -897,40 +760,10 @@ build_infoPanel_and_log() { sync } -restore_ftp() { - log "Restoring original FTP server" - killall -9 tcpsvd - if flag_enabled ftpState; then - if flag_enabled authftpState; then - bftpd -d -c /mnt/SDCARD/.tmp_update/config/bftpdauth.conf & - else - bftpd -d -c /mnt/SDCARD/.tmp_update/config/bftpd.conf & - fi - fi -} -flag_enabled() { - flag="$1" - [ -f "$sysdir/config/.$flag" ] -} -udhcpc_control() { - if pgrep udhcpc >/dev/null; then - killall -9 udhcpc - fi - sleep 1 - udhcpc -i wlan0 -s /etc/init.d/udhcpc.script >/dev/null 2>&1 & -} -is_running() { - process_name="$1" - pgrep "$process_name" >/dev/null -} -enable_flag() { - flag="$1" - touch "$sysdir/config/.$flag" -} ######### ##Main.## diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh index 5150a2227e..2b2ce4e0c6 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh @@ -7,7 +7,9 @@ miyoodir=/mnt/SDCARD/miyoo LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/parasyte" logfile=pokemon_link +# Source scripts . $sysdir/script/log.sh +. $sysdir/script/netplay/netplay_common.sh rm /tmp/stop_now host_rom="$1" @@ -38,69 +40,8 @@ start_ftp() { } # Wait for a hit on the sta list for someone joining the hotspot -wait_for_client() { - check_stop - build_infoPanel_and_log "Hotspot" "Waiting for a client to connect..." - - client_ip="" - client_mac="" - counter=0 - - killall -9 wpa_supplicant - killall -9 udhcpc - - sleep 1 - - while true; do - sta_list=$($sysdir/bin/hostapd_cli all_sta 2>/dev/null) - $sysdir/bin/hostapd_cli all_sta flush - - if [ $? -ne 0 ]; then - build_infoPanel_and_log "Hotspot" "Hostapd hook failing, retrying." - counter=$((counter + 1)) - fi - - if [ ! -z "$sta_list" ]; then - client_mac=$(echo "$sta_list" | awk 'NR==2{print $1; exit}') - client_ip=$(arp -an | awk '/'"$client_mac"'/ {gsub(/[\(\)]/,""); print $2}') - - if [ ! -z "$client_ip" ]; then - case "$client_ip" in - 192.168.100.*) - log "$sta_list" - log "A client has connected. IP: $client_ip" - build_infoPanel_and_log "Hotspot" "A client has connected! \n IP: $client_ip" - break - ;; - esac - fi - fi - - sleep 1 - counter=$((counter + 1)) - - if [ $counter -ge 30 ]; then - log "No client has connected" - build_infoPanel_and_log "Hotspot error" "No client has connected. Exiting..." - cleanup - fi - done - - sleep 1 - log "$client_ip has joined the hotspot" -} # Tell the client we're ready to accept connections -ready_up() { - check_stop - ping -c 5 $client_ip >/dev/null 2>&1 - if [ $? -eq 0 ]; then - notify_peer "host_ready" - else - build_infoPanel_and_log "Error" "No connectivity to $client_ip, \n is the client still connected?" - notify_stop - fi -} # We'll start Retroarch in host mode with -H with the core and rom paths loaded in. start_retroarch() { @@ -159,11 +100,6 @@ cleanup() { ########### # Use the safe word -notify_stop() { - notify_peer "stop_now" - sleep 2 - cleanup -} # Check stop, if the client tells us to stop we will. check_stop() { @@ -240,40 +176,10 @@ build_infoPanel_and_log() { sync } -restore_ftp() { - log "Restoring original FTP server" - killall -9 tcpsvd - if flag_enabled ftpState; then - if flag_enabled authftpState; then - bftpd -d -c /mnt/SDCARD/.tmp_update/config/bftpdauth.conf & - else - bftpd -d -c /mnt/SDCARD/.tmp_update/config/bftpd.conf & - fi - fi -} -flag_enabled() { - flag="$1" - [ -f "$sysdir/config/.$flag" ] -} -udhcpc_control() { - if pgrep udhcpc >/dev/null; then - killall -9 udhcpc - fi - sleep 1 - udhcpc -i wlan0 -s /etc/init.d/udhcpc.script >/dev/null 2>&1 & -} -is_running() { - process_name="$1" - pgrep "$process_name" >/dev/null -} -enable_flag() { - flag="$1" - touch "$sysdir/config/.$flag" -} ######### ##Main.## diff --git a/static/build/.tmp_update/script/netplay/netplay_common.sh b/static/build/.tmp_update/script/netplay/netplay_common.sh new file mode 100644 index 0000000000..c966d72aad --- /dev/null +++ b/static/build/.tmp_update/script/netplay/netplay_common.sh @@ -0,0 +1,191 @@ +# Shared netplay helpers + +checksize_func() { + if [ "$file_check_size" -eq 1 ]; then + if [ -e "$file_path" ]; then + local_file_size=$(stat -c%s "$file_path") + if [ "$remote_file_checksum" == "0" ]; then + same_size=1 + elif [ "$local_file_size" -eq "$remote_file_checksum" ]; then + same_size=1 + else + same_size=0 + fi + else + same_size=0 + fi + else + same_size=1 + fi +} + +checksum_func() { + local_file_size=$(stat -c%s "$file_path") + local func_file_path="$1" + local CRC="$2" + + ########################## File checksum check : same_chksum = 0 different, 1 identical , 2 unknown + + if [ "$CRC" != "0" ]; then # file_checksum=0 means skip the difference check = always replace + local_file_checksum=$(xcrc "$func_file_path") + + if [ "$local_file_size" -gt "$MAX_FILE_CHKSUM_SIZE" ]; then + log "File size too big for checksum: it would be too long" + same_chksum=2 + else + if [ "$CRC" == "$local_file_checksum" ]; then + same_chksum=1 + else + same_chksum=0 + fi + fi + else + same_chksum=0 + fi +} + +enable_flag() { + flag="$1" + touch "$sysdir/config/.$flag" +} + +flag_enabled() { + flag="$1" + [ -f "$sysdir/config/.$flag" ] +} + +is_running() { + process_name="$1" + pgrep "$process_name" >/dev/null +} + +notify_stop() { + notify_peer "stop_now" + sleep 2 + cleanup +} + +ready_up() { + check_stop + ping -c 5 $client_ip >/dev/null 2>&1 + if [ $? -eq 0 ]; then + notify_peer "host_ready" + else + build_infoPanel_and_log "Error" "No connectivity to $client_ip, \n is the client still connected?" + notify_stop + fi +} + +restore_ftp() { + log "Restoring original FTP server" + killall -9 tcpsvd + if flag_enabled ftpState; then + if flag_enabled authftpState; then + bftpd -d -c /mnt/SDCARD/.tmp_update/config/bftpdauth.conf & + else + bftpd -d -c /mnt/SDCARD/.tmp_update/config/bftpd.conf & + fi + fi +} + +udhcpc_control() { + if pgrep udhcpc >/dev/null; then + killall -9 udhcpc + fi + sleep 1 + udhcpc -i wlan0 -s /etc/init.d/udhcpc.script >/dev/null 2>&1 & +} + +url_encode() { + local string="$1" + local length="${#string}" + local encoded="" + local pos c o + + for ((pos = 0; pos < length; pos++)); do + c=${string:$pos:1} + case "$c" in + [-_.~a-zA-Z0-9]) o="$c" ;; + *) printf -v o '%%%02x' "'${c}" ;; + esac + encoded+="$o" + done + echo "$encoded" +} + +wait_for_client() { + check_stop + build_infoPanel_and_log "Hotspot" "Waiting for a client to connect..." + + client_ip="" + client_mac="" + counter=0 + + killall -9 wpa_supplicant + killall -9 udhcpc + + sleep 1 + + while true; do + sta_list=$($sysdir/bin/hostapd_cli all_sta 2>/dev/null) + $sysdir/bin/hostapd_cli all_sta flush + + if [ $? -ne 0 ]; then + build_infoPanel_and_log "Hotspot" "Hostapd hook failing, retrying." + counter=$((counter + 1)) + fi + + if [ ! -z "$sta_list" ]; then + client_mac=$(echo "$sta_list" | awk 'NR==2{print $1; exit}') + client_ip=$(arp -an | awk '/"'"$client_mac"'"/ {gsub(/[\(\)]/,""); print $2}') + + if [ ! -z "$client_ip" ]; then + case "$client_ip" in + 192.168.100.*) + log "$sta_list" + log "A client has connected. IP: $client_ip" + build_infoPanel_and_log "Hotspot" "A client has connected! \n IP: $client_ip" + break + ;; + esac + fi + fi + + sleep 1 + counter=$((counter + 1)) + + if [ $counter -ge 30 ]; then + log "No client has connected" + build_infoPanel_and_log "Hotspot error" "No client has connected. Exiting..." + cleanup + fi + done + + sleep 1 + log "$client_ip has joined the hotspot" +} + +wait_for_host() { + local counter=0 + + build_infoPanel_and_log "Ready" "Waiting for host to ready up" + while true; do + sync + check_stop + for file in /tmp/host_ready; do + if [ -f "$file" ]; then + build_infoPanel_and_log "Message from host" "Setup complete" + rm /tmp/host_ready # be ready for the second use of host_ready flag + break 2 + fi + done + + sleep 1 + counter=$((counter + 1)) + + if [ $counter -ge 25 ]; then + build_infoPanel_and_log "Error" "The host didn't ready up, cannot continue..." + notify_stop + fi + done +} diff --git a/static/build/.tmp_update/script/netplay/standard-netplay.sh b/static/build/.tmp_update/script/netplay/standard-netplay.sh index a62272527f..f79141197c 100644 --- a/static/build/.tmp_update/script/netplay/standard-netplay.sh +++ b/static/build/.tmp_update/script/netplay/standard-netplay.sh @@ -15,7 +15,9 @@ CurrentSystem=$(echo "$1" | grep -o '/Roms/[^/]*' | cut -d'/' -f3) NetplayAction="$3" # host or join logfile=netplay +# Source scripts . $sysdir/script/log.sh +. $sysdir/script/netplay/netplay_common.sh program=$(basename "$0" .sh) ########## @@ -143,10 +145,6 @@ build_infoPanel_and_log() { sync } -is_running() { - process_name="$1" - pgrep "$process_name" >/dev/null -} ######### ##Main.## From fbf75c90e74912bbfe41f40206f31b0295d9016f Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Sat, 17 Jan 2026 21:59:13 +0000 Subject: [PATCH 02/32] *untested* seperate further, move signalling into it's own file - some housekeeping/readability --- .../script/netplay/easy-netplay_client.sh | 37 ++-- .../netplay/easy-netplay_client_pokemon.sh | 95 +++++----- .../easy-netplay_client_pokemon_GBA.sh | 95 +++------- .../script/netplay/easy-netplay_server.sh | 53 ++---- .../netplay/easy-netplay_server_pokemon.sh | 144 +++++++-------- .../easy-netplay_server_pokemon_GBA.sh | 104 ++++------- .../script/netplay/netplay_common.sh | 167 +++++++++--------- .../script/netplay/netplay_signalling.sh | 154 ++++++++++++++++ .../script/netplay/standard-netplay.sh | 50 ++---- 9 files changed, 455 insertions(+), 444 deletions(-) create mode 100644 static/build/.tmp_update/script/netplay/netplay_signalling.sh diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh index e67459ef5b..cdf0c969b2 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh @@ -12,10 +12,12 @@ sysdir=/mnt/SDCARD/.tmp_update miyoodir=/mnt/SDCARD/miyoo export LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/parasyte" export hostip="192.168.100.100" # This should be the default unless the user has changed it.. +peer_ip="$hostip" logfile=easy_netplay # Source scripts . $sysdir/script/log.sh +# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp . $sysdir/script/netplay/netplay_common.sh program=$(basename "$0" .sh) @@ -382,21 +384,6 @@ wifi_disabled() { [ $(/customer/app/jsonval wifi) -eq 0 ] } -build_infoPanel_and_log() { - local title="$1" - local message="$2" - - log "Info Panel: \n\tStage: $title\n\tMessage: $message" - if is_running infoPanel; then - killall -9 infoPanel - fi - infoPanel --title "$title" --message "$message" --persistent & - sync - touch /tmp/dismiss_info_panel - sync - sleep 0.3 - sync -} confirm_join_panel() { local title="$1" @@ -451,18 +438,36 @@ cleanup() { ######### lets_go() { - + # Allow user to abort via menu while setup runs pressMenu2Kill $(basename $0) & + + # Join host hotspot . "$sysdir/script/network/hotspot_join.sh" + + # Fetch cookie from host sync_file "Cookie" "/mnt/SDCARD/RetroArch/retroarch.cookie" 0 0 -f -m + + # Read host cookie and parse paths/checksums read_cookie + + # Sync required core, rom, and image sync_file "Core" "$core" 1 "$corechecksum" -b -m sync_file "Rom" "$rom" 1 "$romchecksum" -b -m sync_file "Img" "$Img_path" 0 0 -o + + # Build display name for confirmation prompt stripped_game_name + + # Stop menu watcher before launch pkill -9 pressMenu2Kill + + # Confirm join with host info confirm_join_panel "Join now?" "$game_name" + + # Launch RetroArch client session start_retroarch + + # Cleanup and restore state cleanup } diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh index 14001ec462..4cd9da8cff 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh @@ -8,6 +8,7 @@ miyoodir=/mnt/SDCARD/miyoo LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/parasyte" WPACLI=/customer/app/wpa_cli hostip="192.168.100.100" # This should be the default unless the user has changed it.. +peer_ip="$hostip" rm /tmp/stop_now client_rom="$cookie_rom_path" client_rom_filename=$(basename "$client_rom") @@ -18,7 +19,10 @@ SaveFromGambatte=0 logfile=pokemon_link # Source scripts . $sysdir/script/log.sh +# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp . $sysdir/script/netplay/netplay_common.sh +# netplay_signalling.sh: check_stop, notify_peer, notify_stop, wait_for_host +. $sysdir/script/netplay/netplay_signalling.sh program=$(basename "$0" .sh) export CurDate=$(date +%Y%m%d_%H%M%S) @@ -76,7 +80,8 @@ read_cookie() { # Push our save over to the host - The save will be found based on the rom we've started GLO on and it will look in the $save_dir path for it (see line13) - Backs up first backup_and_send_save() { - check_stop + # check_stop: host reported a setup issue + check_stop "The host has had a problem setting up the session" missing="" build_infoPanel_and_log "Syncing saves" "Syncing our save files with the host" @@ -157,7 +162,8 @@ start_retroarch() { # Go into a waiting state for the host to return the save (If you don't call this you don't retransfer the saves - Users cannot under any circumstances miss this function) wait_for_save_return() { build_infoPanel_and_log "Syncing" "Waiting for host to be ready for save sync" - notify_peer "ready_to_receive" + # notify_peer: signal ready to receive save + notify_peer "$hostip" "ready_to_receive" sync @@ -244,28 +250,8 @@ cleanup() { # Use the safe word # Check stop, if the client tells us to stop we will. -check_stop() { - sync - if [ -e "/tmp/stop_now" ]; then - build_infoPanel_and_log "Message from client" "The host has had a problem setting up the session" - sleep 2 - cleanup - fi -} # Notify other MMP -notify_peer() { - local notify_file="/tmp/$1" - touch "$notify_file" - sync - curl -T "$notify_file" "ftp://${hostip}/${notify_file}" >/dev/null 2>&1 # the first / after the IP must be not encoded - - if [ $? -eq 0 ]; then - log "Successfully transferred $notify_file to ftp://${hostip}/${notify_file}" - else - log "Failed to transfer $notify_file to ftp://${hostip}/${notify_file}" - fi -} # Function to sync files @@ -513,7 +499,8 @@ sync_file() { fi sleep 2 if [ "$file_mandatory" = "-m" ]; then - notify_peer "stop_now" + # notify_peer: signal stop to host + notify_peer "$hostip" "stop_now" cleanup fi fi @@ -542,18 +529,6 @@ sync_file() { } # We'll need FTP to transfer files -start_ftp() { - if is_running bftpd; then - log "FTP already running, killing to rebind" - bftpd_p=$(ps | grep bftpd | grep -v grep | awk '{for(i=4;i<=NF;++i) printf $i" "}') - killall -9 bftpd - killall -9 tcpsvd - tcpsvd -E 0.0.0.0 21 ftpd -w / & - else - tcpsvd -E 0.0.0.0 21 ftpd -w / & - log "Starting FTP server" - fi -} # Create a cookie with all the required info for the client. (client will use this cookie) create_cookie_info() { @@ -593,21 +568,6 @@ create_cookie_info() { # This will restore the users original ftp state -build_infoPanel_and_log() { - local title="$1" - local message="$2" - - log "Info Panel: \n\tStage: $title\n\tMessage: $message" - if is_running infoPanel; then - killall -9 infoPanel - fi - infoPanel --title "$title" --message "$message" --persistent & - sync - touch /tmp/dismiss_info_panel - sync - sleep 0.3 - sync -} confirm_join_panel() { local title="$1" @@ -654,25 +614,52 @@ stripped_game_names() { ######### lets_go() { + # Allow user to abort via menu while setup runs pressMenu2Kill $(basename $0) & + + # Write cookie for host (core/rom metadata) create_cookie_info + + # Join host hotspot . "$sysdir/script/network/hotspot_join.sh" - start_ftp + + # Start FTP for file transfers + # start_ftp: start FTP without preflight + start_ftp + + # Send cookie to host sync_file "Cookie" "/mnt/SDCARD/RetroArch/retroarch.cookie" 0 0 -f -m + + # Read host cookie and parse paths/checksums read_cookie + + # Send local save to host backup_and_send_save - # backup_save - # sync_file Rom "$client_rom" # Doesn't sync anything, just uses the sync function to confirm it exists locally + + # Sync required core, rom, and image sync_file "Core" "$core" 1 "$corechecksum" -b -m sync_file "Rom" "$rom" 1 "$romchecksum" -b -m sync_file "Img" "$Img_path" 0 0 -o + + # Build display names for confirmation prompt stripped_game_names + + # Wait for host ready signal wait_for_host + + # Confirm join with host/client info confirm_join_panel "Join now?" "Start the game on the host first! \n $game_name \n $game_name_client" + + # Stop menu watcher before launch pkill -9 pressMenu2Kill + + # Launch RetroArch client session start_retroarch + + # Wait for save return from host wait_for_save_return - # TO DO : export save to Gambatte (with question) + + # Cleanup and restore state cleanup } diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh index e6c3ddc198..7ac2119288 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh @@ -6,6 +6,7 @@ sysdir=/mnt/SDCARD/.tmp_update miyoodir=/mnt/SDCARD/miyoo LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/parasyte" hostip="192.168.100.100" # This should be the default unless the user has changed it.. +peer_ip="$hostip" rm /tmp/stop_now client_rom="$1" romdirname=$(echo "$client_rom" | grep -o '/Roms/[^/]*' | cut -d'/' -f3) @@ -16,7 +17,10 @@ netplaycore="/mnt/SDCARD/RetroArch/.retroarch/cores/gpsp_libretro.so" logfile=pokemon_link # Source scripts . $sysdir/script/log.sh +# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp . $sysdir/script/netplay/netplay_common.sh +# netplay_signalling.sh: wait_for_host, check_stop, notify_stop +. $sysdir/script/netplay/netplay_signalling.sh log "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* Easy Netplay Pokemon Client GBA -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" @@ -24,9 +28,7 @@ log "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* Easy Netplay Pokemon Client GBA -* ##Setup.## ########## -# Wait for the host to tell us it's ready, this happens just before it starts its RA session and we look in /tmp for a file indicator (file removed in host script cleanup) - -# Start retroarch with -C in client mode if everything's gone to plan +# start_retroarch: launch RetroArch in client mode with local ROM start_retroarch() { build_infoPanel_and_log "Starting RA" "Starting RetroArch" @@ -57,6 +59,7 @@ start_retroarch() { fi } +# cleanup: restore network/ftp and clean temp files cleanup() { build_infoPanel_and_log "Cleanup" "Cleaning up after Pokemon session\n Do not power off!" @@ -83,69 +86,10 @@ cleanup() { exit } -########### -#Utilities# -########### - -# Use the safe word - -# Check stop, if the client tells us to stop we will. -check_stop() { - sync - if [ -e "/tmp/stop_now" ]; then - build_infoPanel_and_log "Message from client" "The host has had a problem setting up the session" - sleep 2 - cleanup - fi -} - -# Notify other MMP -notify_peer() { - local notify_file="/tmp/$1" - touch "$notify_file" - sync - curl -T "$notify_file" "ftp://${hostip}/${notify_file}" >/dev/null 2>&1 # the first / after the IP must be not encoded - - if [ $? -eq 0 ]; then - log "Successfully transferred $notify_file to ftp://${hostip}/${notify_file}" - else - log "Failed to transfer $notify_file to ftp://${hostip}/${notify_file}" - fi -} - -# We'll need FTP to transfer files -start_ftp() { - if is_running bftpd; then - log "FTP already running, killing to rebind" - bftpd_p=$(ps | grep bftpd | grep -v grep | awk '{for(i=4;i<=NF;++i) printf $i" "}') - killall -9 bftpd - killall -9 tcpsvd - tcpsvd -E 0.0.0.0 21 ftpd -w / & - else - tcpsvd -E 0.0.0.0 21 ftpd -w / & - log "Starting FTP server" - fi -} - -# This will restore the users original ftp state - - -build_infoPanel_and_log() { - local title="$1" - local message="$2" - log "Info Panel: \n\tStage: $title\n\tMessage: $message" - if is_running infoPanel; then - killall -9 infoPanel - fi - infoPanel --title "$title" --message "$message" --persistent & - sync - touch /tmp/dismiss_info_panel - sync - sleep 0.3 - sync -} +# build_infoPanel_and_log: show persistent infoPanel and log message +# confirm_join_panel: show join confirmation UI with local ROM image confirm_join_panel() { local title="$1" local message="$2" @@ -169,29 +113,48 @@ confirm_join_panel() { fi } +# stripped_game_names: format local ROM display name stripped_game_names() { client_rom_trimmed="$(echo "$client_rom_filename_NoExt" | sed -e 's/ ([^()]*)//g' -e 's/ [[A-z0-9!+]*]//g' -e 's/([^()]*)//g' -e 's/[[A-z0-9!+]*]//g')" game_name_client="Client (me): \n$client_rom_trimmed" } - - ######### ##Main.## ######### +# lets_go: main flow for joining GBA session lets_go() { + # Allow user to abort via menu while setup runs pressMenu2Kill $(basename $0) & + + # Ensure ROM path is provided if [ -z "$client_rom" ]; then build_infoPanel_and_log "Error" "No ROM path provided." exit 1 fi + + # Join host hotspot . "$sysdir/script/network/hotspot_join.sh" + + # Start FTP for lightweight signaling start_ftp + + # Build display names for confirmation prompt stripped_game_names + + # Wait for host ready signal wait_for_host + + # Confirm join with local ROM display confirm_join_panel "Join now?" "Start the game on the host first! \n $game_name_client" + + # Stop menu watcher before launch pkill -9 pressMenu2Kill + + # Launch RetroArch client session start_retroarch + + # Cleanup and restore state cleanup } diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh index 0ae4439cbc..d45109ea17 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh @@ -14,6 +14,7 @@ export LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/p logfile=easy_netplay # Source scripts . $sysdir/script/log.sh +# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp . $sysdir/script/netplay/netplay_common.sh program=$(basename "$0" .sh) @@ -22,18 +23,6 @@ program=$(basename "$0" .sh) ########## # We'll need FTP to host the cookie to the client - use the built in FTP, it allows us to curl (errors on bftpd re: path) -start_ftp() { - if is_running bftpd; then - log "FTP already running, killing to rebind" - bftpd_p=$(ps | grep bftpd | grep -v grep | awk '{for(i=4;i<=NF;++i) printf $i" "}') - killall -9 bftpd - killall -9 tcpsvd - tcpsvd -E 0.0.0.0 21 ftpd -w / & - else - tcpsvd -E 0.0.0.0 21 ftpd -w / & - log "Starting FTP server" - fi -} # Find the recommended core for the current system. Get_NetplayCore() { @@ -144,42 +133,34 @@ cleanup() { } -########### -#Utilities# -########### - -build_infoPanel_and_log() { - local title="$1" - local message="$2" - - log "Info Panel: \n\tStage: $title\n\tMessage: $message" - if is_running infoPanel; then - killall -9 infoPanel - fi - infoPanel --title "$title" --message "$message" --persistent & - sync - touch /tmp/dismiss_info_panel - sync - sleep 0.3 - sync -} - - - - - ######### ##Main.## ######### lets_go() { + # Allow user to abort via menu while setup runs pressMenu2Kill $(basename $0) & + + # Create hotspot for client . "$sysdir/script/network/hotspot_create.sh" + + # Start FTP for cookie transfer + # start_ftp: start FTP without preflight start_ftp + + # Determine netplay core based on ROM/core config Get_NetplayCore + + # Write cookie with core/rom metadata create_cookie_info + + # Stop menu watcher before launch pkill -9 pressMenu2Kill + + # Launch RetroArch host session start_retroarch + + # Cleanup and restore state cleanup } diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh index 859bc12981..3367aabbef 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh @@ -5,11 +5,15 @@ sysdir=/mnt/SDCARD/.tmp_update miyoodir=/mnt/SDCARD/miyoo LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/parasyte" +INFOPANEL_SLEEP=0.5 logfile=pokemon_link # Source scripts . $sysdir/script/log.sh +# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp . $sysdir/script/netplay/netplay_common.sh +# netplay_signalling.sh: wait_for_client, ready_up, notify_peer, check_stop, notify_stop +. $sysdir/script/netplay/netplay_signalling.sh program=$(basename "$0" .sh) rm /tmp/stop_now @@ -26,29 +30,6 @@ log "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* Easy Netplay Pokemon Host -*-*-*-* ########## # We'll need wifi up for this. Lets try and start it.. -check_wifi() { - if ifconfig wlan0 &>/dev/null; then - build_infoPanel_and_log "WIFI" "Wifi up" - else - build_infoPanel_and_log "WIFI" "Wifi disabled, starting..." - - /customer/app/axp_test wifion - sleep 2 - ifconfig wlan0 up - sleep 1 - $miyoodir/app/wpa_supplicant -B -D nl80211 -iwlan0 -c /appconfigs/wpa_supplicant.conf - udhcpc_control - - if is_running wpa_supplicant && ifconfig wlan0 >/dev/null 2>&1; then - build_infoPanel_and_log "WIFI" "Wifi started." - else - build_infoPanel_and_log "WIFI" "Unable to start WiFi\n unable to continue." - notify_stop - fi - - sleep 2 - fi -} # We'll need hotspot to host the local connection start_hotspot() { @@ -65,19 +46,6 @@ start_hotspot() { } # We'll need FTP to host the cookie to the client - use the built in FTP, it allows us to curl (errors on bftpd re: path) -start_ftp() { - check_stop - if is_running bftpd; then - log "FTP already running, killing to rebind" - bftpd_p=$(ps | grep bftpd | grep -v grep | awk '{for(i=4;i<=NF;++i) printf $i" "}') - killall -9 bftpd - killall -9 tcpsvd - tcpsvd -E 0.0.0.0 21 ftpd -w / & - else - tcpsvd -E 0.0.0.0 21 ftpd -w / & - log "Starting FTP server" - fi -} # Create a cookie with all the required info for the client. (client will use this cookie) create_cookie_info() { @@ -119,7 +87,8 @@ create_cookie_info() { # Backup the save we're going to use before we do anythign else host_save_backup() { - check_stop + # check_stop: client reported a setup/join issue + check_stop "The client has had a problem joining the session." mkdir -p "/mnt/SDCARD/Saves/CurrentProfile/saves/TGB Dual" save_gambatte="/mnt/SDCARD/Saves/CurrentProfile/saves/Gambatte/$host_rom_filename_NoExt.srm" save_tgbdual="/mnt/SDCARD/Saves/CurrentProfile/saves/TGB Dual/$host_rom_filename_NoExt.srm" @@ -147,7 +116,8 @@ host_save_backup() { # The client will send us a save file, we'll pull the name from this, find it on the host and call duplicate_rename_rom - send to tmp client_save_get() { - check_stop + # check_stop: client reported a setup/join issue + check_stop "The client has had a problem joining the session." build_infoPanel_and_log "Setting up" "Setting up session \n Waiting for save files." client_save_file="" @@ -180,7 +150,8 @@ client_save_get() { # Prep the clients save file client_save_rename() { - check_stop + # check_stop: client reported a setup/join issue + check_stop "The client has had a problem joining the session." if [ ! -z "$client_save_file" ]; then save_base_name=$(basename "$client_save_file" .srm) save_new_name="${save_base_name}_client.srm" @@ -241,7 +212,8 @@ client_read_cookie() { # Duplicate the rom to spoof the save loaded in on the host client_rom_rename() { - check_stop + # check_stop: client reported a setup/join issue + check_stop "The client has had a problem joining the session." rom_extension="${client_rom##*.}" client_rom_clone="${client_rom%.*}_client.$rom_extension" @@ -273,7 +245,8 @@ start_retroarch() { cd /mnt/SDCARD/RetroArch log "Starting RetroArch loaded with $host_rom and $client_rom_clone" - (sleep 2 && notify_peer "host_ready" &) & + # notify_peer: signal host ready to client + (sleep 2 && notify_peer "$client_ip" "host_ready" &) & HOME=/mnt/SDCARD/RetroArch ./retroarch --appendconfig=./.retroarch/easynetplay_override.cfg -H -v -L .retroarch/cores/tgbdual_libretro.so --subsystem "gb_link_2p" "$host_rom" "$client_rom_clone" if [ -n "$PreviousCPUspeed" ]; then @@ -299,11 +272,13 @@ host_save_overwrite() { # Go into a waiting state for the client to be ready to accept the save client_wait_for_save_return() { - check_stop + # check_stop: client reported a setup/join issue + check_stop "The client has had a problem joining the session." local counter=0 build_infoPanel_and_log "Syncing" "Waiting for client to be ready for save sync" - notify_peer "ready_to_send" + # notify_peer: signal ready to send save + notify_peer "$client_ip" "ready_to_send" sync while true; do @@ -328,7 +303,8 @@ client_wait_for_save_return() { # Push the clients save file back client_save_send() { - check_stop + # check_stop: client reported a setup/join issue + check_stop "The client has had a problem joining the session." build_infoPanel_and_log "Syncing" "Returning client save..." received_save="tmp/$(basename "${save_new_path/_client/}")" encoded_path=$(url_encode "${received_save}") @@ -378,27 +354,7 @@ cleanup() { # Use the safe word # Check stop, if the client tells us to stop we will. -check_stop() { - sync - if [ -e "/tmp/stop_now" ]; then - build_infoPanel_and_log "Message from client" "The client has had a problem joining the session." - sleep 2 - cleanup - fi -} - -notify_peer() { - local notify_file="/tmp/$1" - touch "$notify_file" - sync - curl -T "$notify_file" "ftp://${client_ip}/${notify_file}" >/dev/null 2>&1 # the first / after the IP must be not encoded - if [ $? -eq 0 ]; then - log "Successfully transferred $notify_file to ftp://${client_ip}/${notify_file}" - else - log "Failed to transfer $notify_file to ftp://${client_ip}/${notify_file}" - fi -} # Rename the new save back to the original one ready to be re-transferred remove_client_save_suffix() { @@ -702,7 +658,8 @@ sync_file() { fi sleep 2 if [ "$file_mandatory" = "-m" ]; then - notify_peer "stop_now" + # notify_peer: signal stop to client + notify_peer "$client_ip" "stop_now" cleanup fi fi @@ -744,21 +701,6 @@ unpack_rom() { fi } -build_infoPanel_and_log() { - local title="$1" - local message="$2" - - log "Info Panel: \n\tStage: $title\n\tMessage: $message" - if is_running infoPanel; then - killall -9 infoPanel - fi - infoPanel --title "$title" --message "$message" --persistent & - sync - touch /tmp/dismiss_info_panel - sync - sleep 0.5 - sync -} @@ -770,27 +712,65 @@ build_infoPanel_and_log() { ######### lets_go() { + # Allow user to abort via menu while setup runs pressMenu2Kill $(basename $0) & + + # Ensure WiFi is up (udhcpc, hard fail, keep wlan1) + # check_wifi: use udhcpc, hard fail, keep wlan1 + check_wifi 1 1 0 + + # Write cookie with host metadata create_cookie_info + + # Create hotspot for client . "$sysdir/script/network/hotspot_create.sh" - start_ftp + + # Start FTP with preflight stop check + # start_ftp: preflight check_stop for client join issues + start_ftp "The client has had a problem joining the session." + + # Wait for client connection wait_for_client - sync_file "Cookie" "/mnt/SDCARD/RetroArch/retroarch.cookie" 0 0 -f -m # will be downloaded as retroarch.cookie.client ! + + # Send cookie to client (downloaded as retroarch.cookie.client) + sync_file "Cookie" "/mnt/SDCARD/RetroArch/retroarch.cookie" 0 0 -f -m + + # Read client cookie for display and params client_read_cookie + + # Backup host save and fetch client save host_save_backup client_save_get client_save_rename + + # Sync client ROM and prepare local clone sync_file "Rom" "$client_rom" 1 "$romchecksum" -b -m client_rom_rename + + # Signal client that host is ready ready_up + + # Sync client image for confirmation display sync_file "Img" "$client_Img_path" 0 0 -o + + # Build display names for confirmation prompt stripped_game_names + + # Confirm host start with host/client info confirm_join_panel "Host now?" "$host_game_name \n $client_game_name" + + # Stop menu watcher before launch pkill -9 pressMenu2Kill + + # Launch RetroArch host session start_retroarch + + # Restore saves and send back to client host_save_overwrite client_wait_for_save_return client_save_send + + # Cleanup and restore state cleanup } diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh index 2b2ce4e0c6..1758d3b727 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh @@ -5,11 +5,15 @@ sysdir=/mnt/SDCARD/.tmp_update miyoodir=/mnt/SDCARD/miyoo LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/parasyte" +INFOPANEL_SLEEP=0.5 logfile=pokemon_link # Source scripts . $sysdir/script/log.sh +# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp . $sysdir/script/netplay/netplay_common.sh +# netplay_signalling.sh: wait_for_client, ready_up, notify_peer, check_stop, notify_stop +. $sysdir/script/netplay/netplay_signalling.sh rm /tmp/stop_now host_rom="$1" @@ -24,26 +28,8 @@ log "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* Easy Netplay Pokemon Host GBA -*-* ##Setup.## ########## -# We'll need FTP for lightweight signaling - use the built in FTP, it allows us to curl (errors on bftpd re: path) -start_ftp() { - check_stop - if is_running bftpd; then - log "FTP already running, killing to rebind" - bftpd_p=$(ps | grep bftpd | grep -v grep | awk '{for(i=4;i<=NF;++i) printf $i" "}') - killall -9 bftpd - killall -9 tcpsvd - tcpsvd -E 0.0.0.0 21 ftpd -w / & - else - tcpsvd -E 0.0.0.0 21 ftpd -w / & - log "Starting FTP server" - fi -} -# Wait for a hit on the sta list for someone joining the hotspot - -# Tell the client we're ready to accept connections - -# We'll start Retroarch in host mode with -H with the core and rom paths loaded in. +# start_retroarch: launch RetroArch in host mode with the local ROM start_retroarch() { log "\n############################ RETROARCH DEBUGGING ############################" @@ -60,7 +46,8 @@ start_retroarch() { cd /mnt/SDCARD/RetroArch log "Starting RetroArch loaded with $host_rom" - (sleep 2 && notify_peer "host_ready" &) & + # notify_peer: signal host ready to client + (sleep 2 && notify_peer "$client_ip" "host_ready" &) & HOME=/mnt/SDCARD/RetroArch ./retroarch --appendconfig=./.retroarch/easynetplay_override.cfg -H -v -L .retroarch/cores/gpsp_libretro.so "$host_rom" if [ -n "$PreviousCPUspeed" ]; then @@ -71,7 +58,7 @@ start_retroarch() { fi } -# Cleanup. If you don't call this you don't retransfer the saves - Users cannot under any circumstances miss this function. +# cleanup: restore network/ftp and clean temp files cleanup() { build_infoPanel_and_log "Cleanup" "Cleaning up after Pokemon session\n Do not power off!" @@ -95,35 +82,7 @@ cleanup() { exit } -########### -#Utilities# -########### - -# Use the safe word - -# Check stop, if the client tells us to stop we will. -check_stop() { - sync - if [ -e "/tmp/stop_now" ]; then - build_infoPanel_and_log "Message from client" "The client has had a problem joining the session." - sleep 2 - cleanup - fi -} - -notify_peer() { - local notify_file="/tmp/$1" - touch "$notify_file" - sync - curl -T "$notify_file" "ftp://${client_ip}/${notify_file}" >/dev/null 2>&1 # the first / after the IP must be not encoded - - if [ $? -eq 0 ]; then - log "Successfully transferred $notify_file to ftp://${client_ip}/${notify_file}" - else - log "Failed to transfer $notify_file to ftp://${client_ip}/${notify_file}" - fi -} - +# confirm_join_panel: show host confirmation UI with local ROM image confirm_join_panel() { local title="$1" local message="$2" @@ -154,51 +113,56 @@ confirm_join_panel() { fi } +# stripped_game_names: format local ROM display name stripped_game_names() { host_game_name="$(basename "${host_rom%.*}")" host_game_name="$(echo "$host_game_name" | sed -e 's/ ([^()]*)//g' -e 's/ [[A-z0-9!+]*]//g' -e 's/([^()]*)//g' -e 's/[[A-z0-9!+]*]//g')" host_game_name="Host (me): \n$host_game_name" } -build_infoPanel_and_log() { - local title="$1" - local message="$2" - - log "Info Panel: \n\tStage: $title\n\tMessage: $message" - if is_running infoPanel; then - killall -9 infoPanel - fi - infoPanel --title "$title" --message "$message" --persistent & - sync - touch /tmp/dismiss_info_panel - sync - sleep 0.5 - sync -} - - - - +# build_infoPanel_and_log: show persistent infoPanel and log message ######### ##Main.## ######### +# lets_go: main flow for hosting GBA session lets_go() { + # Allow user to abort via menu while setup runs pressMenu2Kill $(basename $0) & + + # Ensure ROM path is provided if [ -z "$host_rom" ]; then build_infoPanel_and_log "Error" "No ROM path provided." exit 1 fi + + # Create hotspot for client . "$sysdir/script/network/hotspot_create.sh" - start_ftp + + # Start FTP with preflight stop check + start_ftp "The client has had a problem joining the session." + + # Wait for client connection wait_for_client + + # Signal client that host is ready ready_up + + # Build display names for confirmation prompt stripped_game_names + + # Confirm host start with local ROM display confirm_join_panel "Host now?" "$host_game_name" + + # Stop menu watcher before launch pkill -9 pressMenu2Kill + + # Launch RetroArch host session start_retroarch + + # Cleanup and restore state cleanup } diff --git a/static/build/.tmp_update/script/netplay/netplay_common.sh b/static/build/.tmp_update/script/netplay/netplay_common.sh index c966d72aad..c080026814 100644 --- a/static/build/.tmp_update/script/netplay/netplay_common.sh +++ b/static/build/.tmp_update/script/netplay/netplay_common.sh @@ -1,5 +1,8 @@ # Shared netplay helpers +# checksize_func +# - uses: file_check_size, file_path, remote_file_checksum +# - sets: same_size checksize_func() { if [ "$file_check_size" -eq 1 ]; then if [ -e "$file_path" ]; then @@ -19,6 +22,9 @@ checksize_func() { fi } +# checksum_func +# - uses: MAX_FILE_CHKSUM_SIZE +# - sets: same_chksum checksum_func() { local_file_size=$(stat -c%s "$file_path") local func_file_path="$1" @@ -44,38 +50,49 @@ checksum_func() { fi } +# enable_flag +# - creates $sysdir/config/. enable_flag() { flag="$1" touch "$sysdir/config/.$flag" } +# flag_enabled +# - returns 0 if flag file exists flag_enabled() { flag="$1" [ -f "$sysdir/config/.$flag" ] } +# is_running +# - returns 0 if process is running is_running() { process_name="$1" pgrep "$process_name" >/dev/null } -notify_stop() { - notify_peer "stop_now" - sleep 2 - cleanup -} - -ready_up() { - check_stop - ping -c 5 $client_ip >/dev/null 2>&1 - if [ $? -eq 0 ]; then - notify_peer "host_ready" - else - build_infoPanel_and_log "Error" "No connectivity to $client_ip, \n is the client still connected?" - notify_stop +# build_infoPanel_and_log <message> +# - uses: INFOPANEL_SLEEP (default 0.3s) +# - shows persistent infoPanel and logs message +build_infoPanel_and_log() { + local title="$1" + local message="$2" + local delay="${INFOPANEL_SLEEP:-0.3}" + + log "Info Panel: \n\tStage: $title\n\tMessage: $message" + if is_running infoPanel; then + killall -9 infoPanel fi + infoPanel --title "$title" --message "$message" --persistent & + sync + touch /tmp/dismiss_info_panel + sync + sleep "$delay" + sync } +# restore_ftp +# - restores original FTP state based on flags restore_ftp() { log "Restoring original FTP server" killall -9 tcpsvd @@ -88,6 +105,8 @@ restore_ftp() { fi } +# udhcpc_control +# - restarts udhcpc on wlan0 udhcpc_control() { if pgrep udhcpc >/dev/null; then killall -9 udhcpc @@ -96,6 +115,8 @@ udhcpc_control() { udhcpc -i wlan0 -s /etc/init.d/udhcpc.script >/dev/null 2>&1 & } +# url_encode <string> +# - percent-encodes string for URLs url_encode() { local string="$1" local length="${#string}" @@ -113,79 +134,63 @@ url_encode() { echo "$encoded" } -wait_for_client() { - check_stop - build_infoPanel_and_log "Hotspot" "Waiting for a client to connect..." - - client_ip="" - client_mac="" - counter=0 - - killall -9 wpa_supplicant - killall -9 udhcpc - - sleep 1 - - while true; do - sta_list=$($sysdir/bin/hostapd_cli all_sta 2>/dev/null) - $sysdir/bin/hostapd_cli all_sta flush - - if [ $? -ne 0 ]; then - build_infoPanel_and_log "Hotspot" "Hostapd hook failing, retrying." - counter=$((counter + 1)) - fi +# start_ftp [check_stop_message] +# - starts built-in FTP server for signaling +# - if a message is provided, check_stop is invoked with it first +start_ftp() { + if [ -n "$1" ]; then + check_stop "$1" + fi + if is_running bftpd; then + log "FTP already running, killing to rebind" + bftpd_p=$(ps | grep bftpd | grep -v grep | awk '{for(i=4;i<=NF;++i) printf $i\" \"}') + killall -9 bftpd + killall -9 tcpsvd + tcpsvd -E 0.0.0.0 21 ftpd -w / & + else + tcpsvd -E 0.0.0.0 21 ftpd -w / & + log "Starting FTP server" + fi +} +# check_wifi <use_udhcpc> <hard_fail> <down_wlan1> +# - use_udhcpc: 1 to call udhcpc_control after wpa_supplicant +# - hard_fail: 1 to notify_stop on failure, 0 to just pause +# - down_wlan1: 1 to bring wlan1 down before checks +check_wifi() { + local use_udhcpc="$1" + local hard_fail="$2" + local down_wlan1="$3" + + if [ "$down_wlan1" -eq 1 ]; then + ifconfig wlan1 down + fi - if [ ! -z "$sta_list" ]; then - client_mac=$(echo "$sta_list" | awk 'NR==2{print $1; exit}') - client_ip=$(arp -an | awk '/"'"$client_mac"'"/ {gsub(/[\(\)]/,""); print $2}') - - if [ ! -z "$client_ip" ]; then - case "$client_ip" in - 192.168.100.*) - log "$sta_list" - log "A client has connected. IP: $client_ip" - build_infoPanel_and_log "Hotspot" "A client has connected! \n IP: $client_ip" - break - ;; - esac - fi - fi + if ifconfig wlan0 &>/dev/null; then + log "Wifi up" + else + build_infoPanel_and_log "WIFI" "Wifi disabled, starting..." + /customer/app/axp_test wifion + sleep 2 + ifconfig wlan0 up sleep 1 - counter=$((counter + 1)) + $miyoodir/app/wpa_supplicant -B -D nl80211 -iwlan0 -c /appconfigs/wpa_supplicant.conf - if [ $counter -ge 30 ]; then - log "No client has connected" - build_infoPanel_and_log "Hotspot error" "No client has connected. Exiting..." - cleanup + if [ "$use_udhcpc" -eq 1 ]; then + udhcpc_control fi - done - sleep 1 - log "$client_ip has joined the hotspot" -} - -wait_for_host() { - local counter=0 - - build_infoPanel_and_log "Ready" "Waiting for host to ready up" - while true; do - sync - check_stop - for file in /tmp/host_ready; do - if [ -f "$file" ]; then - build_infoPanel_and_log "Message from host" "Setup complete" - rm /tmp/host_ready # be ready for the second use of host_ready flag - break 2 + if is_running wpa_supplicant && ifconfig wlan0 >/dev/null 2>&1; then + build_infoPanel_and_log "WIFI" "Wifi started." + else + build_infoPanel_and_log "WIFI" "Unable to start WiFi\n unable to continue." + if [ "$hard_fail" -eq 1 ]; then + notify_stop + else + sleep 1 fi - done - - sleep 1 - counter=$((counter + 1)) - - if [ $counter -ge 25 ]; then - build_infoPanel_and_log "Error" "The host didn't ready up, cannot continue..." - notify_stop fi - done + + sleep 2 + fi } diff --git a/static/build/.tmp_update/script/netplay/netplay_signalling.sh b/static/build/.tmp_update/script/netplay/netplay_signalling.sh new file mode 100644 index 0000000000..c94985f627 --- /dev/null +++ b/static/build/.tmp_update/script/netplay/netplay_signalling.sh @@ -0,0 +1,154 @@ +# Netplay signalling helpers + +# notify_peer [target_ip] <flag> +# - uses: peer_ip if target_ip is omitted +# - sends /tmp/<flag> via FTP to peer +notify_peer() { + local target_ip="" + local notify_flag="" + + if [ $# -eq 1 ]; then + target_ip="$peer_ip" + notify_flag="$1" + else + target_ip="$1" + notify_flag="$2" + fi + + if [ -z "$target_ip" ]; then + log "No peer IP set for notify_peer ($notify_flag)." + return 1 + fi + + local notify_file="/tmp/$notify_flag" + touch "$notify_file" + sync + curl -T "$notify_file" "ftp://${target_ip}/${notify_file}" >/dev/null 2>&1 # the first / after the IP must be not encoded + + if [ $? -eq 0 ]; then + log "Successfully transferred $notify_file to ftp://${target_ip}/${notify_file}" + else + log "Failed to transfer $notify_file to ftp://${target_ip}/${notify_file}" + fi +} + +# check_stop [message] +# - uses: /tmp/stop_now sentinel to abort +check_stop() { + local message="$1" + sync + if [ -e "/tmp/stop_now" ]; then + build_infoPanel_and_log "Message from client" "${message:-The client has had a problem joining the session.}" + sleep 2 + cleanup + fi +} + +# notify_stop +# - best-effort notify peer and cleanup +notify_stop() { + # notify_peer: best-effort stop signal to peer + notify_peer "stop_now" >/dev/null 2>&1 + sleep 2 + cleanup +} + +# ready_up +# - pings client_ip then signals host_ready +ready_up() { + # check_stop: client reported a setup/join issue + check_stop "The client has had a problem joining the session." + ping -c 5 $client_ip >/dev/null 2>&1 + if [ $? -eq 0 ]; then + # notify_peer: signal host ready to client + notify_peer "$client_ip" "host_ready" + else + build_infoPanel_and_log "Error" "No connectivity to $client_ip, \n is the client still connected?" + notify_stop + fi +} + +# wait_for_client +# - waits for client connection on hotspot +# - sets: client_ip, peer_ip +wait_for_client() { + # check_stop: client reported a setup/join issue + check_stop "The client has had a problem joining the session." + build_infoPanel_and_log "Hotspot" "Waiting for a client to connect..." + + client_ip="" + client_mac="" + counter=0 + + killall -9 wpa_supplicant + killall -9 udhcpc + + sleep 1 + + while true; do + sta_list=$($sysdir/bin/hostapd_cli all_sta 2>/dev/null) + $sysdir/bin/hostapd_cli all_sta flush + + if [ $? -ne 0 ]; then + build_infoPanel_and_log "Hotspot" "Hostapd hook failing, retrying." + counter=$((counter + 1)) + fi + + if [ ! -z "$sta_list" ]; then + client_mac=$(echo "$sta_list" | awk 'NR==2{print $1; exit}') + client_ip=$(arp -an | awk '/"'"$client_mac"'"/ {gsub(/[\(\)]/,""); print $2}') + + if [ ! -z "$client_ip" ]; then + case "$client_ip" in + 192.168.100.*) + log "$sta_list" + log "A client has connected. IP: $client_ip" + build_infoPanel_and_log "Hotspot" "A client has connected! \n IP: $client_ip" + peer_ip="$client_ip" + break + ;; + esac + fi + fi + + sleep 1 + counter=$((counter + 1)) + + if [ $counter -ge 30 ]; then + log "No client has connected" + build_infoPanel_and_log "Hotspot error" "No client has connected. Exiting..." + cleanup + fi + done + + sleep 1 + log "$client_ip has joined the hotspot" +} + +# wait_for_host +# - waits for /tmp/host_ready signal +wait_for_host() { + local counter=0 + + build_infoPanel_and_log "Ready" "Waiting for host to ready up" + while true; do + sync + # check_stop: host reported a setup issue + check_stop "The host has had a problem setting up the session" + for file in /tmp/host_ready; do + if [ -f "$file" ]; then + build_infoPanel_and_log "Message from host" "Setup complete" + rm /tmp/host_ready # be ready for the second use of host_ready flag + break 2 + fi + done + + sleep 1 + counter=$((counter + 1)) + + if [ $counter -ge 25 ]; then + build_infoPanel_and_log "Error" "The host didn't ready up, cannot continue..." + notify_stop + fi + done +} diff --git a/static/build/.tmp_update/script/netplay/standard-netplay.sh b/static/build/.tmp_update/script/netplay/standard-netplay.sh index f79141197c..c2e73a034f 100644 --- a/static/build/.tmp_update/script/netplay/standard-netplay.sh +++ b/static/build/.tmp_update/script/netplay/standard-netplay.sh @@ -8,6 +8,7 @@ sysdir=/mnt/SDCARD/.tmp_update miyoodir=/mnt/SDCARD/miyoo export LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/parasyte" +INFOPANEL_SLEEP=0.5 romfullpath="$1" romname=$(basename "$1") echo "cookie_core_path $cookie_core_path" @@ -17,6 +18,7 @@ NetplayAction="$3" # host or join logfile=netplay # Source scripts . $sysdir/script/log.sh +# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp . $sysdir/script/netplay/netplay_common.sh program=$(basename "$0" .sh) @@ -25,29 +27,6 @@ program=$(basename "$0" .sh) ########## # We'll need wifi up for this. Lets try and start it.. -check_wifi() { - ifconfig wlan1 down - if ifconfig wlan0 &>/dev/null; then - log "Wifi up" - else - build_infoPanel_and_log "WIFI" "Wifi disabled, starting..." - - /customer/app/axp_test wifion - sleep 2 - ifconfig wlan0 up - sleep 1 - $miyoodir/app/wpa_supplicant -B -D nl80211 -iwlan0 -c /appconfigs/wpa_supplicant.conf - - if is_running wpa_supplicant && ifconfig wlan0 >/dev/null 2>&1; then - build_infoPanel_and_log "WIFI" "Wifi started." - else - build_infoPanel_and_log "WIFI" "Unable to start WiFi\n unable to continue." - sleep 1 - fi - - sleep 2 - fi -} # Find the recommended core for the current system. Get_NetplayCore() { @@ -129,21 +108,6 @@ Check_PlayerName() { #Utilities# ########### -build_infoPanel_and_log() { - local title="$1" - local message="$2" - - log "Info Panel: \n\tStage: $title\n\tMessage: $message" - if is_running infoPanel; then - killall -9 infoPanel - fi - infoPanel --title "$title" --message "$message" --persistent & - sync - touch /tmp/dismiss_info_panel - sync - sleep 0.5 - sync -} ######### @@ -151,7 +115,11 @@ build_infoPanel_and_log() { ######### lets_go() { - check_wifi + # Ensure WiFi is ready (no udhcpc, soft fail, down wlan1) + # check_wifi: no udhcpc, soft fail, down wlan1 + check_wifi 0 0 1 + + # Determine netplay core based on platform Get_NetplayCore "$CurrentSystem" if [ $? -eq 0 ]; then echo "*****************************************" @@ -164,7 +132,11 @@ lets_go() { else exit fi + + # Validate player name before launch Check_PlayerName + + # Launch RetroArch netplay session start_retroarch } From 418f06cb0e0f19ed237cc3c4599b37ef1cd54160 Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Sat, 17 Jan 2026 22:00:26 +0000 Subject: [PATCH 03/32] *untested* some comments --- .../.tmp_update/script/netplay/easy-netplay_client_pokemon.sh | 1 - static/build/.tmp_update/script/netplay/easy-netplay_server.sh | 1 - .../.tmp_update/script/netplay/easy-netplay_server_pokemon.sh | 1 - 3 files changed, 3 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh index 4cd9da8cff..1ccef63b10 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh @@ -623,7 +623,6 @@ lets_go() { # Join host hotspot . "$sysdir/script/network/hotspot_join.sh" - # Start FTP for file transfers # start_ftp: start FTP without preflight start_ftp diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh index d45109ea17..2438d5c33b 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh @@ -144,7 +144,6 @@ lets_go() { # Create hotspot for client . "$sysdir/script/network/hotspot_create.sh" - # Start FTP for cookie transfer # start_ftp: start FTP without preflight start_ftp diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh index 3367aabbef..9953d4ebd0 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh @@ -725,7 +725,6 @@ lets_go() { # Create hotspot for client . "$sysdir/script/network/hotspot_create.sh" - # Start FTP with preflight stop check # start_ftp: preflight check_stop for client join issues start_ftp "The client has had a problem joining the session." From 0cb0ca9b9e1bd7e362f658ee65f42ddd8b809a00 Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Sat, 17 Jan 2026 22:05:15 +0000 Subject: [PATCH 04/32] move read_cookie into netplay_common.sh --- .../script/netplay/easy-netplay_client.sh | 42 +---------- .../netplay/easy-netplay_client_pokemon.sh | 70 +------------------ .../netplay/easy-netplay_server_pokemon.sh | 20 ------ .../script/netplay/netplay_common.sh | 53 ++++++++++++++ 4 files changed, 57 insertions(+), 128 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh index cdf0c969b2..fb8466dda8 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh @@ -17,7 +17,7 @@ peer_ip="$hostip" logfile=easy_netplay # Source scripts . $sysdir/script/log.sh -# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp +# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, read_cookie, check_wifi, start_ftp . $sysdir/script/netplay/netplay_common.sh program=$(basename "$0" .sh) @@ -26,46 +26,6 @@ program=$(basename "$0" .sh) ########## # Read the cookie and store the paths and checksums into a var. -read_cookie() { - sync - while IFS= read -r line; do - case $line in - "[core]: "*) - core="${line##"[core]: "}" - ;; - "[rom]: "*) - rom="${line##"[rom]: "}" - ;; - "[coresize]: "*) - corechecksum="${line##"[coresize]: "}" - ;; - "[corechksum]: "*) - corechecksum="${line##"[corechksum]: "}" - ;; - "[romsize]: "*) - romchecksum="${line##"[romsize]: "}" - ;; - "[romchksum]: "*) - romchecksum="${line##"[romchksum]: "}" - ;; - "[cpuspeed]: "*) - cpuspeed="${line##"[cpuspeed]: "}" - ;; - esac - log "$core $rom $coresize $corechksum $romsize $romchksum" - done <"/mnt/SDCARD/RetroArch/retroarch.cookie.client" - - #url encode or curl complains - export core_url=$(url_encode "$core") - export rom_url=$(url_encode "$rom") - - romdirname=$(echo "$rom" | grep -o '/Roms/[^/]*' | cut -d'/' -f3) - romName=$(basename "$rom") - romNameNoExtension=${romName%.*} - Img_path="/mnt/SDCARD/Roms/$romdirname/Imgs/$romNameNoExtension.png" - - log "Cookie file read" -} sync_file() { diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh index 1ccef63b10..79745d2fec 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh @@ -19,7 +19,7 @@ SaveFromGambatte=0 logfile=pokemon_link # Source scripts . $sysdir/script/log.sh -# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp +# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, read_cookie, check_wifi, start_ftp . $sysdir/script/netplay/netplay_common.sh # netplay_signalling.sh: check_stop, notify_peer, notify_stop, wait_for_host . $sysdir/script/netplay/netplay_signalling.sh @@ -32,52 +32,6 @@ log "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* Easy Netplay Pokemon Client -*-*-* ##Setup.## ########## -# Read the cookie and store the paths and checksums into a var. -read_cookie() { - sync - while IFS= read -r line; do - case $line in - "[core]: "*) - core="${line##"[core]: "}" - ;; - "[rom]: "*) - rom="${line##"[rom]: "}" - ;; - "[coresize]: "*) - corechecksum="${line##"[coresize]: "}" - ;; - "[corechksum]: "*) - corechecksum="${line##"[corechksum]: "}" - ;; - "[romsize]: "*) - romchecksum="${line##"[romsize]: "}" - ;; - "[romchksum]: "*) - romchecksum="${line##"[romchksum]: "}" - ;; - "[cpuspeed]: "*) - cpuspeed="${line##"[cpuspeed]: "}" - ;; - esac - log "$core $rom $coresize $corechksum $romsize $romchksum" - done <"/mnt/SDCARD/RetroArch/retroarch.cookie.client" - - #url encode or curl complains - export core_url=$(url_encode "$core") - export rom_url=$(url_encode "$rom") - - romdirname=$(echo "$rom" | grep -o '/Roms/[^/]*' | cut -d'/' -f3) - romName=$(basename "$rom") - romNameNoExtension=${romName%.*} - Img_path="/mnt/SDCARD/Roms/$romdirname/Imgs/$romNameNoExtension.png" - log "Cookie file read :" - log "romdirname $romdirname" - log "romName $romName" - log "romNameNoExtension $romNameNoExtension" - log "Img_path $Img_path" - -} - # Push our save over to the host - The save will be found based on the rom we've started GLO on and it will look in the $save_dir path for it (see line13) - Backs up first backup_and_send_save() { # check_stop: host reported a setup issue @@ -125,8 +79,6 @@ backup_and_send_save() { } -# Wait for the host to tell us it's ready, this happens just before it starts its RA session and we look in /tmp for a file indicator (file removed in host script cleanup) - # Start retroarch with -C in client mode if everything's gone to plan start_retroarch() { build_infoPanel_and_log "Starting RA" "Starting RetroArch" @@ -245,14 +197,6 @@ cleanup() { #Utilities# ########### -# URL encode helper - -# Use the safe word - -# Check stop, if the client tells us to stop we will. - -# Notify other MMP - # Function to sync files sync_file() { @@ -528,8 +472,6 @@ sync_file() { } -# We'll need FTP to transfer files - # Create a cookie with all the required info for the client. (client will use this cookie) create_cookie_info() { COOKIE_FILE="/mnt/SDCARD/RetroArch/retroarch.cookie" @@ -565,10 +507,6 @@ create_cookie_info() { } -# This will restore the users original ftp state - - - confirm_join_panel() { local title="$1" local message="$2" @@ -607,8 +545,6 @@ stripped_game_names() { } - - ######### ##Main.## ######### @@ -629,8 +565,8 @@ lets_go() { # Send cookie to host sync_file "Cookie" "/mnt/SDCARD/RetroArch/retroarch.cookie" 0 0 -f -m - # Read host cookie and parse paths/checksums - read_cookie + # Read host cookie and parse paths/checksums (verbose logging) + read_cookie 1 # Send local save to host backup_and_send_save diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh index 9953d4ebd0..f867ddf534 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh @@ -29,8 +29,6 @@ log "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* Easy Netplay Pokemon Host -*-*-*-* ##Setup.## ########## -# We'll need wifi up for this. Lets try and start it.. - # We'll need hotspot to host the local connection start_hotspot() { build_infoPanel_and_log "Hotspot" "Starting hotspot..." @@ -45,8 +43,6 @@ start_hotspot() { $sysdir/script/network/update_networking.sh hotspot toggle } -# We'll need FTP to host the cookie to the client - use the built in FTP, it allows us to curl (errors on bftpd re: path) - # Create a cookie with all the required info for the client. (client will use this cookie) create_cookie_info() { COOKIE_FILE="/mnt/SDCARD/RetroArch/retroarch.cookie" @@ -82,8 +78,6 @@ create_cookie_info() { } -# Wait for a hit on the sta list for someone joining the hotspot - # Backup the save we're going to use before we do anythign else host_save_backup() { @@ -225,8 +219,6 @@ client_rom_rename() { fi } -# Tell the client we're ready to accept connections - # We'll start Retroarch in host mode with -H with the core and rom paths loaded in. start_retroarch() { @@ -349,13 +341,6 @@ cleanup() { #Utilities# ########### -# URL encode helper - -# Use the safe word - -# Check stop, if the client tells us to stop we will. - - # Rename the new save back to the original one ready to be re-transferred remove_client_save_suffix() { if [ ! -z "$save_new_path" ]; then @@ -702,11 +687,6 @@ unpack_rom() { } - - - - - ######### ##Main.## ######### diff --git a/static/build/.tmp_update/script/netplay/netplay_common.sh b/static/build/.tmp_update/script/netplay/netplay_common.sh index c080026814..1a8bec9164 100644 --- a/static/build/.tmp_update/script/netplay/netplay_common.sh +++ b/static/build/.tmp_update/script/netplay/netplay_common.sh @@ -134,6 +134,59 @@ url_encode() { echo "$encoded" } +# read_cookie [verbose] +# - parses /mnt/SDCARD/RetroArch/retroarch.cookie.client into core/rom/checksum vars +# - sets: core_url, rom_url, romdirname, romName, romNameNoExtension, Img_path +read_cookie() { + local verbose="$1" + sync + while IFS= read -r line; do + case $line in + "[core]: "*) + core="${line##"[core]: "}" + ;; + "[rom]: "*) + rom="${line##"[rom]: "}" + ;; + "[coresize]: "*) + corechecksum="${line##"[coresize]: "}" + ;; + "[corechksum]: "*) + corechecksum="${line##"[corechksum]: "}" + ;; + "[romsize]: "*) + romchecksum="${line##"[romsize]: "}" + ;; + "[romchksum]: "*) + romchecksum="${line##"[romchksum]: "}" + ;; + "[cpuspeed]: "*) + cpuspeed="${line##"[cpuspeed]: "}" + ;; + esac + log "$core $rom $coresize $corechksum $romsize $romchksum" + done <"/mnt/SDCARD/RetroArch/retroarch.cookie.client" + + # url encode or curl complains + export core_url=$(url_encode "$core") + export rom_url=$(url_encode "$rom") + + romdirname=$(echo "$rom" | grep -o '/Roms/[^/]*' | cut -d'/' -f3) + romName=$(basename "$rom") + romNameNoExtension=${romName%.*} + Img_path="/mnt/SDCARD/Roms/$romdirname/Imgs/$romNameNoExtension.png" + + if [ "$verbose" = "1" ]; then + log "Cookie file read :" + log "romdirname $romdirname" + log "romName $romName" + log "romNameNoExtension $romNameNoExtension" + log "Img_path $Img_path" + else + log "Cookie file read" + fi +} + # start_ftp [check_stop_message] # - starts built-in FTP server for signaling # - if a message is provided, check_stop is invoked with it first From 6eb242a5b62cc626b2cea32ea540c9e8588df0a4 Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Sat, 17 Jan 2026 22:06:09 +0000 Subject: [PATCH 05/32] remove some floating comments --- .../script/netplay/easy-netplay_client_pokemon_GBA.sh | 3 --- .../build/.tmp_update/script/netplay/easy-netplay_server.sh | 2 -- .../script/netplay/easy-netplay_server_pokemon_GBA.sh | 4 ---- 3 files changed, 9 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh index 7ac2119288..9b9b13c221 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh @@ -86,9 +86,6 @@ cleanup() { exit } - -# build_infoPanel_and_log: show persistent infoPanel and log message - # confirm_join_panel: show join confirmation UI with local ROM image confirm_join_panel() { local title="$1" diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh index 2438d5c33b..04f1d3290d 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh @@ -22,8 +22,6 @@ program=$(basename "$0" .sh) ##Setup.## ########## -# We'll need FTP to host the cookie to the client - use the built in FTP, it allows us to curl (errors on bftpd re: path) - # Find the recommended core for the current system. Get_NetplayCore() { diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh index 1758d3b727..64dfad9edc 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh @@ -28,7 +28,6 @@ log "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* Easy Netplay Pokemon Host GBA -*-* ##Setup.## ########## - # start_retroarch: launch RetroArch in host mode with the local ROM start_retroarch() { @@ -120,9 +119,6 @@ stripped_game_names() { host_game_name="Host (me): \n$host_game_name" } -# build_infoPanel_and_log: show persistent infoPanel and log message - - ######### ##Main.## ######### From 01ae0c301ab8892d5f26f4688956b00c70be54af Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Sat, 17 Jan 2026 22:16:06 +0000 Subject: [PATCH 06/32] tidy up header sections --- .../build/.tmp_update/script/netplay/easy-netplay_client.sh | 6 ++---- .../script/netplay/easy-netplay_client_pokemon.sh | 6 ++++-- .../script/netplay/easy-netplay_client_pokemon_GBA.sh | 3 +++ .../build/.tmp_update/script/netplay/easy-netplay_server.sh | 4 ++++ .../script/netplay/easy-netplay_server_pokemon.sh | 6 +++--- .../script/netplay/easy-netplay_server_pokemon_GBA.sh | 6 ++++-- static/build/.tmp_update/script/netplay/standard-netplay.sh | 6 ++++-- 7 files changed, 24 insertions(+), 13 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh index fb8466dda8..88b28ea6b3 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh @@ -15,10 +15,12 @@ export hostip="192.168.100.100" # This should be the default unless the user has peer_ip="$hostip" logfile=easy_netplay + # Source scripts . $sysdir/script/log.sh # netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, read_cookie, check_wifi, start_ftp . $sysdir/script/netplay/netplay_common.sh + program=$(basename "$0" .sh) ########## @@ -302,8 +304,6 @@ sync_file() { } - - # Start retroarch with -C in client mode if everything's gone to plan start_retroarch() { build_infoPanel_and_log "Starting RA" "Starting RetroArch" @@ -344,7 +344,6 @@ wifi_disabled() { [ $(/customer/app/jsonval wifi) -eq 0 ] } - confirm_join_panel() { local title="$1" local message="$2" @@ -370,7 +369,6 @@ stripped_game_name() { game_name=$(awk -F'/' '/\[rom\]:/ {print $NF}' /mnt/SDCARD/RetroArch/retroarch.cookie.client | sed 's/\(.*\)\..*/\1/') } - cleanup() { build_infoPanel_and_log "Cleanup" "Cleaning up after netplay session..." diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh index 79745d2fec..540bdae125 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh @@ -4,11 +4,12 @@ # Env setup sysdir=/mnt/SDCARD/.tmp_update miyoodir=/mnt/SDCARD/miyoo -# save_dir="/mnt/SDCARD/Saves/CurrentProfile/saves/TGB Dual/" LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/parasyte" WPACLI=/customer/app/wpa_cli hostip="192.168.100.100" # This should be the default unless the user has changed it.. peer_ip="$hostip" + +# Runtime vars rm /tmp/stop_now client_rom="$cookie_rom_path" client_rom_filename=$(basename "$client_rom") @@ -17,12 +18,14 @@ client_rom_filename_NoExt="${client_rom_filename%.*}" SaveFromGambatte=0 logfile=pokemon_link + # Source scripts . $sysdir/script/log.sh # netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, read_cookie, check_wifi, start_ftp . $sysdir/script/netplay/netplay_common.sh # netplay_signalling.sh: check_stop, notify_peer, notify_stop, wait_for_host . $sysdir/script/netplay/netplay_signalling.sh + program=$(basename "$0" .sh) export CurDate=$(date +%Y%m%d_%H%M%S) @@ -544,7 +547,6 @@ stripped_game_names() { game_name_client="\n Client (me): \n$client_rom_trimmed" } - ######### ##Main.## ######### diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh index 9b9b13c221..520bac95e0 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh @@ -7,6 +7,8 @@ miyoodir=/mnt/SDCARD/miyoo LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/parasyte" hostip="192.168.100.100" # This should be the default unless the user has changed it.. peer_ip="$hostip" + +# Runtime vars rm /tmp/stop_now client_rom="$1" romdirname=$(echo "$client_rom" | grep -o '/Roms/[^/]*' | cut -d'/' -f3) @@ -15,6 +17,7 @@ client_rom_filename_NoExt="${client_rom_filename%.*}" netplaycore="/mnt/SDCARD/RetroArch/.retroarch/cores/gpsp_libretro.so" logfile=pokemon_link + # Source scripts . $sysdir/script/log.sh # netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh index 04f1d3290d..7d33ea6aa2 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh @@ -12,10 +12,12 @@ miyoodir=/mnt/SDCARD/miyoo export LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/parasyte" logfile=easy_netplay + # Source scripts . $sysdir/script/log.sh # netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp . $sysdir/script/netplay/netplay_common.sh + program=$(basename "$0" .sh) ########## @@ -28,6 +30,8 @@ Get_NetplayCore() { platform=$(echo "$cookie_rom_path" | grep -o '/Roms/[^/]*' | cut -d'/' -f3) netplaycore_info=$(grep "^${platform};" "$sysdir/config/netplay_cores.conf") if [ -n "$netplaycore_info" ]; then + +# Runtime vars netplaycore=$(echo "$netplaycore_info" | cut -d ';' -f 2) netplaycore="/mnt/SDCARD/RetroArch/.retroarch/cores/$netplaycore" core_config_folder=$(echo "$netplaycore_info" | cut -d ';' -f 3) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh index f867ddf534..7ff9d3ab19 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh @@ -8,14 +8,17 @@ LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/parasyte INFOPANEL_SLEEP=0.5 logfile=pokemon_link + # Source scripts . $sysdir/script/log.sh # netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp . $sysdir/script/netplay/netplay_common.sh # netplay_signalling.sh: wait_for_client, ready_up, notify_peer, check_stop, notify_stop . $sysdir/script/netplay/netplay_signalling.sh + program=$(basename "$0" .sh) +# Runtime vars rm /tmp/stop_now host_rom="$cookie_rom_path" host_rom_filename=$(basename "$host_rom") @@ -672,8 +675,6 @@ sync_file() { } - - unpack_rom() { file="$1" folder=$(dirname "$file") @@ -686,7 +687,6 @@ unpack_rom() { fi } - ######### ##Main.## ######### diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh index 64dfad9edc..b2066b5e26 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh @@ -8,6 +8,7 @@ LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/parasyte INFOPANEL_SLEEP=0.5 logfile=pokemon_link + # Source scripts . $sysdir/script/log.sh # netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp @@ -15,6 +16,7 @@ logfile=pokemon_link # netplay_signalling.sh: wait_for_client, ready_up, notify_peer, check_stop, notify_stop . $sysdir/script/netplay/netplay_signalling.sh +# Runtime vars rm /tmp/stop_now host_rom="$1" romdirname=$(echo "$host_rom" | grep -o '/Roms/[^/]*' | cut -d'/' -f3) @@ -74,10 +76,10 @@ cleanup() { rm "/tmp/dismiss_info_panel" sync log "Cleanup done" - + #Rename savestate_auto_load so savestate doesn't overwrite next loadsave mv -f "/mnt/SDCARD/Saves/CurrentProfile/states/gpSP/$host_rom_filename_NoExt.state.auto" "/mnt/SDCARD/Saves/CurrentProfile/states/gpSP/$host_rom_filename_NoExt.state.auto_$CurDate" - + exit } diff --git a/static/build/.tmp_update/script/netplay/standard-netplay.sh b/static/build/.tmp_update/script/netplay/standard-netplay.sh index c2e73a034f..9b3ad50dff 100644 --- a/static/build/.tmp_update/script/netplay/standard-netplay.sh +++ b/static/build/.tmp_update/script/netplay/standard-netplay.sh @@ -9,6 +9,8 @@ sysdir=/mnt/SDCARD/.tmp_update miyoodir=/mnt/SDCARD/miyoo export LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/parasyte" INFOPANEL_SLEEP=0.5 + +# Runtime vars romfullpath="$1" romname=$(basename "$1") echo "cookie_core_path $cookie_core_path" @@ -16,10 +18,12 @@ CurrentSystem=$(echo "$1" | grep -o '/Roms/[^/]*' | cut -d'/' -f3) NetplayAction="$3" # host or join logfile=netplay + # Source scripts . $sysdir/script/log.sh # netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp . $sysdir/script/netplay/netplay_common.sh + program=$(basename "$0" .sh) ########## @@ -108,8 +112,6 @@ Check_PlayerName() { #Utilities# ########### - - ######### ##Main.## ######### From 340baf2a924c27249fb51ade4e7db225e62cdddb Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Sat, 17 Jan 2026 22:16:23 +0000 Subject: [PATCH 07/32] comment --- .../.tmp_update/script/netplay/easy-netplay_client_pokemon.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh index 540bdae125..f677c63e2f 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh @@ -35,7 +35,7 @@ log "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* Easy Netplay Pokemon Client -*-*-* ##Setup.## ########## -# Push our save over to the host - The save will be found based on the rom we've started GLO on and it will look in the $save_dir path for it (see line13) - Backs up first +# Push our save over to the host - The save will be found based on the rom we've started GLO on and it will look in the $save_dir path for it - Backs up first backup_and_send_save() { # check_stop: host reported a setup issue check_stop "The host has had a problem setting up the session" From 9d088237e55bb1594ca832b034ee541bd7832ba7 Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Sat, 17 Jan 2026 23:26:18 +0000 Subject: [PATCH 08/32] changes to wai_for_client, testing connection flow of gba, some issues but does standup the session --- .../script/netplay/easy-netplay_client.sh | 2 +- .../netplay/easy-netplay_client_pokemon.sh | 2 +- .../easy-netplay_client_pokemon_GBA.sh | 14 +++++------ .../script/netplay/easy-netplay_server.sh | 2 +- .../netplay/easy-netplay_server_pokemon.sh | 6 +++-- .../easy-netplay_server_pokemon_GBA.sh | 2 +- .../script/netplay/netplay_common.sh | 21 +++++++++++----- .../script/netplay/netplay_signalling.sh | 24 ++++++++++++++++--- .../script/netplay/standard-netplay.sh | 2 +- 9 files changed, 52 insertions(+), 23 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh index 88b28ea6b3..253895b16c 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh @@ -18,7 +18,7 @@ logfile=easy_netplay # Source scripts . $sysdir/script/log.sh -# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, read_cookie, check_wifi, start_ftp +# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, read_cookie, check_wifi, start_ftp . $sysdir/script/netplay/netplay_common.sh program=$(basename "$0" .sh) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh index f677c63e2f..f9e0df33c4 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh @@ -21,7 +21,7 @@ logfile=pokemon_link # Source scripts . $sysdir/script/log.sh -# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, read_cookie, check_wifi, start_ftp +# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, read_cookie, check_wifi, start_ftp . $sysdir/script/netplay/netplay_common.sh # netplay_signalling.sh: check_stop, notify_peer, notify_stop, wait_for_host . $sysdir/script/netplay/netplay_signalling.sh diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh index 520bac95e0..687e0437d1 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh @@ -20,7 +20,7 @@ logfile=pokemon_link # Source scripts . $sysdir/script/log.sh -# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp +# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp . $sysdir/script/netplay/netplay_common.sh # netplay_signalling.sh: wait_for_host, check_stop, notify_stop . $sysdir/script/netplay/netplay_signalling.sh @@ -133,14 +133,14 @@ lets_go() { exit 1 fi - # Join host hotspot - . "$sysdir/script/network/hotspot_join.sh" + # Join host hotspot + . "$sysdir/script/network/hotspot_join.sh" - # Start FTP for lightweight signaling - start_ftp + # Start FTP for lightweight signaling + start_ftp - # Build display names for confirmation prompt - stripped_game_names + # Build display names for confirmation prompt + stripped_game_names # Wait for host ready signal wait_for_host diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh index 7d33ea6aa2..2ada70407b 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh @@ -15,7 +15,7 @@ logfile=easy_netplay # Source scripts . $sysdir/script/log.sh -# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp +# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp . $sysdir/script/netplay/netplay_common.sh program=$(basename "$0" .sh) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh index 7ff9d3ab19..2bac9bd5db 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh @@ -11,15 +11,17 @@ logfile=pokemon_link # Source scripts . $sysdir/script/log.sh -# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp +# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp . $sysdir/script/netplay/netplay_common.sh # netplay_signalling.sh: wait_for_client, ready_up, notify_peer, check_stop, notify_stop . $sysdir/script/netplay/netplay_signalling.sh program=$(basename "$0" .sh) -# Runtime vars +# Remove existing stop_now rm /tmp/stop_now + +# Runtime vars host_rom="$cookie_rom_path" host_rom_filename=$(basename "$host_rom") host_rom_filename_NoExt="${host_rom_filename%.*}" diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh index b2066b5e26..36bbe95dea 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh @@ -11,7 +11,7 @@ logfile=pokemon_link # Source scripts . $sysdir/script/log.sh -# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp +# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp . $sysdir/script/netplay/netplay_common.sh # netplay_signalling.sh: wait_for_client, ready_up, notify_peer, check_stop, notify_stop . $sysdir/script/netplay/netplay_signalling.sh diff --git a/static/build/.tmp_update/script/netplay/netplay_common.sh b/static/build/.tmp_update/script/netplay/netplay_common.sh index 1a8bec9164..f9826cbda0 100644 --- a/static/build/.tmp_update/script/netplay/netplay_common.sh +++ b/static/build/.tmp_update/script/netplay/netplay_common.sh @@ -57,6 +57,13 @@ enable_flag() { touch "$sysdir/config/.$flag" } +# disable_flag <flag_name> +# - removes $sysdir/config/.<flag_name> +disable_flag() { + flag="$1" + mv "$sysdir/config/.$flag" "$sysdir/config/.$flag_" +} + # flag_enabled <flag_name> # - returns 0 if flag file exists flag_enabled() { @@ -121,17 +128,19 @@ url_encode() { local string="$1" local length="${#string}" local encoded="" - local pos c o + local pos=0 + local c o - for ((pos = 0; pos < length; pos++)); do - c=${string:$pos:1} + while [ "$pos" -lt "$length" ]; do + c=$(printf '%s' "$string" | cut -c $((pos + 1))) case "$c" in [-_.~a-zA-Z0-9]) o="$c" ;; - *) printf -v o '%%%02x' "'${c}" ;; + *) o=$(printf '%%%02x' "'$c") ;; esac - encoded+="$o" + encoded="${encoded}${o}" + pos=$((pos + 1)) done - echo "$encoded" + printf '%s\n' "$encoded" } # read_cookie [verbose] diff --git a/static/build/.tmp_update/script/netplay/netplay_signalling.sh b/static/build/.tmp_update/script/netplay/netplay_signalling.sh index c94985f627..f477f36cb1 100644 --- a/static/build/.tmp_update/script/netplay/netplay_signalling.sh +++ b/static/build/.tmp_update/script/netplay/netplay_signalling.sh @@ -75,10 +75,12 @@ wait_for_client() { # check_stop: client reported a setup/join issue check_stop "The client has had a problem joining the session." build_infoPanel_and_log "Hotspot" "Waiting for a client to connect..." + log "wait_for_client: start (sysdir=$sysdir)" client_ip="" client_mac="" counter=0 + lease_file=$(grep -E '^dhcp-leasefile=' "$sysdir/config/dnsmasq.conf" 2>/dev/null | head -n 1 | cut -d'=' -f2) killall -9 wpa_supplicant killall -9 udhcpc @@ -89,14 +91,29 @@ wait_for_client() { sta_list=$($sysdir/bin/hostapd_cli all_sta 2>/dev/null) $sysdir/bin/hostapd_cli all_sta flush + log "wait_for_client: sta_list='${sta_list}'" + if [ $? -ne 0 ]; then build_infoPanel_and_log "Hotspot" "Hostapd hook failing, retrying." counter=$((counter + 1)) fi if [ ! -z "$sta_list" ]; then - client_mac=$(echo "$sta_list" | awk 'NR==2{print $1; exit}') - client_ip=$(arp -an | awk '/"'"$client_mac"'"/ {gsub(/[\(\)]/,""); print $2}') + client_mac=$(printf '%s\n' "$sta_list" | awk 'NR==2{print $1; exit}') + client_mac=$(printf '%s' "$client_mac" | tr -cd '0-9a-fA-F:' | tr 'A-F' 'a-f') + log "wait_for_client: client_mac='${client_mac}'" + if [ -n "$client_mac" ] && [ -n "$lease_file" ] && [ -f "$lease_file" ]; then + sync + lease_dump=$(cat "$lease_file" 2>/dev/null) + client_ip=$(printf '%s\n' "$lease_dump" | awk -v mac="$client_mac" 'tolower($2)==tolower(mac){print $3; exit}') + fi + if [ -z "$client_ip" ]; then + arp_dump=$(arp -an 2>/dev/null) + if [ -n "$client_mac" ]; then + client_ip=$(printf '%s\n' "$arp_dump" | awk -v mac="$client_mac" 'tolower($0) ~ tolower(mac) {gsub(/[()]/,"",$2); print $2; exit}') + fi + fi + log "wait_for_client: client_ip='${client_ip}'" if [ ! -z "$client_ip" ]; then case "$client_ip" in @@ -105,13 +122,14 @@ wait_for_client() { log "A client has connected. IP: $client_ip" build_infoPanel_and_log "Hotspot" "A client has connected! \n IP: $client_ip" peer_ip="$client_ip" + sync break ;; esac fi fi - sleep 1 + sleep 0.5 counter=$((counter + 1)) if [ $counter -ge 30 ]; then diff --git a/static/build/.tmp_update/script/netplay/standard-netplay.sh b/static/build/.tmp_update/script/netplay/standard-netplay.sh index 9b3ad50dff..dc47c3c7a6 100644 --- a/static/build/.tmp_update/script/netplay/standard-netplay.sh +++ b/static/build/.tmp_update/script/netplay/standard-netplay.sh @@ -21,7 +21,7 @@ logfile=netplay # Source scripts . $sysdir/script/log.sh -# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp +# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp . $sysdir/script/netplay/netplay_common.sh program=$(basename "$0" .sh) From 40f0ff6adb4a1ce9ca25705fc6e45698a687a9b5 Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Tue, 20 Jan 2026 20:19:35 +0000 Subject: [PATCH 09/32] fix gba/gbc path, url encoding of file path, file size checks --- .../script/netplay/easy-netplay_client.sh | 26 ++++--- .../netplay/easy-netplay_client_pokemon.sh | 26 ++++--- .../netplay/easy-netplay_server_pokemon.sh | 26 ++++--- .../script/netplay/netplay_common.sh | 77 +++++++++++++------ 4 files changed, 101 insertions(+), 54 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh index 253895b16c..102ce1bcbb 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh @@ -53,7 +53,7 @@ sync_file() { # some useful vars dir_path=$(dirname "$file_path") - file_url="ftp://${hostip}/$(url_encode "${file_path#*/}")" + file_url="ftp://${hostip}/$(url_encode_path "${file_path#*/}")" echo "############################ DEBUGGING #######################################" echo file_type $file_type @@ -89,9 +89,9 @@ sync_file() { else remote_file_size=$(echo "$RequestResult" | grep -i "Content-Length" | awk '{print $2}') if ! echo "$remote_file_size" | grep -q "^[0-9][0-9]*$"; then # check if the remote file size is a numeric value - log "Impossible to get remote file size." + log "Non-numeric remote file size: '$remote_file_size'" + log "HEAD response: $RequestResult" same_size=0 - run_sync=0 else log "remote_file_size: $remote_file_size" fi @@ -118,11 +118,15 @@ sync_file() { fi ########################## exception : max file size check on the remote - if [ "$remote_file_size" -le "$MAX_FILE_DL_SIZE" ]; then - log "Remote file size ok: $remote_file_size bytes (<= $MAX_FILE_DL_SIZE bytes)" + if echo "$remote_file_size" | grep -q "^[0-9][0-9]*$"; then + if [ "$remote_file_size" -le "$MAX_FILE_DL_SIZE" ]; then + log "Remote file size ok: $remote_file_size bytes (<= $MAX_FILE_DL_SIZE bytes)" + else + log "Remote file size too big: $remote_file_size bytes (> $MAX_FILE_DL_SIZE bytes)" + run_sync=0 + fi else - log "Remote file size too big: $remote_file_size bytes (> $MAX_FILE_DL_SIZE bytes)" - run_sync=0 + log "Skipping max file size check due to non-numeric remote size: '$remote_file_size'" fi ########################## We have all the required information, depending the choosen option we run the copy or not @@ -228,12 +232,14 @@ sync_file() { fi log "Starting to download $file_type from $file_url" - curl -o "$file_path" "$file_url" >/dev/null 2>&1 + curl_output=$(curl -S -o "$file_path" "$file_url" 2>&1) + curl_exit=$? - if [ $? -eq 0 ]; then + if [ $curl_exit -eq 0 ]; then log "$file_type download completed" else - log "$file_type download failed" + log "$file_type download failed (curl exit=$curl_exit)" + log "curl error: $curl_output" fi fi diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh index f9e0df33c4..3332d22fbc 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh @@ -226,7 +226,7 @@ sync_file() { # some useful vars dir_path=$(dirname "$file_path") - file_url="ftp://${hostip}/$(url_encode "${file_path#*/}")" + file_url="ftp://${hostip}/$(url_encode_path "${file_path#*/}")" log -e "\n############################ SYNC_FILE DEBUGGING ############################" log file_type $file_type @@ -257,9 +257,9 @@ sync_file() { else remote_file_size=$(echo "$RequestResult" | grep -i "Content-Length" | awk '{print $2}') if ! echo "$remote_file_size" | grep -q "^[0-9][0-9]*$"; then # check if the remote file size is a numeric value - log "Impossible to get remote file size." + log "Non-numeric remote file size: '$remote_file_size'" + log "HEAD response: $RequestResult" same_size=0 - run_sync=0 else log "remote_file_size: $remote_file_size" fi @@ -286,11 +286,15 @@ sync_file() { fi ########################## exception : max file size check on the remote - if [ "$remote_file_size" -le "$MAX_FILE_DL_SIZE" ]; then - log "Remote file size ok: $remote_file_size bytes (<= $MAX_FILE_DL_SIZE bytes)" + if echo "$remote_file_size" | grep -q "^[0-9][0-9]*$"; then + if [ "$remote_file_size" -le "$MAX_FILE_DL_SIZE" ]; then + log "Remote file size ok: $remote_file_size bytes (<= $MAX_FILE_DL_SIZE bytes)" + else + log "Remote file size too big: $remote_file_size bytes (> $MAX_FILE_DL_SIZE bytes)" + run_sync=0 + fi else - log "Remote file size too big: $remote_file_size bytes (> $MAX_FILE_DL_SIZE bytes)" - run_sync=0 + log "Skipping max file size check due to non-numeric remote size: '$remote_file_size'" fi ########################## We have all the required information, depending the choosen option we run the copy or not @@ -395,12 +399,14 @@ sync_file() { fi log "Starting to download $file_type from $file_url" - curl -o "$file_path" "$file_url" >/dev/null 2>&1 + curl_output=$(curl -S -o "$file_path" "$file_url" 2>&1) + curl_exit=$? - if [ $? -eq 0 ]; then + if [ $curl_exit -eq 0 ]; then log "$file_type download completed" else - log "$file_type download failed" + log "$file_type download failed (curl exit=$curl_exit)" + log "curl error: $curl_output" fi fi diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh index 2bac9bd5db..63cf386480 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh @@ -427,7 +427,7 @@ sync_file() { # some useful vars dir_path=$(dirname "$file_path") - file_url="ftp://${client_ip}/$(url_encode "${file_path#*/}")" + file_url="ftp://${client_ip}/$(url_encode_path "${file_path#*/}")" log "\n############################ SYNC_FILE DEBUGGING ############################" log file_type $file_type @@ -458,9 +458,9 @@ sync_file() { else remote_file_size=$(echo "$RequestResult" | grep -i "Content-Length" | awk '{print $2}') if ! echo "$remote_file_size" | grep -q "^[0-9][0-9]*$"; then # check if the remote file size is a numeric value - log "Impossible to get remote file size." + log "Non-numeric remote file size: '$remote_file_size'" + log "HEAD response: $RequestResult" same_size=0 - run_sync=0 else log "remote_file_size: $remote_file_size" fi @@ -487,11 +487,15 @@ sync_file() { fi ########################## exception : max file size check on the remote - if [ "$remote_file_size" -le "$MAX_FILE_DL_SIZE" ]; then - log "Remote file size ok: $remote_file_size bytes (<= $MAX_FILE_DL_SIZE bytes)" + if echo "$remote_file_size" | grep -q "^[0-9][0-9]*$"; then + if [ "$remote_file_size" -le "$MAX_FILE_DL_SIZE" ]; then + log "Remote file size ok: $remote_file_size bytes (<= $MAX_FILE_DL_SIZE bytes)" + else + log "Remote file size too big: $remote_file_size bytes (> $MAX_FILE_DL_SIZE bytes)" + run_sync=0 + fi else - log "Remote file size too big: $remote_file_size bytes (> $MAX_FILE_DL_SIZE bytes)" - run_sync=0 + log "Skipping max file size check due to non-numeric remote size: '$remote_file_size'" fi ########################## We have all the required information, depending the choosen option we run the copy or not @@ -597,12 +601,14 @@ sync_file() { fi log "Starting to download $file_type from $file_url" - curl -o "$file_path" "$file_url" >/dev/null 2>&1 + curl_output=$(curl -S -o "$file_path" "$file_url" 2>&1) + curl_exit=$? - if [ $? -eq 0 ]; then + if [ $curl_exit -eq 0 ]; then log "$file_type download completed" else - log "$file_type download failed" + log "$file_type download failed (curl exit=$curl_exit)" + log "curl error: $curl_output" fi fi diff --git a/static/build/.tmp_update/script/netplay/netplay_common.sh b/static/build/.tmp_update/script/netplay/netplay_common.sh index f9826cbda0..eb3fac3391 100644 --- a/static/build/.tmp_update/script/netplay/netplay_common.sh +++ b/static/build/.tmp_update/script/netplay/netplay_common.sh @@ -1,24 +1,25 @@ # Shared netplay helpers -# checksize_func -# - uses: file_check_size, file_path, remote_file_checksum -# - sets: same_size +# checksize_func <file_path> <remote_size> +# - sets: same_size (0 different, 1 identical, 2 unknown) checksize_func() { - if [ "$file_check_size" -eq 1 ]; then - if [ -e "$file_path" ]; then - local_file_size=$(stat -c%s "$file_path") - if [ "$remote_file_checksum" == "0" ]; then - same_size=1 - elif [ "$local_file_size" -eq "$remote_file_checksum" ]; then + local func_file_path="${1:-$file_path}" + local filesize_tocheck="${2:-$remote_file_size}" + + if [ -e "$func_file_path" ]; then + local_file_size=$(stat -c%s "$func_file_path") + if echo "$filesize_tocheck" | grep -q "^[0-9][0-9]*$"; then + if [ "$filesize_tocheck" -eq "$local_file_size" ]; then same_size=1 else same_size=0 fi else - same_size=0 + log "Non-numeric remote file size for checksize_func: '$filesize_tocheck'" + same_size=2 fi else - same_size=1 + same_size=0 fi } @@ -46,7 +47,8 @@ checksum_func() { fi fi else - same_chksum=0 + log "Skipping checksum check." + same_chksum=1 fi } @@ -125,21 +127,48 @@ udhcpc_control() { # url_encode <string> # - percent-encodes string for URLs url_encode() { - local string="$1" - local length="${#string}" + encoded_str=$(echo "$*" | awk ' + BEGIN { + split ("1 2 3 4 5 6 7 8 9 A B C D E F", hextab, " ") + hextab [0] = 0 + for ( i=1; i<=255; ++i ) ord [ sprintf ("%c", i) "" ] = i + 0 + } + { + encoded = "" + for ( i=1; i<=length ($0); ++i ) { + c = substr ($0, i, 1) + if ( c ~ /[a-zA-Z0-9.-]/ ) { + encoded = encoded c # safe character + } else if ( c == " " ) { + encoded = encoded "%20" # special handling + } else { + # unsafe character, encode it as a two-digit hex-number + lo = ord [c] % 16 + hi = int (ord [c] / 16); + encoded = encoded "%" hextab [hi] hextab [lo] + } + } + print encoded + } +') + echo "$encoded_str" +} + +# url_encode_path <path> +# - encodes each path segment but keeps '/' +url_encode_path() { + local path="$1" local encoded="" - local pos=0 - local c o + local IFS='/' + local part - while [ "$pos" -lt "$length" ]; do - c=$(printf '%s' "$string" | cut -c $((pos + 1))) - case "$c" in - [-_.~a-zA-Z0-9]) o="$c" ;; - *) o=$(printf '%%%02x' "'$c") ;; - esac - encoded="${encoded}${o}" - pos=$((pos + 1)) + for part in $path; do + if [ -n "$encoded" ]; then + encoded="${encoded}/" + fi + encoded="${encoded}$(url_encode "$part")" done + printf '%s\n' "$encoded" } From 64cb0a5816ac6bfe2738a8f8f1cba817b5eaafbc Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Tue, 20 Jan 2026 20:44:38 +0000 Subject: [PATCH 10/32] harden FTP setup for cookie and comms transfers gb/gbc --- .../script/netplay/easy-netplay_client.sh | 8 ++- .../netplay/easy-netplay_client_pokemon.sh | 8 ++- .../netplay/easy-netplay_server_pokemon.sh | 8 ++- .../script/netplay/netplay_common.sh | 63 +++++++++++++++++++ 4 files changed, 84 insertions(+), 3 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh index 102ce1bcbb..ffabaa65fb 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh @@ -54,6 +54,7 @@ sync_file() { # some useful vars dir_path=$(dirname "$file_path") file_url="ftp://${hostip}/$(url_encode_path "${file_path#*/}")" + remote_ip="$hostip" echo "############################ DEBUGGING #######################################" echo file_type $file_type @@ -77,7 +78,12 @@ sync_file() { sync_success= run_sync= # tell if the sync task must be done or not - RequestResult=$(curl -I "$file_url" 2>&1) + if ! ensure_ftp_head "$file_url" "$remote_ip" "$file_mandatory"; then + same_size=0 + run_sync=0 + sync_success=0 + fi + RequestResult="$ftp_head_result" if [[ $RequestResult == *"The file does not exist"* ]]; then log "The remote file does not exist." diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh index 3332d22fbc..02be8c0410 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh @@ -227,6 +227,7 @@ sync_file() { # some useful vars dir_path=$(dirname "$file_path") file_url="ftp://${hostip}/$(url_encode_path "${file_path#*/}")" + remote_ip="$hostip" log -e "\n############################ SYNC_FILE DEBUGGING ############################" log file_type $file_type @@ -245,7 +246,12 @@ sync_file() { sync_success= run_sync= # tell if the sync task must be done or not - RequestResult=$(curl -I "$file_url" 2>&1) + if ! ensure_ftp_head "$file_url" "$remote_ip" "$file_mandatory"; then + same_size=0 + run_sync=0 + sync_success=0 + fi + RequestResult="$ftp_head_result" if [[ $RequestResult == *"The file does not exist"* ]]; then log "The remote file does not exist." diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh index 63cf386480..b8b2351dee 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh @@ -428,6 +428,7 @@ sync_file() { # some useful vars dir_path=$(dirname "$file_path") file_url="ftp://${client_ip}/$(url_encode_path "${file_path#*/}")" + remote_ip="$client_ip" log "\n############################ SYNC_FILE DEBUGGING ############################" log file_type $file_type @@ -446,7 +447,12 @@ sync_file() { sync_success= run_sync= # tell if the sync task must be done or not - RequestResult=$(curl -I "$file_url" 2>&1) + if ! ensure_ftp_head "$file_url" "$remote_ip" "$file_mandatory"; then + same_size=0 + run_sync=0 + sync_success=0 + fi + RequestResult="$ftp_head_result" if [[ $RequestResult == *"The file does not exist"* ]]; then log "The remote file does not exist." diff --git a/static/build/.tmp_update/script/netplay/netplay_common.sh b/static/build/.tmp_update/script/netplay/netplay_common.sh index eb3fac3391..74ede92137 100644 --- a/static/build/.tmp_update/script/netplay/netplay_common.sh +++ b/static/build/.tmp_update/script/netplay/netplay_common.sh @@ -1,5 +1,9 @@ # Shared netplay helpers +# Tunables +NETPLAY_FTP_CHECK_RETRIES=${NETPLAY_FTP_CHECK_RETRIES:-5} +NETPLAY_FTP_CHECK_DELAY=${NETPLAY_FTP_CHECK_DELAY:-1} + # checksize_func <file_path> <remote_size> # - sets: same_size (0 different, 1 identical, 2 unknown) checksize_func() { @@ -242,6 +246,65 @@ start_ftp() { tcpsvd -E 0.0.0.0 21 ftpd -w / & log "Starting FTP server" fi + check_ftp_local + sleep 0.5 +} + +# check_ftp_local [port] +# - logs whether tcpsvd is running and its args/port +check_ftp_local() { + local port="${1:-21}" + if pgrep tcpsvd >/dev/null; then + local tcpsvd_ps + tcpsvd_ps=$(ps | grep tcpsvd | grep -v grep) + log "FTP tcpsvd running (expected port $port): $tcpsvd_ps" + else + log "FTP tcpsvd not running (expected port $port)" + build_infoPanel_and_log "FTP Error" "FTP server failed to start." + fi +} + +# ensure_ftp_head <url> <remote_ip> <mandatory> +# - pings remote and performs FTP HEAD with retries +# - sets: ftp_head_result, ftp_head_exit +ensure_ftp_head() { + local url="$1" + local remote_ip="$2" + local mandatory="$3" + local attempt=1 + + while [ $attempt -le $NETPLAY_FTP_CHECK_RETRIES ]; do + log "FTP check attempt $attempt/$NETPLAY_FTP_CHECK_RETRIES for $remote_ip" + ping -c 1 "$remote_ip" >/dev/null 2>&1 + if [ $? -ne 0 ]; then + log "Ping to $remote_ip failed (attempt $attempt)" + fi + + ftp_head_result=$(curl -I --connect-timeout 3 "$url" 2>&1) + ftp_head_exit=$? + + if [ $ftp_head_exit -eq 0 ]; then + return 0 + fi + + if echo "$ftp_head_result" | grep -q "The file does not exist"; then + log "FTP reachable but file missing for $remote_ip" + return 0 + fi + + log "FTP HEAD failed for $remote_ip (curl exit=$ftp_head_exit)" + log "FTP HEAD error: $ftp_head_result" + attempt=$((attempt + 1)) + sleep "$NETPLAY_FTP_CHECK_DELAY" + done + + build_infoPanel_and_log "Sync Failed" "Unable to reach FTP server at $remote_ip." + if [ "$mandatory" = "-m" ]; then + if type cleanup >/dev/null 2>&1; then + cleanup + fi + fi + return 1 } # check_wifi <use_udhcpc> <hard_fail> <down_wlan1> # - use_udhcpc: 1 to call udhcpc_control after wpa_supplicant From d8484022b7a3873396d71f9745c9de88c4d7d497 Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Tue, 20 Jan 2026 20:55:16 +0000 Subject: [PATCH 11/32] short circuit on curl exit 9 - failing when image doesn't exist & we'll never recover even after 3 attempts. change attempts to 3, change interval to 0.5 --- .../script/netplay/easy-netplay_client.sh | 2 +- .../script/netplay/easy-netplay_client_pokemon.sh | 2 +- .../script/netplay/easy-netplay_server_pokemon.sh | 2 +- .../.tmp_update/script/netplay/netplay_common.sh | 15 +++++++++++---- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh index ffabaa65fb..857617ee3f 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh @@ -238,7 +238,7 @@ sync_file() { fi log "Starting to download $file_type from $file_url" - curl_output=$(curl -S -o "$file_path" "$file_url" 2>&1) + curl_output=$(curl -sS -o "$file_path" "$file_url" 2>&1) curl_exit=$? if [ $curl_exit -eq 0 ]; then diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh index 02be8c0410..d675ce2f83 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh @@ -405,7 +405,7 @@ sync_file() { fi log "Starting to download $file_type from $file_url" - curl_output=$(curl -S -o "$file_path" "$file_url" 2>&1) + curl_output=$(curl -sS -o "$file_path" "$file_url" 2>&1) curl_exit=$? if [ $curl_exit -eq 0 ]; then diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh index b8b2351dee..20bfddda65 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh @@ -607,7 +607,7 @@ sync_file() { fi log "Starting to download $file_type from $file_url" - curl_output=$(curl -S -o "$file_path" "$file_url" 2>&1) + curl_output=$(curl -sS -o "$file_path" "$file_url" 2>&1) curl_exit=$? if [ $curl_exit -eq 0 ]; then diff --git a/static/build/.tmp_update/script/netplay/netplay_common.sh b/static/build/.tmp_update/script/netplay/netplay_common.sh index 74ede92137..61de653014 100644 --- a/static/build/.tmp_update/script/netplay/netplay_common.sh +++ b/static/build/.tmp_update/script/netplay/netplay_common.sh @@ -1,8 +1,8 @@ # Shared netplay helpers # Tunables -NETPLAY_FTP_CHECK_RETRIES=${NETPLAY_FTP_CHECK_RETRIES:-5} -NETPLAY_FTP_CHECK_DELAY=${NETPLAY_FTP_CHECK_DELAY:-1} +NETPLAY_FTP_CHECK_RETRIES=${NETPLAY_FTP_CHECK_RETRIES:-3} +NETPLAY_FTP_CHECK_DELAY=${NETPLAY_FTP_CHECK_DELAY:-0.5} # checksize_func <file_path> <remote_size> # - sets: same_size (0 different, 1 identical, 2 unknown) @@ -275,18 +275,25 @@ ensure_ftp_head() { while [ $attempt -le $NETPLAY_FTP_CHECK_RETRIES ]; do log "FTP check attempt $attempt/$NETPLAY_FTP_CHECK_RETRIES for $remote_ip" - ping -c 1 "$remote_ip" >/dev/null 2>&1 + ping -c 2 "$remote_ip" >/dev/null 2>&1 if [ $? -ne 0 ]; then log "Ping to $remote_ip failed (attempt $attempt)" fi - ftp_head_result=$(curl -I --connect-timeout 3 "$url" 2>&1) + ftp_head_result=$(curl -sS -I --connect-timeout 3 "$url" 2>&1) ftp_head_exit=$? if [ $ftp_head_exit -eq 0 ]; then return 0 fi + if [ $ftp_head_exit -eq 9 ]; then + log "FTP path denied for $remote_ip (curl exit=$ftp_head_exit)" + log "FTP HEAD error: $ftp_head_result" + build_infoPanel_and_log "Sync Failed" "FTP path denied at $remote_ip." + return 1 + fi + if echo "$ftp_head_result" | grep -q "The file does not exist"; then log "FTP reachable but file missing for $remote_ip" return 0 From 38b658cd1c4710732d3f7b050803fc55714b137c Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Tue, 20 Jan 2026 21:15:42 +0000 Subject: [PATCH 12/32] Revert "short circuit on curl exit 9 - failing when image doesn't exist & we'll never recover even after 3 attempts. change attempts to 3, change interval to 0.5" This reverts commit d8484022b7a3873396d71f9745c9de88c4d7d497. --- .../script/netplay/easy-netplay_client.sh | 2 +- .../script/netplay/easy-netplay_client_pokemon.sh | 2 +- .../script/netplay/easy-netplay_server_pokemon.sh | 2 +- .../.tmp_update/script/netplay/netplay_common.sh | 15 ++++----------- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh index 857617ee3f..ffabaa65fb 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh @@ -238,7 +238,7 @@ sync_file() { fi log "Starting to download $file_type from $file_url" - curl_output=$(curl -sS -o "$file_path" "$file_url" 2>&1) + curl_output=$(curl -S -o "$file_path" "$file_url" 2>&1) curl_exit=$? if [ $curl_exit -eq 0 ]; then diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh index d675ce2f83..02be8c0410 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh @@ -405,7 +405,7 @@ sync_file() { fi log "Starting to download $file_type from $file_url" - curl_output=$(curl -sS -o "$file_path" "$file_url" 2>&1) + curl_output=$(curl -S -o "$file_path" "$file_url" 2>&1) curl_exit=$? if [ $curl_exit -eq 0 ]; then diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh index 20bfddda65..b8b2351dee 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh @@ -607,7 +607,7 @@ sync_file() { fi log "Starting to download $file_type from $file_url" - curl_output=$(curl -sS -o "$file_path" "$file_url" 2>&1) + curl_output=$(curl -S -o "$file_path" "$file_url" 2>&1) curl_exit=$? if [ $curl_exit -eq 0 ]; then diff --git a/static/build/.tmp_update/script/netplay/netplay_common.sh b/static/build/.tmp_update/script/netplay/netplay_common.sh index 61de653014..74ede92137 100644 --- a/static/build/.tmp_update/script/netplay/netplay_common.sh +++ b/static/build/.tmp_update/script/netplay/netplay_common.sh @@ -1,8 +1,8 @@ # Shared netplay helpers # Tunables -NETPLAY_FTP_CHECK_RETRIES=${NETPLAY_FTP_CHECK_RETRIES:-3} -NETPLAY_FTP_CHECK_DELAY=${NETPLAY_FTP_CHECK_DELAY:-0.5} +NETPLAY_FTP_CHECK_RETRIES=${NETPLAY_FTP_CHECK_RETRIES:-5} +NETPLAY_FTP_CHECK_DELAY=${NETPLAY_FTP_CHECK_DELAY:-1} # checksize_func <file_path> <remote_size> # - sets: same_size (0 different, 1 identical, 2 unknown) @@ -275,25 +275,18 @@ ensure_ftp_head() { while [ $attempt -le $NETPLAY_FTP_CHECK_RETRIES ]; do log "FTP check attempt $attempt/$NETPLAY_FTP_CHECK_RETRIES for $remote_ip" - ping -c 2 "$remote_ip" >/dev/null 2>&1 + ping -c 1 "$remote_ip" >/dev/null 2>&1 if [ $? -ne 0 ]; then log "Ping to $remote_ip failed (attempt $attempt)" fi - ftp_head_result=$(curl -sS -I --connect-timeout 3 "$url" 2>&1) + ftp_head_result=$(curl -I --connect-timeout 3 "$url" 2>&1) ftp_head_exit=$? if [ $ftp_head_exit -eq 0 ]; then return 0 fi - if [ $ftp_head_exit -eq 9 ]; then - log "FTP path denied for $remote_ip (curl exit=$ftp_head_exit)" - log "FTP HEAD error: $ftp_head_result" - build_infoPanel_and_log "Sync Failed" "FTP path denied at $remote_ip." - return 1 - fi - if echo "$ftp_head_result" | grep -q "The file does not exist"; then log "FTP reachable but file missing for $remote_ip" return 0 From f4d1de1f8e36734edfa40164f690497298a9c6c0 Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Tue, 20 Jan 2026 21:55:07 +0000 Subject: [PATCH 13/32] harden netplay ftp transfers and path encoding --- .../script/netplay/easy-netplay_client.sh | 39 ++++++-- .../netplay/easy-netplay_client_pokemon.sh | 39 ++++++-- .../netplay/easy-netplay_server_pokemon.sh | 50 ++++++---- .../script/netplay/netplay_common.sh | 95 ++++++------------- 4 files changed, 123 insertions(+), 100 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh index ffabaa65fb..720f2e73ef 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh @@ -53,7 +53,7 @@ sync_file() { # some useful vars dir_path=$(dirname "$file_path") - file_url="ftp://${hostip}/$(url_encode_path "${file_path#*/}")" + file_url="ftp://${hostip}/$(url_encode "${file_path#*/}")" remote_ip="$hostip" echo "############################ DEBUGGING #######################################" @@ -238,22 +238,37 @@ sync_file() { fi log "Starting to download $file_type from $file_url" - curl_output=$(curl -S -o "$file_path" "$file_url" 2>&1) - curl_exit=$? + download_attempt=1 + while [ $download_attempt -le $NETPLAY_FTP_DOWNLOAD_RETRIES ]; do + curl_output=$(curl -S -o "$file_path" "$file_url" 2>&1) + curl_exit=$? + + if [ $curl_exit -eq 0 ]; then + log "$file_type download completed" + break + fi - if [ $curl_exit -eq 0 ]; then - log "$file_type download completed" - else - log "$file_type download failed (curl exit=$curl_exit)" + log "$file_type download failed (curl exit=$curl_exit, attempt $download_attempt/$NETPLAY_FTP_DOWNLOAD_RETRIES)" log "curl error: $curl_output" - fi + if [ $curl_exit -eq 9 ] || [ $curl_exit -eq 78 ]; then + log "FTP path denied for $file_url" + break + fi + + download_attempt=$((download_attempt + 1)) + sleep "$NETPLAY_FTP_DOWNLOAD_DELAY" + done fi ###################### FINAL CHECK RESULT ######################### if [ ! -e "$file_path" ]; then - build_infoPanel_and_log "Sync Failed" "Failed to download the $file_type file." + if [ "$file_type" = "Img" ]; then + log "Image not found on peer; continuing without image." + else + build_infoPanel_and_log "Sync Failed" "Failed to download the $file_type file." + fi # copy has failed : restoring the original file if [ $file_type != "Rom" ] && [ $file_type != "Core" ]; then @@ -261,7 +276,11 @@ sync_file() { log "backup restored" fi sleep 2 - [ "$file_mandatory" = "-m" ] && cleanup + if [ "$file_mandatory" = "-m" ]; then + if [ "$file_type" != "Img" ]; then + cleanup + fi + fi else diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh index 02be8c0410..b536837d2e 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh @@ -226,7 +226,7 @@ sync_file() { # some useful vars dir_path=$(dirname "$file_path") - file_url="ftp://${hostip}/$(url_encode_path "${file_path#*/}")" + file_url="ftp://${hostip}/$(url_encode "${file_path#*/}")" remote_ip="$hostip" log -e "\n############################ SYNC_FILE DEBUGGING ############################" @@ -405,22 +405,37 @@ sync_file() { fi log "Starting to download $file_type from $file_url" - curl_output=$(curl -S -o "$file_path" "$file_url" 2>&1) - curl_exit=$? + download_attempt=1 + while [ $download_attempt -le $NETPLAY_FTP_DOWNLOAD_RETRIES ]; do + curl_output=$(curl -S -o "$file_path" "$file_url" 2>&1) + curl_exit=$? + + if [ $curl_exit -eq 0 ]; then + log "$file_type download completed" + break + fi - if [ $curl_exit -eq 0 ]; then - log "$file_type download completed" - else - log "$file_type download failed (curl exit=$curl_exit)" + log "$file_type download failed (curl exit=$curl_exit, attempt $download_attempt/$NETPLAY_FTP_DOWNLOAD_RETRIES)" log "curl error: $curl_output" - fi + if [ $curl_exit -eq 9 ] || [ $curl_exit -eq 78 ]; then + log "FTP path denied for $file_url" + break + fi + + download_attempt=$((download_attempt + 1)) + sleep "$NETPLAY_FTP_DOWNLOAD_DELAY" + done fi ###################### FINAL CHECK RESULT ######################### if [ ! -e "$file_path" ]; then - build_infoPanel_and_log "Sync Failed" "Failed to download the $file_type file." + if [ "$file_type" = "Img" ]; then + log "Image not found on peer; continuing without image." + else + build_infoPanel_and_log "Sync Failed" "Failed to download the $file_type file." + fi # copy has failed : restoring the original file if [ $file_type != "Rom" ] && [ $file_type != "Core" ]; then @@ -428,7 +443,11 @@ sync_file() { log "backup restored" fi sleep 2 - [ "$file_mandatory" = "-m" ] && cleanup + if [ "$file_mandatory" = "-m" ]; then + if [ "$file_type" != "Img" ]; then + cleanup + fi + fi else diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh index b8b2351dee..a9067623f9 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh @@ -427,7 +427,7 @@ sync_file() { # some useful vars dir_path=$(dirname "$file_path") - file_url="ftp://${client_ip}/$(url_encode_path "${file_path#*/}")" + file_url="ftp://${client_ip}/$(url_encode "${file_path#*/}")" remote_ip="$client_ip" log "\n############################ SYNC_FILE DEBUGGING ############################" @@ -566,8 +566,11 @@ sync_file() { if [ "$run_sync" -eq 1 ]; then - # let's make a backup first whatever the case - if [ -e "$file_path" ]; then + # Cookie uses a separate client file; keep host cookie intact. + if [ $file_type == "Cookie" ]; then + file_path="${file_path}.client" + elif [ -e "$file_path" ]; then + # let's make a backup first whatever the case if [ $file_type == "Rom" ]; then # if rom already here and different file then we create a rom_neplay to avoid to override user games @@ -598,31 +601,42 @@ sync_file() { log "Existing $file_type file moved to ${file_path}_old" fi fi - if [ $file_type == "Cookie" ]; then # exception for cookies : we don't download with the same target name - file_path="${file_path}.client" - fi - if [ ! -d "$dir_path" ]; then mkdir -p "$dir_path" fi log "Starting to download $file_type from $file_url" - curl_output=$(curl -S -o "$file_path" "$file_url" 2>&1) - curl_exit=$? + download_attempt=1 + while [ $download_attempt -le $NETPLAY_FTP_DOWNLOAD_RETRIES ]; do + curl_output=$(curl -S -o "$file_path" "$file_url" 2>&1) + curl_exit=$? + + if [ $curl_exit -eq 0 ]; then + log "$file_type download completed" + break + fi - if [ $curl_exit -eq 0 ]; then - log "$file_type download completed" - else - log "$file_type download failed (curl exit=$curl_exit)" + log "$file_type download failed (curl exit=$curl_exit, attempt $download_attempt/$NETPLAY_FTP_DOWNLOAD_RETRIES)" log "curl error: $curl_output" - fi + if [ $curl_exit -eq 9 ] || [ $curl_exit -eq 78 ]; then + log "FTP path denied for $file_url" + break + fi + + download_attempt=$((download_attempt + 1)) + sleep "$NETPLAY_FTP_DOWNLOAD_DELAY" + done fi ###################### FINAL CHECK RESULT ######################### if [ ! -e "$file_path" ]; then - build_infoPanel_and_log "Sync Failed" "Failed to download the $file_type file." + if [ "$file_type" = "Img" ]; then + log "Image not found on peer; continuing without image." + else + build_infoPanel_and_log "Sync Failed" "Failed to download the $file_type file." + fi # copy has failed : restoring the original file if [ $file_type != "Rom" ] && [ $file_type != "Core" ]; then @@ -630,7 +644,11 @@ sync_file() { log "backup restored" fi sleep 2 - [ "$file_mandatory" = "-m" ] && cleanup + if [ "$file_mandatory" = "-m" ]; then + if [ "$file_type" != "Img" ]; then + cleanup + fi + fi else diff --git a/static/build/.tmp_update/script/netplay/netplay_common.sh b/static/build/.tmp_update/script/netplay/netplay_common.sh index 74ede92137..6157576f85 100644 --- a/static/build/.tmp_update/script/netplay/netplay_common.sh +++ b/static/build/.tmp_update/script/netplay/netplay_common.sh @@ -1,8 +1,12 @@ # Shared netplay helpers # Tunables -NETPLAY_FTP_CHECK_RETRIES=${NETPLAY_FTP_CHECK_RETRIES:-5} -NETPLAY_FTP_CHECK_DELAY=${NETPLAY_FTP_CHECK_DELAY:-1} +NETPLAY_FTP_CHECK_RETRIES=5 +NETPLAY_FTP_CHECK_DELAY=1 +NETPLAY_FTP_READY_DELAY=3 +NETPLAY_FTP_DOWNLOAD_RETRIES=5 +NETPLAY_FTP_DOWNLOAD_DELAY=1 +NETPLAY_FTP_HEAD_TIMEOUT=2 # checksize_func <file_path> <remote_size> # - sets: same_size (0 different, 1 identical, 2 unknown) @@ -12,15 +16,18 @@ checksize_func() { if [ -e "$func_file_path" ]; then local_file_size=$(stat -c%s "$func_file_path") + log "checksize_func: local_file_size=$local_file_size for $func_file_path" + log "checksize_func: remote_file_size='$filesize_tocheck'" if echo "$filesize_tocheck" | grep -q "^[0-9][0-9]*$"; then if [ "$filesize_tocheck" -eq "$local_file_size" ]; then same_size=1 else same_size=0 fi + log "checksize_func: same_size=$same_size (numeric compare)" else - log "Non-numeric remote file size for checksize_func: '$filesize_tocheck'" - same_size=2 + log "Non-numeric remote file size for checksize_func: '$filesize_tocheck' (skipping size check)" + same_size=1 fi else same_size=0 @@ -128,10 +135,19 @@ udhcpc_control() { udhcpc -i wlan0 -s /etc/init.d/udhcpc.script >/dev/null 2>&1 & } -# url_encode <string> -# - percent-encodes string for URLs +# url_encode <path> +# - encodes each path segment but keeps '/' url_encode() { - encoded_str=$(echo "$*" | awk ' + local path="$1" + local encoded="" + local IFS='/' + local part + + for part in $path; do + if [ -n "$encoded" ]; then + encoded="${encoded}/" + fi + encoded="${encoded}$(echo "$part" | awk ' BEGIN { split ("1 2 3 4 5 6 7 8 9 A B C D E F", hextab, " ") hextab [0] = 0 @@ -141,7 +157,7 @@ url_encode() { encoded = "" for ( i=1; i<=length ($0); ++i ) { c = substr ($0, i, 1) - if ( c ~ /[a-zA-Z0-9.-]/ ) { + if ( c ~ /[a-zA-Z0-9._-]/ ) { encoded = encoded c # safe character } else if ( c == " " ) { encoded = encoded "%20" # special handling @@ -153,24 +169,7 @@ url_encode() { } } print encoded - } -') - echo "$encoded_str" -} - -# url_encode_path <path> -# - encodes each path segment but keeps '/' -url_encode_path() { - local path="$1" - local encoded="" - local IFS='/' - local part - - for part in $path; do - if [ -n "$encoded" ]; then - encoded="${encoded}/" - fi - encoded="${encoded}$(url_encode "$part")" + }')" done printf '%s\n' "$encoded" @@ -265,46 +264,14 @@ check_ftp_local() { } # ensure_ftp_head <url> <remote_ip> <mandatory> -# - pings remote and performs FTP HEAD with retries +# - give peer time to start FTP before first transfer, then do a quick HEAD # - sets: ftp_head_result, ftp_head_exit ensure_ftp_head() { - local url="$1" - local remote_ip="$2" - local mandatory="$3" - local attempt=1 - - while [ $attempt -le $NETPLAY_FTP_CHECK_RETRIES ]; do - log "FTP check attempt $attempt/$NETPLAY_FTP_CHECK_RETRIES for $remote_ip" - ping -c 1 "$remote_ip" >/dev/null 2>&1 - if [ $? -ne 0 ]; then - log "Ping to $remote_ip failed (attempt $attempt)" - fi - - ftp_head_result=$(curl -I --connect-timeout 3 "$url" 2>&1) - ftp_head_exit=$? - - if [ $ftp_head_exit -eq 0 ]; then - return 0 - fi - - if echo "$ftp_head_result" | grep -q "The file does not exist"; then - log "FTP reachable but file missing for $remote_ip" - return 0 - fi - - log "FTP HEAD failed for $remote_ip (curl exit=$ftp_head_exit)" - log "FTP HEAD error: $ftp_head_result" - attempt=$((attempt + 1)) - sleep "$NETPLAY_FTP_CHECK_DELAY" - done - - build_infoPanel_and_log "Sync Failed" "Unable to reach FTP server at $remote_ip." - if [ "$mandatory" = "-m" ]; then - if type cleanup >/dev/null 2>&1; then - cleanup - fi - fi - return 1 + # wait for peer tcpsvd to be ready (reduces race on first FTP request) + sleep "$NETPLAY_FTP_READY_DELAY" + ftp_head_result=$(curl -sS -I --connect-timeout "$NETPLAY_FTP_HEAD_TIMEOUT" "$1" 2>&1) + ftp_head_exit=$? + return 0 } # check_wifi <use_udhcpc> <hard_fail> <down_wlan1> # - use_udhcpc: 1 to call udhcpc_control after wpa_supplicant From 7cbf459406d4d77b257a83cd5def357c0db9a11c Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Tue, 20 Jan 2026 22:05:56 +0000 Subject: [PATCH 14/32] consolidate netplay helpers, rename scripts, and update sources --- .../script/netplay/easy-netplay_client.sh | 4 +- .../netplay/easy-netplay_client_pokemon.sh | 348 +--------- .../easy-netplay_client_pokemon_GBA.sh | 8 +- .../script/netplay/easy-netplay_common.sh | 614 ++++++++++++++++++ .../script/netplay/easy-netplay_server.sh | 38 +- .../netplay/easy-netplay_server_pokemon.sh | 348 +--------- .../easy-netplay_server_pokemon_GBA.sh | 8 +- ...gnalling.sh => easy-netplay_signalling.sh} | 0 .../script/netplay/netplay_common.sh | 317 --------- .../script/netplay/standard-netplay.sh | 4 +- 10 files changed, 636 insertions(+), 1053 deletions(-) create mode 100644 static/build/.tmp_update/script/netplay/easy-netplay_common.sh rename static/build/.tmp_update/script/netplay/{netplay_signalling.sh => easy-netplay_signalling.sh} (100%) delete mode 100644 static/build/.tmp_update/script/netplay/netplay_common.sh diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh index 720f2e73ef..ef45a3fc95 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh @@ -18,8 +18,8 @@ logfile=easy_netplay # Source scripts . $sysdir/script/log.sh -# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, read_cookie, check_wifi, start_ftp -. $sysdir/script/netplay/netplay_common.sh +# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, read_cookie, check_wifi, start_ftp +. $sysdir/script/netplay/easy-netplay_common.sh program=$(basename "$0" .sh) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh index b536837d2e..69977ee6e7 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh @@ -21,10 +21,10 @@ logfile=pokemon_link # Source scripts . $sysdir/script/log.sh -# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, read_cookie, check_wifi, start_ftp -. $sysdir/script/netplay/netplay_common.sh -# netplay_signalling.sh: check_stop, notify_peer, notify_stop, wait_for_host -. $sysdir/script/netplay/netplay_signalling.sh +# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, read_cookie, check_wifi, start_ftp, sync_file +. $sysdir/script/netplay/easy-netplay_common.sh +# easy-netplay_signalling.sh: check_stop, notify_peer, notify_stop, wait_for_host +. $sysdir/script/netplay/easy-netplay_signalling.sh program=$(basename "$0" .sh) @@ -200,347 +200,7 @@ cleanup() { #Utilities# ########### -# Function to sync files - -sync_file() { - - MAX_FILE_CHKSUM_SIZE=26214400 - MAX_FILE_DL_SIZE=104857600 - - file_type="$1" # Used in displayed message and some custom actions - file_path="$2" # Local file path - file_check_size="$3" # 0 or 1 to indicate if we have to check the file size - remote_file_checksum="$4" # 0 to skip , real checksum value to check - sync_type="$5" # -o overwrite if different (require file_size or/and checksum != 0) , (if file_size & checksum = 0 then the file is never overwritted, only copied if not present) - # -f overwrite all the time (whatever the value of file_size and checksum) (if file_size & checksum = 0 then the file is overwritted, even if already present ) - # -b if different, backup local file before copying remote file - # -c check only, allows to check the presence of a file, to check its CRC or size and to quit or not the script - file_mandatory="$6" # -m , exit the script on failed sync_success - - #examples : - # sync_file archive /mnt/SDCARD/test.zip 1 5AFC442 -b -m # backup and replace if different file - # sync_file archive /mnt/SDCARD/test.zip 0 0 -f -m # the local file will be systematically replaced - # sync_file archive /mnt/SDCARD/test.zip 0 0 -o -m # the local file will be copied if not exist - # sync_file archive /mnt/SDCARD/test.zip 0 5AFC442 -c -m # exit if the file doesn't have the right checksum - # sync_file archive /mnt/SDCARD/test.zip 1 5AFC442 -o -m # the local file will be replaced if the size or the checksum is different - - # some useful vars - dir_path=$(dirname "$file_path") - file_url="ftp://${hostip}/$(url_encode "${file_path#*/}")" - remote_ip="$hostip" - - log -e "\n############################ SYNC_FILE DEBUGGING ############################" - log file_type $file_type - log file_path $file_path - log file_check_size $file_check_size - log remote_file_checksum $remote_file_checksum - log sync_type $sync_type - log file_mandatory $file_mandatory - log file_url $file_url - log dir_path $dir_path - log "#############################################################################" - - # state vars - same_size= - same_chksum= - sync_success= - run_sync= # tell if the sync task must be done or not - - if ! ensure_ftp_head "$file_url" "$remote_ip" "$file_mandatory"; then - same_size=0 - run_sync=0 - sync_success=0 - fi - RequestResult="$ftp_head_result" - - if [[ $RequestResult == *"The file does not exist"* ]]; then - log "The remote file does not exist." - msg="The remote file does not exist." - build_infoPanel_and_log "Syncing" "The remote file does not exist." - run_sync=0 - sync_success=0 - same_size=0 - else - remote_file_size=$(echo "$RequestResult" | grep -i "Content-Length" | awk '{print $2}') - if ! echo "$remote_file_size" | grep -q "^[0-9][0-9]*$"; then # check if the remote file size is a numeric value - log "Non-numeric remote file size: '$remote_file_size'" - log "HEAD response: $RequestResult" - same_size=0 - else - log "remote_file_size: $remote_file_size" - fi - - fi - - if [ -e "$file_path" ]; then - - ########################## File checksum check : same_chksum = 0 different, 1 identical , 2 unknown - checksum_func "$file_path" "$remote_file_checksum" - - ########################## File size check same_size = 0 different, 1 identical , 2 unknown - if [ "$file_check_size" -eq 1 ]; then # file_checksum=0 means skip the difference check = always replace - checksize_func "$file_path" "$remote_file_size" - else - log "Skipping file size check." - same_size=1 # fake same size for skipping - fi - - else - log "The local file does not exist." - same_size=0 - same_chksum=0 - fi - - ########################## exception : max file size check on the remote - if echo "$remote_file_size" | grep -q "^[0-9][0-9]*$"; then - if [ "$remote_file_size" -le "$MAX_FILE_DL_SIZE" ]; then - log "Remote file size ok: $remote_file_size bytes (<= $MAX_FILE_DL_SIZE bytes)" - else - log "Remote file size too big: $remote_file_size bytes (> $MAX_FILE_DL_SIZE bytes)" - run_sync=0 - fi - else - log "Skipping max file size check due to non-numeric remote size: '$remote_file_size'" - fi - - ########################## We have all the required information, depending the choosen option we run the copy or not - - if [ "$sync_type" == "-o" ]; then # we overwrite the file if different - log "option -o selected : we overwrite the file if different." - if [ "$same_size" -ne 1 ] || [ "$same_chksum" -ne 1 ]; then - [ -z "$run_sync" ] && run_sync=1 - fi - fi - - if [ "$sync_type" == "-b" ]; then # backup - log "option -b selected : we backup before overwrite." - if { [ "$remote_file_checksum" != "0" ] && [ "$same_chksum" -ne 1 ]; } || [ "$remote_file_checksum" == "0" ]; then # if (we don't skip CRC and CRC is not identical) or (if we skip CRC) then we sync -> in other words we only skip the copy when we have an identical CRC - [ -z "$run_sync" ] && run_sync=1 - fi - fi - - if [ "$sync_type" == "-f" ]; then # we overwrite the file if different - log "option -f selected : forced file syncing." - if { [ "$remote_file_checksum" != "0" ] && [ "$same_chksum" -ne 1 ]; } || [ "$remote_file_checksum" == "0" ]; then # if (we don't skip CRC and CRC is not identical) or (if we skip CRC) then we sync -> in other words we only skip the copy when we have an identical CRC - [ -z "$run_sync" ] && run_sync=1 - fi - - fi - - if [ "$sync_type" == "-c" ]; then # we overwrite the file if different - log "option -c selected : no file copy, only check." - run_sync=0 - - if [ "$same_size" -ne 1 ]; then - msg="Files doesn't have the same size." - sync_success=0 - [ "$file_mandatory" = "-m" ] && cleanup - - fi - if [ "$same_chksum" -ne 1 ]; then - msg="$msg\nFiles doesn't have the same checksum." - sync_success=0 - [ "$file_mandatory" = "-m" ] && cleanup - - fi - if [ "$same_size" -eq 1 ] && [ "$same_chksum" -eq 1 ]; then - msg="Remote and local files are identical." - sync_success=1 - fi - build_infoPanel_and_log "File check" "$msg" - - fi - - # log "############################ DEBUGGING #######################################" - # log sync_type $sync_type - # log remote_file_checksum $remote_file_checksum - # log same_chksum $same_chksum - # log run_sync $run_sync - # log file_type $file_type - # log -e "\n\n" - # log "##############################################################################" - - ########################## COPY Operation ########################## - - if [ "$run_sync" -eq 1 ]; then - - if [ $file_type == "Cookie" ]; then # exception for cookies : we don't download with the same target name - file_path="${file_path}.client" - fi - # let's make a backup first whatever the case - if [ -e "$file_path" ]; then - if [ $file_type == "Rom" ]; then - # if rom already here and different file then we create a rom_neplay to avoid to override user games - - # oldpath="$file_path" - # file_path_without_extension="${file_path%.*}" - # file_path="${file_path_without_extension}_netplay.${file_path##*.}" - # if [ -e "$Img_path" ]; then - # cp "$Img_path" "/mnt/SDCARD/Roms/$romdirname/Imgs/${romNameNoExtension}_netplay.png" - # Img_path="/mnt/SDCARD/Roms/$romdirname/Imgs/${romNameNoExtension}_netplay.png" - # fi - - Netplay_Rom_Folder="$(dirname "$file_path")/.netplay" - mkdir -p "$Netplay_Rom_Folder" - file_path="$Netplay_Rom_Folder/$(basename "$file_path")" - rom=$file_path - - elif [ $file_type == "Core" ]; then - # oldpath="$file_path" - # file_path_without_extension="${file_path%.*}" - # file_path="${file_path_without_extension}_netplay.${file_path##*.}" - - Netplay_Core_Folder="$(dirname "$file_path")/.netplay" - mkdir -p "$Netplay_Core_Folder" - file_path="$Netplay_Core_Folder/$(basename "$file_path")" - core=$file_path - else - mv "$file_path" "${file_path}_old" - log "Existing $file_type file moved to ${file_path}_old" - fi - fi - - if [ ! -d "$dir_path" ]; then - mkdir -p "$dir_path" - fi - - log "Starting to download $file_type from $file_url" - download_attempt=1 - while [ $download_attempt -le $NETPLAY_FTP_DOWNLOAD_RETRIES ]; do - curl_output=$(curl -S -o "$file_path" "$file_url" 2>&1) - curl_exit=$? - - if [ $curl_exit -eq 0 ]; then - log "$file_type download completed" - break - fi - - log "$file_type download failed (curl exit=$curl_exit, attempt $download_attempt/$NETPLAY_FTP_DOWNLOAD_RETRIES)" - log "curl error: $curl_output" - if [ $curl_exit -eq 9 ] || [ $curl_exit -eq 78 ]; then - log "FTP path denied for $file_url" - break - fi - - download_attempt=$((download_attempt + 1)) - sleep "$NETPLAY_FTP_DOWNLOAD_DELAY" - done - - fi - - ###################### FINAL CHECK RESULT ######################### - - if [ ! -e "$file_path" ]; then - if [ "$file_type" = "Img" ]; then - log "Image not found on peer; continuing without image." - else - build_infoPanel_and_log "Sync Failed" "Failed to download the $file_type file." - fi - - # copy has failed : restoring the original file - if [ $file_type != "Rom" ] && [ $file_type != "Core" ]; then - mv "${file_path}_old" "$file_path" - log "backup restored" - fi - sleep 2 - if [ "$file_mandatory" = "-m" ]; then - if [ "$file_type" != "Img" ]; then - cleanup - fi - fi - - else - - checksum_func "$file_path" "$remote_file_checksum" - - if [ "$file_check_size" -eq 1 ]; then # file_checksum=0 means skip the difference check = always replace - checksize_func "$file_path" "$remote_file_size" - else - log "Skipping file size check." - same_size=1 # fake same size for skipping - fi - - if [ "$same_size" -eq 1 ] && [ "$same_chksum" -eq 1 ]; then - build_infoPanel_and_log "Syncing" "$file_type synced." - if [ $file_type == "Rom" ]; then - log "Refreshing roms list ${rom%/*}/${romdirname}_cache6.db" - rm "${rom%/*}/${romdirname}_cache6.db" - fi - - else - build_infoPanel_and_log "Sync Failed" "Failed to download the $file_type file." - - # copy has failed : restoring the original file - if [ $file_type != "Rom" ] && [ $file_type != "Core" ]; then - mv "${file_path}_old" "$file_path" - log "backup restored" - fi - sleep 2 - if [ "$file_mandatory" = "-m" ]; then - # notify_peer: signal stop to host - notify_peer "$hostip" "stop_now" - cleanup - fi - fi - #####" - - fi - ###################### FINAL RESULT DISPLAY######################### - - # if [ "$sync_success" -ne 1 ]; then - # build_infoPanel_and_log "Sync Failed" "Failed to download the $file_type file." - # sleep 2 - # cleanup - # else - # build_infoPanel_and_log "Syncing" "$file_type synced." - # fi - - # build_infoPanel_and_log "Syncing" "$file_type checksums don't match, syncing" - # build_infoPanel_and_log "Sync Failed" "Failed to download the $file_type file." - # build_infoPanel_and_log "Syncing" "$file_type synced." - # build_infoPanel_and_log "Syncing" "$file_type doesn't exist locally; syncing with host." - # build_infoPanel_and_log "Sync Failed" "Failed to download the $file_type file." - # build_infoPanel_and_log "Syncing" "$file_type synced." - - ################### END ########################## - -} - # Create a cookie with all the required info for the client. (client will use this cookie) -create_cookie_info() { - COOKIE_FILE="/mnt/SDCARD/RetroArch/retroarch.cookie" - MAX_FILE_SIZE_BYTES=26214400 - - echo "[core]: $netplaycore" >"$COOKIE_FILE" - echo "[rom]: $cookie_rom_path" >>"$COOKIE_FILE" - - if [ -s "$netplaycore" ]; then - log "Writing core size" - core_size=$(stat -c%s "$netplaycore") - if [ "$core_size" -gt "$MAX_FILE_SIZE_BYTES" ]; then - echo "[corechksum]: 0" >>"$COOKIE_FILE" - else - echo "[corechksum]: $(xcrc "$netplaycore")" >>"$COOKIE_FILE" - fi - fi - - if [ -s "$cookie_rom_path" ]; then - log "Writing rom size" - rom_size=$(stat -c%s "$cookie_rom_path") - if [ "$rom_size" -gt "$MAX_FILE_SIZE_BYTES" ]; then - echo "[romchksum]: 0" >>"$COOKIE_FILE" - else - echo "[romchksum]: $(xcrc "$cookie_rom_path")" >>"$COOKIE_FILE" - fi - fi - - if [ -s "$cpuspeed" ]; then - echo "[cpuspeed]: $cpuspeed" >>"$COOKIE_FILE" - log "Writing cpuspeed: $cpuspeed" - fi - -} - confirm_join_panel() { local title="$1" local message="$2" diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh index 687e0437d1..4929e61640 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh @@ -20,10 +20,10 @@ logfile=pokemon_link # Source scripts . $sysdir/script/log.sh -# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp -. $sysdir/script/netplay/netplay_common.sh -# netplay_signalling.sh: wait_for_host, check_stop, notify_stop -. $sysdir/script/netplay/netplay_signalling.sh +# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp +. $sysdir/script/netplay/easy-netplay_common.sh +# easy-netplay_signalling.sh: wait_for_host, check_stop, notify_stop +. $sysdir/script/netplay/easy-netplay_signalling.sh log "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* Easy Netplay Pokemon Client GBA -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_common.sh b/static/build/.tmp_update/script/netplay/easy-netplay_common.sh new file mode 100644 index 0000000000..3e4335fcba --- /dev/null +++ b/static/build/.tmp_update/script/netplay/easy-netplay_common.sh @@ -0,0 +1,614 @@ +# Shared netplay helpers + +# Tunables +NETPLAY_FTP_CHECK_RETRIES=5 +NETPLAY_FTP_CHECK_DELAY=1 +NETPLAY_FTP_READY_DELAY=3 +NETPLAY_FTP_DOWNLOAD_RETRIES=5 +NETPLAY_FTP_DOWNLOAD_DELAY=1 +NETPLAY_FTP_HEAD_TIMEOUT=2 + +# checksize_func <file_path> <remote_size> +# - sets: same_size (0 different, 1 identical, 2 unknown) +checksize_func() { + local func_file_path="${1:-$file_path}" + local filesize_tocheck="${2:-$remote_file_size}" + + if [ -e "$func_file_path" ]; then + local_file_size=$(stat -c%s "$func_file_path") + log "checksize_func: local_file_size=$local_file_size for $func_file_path" + log "checksize_func: remote_file_size='$filesize_tocheck'" + if echo "$filesize_tocheck" | grep -q "^[0-9][0-9]*$"; then + if [ "$filesize_tocheck" -eq "$local_file_size" ]; then + same_size=1 + else + same_size=0 + fi + log "checksize_func: same_size=$same_size (numeric compare)" + else + log "Non-numeric remote file size for checksize_func: '$filesize_tocheck' (skipping size check)" + same_size=1 + fi + else + same_size=0 + fi +} + +# checksum_func <file_path> <crc> +# - uses: MAX_FILE_CHKSUM_SIZE +# - sets: same_chksum +checksum_func() { + local_file_size=$(stat -c%s "$file_path") + local func_file_path="$1" + local CRC="$2" + + ########################## File checksum check : same_chksum = 0 different, 1 identical , 2 unknown + + if [ "$CRC" != "0" ]; then # file_checksum=0 means skip the difference check = always replace + local_file_checksum=$(xcrc "$func_file_path") + + if [ "$local_file_size" -gt "$MAX_FILE_CHKSUM_SIZE" ]; then + log "File size too big for checksum: it would be too long" + same_chksum=2 + else + if [ "$CRC" == "$local_file_checksum" ]; then + same_chksum=1 + else + same_chksum=0 + fi + fi + else + log "Skipping checksum check." + same_chksum=1 + fi +} + +# enable_flag <flag_name> +# - creates $sysdir/config/.<flag_name> +enable_flag() { + flag="$1" + touch "$sysdir/config/.$flag" +} + +# disable_flag <flag_name> +# - removes $sysdir/config/.<flag_name> +disable_flag() { + flag="$1" + mv "$sysdir/config/.$flag" "$sysdir/config/.$flag_" +} + +# flag_enabled <flag_name> +# - returns 0 if flag file exists +flag_enabled() { + flag="$1" + [ -f "$sysdir/config/.$flag" ] +} + +# is_running <process_name> +# - returns 0 if process is running +is_running() { + process_name="$1" + pgrep "$process_name" >/dev/null +} + +# build_infoPanel_and_log <title> <message> +# - uses: INFOPANEL_SLEEP (default 0.3s) +# - shows persistent infoPanel and logs message +build_infoPanel_and_log() { + local title="$1" + local message="$2" + local delay="${INFOPANEL_SLEEP:-0.3}" + + log "Info Panel: \n\tStage: $title\n\tMessage: $message" + if is_running infoPanel; then + killall -9 infoPanel + fi + infoPanel --title "$title" --message "$message" --persistent & + sync + touch /tmp/dismiss_info_panel + sync + sleep "$delay" + sync +} + +# restore_ftp +# - restores original FTP state based on flags +restore_ftp() { + log "Restoring original FTP server" + killall -9 tcpsvd + if flag_enabled ftpState; then + if flag_enabled authftpState; then + bftpd -d -c /mnt/SDCARD/.tmp_update/config/bftpdauth.conf & + else + bftpd -d -c /mnt/SDCARD/.tmp_update/config/bftpd.conf & + fi + fi +} + +# udhcpc_control +# - restarts udhcpc on wlan0 +udhcpc_control() { + if pgrep udhcpc >/dev/null; then + killall -9 udhcpc + fi + sleep 1 + udhcpc -i wlan0 -s /etc/init.d/udhcpc.script >/dev/null 2>&1 & +} + +# url_encode <path> +# - encodes each path segment but keeps '/' +url_encode() { + local path="$1" + local encoded="" + local IFS='/' + local part + + for part in $path; do + if [ -n "$encoded" ]; then + encoded="${encoded}/" + fi + encoded="${encoded}$(echo "$part" | awk ' + BEGIN { + split ("1 2 3 4 5 6 7 8 9 A B C D E F", hextab, " ") + hextab [0] = 0 + for ( i=1; i<=255; ++i ) ord [ sprintf ("%c", i) "" ] = i + 0 + } + { + encoded = "" + for ( i=1; i<=length ($0); ++i ) { + c = substr ($0, i, 1) + if ( c ~ /[a-zA-Z0-9._-]/ ) { + encoded = encoded c # safe character + } else if ( c == " " ) { + encoded = encoded "%20" # special handling + } else { + # unsafe character, encode it as a two-digit hex-number + lo = ord [c] % 16 + hi = int (ord [c] / 16); + encoded = encoded "%" hextab [hi] hextab [lo] + } + } + print encoded + }')" + done + + printf '%s\n' "$encoded" +} + +# read_cookie [verbose] +# - parses /mnt/SDCARD/RetroArch/retroarch.cookie.client into core/rom/checksum vars +# - sets: core_url, rom_url, romdirname, romName, romNameNoExtension, Img_path +read_cookie() { + local verbose="$1" + sync + while IFS= read -r line; do + case $line in + "[core]: "*) + core="${line##"[core]: "}" + ;; + "[rom]: "*) + rom="${line##"[rom]: "}" + ;; + "[coresize]: "*) + corechecksum="${line##"[coresize]: "}" + ;; + "[corechksum]: "*) + corechecksum="${line##"[corechksum]: "}" + ;; + "[romsize]: "*) + romchecksum="${line##"[romsize]: "}" + ;; + "[romchksum]: "*) + romchecksum="${line##"[romchksum]: "}" + ;; + "[cpuspeed]: "*) + cpuspeed="${line##"[cpuspeed]: "}" + ;; + esac + log "$core $rom $coresize $corechksum $romsize $romchksum" + done <"/mnt/SDCARD/RetroArch/retroarch.cookie.client" + + # url encode or curl complains + export core_url=$(url_encode "$core") + export rom_url=$(url_encode "$rom") + + romdirname=$(echo "$rom" | grep -o '/Roms/[^/]*' | cut -d'/' -f3) + romName=$(basename "$rom") + romNameNoExtension=${romName%.*} + Img_path="/mnt/SDCARD/Roms/$romdirname/Imgs/$romNameNoExtension.png" + + if [ "$verbose" = "1" ]; then + log "Cookie file read :" + log "romdirname $romdirname" + log "romName $romName" + log "romNameNoExtension $romNameNoExtension" + log "Img_path $Img_path" + else + log "Cookie file read" + fi +} + +# sync_file <type> <path> <check_size> <checksum> <sync_type> <mandatory> +# - uses: peer_ip or hostip, ensure_ftp_head, checksize_func, checksum_func +# - sync_type: -o overwrite if different, -f force, -b backup, -c check only +# - mandatory: -m to cleanup on failure +sync_file() { + MAX_FILE_CHKSUM_SIZE=26214400 + MAX_FILE_DL_SIZE=104857600 + + file_type="$1" # Used in displayed message and some custom actions + file_path="$2" # Local file path + file_check_size="$3" # 0 or 1 to indicate if we have to check the file size + remote_file_checksum="$4" # 0 to skip , real checksum value to check + sync_type="$5" # -o overwrite if different, -f forced, -b backup, -c check only + file_mandatory="$6" # -m , exit the script on failed sync_success + + # some useful vars + dir_path=$(dirname "$file_path") + remote_ip="${peer_ip:-$hostip}" + file_url="ftp://${remote_ip}/$(url_encode "${file_path#*/}")" + + log "\n############################ SYNC_FILE DEBUGGING ############################" + log file_type $file_type + log file_path $file_path + log file_check_size $file_check_size + log remote_file_checksum $remote_file_checksum + log sync_type $sync_type + log file_mandatory $file_mandatory + log file_url $file_url + log dir_path $dir_path + log "#############################################################################" + + # state vars + same_size= + same_chksum= + sync_success= + run_sync= # tell if the sync task must be done or not + + if ! ensure_ftp_head "$file_url" "$remote_ip" "$file_mandatory"; then + same_size=0 + run_sync=0 + sync_success=0 + fi + RequestResult="$ftp_head_result" + + if [[ $RequestResult == *"The file does not exist"* ]]; then + log "The remote file does not exist." + msg="The remote file does not exist." + build_infoPanel_and_log "Syncing" "The remote file does not exist." + run_sync=0 + sync_success=0 + same_size=0 + else + remote_file_size=$(echo "$RequestResult" | grep -i "Content-Length" | awk '{print $2}') + if ! echo "$remote_file_size" | grep -q "^[0-9][0-9]*$"; then # check if the remote file size is a numeric value + log "Non-numeric remote file size: '$remote_file_size'" + log "HEAD response: $RequestResult" + same_size=0 + else + log "remote_file_size: $remote_file_size" + fi + + fi + + if [ -e "$file_path" ]; then + + ########################## File checksum check : same_chksum = 0 different, 1 identical , 2 unknown + checksum_func "$file_path" "$remote_file_checksum" + + ########################## File size check same_size = 0 different, 1 identical , 2 unknown + if [ "$file_check_size" -eq 1 ]; then # file_checksum=0 means skip the difference check = always replace + checksize_func "$file_path" "$remote_file_size" + else + log "Skipping file size check." + same_size=1 # fake same size for skipping + fi + + else + log "The local file does not exist." + same_size=0 + same_chksum=0 + fi + + ########################## exception : max file size check on the remote + if echo "$remote_file_size" | grep -q "^[0-9][0-9]*$"; then + if [ "$remote_file_size" -le "$MAX_FILE_DL_SIZE" ]; then + log "Remote file size ok: $remote_file_size bytes (<= $MAX_FILE_DL_SIZE bytes)" + else + log "Remote file size too big: $remote_file_size bytes (> $MAX_FILE_DL_SIZE bytes)" + run_sync=0 + fi + else + log "Skipping max file size check due to non-numeric remote size: '$remote_file_size'" + fi + + ########################## We have all the required information, depending the chosen option we run the copy or not + + if [ "$sync_type" == "-o" ]; then # we overwrite the file if different + log "option -o selected : we overwrite the file if different." + if [ "$same_size" -ne 1 ] || [ "$same_chksum" -ne 1 ]; then + [ -z "$run_sync" ] && run_sync=1 + fi + fi + + if [ "$sync_type" == "-b" ]; then # backup + log "option -b selected : we backup before overwrite." + if { [ "$remote_file_checksum" != "0" ] && [ "$same_chksum" -ne 1 ]; } || [ "$remote_file_checksum" == "0" ]; then + [ -z "$run_sync" ] && run_sync=1 + fi + fi + + if [ "$sync_type" == "-f" ]; then # we overwrite the file if different + log "option -f selected : forced file syncing." + if { [ "$remote_file_checksum" != "0" ] && [ "$same_chksum" -ne 1 ]; } || [ "$remote_file_checksum" == "0" ]; then + [ -z "$run_sync" ] && run_sync=1 + fi + + fi + + if [ "$sync_type" == "-c" ]; then # we overwrite the file if different + log "option -c selected : no file copy, only check." + run_sync=0 + + if [ "$same_size" -ne 1 ]; then + msg="Files doesn't have the same size." + sync_success=0 + [ "$file_mandatory" = "-m" ] && cleanup + + fi + if [ "$same_chksum" -ne 1 ]; then + msg="$msg\nFiles doesn't have the same checksum." + sync_success=0 + [ "$file_mandatory" = "-m" ] && cleanup + + fi + if [ "$same_size" -eq 1 ] && [ "$same_chksum" -eq 1 ]; then + msg="Remote and local files are identical." + sync_success=1 + fi + build_infoPanel_and_log "File check" "$msg" + + fi + + ########################## COPY Operation ########################## + + if [ "$run_sync" -eq 1 ]; then + + if [ $file_type == "Cookie" ]; then # exception for cookies : we don't download with the same target name + file_path="${file_path}.client" + fi + # let's make a backup first whatever the case + if [ -e "$file_path" ]; then + if [ $file_type == "Rom" ]; then + Netplay_Rom_Folder="$(dirname "$file_path")/.netplay" + mkdir -p "$Netplay_Rom_Folder" + file_path="$Netplay_Rom_Folder/$(basename "$file_path")" + rom=$file_path + + elif [ $file_type == "Core" ]; then + Netplay_Core_Folder="$(dirname "$file_path")/.netplay" + mkdir -p "$Netplay_Core_Folder" + file_path="$Netplay_Core_Folder/$(basename "$file_path")" + core=$file_path + else + mv "$file_path" "${file_path}_old" + log "Existing $file_type file moved to ${file_path}_old" + fi + fi + + if [ ! -d "$dir_path" ]; then + mkdir -p "$dir_path" + fi + + log "Starting to download $file_type from $file_url" + download_attempt=1 + while [ $download_attempt -le $NETPLAY_FTP_DOWNLOAD_RETRIES ]; do + curl_output=$(curl -S -o "$file_path" "$file_url" 2>&1) + curl_exit=$? + + if [ $curl_exit -eq 0 ]; then + log "$file_type download completed" + break + fi + + log "$file_type download failed (curl exit=$curl_exit, attempt $download_attempt/$NETPLAY_FTP_DOWNLOAD_RETRIES)" + log "curl error: $curl_output" + if [ $curl_exit -eq 9 ] || [ $curl_exit -eq 78 ]; then + log "FTP path denied for $file_url" + break + fi + + download_attempt=$((download_attempt + 1)) + sleep "$NETPLAY_FTP_DOWNLOAD_DELAY" + done + + fi + + ###################### FINAL CHECK RESULT ######################### + + if [ ! -e "$file_path" ]; then + if [ "$file_type" = "Img" ]; then + log "Image not found on peer; continuing without image." + else + build_infoPanel_and_log "Sync Failed" "Failed to download the $file_type file." + fi + + # copy has failed : restoring the original file + if [ $file_type != "Rom" ] && [ $file_type != "Core" ]; then + mv "${file_path}_old" "$file_path" + log "backup restored" + fi + sleep 2 + if [ "$file_mandatory" = "-m" ]; then + if [ "$file_type" != "Img" ]; then + if type notify_peer >/dev/null 2>&1; then + notify_peer "$remote_ip" "stop_now" + fi + cleanup + fi + fi + + else + + checksum_func "$file_path" "$remote_file_checksum" + + if [ "$file_check_size" -eq 1 ]; then # file_checksum=0 means skip the difference check = always replace + checksize_func "$file_path" "$remote_file_size" + else + log "Skipping file size check." + same_size=1 # fake same size for skipping + fi + + if [ "$same_size" -eq 1 ] && [ "$same_chksum" -eq 1 ]; then + build_infoPanel_and_log "Syncing" "$file_type synced." + if [ $file_type == "Rom" ]; then + log "Refreshing roms list ${rom%/*}/${romdirname}_cache6.db" + rm "${rom%/*}/${romdirname}_cache6.db" + fi + + else + build_infoPanel_and_log "Sync Failed" "Failed to download the $file_type file." + + # copy has failed : restoring the original file + if [ $file_type != "Rom" ] && [ $file_type != "Core" ]; then + mv "${file_path}_old" "$file_path" + log "backup restored" + fi + sleep 2 + if [ "$file_mandatory" = "-m" ]; then + if type notify_peer >/dev/null 2>&1; then + notify_peer "$remote_ip" "stop_now" + fi + cleanup + fi + fi + #####" + + fi + + ################### END ########################## +} + +# create_cookie_info +# - writes core/rom/checksum/cpuspeed into retroarch.cookie +create_cookie_info() { + COOKIE_FILE="/mnt/SDCARD/RetroArch/retroarch.cookie" + MAX_FILE_SIZE_BYTES=26214400 + + echo "[core]: $netplaycore" >"$COOKIE_FILE" + echo "[rom]: $cookie_rom_path" >>"$COOKIE_FILE" + + if [ -s "$netplaycore" ]; then + log "Writing core size" + core_size=$(stat -c%s "$netplaycore") + if [ "$core_size" -gt "$MAX_FILE_SIZE_BYTES" ]; then + echo "[corechksum]: 0" >>"$COOKIE_FILE" + else + echo "[corechksum]: $(xcrc "$netplaycore")" >>"$COOKIE_FILE" + fi + fi + + if [ -s "$cookie_rom_path" ]; then + rom_size=$(stat -c%s "$cookie_rom_path") + log "Cookie local rom size : $rom_size" + if [ "$rom_size" -gt "$MAX_FILE_SIZE_BYTES" ]; then + echo "[romchksum]: 0" >>"$COOKIE_FILE" + else + echo "[romchksum]: $(xcrc "$cookie_rom_path")" >>"$COOKIE_FILE" + fi + fi + + if [ -s "$cpuspeed" ]; then + echo "[cpuspeed]: $cpuspeed" >>"$COOKIE_FILE" + log "Writing custom cpuspeed: $cpuspeed" + fi +} + +# start_ftp [check_stop_message] +# - starts built-in FTP server for signaling +# - if a message is provided, check_stop is invoked with it first +start_ftp() { + if [ -n "$1" ]; then + check_stop "$1" + fi + if is_running bftpd; then + log "FTP already running, killing to rebind" + bftpd_p=$(ps | grep bftpd | grep -v grep | awk '{for(i=4;i<=NF;++i) printf $i\" \"}') + killall -9 bftpd + killall -9 tcpsvd + tcpsvd -E 0.0.0.0 21 ftpd -w / & + else + tcpsvd -E 0.0.0.0 21 ftpd -w / & + log "Starting FTP server" + fi + check_ftp_local + sleep 0.5 +} + +# check_ftp_local [port] +# - logs whether tcpsvd is running and its args/port +check_ftp_local() { + local port="${1:-21}" + if pgrep tcpsvd >/dev/null; then + local tcpsvd_ps + tcpsvd_ps=$(ps | grep tcpsvd | grep -v grep) + log "FTP tcpsvd running (expected port $port): $tcpsvd_ps" + else + log "FTP tcpsvd not running (expected port $port)" + build_infoPanel_and_log "FTP Error" "FTP server failed to start." + fi +} + +# ensure_ftp_head <url> <remote_ip> <mandatory> +# - give peer time to start FTP before first transfer, then do a quick HEAD +# - sets: ftp_head_result, ftp_head_exit +ensure_ftp_head() { + # wait for peer tcpsvd to be ready (reduces race on first FTP request) + sleep "$NETPLAY_FTP_READY_DELAY" + ftp_head_result=$(curl -sS -I --connect-timeout "$NETPLAY_FTP_HEAD_TIMEOUT" "$1" 2>&1) + ftp_head_exit=$? + return 0 +} + +# check_wifi <use_udhcpc> <hard_fail> <down_wlan1> +# - use_udhcpc: 1 to call udhcpc_control after wpa_supplicant +# - hard_fail: 1 to notify_stop on failure, 0 to just pause +# - down_wlan1: 1 to bring wlan1 down before checks +check_wifi() { + local use_udhcpc="$1" + local hard_fail="$2" + local down_wlan1="$3" + + if [ "$down_wlan1" -eq 1 ]; then + ifconfig wlan1 down + fi + + if ifconfig wlan0 &>/dev/null; then + log "Wifi up" + else + build_infoPanel_and_log "WIFI" "Wifi disabled, starting..." + + /customer/app/axp_test wifion + sleep 2 + ifconfig wlan0 up + sleep 1 + $miyoodir/app/wpa_supplicant -B -D nl80211 -iwlan0 -c /appconfigs/wpa_supplicant.conf + + if [ "$use_udhcpc" -eq 1 ]; then + udhcpc_control + fi + + if is_running wpa_supplicant && ifconfig wlan0 >/dev/null 2>&1; then + build_infoPanel_and_log "WIFI" "Wifi started." + else + build_infoPanel_and_log "WIFI" "Unable to start WiFi\n unable to continue." + if [ "$hard_fail" -eq 1 ]; then + notify_stop + else + sleep 1 + fi + fi + + sleep 2 + fi +} diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh index 2ada70407b..c05e375f1e 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh @@ -15,8 +15,8 @@ logfile=easy_netplay # Source scripts . $sysdir/script/log.sh -# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp -. $sysdir/script/netplay/netplay_common.sh +# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp +. $sysdir/script/netplay/easy-netplay_common.sh program=$(basename "$0" .sh) @@ -51,40 +51,6 @@ Get_NetplayCore() { } # Create a cookie with all the required info for the client. (client will use this cookie) -create_cookie_info() { - COOKIE_FILE="/mnt/SDCARD/RetroArch/retroarch.cookie" - MAX_FILE_SIZE_BYTES=26214400 - - echo "[core]: $netplaycore" >"$COOKIE_FILE" - echo "[rom]: $cookie_rom_path" >>"$COOKIE_FILE" - - if [ -s "$netplaycore" ]; then - log "Writing core size" - core_size=$(stat -c%s "$netplaycore") - if [ "$core_size" -gt "$MAX_FILE_SIZE_BYTES" ]; then - echo "[corechksum]: 0" >>"$COOKIE_FILE" - else - echo "[corechksum]: $(xcrc "$netplaycore")" >>"$COOKIE_FILE" - fi - fi - - if [ -s "$cookie_rom_path" ]; then - log "Writing rom size" - rom_size=$(stat -c%s "$cookie_rom_path") - if [ "$rom_size" -gt "$MAX_FILE_SIZE_BYTES" ]; then - echo "[romchksum]: 0" >>"$COOKIE_FILE" - else - echo "[romchksum]: $(xcrc "$cookie_rom_path")" >>"$COOKIE_FILE" - fi - fi - - if [ -s "$cpuspeed" ]; then - echo "[cpuspeed]: $cpuspeed" >>"$COOKIE_FILE" - log "Writing cpuspeed: $cpuspeed" - fi - -} - # We'll start Retroarch in host mode with -H with the core and rom paths loaded in. start_retroarch() { log "RetroArch" "Starting RetroArch..." diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh index a9067623f9..ac7d8dd8e5 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh @@ -11,10 +11,10 @@ logfile=pokemon_link # Source scripts . $sysdir/script/log.sh -# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp -. $sysdir/script/netplay/netplay_common.sh -# netplay_signalling.sh: wait_for_client, ready_up, notify_peer, check_stop, notify_stop -. $sysdir/script/netplay/netplay_signalling.sh +# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp, sync_file +. $sysdir/script/netplay/easy-netplay_common.sh +# easy-netplay_signalling.sh: wait_for_client, ready_up, notify_peer, check_stop, notify_stop +. $sysdir/script/netplay/easy-netplay_signalling.sh program=$(basename "$0" .sh) @@ -49,40 +49,6 @@ start_hotspot() { } # Create a cookie with all the required info for the client. (client will use this cookie) -create_cookie_info() { - COOKIE_FILE="/mnt/SDCARD/RetroArch/retroarch.cookie" - MAX_FILE_SIZE_BYTES=26214400 - - echo "[core]: $netplaycore" >"$COOKIE_FILE" - echo "[rom]: $cookie_rom_path" >>"$COOKIE_FILE" - - if [ -s "$netplaycore" ]; then - log "Writing core size" - core_size=$(stat -c%s "$netplaycore") - if [ "$core_size" -gt "$MAX_FILE_SIZE_BYTES" ]; then - echo "[corechksum]: 0" >>"$COOKIE_FILE" - else - echo "[corechksum]: $(xcrc "$netplaycore")" >>"$COOKIE_FILE" - fi - fi - - if [ -s "$cookie_rom_path" ]; then - rom_size=$(stat -c%s "$cookie_rom_path") - log "Cookie local rom size : $rom_size" - if [ "$rom_size" -gt "$MAX_FILE_SIZE_BYTES" ]; then - echo "[romchksum]: 0" >>"$COOKIE_FILE" - else - echo "[romchksum]: $(xcrc "$cookie_rom_path")" >>"$COOKIE_FILE" - fi - fi - - if [ -s "$cpuspeed" ]; then - echo "[cpuspeed]: $cpuspeed" >>"$COOKIE_FILE" - log "Writing custom cpuspeed: $cpuspeed" - fi - -} - # Backup the save we're going to use before we do anythign else host_save_backup() { @@ -401,312 +367,6 @@ stripped_game_names() { client_game_name="\n Client: \n$client_rom_trimmed" } -# Function to sync files - -sync_file() { - - MAX_FILE_CHKSUM_SIZE=26214400 - MAX_FILE_DL_SIZE=104857600 - - file_type="$1" # Used in displayed message and some custom actions - file_path="$2" # Local file path - file_check_size="$3" # 0 or 1 to indicate if we have to check the file size - remote_file_checksum="$4" # 0 to skip , real checksum value to check - sync_type="$5" # -o overwrite if different (require file_size or/and checksum != 0) , (if file_size & checksum = 0 then the file is never overwritted, only copied if not present) - # -f overwrite all the time (whatever the value of file_size and checksum) (if file_size & checksum = 0 then the file is overwritted, even if already present ) - # -b if different, backup local file before copying remote file - # -c check only, allows to check the presence of a file, to check its CRC or size and to quit or not the script - file_mandatory="$6" # -m , exit the script on failed sync_success - - #examples : - # sync_file archive /mnt/SDCARD/test.zip 1 5AFC442 -b -m # backup and replace if different file - # sync_file archive /mnt/SDCARD/test.zip 0 0 -f -m # the local file will be systematically replaced - # sync_file archive /mnt/SDCARD/test.zip 0 0 -o -m # the local file will be copied if not exist - # sync_file archive /mnt/SDCARD/test.zip 0 5AFC442 -c -m # exit if the file doesn't have the right checksum - # sync_file archive /mnt/SDCARD/test.zip 1 5AFC442 -o -m # the local file will be replaced if the size or the checksum is different - - # some useful vars - dir_path=$(dirname "$file_path") - file_url="ftp://${client_ip}/$(url_encode "${file_path#*/}")" - remote_ip="$client_ip" - - log "\n############################ SYNC_FILE DEBUGGING ############################" - log file_type $file_type - log file_path $file_path - log file_check_size $file_check_size - log remote_file_checksum $remote_file_checksum - log sync_type $sync_type - log file_mandatory $file_mandatory - log file_url $file_url - log dir_path $dir_path - log "#############################################################################" - - # state vars - same_size= - same_chksum= - sync_success= - run_sync= # tell if the sync task must be done or not - - if ! ensure_ftp_head "$file_url" "$remote_ip" "$file_mandatory"; then - same_size=0 - run_sync=0 - sync_success=0 - fi - RequestResult="$ftp_head_result" - - if [[ $RequestResult == *"The file does not exist"* ]]; then - log "The remote file does not exist." - msg="The remote file does not exist." - build_infoPanel_and_log "Syncing" "The remote file does not exist." - run_sync=0 - sync_success=0 - same_size=0 - else - remote_file_size=$(echo "$RequestResult" | grep -i "Content-Length" | awk '{print $2}') - if ! echo "$remote_file_size" | grep -q "^[0-9][0-9]*$"; then # check if the remote file size is a numeric value - log "Non-numeric remote file size: '$remote_file_size'" - log "HEAD response: $RequestResult" - same_size=0 - else - log "remote_file_size: $remote_file_size" - fi - - fi - - if [ -e "$file_path" ]; then - - ########################## File checksum check : same_chksum = 0 different, 1 identical , 2 unknown - checksum_func "$file_path" "$remote_file_checksum" - - ########################## File size check same_size = 0 different, 1 identical , 2 unknown - if [ "$file_check_size" -eq 1 ]; then # file_checksum=0 means skip the difference check = always replace - checksize_func "$file_path" "$remote_file_size" - else - log "Skipping file size check." - same_size=1 # fake same size for skipping - fi - - else - log "The local file does not exist." - same_size=0 - same_chksum=0 - fi - - ########################## exception : max file size check on the remote - if echo "$remote_file_size" | grep -q "^[0-9][0-9]*$"; then - if [ "$remote_file_size" -le "$MAX_FILE_DL_SIZE" ]; then - log "Remote file size ok: $remote_file_size bytes (<= $MAX_FILE_DL_SIZE bytes)" - else - log "Remote file size too big: $remote_file_size bytes (> $MAX_FILE_DL_SIZE bytes)" - run_sync=0 - fi - else - log "Skipping max file size check due to non-numeric remote size: '$remote_file_size'" - fi - - ########################## We have all the required information, depending the choosen option we run the copy or not - - if [ "$sync_type" == "-o" ]; then # we overwrite the file if different - log "option -o selected : we overwrite the file if different." - if [ "$same_size" -ne 1 ] || [ "$same_chksum" -ne 1 ]; then - [ -z "$run_sync" ] && run_sync=1 - fi - fi - - if [ "$sync_type" == "-b" ]; then # backup - log "option -b selected : we backup before overwrite." - if { [ "$remote_file_checksum" != "0" ] && [ "$same_chksum" -ne 1 ]; } || [ "$remote_file_checksum" == "0" ]; then # if (we don't skip CRC and CRC is not identical) or (if we skip CRC) then we sync -> in other words we only skip the copy when we have an identical CRC - [ -z "$run_sync" ] && run_sync=1 - fi - fi - - if [ "$sync_type" == "-f" ]; then # we overwrite the file if different - log "option -f selected : forced file syncing." - if { [ "$remote_file_checksum" != "0" ] && [ "$same_chksum" -ne 1 ]; } || [ "$remote_file_checksum" == "0" ]; then # if (we don't skip CRC and CRC is not identical) or (if we skip CRC) then we sync -> in other words we only skip the copy when we have an identical CRC - [ -z "$run_sync" ] && run_sync=1 - fi - - fi - - if [ "$sync_type" == "-c" ]; then # we overwrite the file if different - log "option -c selected : no file copy, only check." - run_sync=0 - - if [ "$same_size" -ne 1 ]; then - msg="Files doesn't have the same size." - sync_success=0 - [ "$file_mandatory" = "-m" ] && cleanup - - fi - if [ "$same_chksum" -ne 1 ]; then - msg="$msg\nFiles doesn't have the same checksum." - sync_success=0 - [ "$file_mandatory" = "-m" ] && cleanup - - fi - if [ "$same_size" -eq 1 ] && [ "$same_chksum" -eq 1 ]; then - msg="Remote and local files are identical." - sync_success=1 - fi - build_infoPanel_and_log "File check" "$msg" - - fi - - log "############################ DEBUGGING #######################################" - log sync_type $sync_type - log remote_file_checksum $remote_file_checksum - log same_chksum $same_chksum - log run_sync $run_sync - log file_type $file_type - log - log - log "##############################################################################" - - ########################## COPY Operation ########################## - - if [ "$run_sync" -eq 1 ]; then - - # Cookie uses a separate client file; keep host cookie intact. - if [ $file_type == "Cookie" ]; then - file_path="${file_path}.client" - elif [ -e "$file_path" ]; then - # let's make a backup first whatever the case - if [ $file_type == "Rom" ]; then - # if rom already here and different file then we create a rom_neplay to avoid to override user games - - # oldpath="$file_path" - # file_path_without_extension="${file_path%.*}" - # file_path="${file_path_without_extension}_netplay.${file_path##*.}" - # if [ -e "$client_Img_path" ]; then - # cp "$client_Img_path" "/mnt/SDCARD/Roms/$romdirname/Imgs/${romNameNoExtension}_netplay.png" - # client_Img_path="/mnt/SDCARD/Roms/$romdirname/Imgs/${romNameNoExtension}_netplay.png" - # fi - - Netplay_Rom_Folder="$(dirname "$file_path")/.netplay" - mkdir -p "$Netplay_Rom_Folder" - file_path="$Netplay_Rom_Folder/$(basename "$file_path")" - rom=$file_path - - elif [ $file_type == "Core" ]; then - # oldpath="$file_path" - # file_path_without_extension="${file_path%.*}" - # file_path="${file_path_without_extension}_netplay.${file_path##*.}" - - Netplay_Core_Folder="$(dirname "$file_path")/.netplay" - mkdir -p "$Netplay_Core_Folder" - file_path="$Netplay_Core_Folder/$(basename "$file_path")" - core=$file_path - else - mv "$file_path" "${file_path}_old" - log "Existing $file_type file moved to ${file_path}_old" - fi - fi - if [ ! -d "$dir_path" ]; then - mkdir -p "$dir_path" - fi - - log "Starting to download $file_type from $file_url" - download_attempt=1 - while [ $download_attempt -le $NETPLAY_FTP_DOWNLOAD_RETRIES ]; do - curl_output=$(curl -S -o "$file_path" "$file_url" 2>&1) - curl_exit=$? - - if [ $curl_exit -eq 0 ]; then - log "$file_type download completed" - break - fi - - log "$file_type download failed (curl exit=$curl_exit, attempt $download_attempt/$NETPLAY_FTP_DOWNLOAD_RETRIES)" - log "curl error: $curl_output" - if [ $curl_exit -eq 9 ] || [ $curl_exit -eq 78 ]; then - log "FTP path denied for $file_url" - break - fi - - download_attempt=$((download_attempt + 1)) - sleep "$NETPLAY_FTP_DOWNLOAD_DELAY" - done - - fi - - ###################### FINAL CHECK RESULT ######################### - - if [ ! -e "$file_path" ]; then - if [ "$file_type" = "Img" ]; then - log "Image not found on peer; continuing without image." - else - build_infoPanel_and_log "Sync Failed" "Failed to download the $file_type file." - fi - - # copy has failed : restoring the original file - if [ $file_type != "Rom" ] && [ $file_type != "Core" ]; then - mv "${file_path}_old" "$file_path" - log "backup restored" - fi - sleep 2 - if [ "$file_mandatory" = "-m" ]; then - if [ "$file_type" != "Img" ]; then - cleanup - fi - fi - - else - - checksum_func "$file_path" "$remote_file_checksum" - - if [ "$file_check_size" -eq 1 ]; then # file_checksum=0 means skip the difference check = always replace - checksize_func "$file_path" "$remote_file_size" - else - log "Skipping file size check." - same_size=1 # fake same size for skipping - fi - - if [ "$same_size" -eq 1 ] && [ "$same_chksum" -eq 1 ]; then - build_infoPanel_and_log "Syncing" "$file_type synced." - if [ $file_type == "Rom" ]; then - log "Refreshing roms list ${rom%/*}/${romdirname}_cache6.db" - rm "${rom%/*}/${romdirname}_cache6.db" - fi - - else - build_infoPanel_and_log "Sync Failed" "Failed to download the $file_type file." - - # copy has failed : restoring the original file - if [ $file_type != "Rom" ] && [ $file_type != "Core" ]; then - mv "${file_path}_old" "$file_path" - log "backup restored" - fi - sleep 2 - if [ "$file_mandatory" = "-m" ]; then - # notify_peer: signal stop to client - notify_peer "$client_ip" "stop_now" - cleanup - fi - fi - #####" - - fi - ###################### FINAL RESULT DISPLAY######################### - - # if [ "$sync_success" -ne 1 ]; then - # build_infoPanel_and_log "Sync Failed" "Failed to download the $file_type file." - # sleep 2 - # cleanup - # else - # build_infoPanel_and_log "Syncing" "$file_type synced." - # fi - - # build_infoPanel_and_log "Syncing" "$file_type checksums don't match, syncing" - # build_infoPanel_and_log "Sync Failed" "Failed to download the $file_type file." - # build_infoPanel_and_log "Syncing" "$file_type synced." - # build_infoPanel_and_log "Syncing" "$file_type doesn't exist locally; syncing with host." - # build_infoPanel_and_log "Sync Failed" "Failed to download the $file_type file." - # build_infoPanel_and_log "Syncing" "$file_type synced." - - ################### END ########################## - -} - unpack_rom() { file="$1" folder=$(dirname "$file") diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh index 36bbe95dea..908a925636 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh @@ -11,10 +11,10 @@ logfile=pokemon_link # Source scripts . $sysdir/script/log.sh -# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp -. $sysdir/script/netplay/netplay_common.sh -# netplay_signalling.sh: wait_for_client, ready_up, notify_peer, check_stop, notify_stop -. $sysdir/script/netplay/netplay_signalling.sh +# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp +. $sysdir/script/netplay/easy-netplay_common.sh +# easy-netplay_signalling.sh: wait_for_client, ready_up, notify_peer, check_stop, notify_stop +. $sysdir/script/netplay/easy-netplay_signalling.sh # Runtime vars rm /tmp/stop_now diff --git a/static/build/.tmp_update/script/netplay/netplay_signalling.sh b/static/build/.tmp_update/script/netplay/easy-netplay_signalling.sh similarity index 100% rename from static/build/.tmp_update/script/netplay/netplay_signalling.sh rename to static/build/.tmp_update/script/netplay/easy-netplay_signalling.sh diff --git a/static/build/.tmp_update/script/netplay/netplay_common.sh b/static/build/.tmp_update/script/netplay/netplay_common.sh deleted file mode 100644 index 6157576f85..0000000000 --- a/static/build/.tmp_update/script/netplay/netplay_common.sh +++ /dev/null @@ -1,317 +0,0 @@ -# Shared netplay helpers - -# Tunables -NETPLAY_FTP_CHECK_RETRIES=5 -NETPLAY_FTP_CHECK_DELAY=1 -NETPLAY_FTP_READY_DELAY=3 -NETPLAY_FTP_DOWNLOAD_RETRIES=5 -NETPLAY_FTP_DOWNLOAD_DELAY=1 -NETPLAY_FTP_HEAD_TIMEOUT=2 - -# checksize_func <file_path> <remote_size> -# - sets: same_size (0 different, 1 identical, 2 unknown) -checksize_func() { - local func_file_path="${1:-$file_path}" - local filesize_tocheck="${2:-$remote_file_size}" - - if [ -e "$func_file_path" ]; then - local_file_size=$(stat -c%s "$func_file_path") - log "checksize_func: local_file_size=$local_file_size for $func_file_path" - log "checksize_func: remote_file_size='$filesize_tocheck'" - if echo "$filesize_tocheck" | grep -q "^[0-9][0-9]*$"; then - if [ "$filesize_tocheck" -eq "$local_file_size" ]; then - same_size=1 - else - same_size=0 - fi - log "checksize_func: same_size=$same_size (numeric compare)" - else - log "Non-numeric remote file size for checksize_func: '$filesize_tocheck' (skipping size check)" - same_size=1 - fi - else - same_size=0 - fi -} - -# checksum_func <file_path> <crc> -# - uses: MAX_FILE_CHKSUM_SIZE -# - sets: same_chksum -checksum_func() { - local_file_size=$(stat -c%s "$file_path") - local func_file_path="$1" - local CRC="$2" - - ########################## File checksum check : same_chksum = 0 different, 1 identical , 2 unknown - - if [ "$CRC" != "0" ]; then # file_checksum=0 means skip the difference check = always replace - local_file_checksum=$(xcrc "$func_file_path") - - if [ "$local_file_size" -gt "$MAX_FILE_CHKSUM_SIZE" ]; then - log "File size too big for checksum: it would be too long" - same_chksum=2 - else - if [ "$CRC" == "$local_file_checksum" ]; then - same_chksum=1 - else - same_chksum=0 - fi - fi - else - log "Skipping checksum check." - same_chksum=1 - fi -} - -# enable_flag <flag_name> -# - creates $sysdir/config/.<flag_name> -enable_flag() { - flag="$1" - touch "$sysdir/config/.$flag" -} - -# disable_flag <flag_name> -# - removes $sysdir/config/.<flag_name> -disable_flag() { - flag="$1" - mv "$sysdir/config/.$flag" "$sysdir/config/.$flag_" -} - -# flag_enabled <flag_name> -# - returns 0 if flag file exists -flag_enabled() { - flag="$1" - [ -f "$sysdir/config/.$flag" ] -} - -# is_running <process_name> -# - returns 0 if process is running -is_running() { - process_name="$1" - pgrep "$process_name" >/dev/null -} - -# build_infoPanel_and_log <title> <message> -# - uses: INFOPANEL_SLEEP (default 0.3s) -# - shows persistent infoPanel and logs message -build_infoPanel_and_log() { - local title="$1" - local message="$2" - local delay="${INFOPANEL_SLEEP:-0.3}" - - log "Info Panel: \n\tStage: $title\n\tMessage: $message" - if is_running infoPanel; then - killall -9 infoPanel - fi - infoPanel --title "$title" --message "$message" --persistent & - sync - touch /tmp/dismiss_info_panel - sync - sleep "$delay" - sync -} - -# restore_ftp -# - restores original FTP state based on flags -restore_ftp() { - log "Restoring original FTP server" - killall -9 tcpsvd - if flag_enabled ftpState; then - if flag_enabled authftpState; then - bftpd -d -c /mnt/SDCARD/.tmp_update/config/bftpdauth.conf & - else - bftpd -d -c /mnt/SDCARD/.tmp_update/config/bftpd.conf & - fi - fi -} - -# udhcpc_control -# - restarts udhcpc on wlan0 -udhcpc_control() { - if pgrep udhcpc >/dev/null; then - killall -9 udhcpc - fi - sleep 1 - udhcpc -i wlan0 -s /etc/init.d/udhcpc.script >/dev/null 2>&1 & -} - -# url_encode <path> -# - encodes each path segment but keeps '/' -url_encode() { - local path="$1" - local encoded="" - local IFS='/' - local part - - for part in $path; do - if [ -n "$encoded" ]; then - encoded="${encoded}/" - fi - encoded="${encoded}$(echo "$part" | awk ' - BEGIN { - split ("1 2 3 4 5 6 7 8 9 A B C D E F", hextab, " ") - hextab [0] = 0 - for ( i=1; i<=255; ++i ) ord [ sprintf ("%c", i) "" ] = i + 0 - } - { - encoded = "" - for ( i=1; i<=length ($0); ++i ) { - c = substr ($0, i, 1) - if ( c ~ /[a-zA-Z0-9._-]/ ) { - encoded = encoded c # safe character - } else if ( c == " " ) { - encoded = encoded "%20" # special handling - } else { - # unsafe character, encode it as a two-digit hex-number - lo = ord [c] % 16 - hi = int (ord [c] / 16); - encoded = encoded "%" hextab [hi] hextab [lo] - } - } - print encoded - }')" - done - - printf '%s\n' "$encoded" -} - -# read_cookie [verbose] -# - parses /mnt/SDCARD/RetroArch/retroarch.cookie.client into core/rom/checksum vars -# - sets: core_url, rom_url, romdirname, romName, romNameNoExtension, Img_path -read_cookie() { - local verbose="$1" - sync - while IFS= read -r line; do - case $line in - "[core]: "*) - core="${line##"[core]: "}" - ;; - "[rom]: "*) - rom="${line##"[rom]: "}" - ;; - "[coresize]: "*) - corechecksum="${line##"[coresize]: "}" - ;; - "[corechksum]: "*) - corechecksum="${line##"[corechksum]: "}" - ;; - "[romsize]: "*) - romchecksum="${line##"[romsize]: "}" - ;; - "[romchksum]: "*) - romchecksum="${line##"[romchksum]: "}" - ;; - "[cpuspeed]: "*) - cpuspeed="${line##"[cpuspeed]: "}" - ;; - esac - log "$core $rom $coresize $corechksum $romsize $romchksum" - done <"/mnt/SDCARD/RetroArch/retroarch.cookie.client" - - # url encode or curl complains - export core_url=$(url_encode "$core") - export rom_url=$(url_encode "$rom") - - romdirname=$(echo "$rom" | grep -o '/Roms/[^/]*' | cut -d'/' -f3) - romName=$(basename "$rom") - romNameNoExtension=${romName%.*} - Img_path="/mnt/SDCARD/Roms/$romdirname/Imgs/$romNameNoExtension.png" - - if [ "$verbose" = "1" ]; then - log "Cookie file read :" - log "romdirname $romdirname" - log "romName $romName" - log "romNameNoExtension $romNameNoExtension" - log "Img_path $Img_path" - else - log "Cookie file read" - fi -} - -# start_ftp [check_stop_message] -# - starts built-in FTP server for signaling -# - if a message is provided, check_stop is invoked with it first -start_ftp() { - if [ -n "$1" ]; then - check_stop "$1" - fi - if is_running bftpd; then - log "FTP already running, killing to rebind" - bftpd_p=$(ps | grep bftpd | grep -v grep | awk '{for(i=4;i<=NF;++i) printf $i\" \"}') - killall -9 bftpd - killall -9 tcpsvd - tcpsvd -E 0.0.0.0 21 ftpd -w / & - else - tcpsvd -E 0.0.0.0 21 ftpd -w / & - log "Starting FTP server" - fi - check_ftp_local - sleep 0.5 -} - -# check_ftp_local [port] -# - logs whether tcpsvd is running and its args/port -check_ftp_local() { - local port="${1:-21}" - if pgrep tcpsvd >/dev/null; then - local tcpsvd_ps - tcpsvd_ps=$(ps | grep tcpsvd | grep -v grep) - log "FTP tcpsvd running (expected port $port): $tcpsvd_ps" - else - log "FTP tcpsvd not running (expected port $port)" - build_infoPanel_and_log "FTP Error" "FTP server failed to start." - fi -} - -# ensure_ftp_head <url> <remote_ip> <mandatory> -# - give peer time to start FTP before first transfer, then do a quick HEAD -# - sets: ftp_head_result, ftp_head_exit -ensure_ftp_head() { - # wait for peer tcpsvd to be ready (reduces race on first FTP request) - sleep "$NETPLAY_FTP_READY_DELAY" - ftp_head_result=$(curl -sS -I --connect-timeout "$NETPLAY_FTP_HEAD_TIMEOUT" "$1" 2>&1) - ftp_head_exit=$? - return 0 -} -# check_wifi <use_udhcpc> <hard_fail> <down_wlan1> -# - use_udhcpc: 1 to call udhcpc_control after wpa_supplicant -# - hard_fail: 1 to notify_stop on failure, 0 to just pause -# - down_wlan1: 1 to bring wlan1 down before checks -check_wifi() { - local use_udhcpc="$1" - local hard_fail="$2" - local down_wlan1="$3" - - if [ "$down_wlan1" -eq 1 ]; then - ifconfig wlan1 down - fi - - if ifconfig wlan0 &>/dev/null; then - log "Wifi up" - else - build_infoPanel_and_log "WIFI" "Wifi disabled, starting..." - - /customer/app/axp_test wifion - sleep 2 - ifconfig wlan0 up - sleep 1 - $miyoodir/app/wpa_supplicant -B -D nl80211 -iwlan0 -c /appconfigs/wpa_supplicant.conf - - if [ "$use_udhcpc" -eq 1 ]; then - udhcpc_control - fi - - if is_running wpa_supplicant && ifconfig wlan0 >/dev/null 2>&1; then - build_infoPanel_and_log "WIFI" "Wifi started." - else - build_infoPanel_and_log "WIFI" "Unable to start WiFi\n unable to continue." - if [ "$hard_fail" -eq 1 ]; then - notify_stop - else - sleep 1 - fi - fi - - sleep 2 - fi -} diff --git a/static/build/.tmp_update/script/netplay/standard-netplay.sh b/static/build/.tmp_update/script/netplay/standard-netplay.sh index dc47c3c7a6..aa73b931c5 100644 --- a/static/build/.tmp_update/script/netplay/standard-netplay.sh +++ b/static/build/.tmp_update/script/netplay/standard-netplay.sh @@ -21,8 +21,8 @@ logfile=netplay # Source scripts . $sysdir/script/log.sh -# netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp -. $sysdir/script/netplay/netplay_common.sh +# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp +. $sysdir/script/netplay/easy-netplay_common.sh program=$(basename "$0" .sh) From 68100a56d23bc77ea95e95ca5192c44338687df6 Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Tue, 20 Jan 2026 22:20:00 +0000 Subject: [PATCH 15/32] centralize netplay tunables and strip game name helper --- .../netplay/easy-netplay_client_pokemon.sh | 8 +-- .../easy-netplay_client_pokemon_GBA.sh | 4 +- .../script/netplay/easy-netplay_common.sh | 67 ++++++++++++------- .../netplay/easy-netplay_server_pokemon.sh | 7 +- .../easy-netplay_server_pokemon_GBA.sh | 5 +- 5 files changed, 52 insertions(+), 39 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh index 69977ee6e7..a21e37e668 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh @@ -21,7 +21,7 @@ logfile=pokemon_link # Source scripts . $sysdir/script/log.sh -# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, read_cookie, check_wifi, start_ftp, sync_file +# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, strip_game_name, read_cookie, check_wifi, start_ftp, sync_file . $sysdir/script/netplay/easy-netplay_common.sh # easy-netplay_signalling.sh: check_stop, notify_peer, notify_stop, wait_for_host . $sysdir/script/netplay/easy-netplay_signalling.sh @@ -231,10 +231,10 @@ confirm_join_panel() { } stripped_game_names() { - game_name="Host: \n$(basename "${rom%.*}")" - game_name="$(echo "$game_name" | sed -e 's/ ([^()]*)//g' -e 's/ [[A-z0-9!+]*]//g' -e 's/([^()]*)//g' -e 's/[[A-z0-9!+]*]//g')" + host_name_trimmed="$(strip_game_name "$(basename "${rom%.*}")")" + game_name="Host: \n$host_name_trimmed" - client_rom_trimmed="$(echo "$client_rom_filename_NoExt" | sed -e 's/ ([^()]*)//g' -e 's/ [[A-z0-9!+]*]//g' -e 's/([^()]*)//g' -e 's/[[A-z0-9!+]*]//g')" + client_rom_trimmed="$(strip_game_name "$client_rom_filename_NoExt")" game_name_client="\n Client (me): \n$client_rom_trimmed" } diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh index 4929e61640..888caafa05 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh @@ -20,7 +20,7 @@ logfile=pokemon_link # Source scripts . $sysdir/script/log.sh -# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp +# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, strip_game_name, check_wifi, start_ftp . $sysdir/script/netplay/easy-netplay_common.sh # easy-netplay_signalling.sh: wait_for_host, check_stop, notify_stop . $sysdir/script/netplay/easy-netplay_signalling.sh @@ -115,7 +115,7 @@ confirm_join_panel() { # stripped_game_names: format local ROM display name stripped_game_names() { - client_rom_trimmed="$(echo "$client_rom_filename_NoExt" | sed -e 's/ ([^()]*)//g' -e 's/ [[A-z0-9!+]*]//g' -e 's/([^()]*)//g' -e 's/[[A-z0-9!+]*]//g')" + client_rom_trimmed="$(strip_game_name "$client_rom_filename_NoExt")" game_name_client="Client (me): \n$client_rom_trimmed" } ######### diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_common.sh b/static/build/.tmp_update/script/netplay/easy-netplay_common.sh index 3e4335fcba..96c371a85f 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_common.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_common.sh @@ -1,12 +1,24 @@ # Shared netplay helpers # Tunables -NETPLAY_FTP_CHECK_RETRIES=5 -NETPLAY_FTP_CHECK_DELAY=1 -NETPLAY_FTP_READY_DELAY=3 -NETPLAY_FTP_DOWNLOAD_RETRIES=5 -NETPLAY_FTP_DOWNLOAD_DELAY=1 -NETPLAY_FTP_HEAD_TIMEOUT=2 +# seconds unless stated otherwise; bytes unless stated otherwise +NETPLAY_FTP_CHECK_RETRIES=3 # ftp head retry count for preflight checks +NETPLAY_FTP_CHECK_DELAY=1 # delay between ftp head retries +NETPLAY_FTP_READY_DELAY=3 # wait before first ftp head to allow peer ftp start +NETPLAY_FTP_DOWNLOAD_RETRIES=5 # download retry count per file +NETPLAY_FTP_DOWNLOAD_DELAY=1 # delay between download retries +NETPLAY_FTP_HEAD_TIMEOUT=2 # curl connect timeout for ftp head +NETPLAY_UDHCPC_RESTART_DELAY=1 # delay before restarting udhcpc +NETPLAY_FTP_START_DELAY=0.5 # wait after starting ftp before checks +NETPLAY_WIFI_POWER_ON_DELAY=2 # delay after wifi power-on +NETPLAY_WIFI_UP_DELAY=1 # delay after bringing wlan0 up +NETPLAY_WIFI_POST_START_DELAY=2 # delay after wifi start sequence +NETPLAY_WIFI_SOFT_FAIL_DELAY=1 # delay after wifi soft-fail +NETPLAY_SYNC_MAX_FILE_CHKSUM_SIZE=26214400 # max file size to allow checksum +NETPLAY_SYNC_MAX_FILE_DL_SIZE=104857600 # max file size to allow download +NETPLAY_COOKIE_MAX_FILE_SIZE=26214400 # max file size for cookie checksum entries +NETPLAY_SYNC_FAIL_DELAY=2 # delay after sync failures before cleanup +NETPLAY_INFOPANEL_SLEEP_DEFAULT=0.3 # default infoPanel delay when INFOPANEL_SLEEP is unset # checksize_func <file_path> <remote_size> # - sets: same_size (0 different, 1 identical, 2 unknown) @@ -35,7 +47,7 @@ checksize_func() { } # checksum_func <file_path> <crc> -# - uses: MAX_FILE_CHKSUM_SIZE +# - uses: NETPLAY_SYNC_MAX_FILE_CHKSUM_SIZE # - sets: same_chksum checksum_func() { local_file_size=$(stat -c%s "$file_path") @@ -47,7 +59,7 @@ checksum_func() { if [ "$CRC" != "0" ]; then # file_checksum=0 means skip the difference check = always replace local_file_checksum=$(xcrc "$func_file_path") - if [ "$local_file_size" -gt "$MAX_FILE_CHKSUM_SIZE" ]; then + if [ "$local_file_size" -gt "$NETPLAY_SYNC_MAX_FILE_CHKSUM_SIZE" ]; then log "File size too big for checksum: it would be too long" same_chksum=2 else @@ -92,12 +104,12 @@ is_running() { } # build_infoPanel_and_log <title> <message> -# - uses: INFOPANEL_SLEEP (default 0.3s) +# - uses: INFOPANEL_SLEEP or NETPLAY_INFOPANEL_SLEEP_DEFAULT # - shows persistent infoPanel and logs message build_infoPanel_and_log() { local title="$1" local message="$2" - local delay="${INFOPANEL_SLEEP:-0.3}" + local delay="${INFOPANEL_SLEEP:-$NETPLAY_INFOPANEL_SLEEP_DEFAULT}" log "Info Panel: \n\tStage: $title\n\tMessage: $message" if is_running infoPanel; then @@ -131,7 +143,7 @@ udhcpc_control() { if pgrep udhcpc >/dev/null; then killall -9 udhcpc fi - sleep 1 + sleep "$NETPLAY_UDHCPC_RESTART_DELAY" udhcpc -i wlan0 -s /etc/init.d/udhcpc.script >/dev/null 2>&1 & } @@ -175,6 +187,12 @@ url_encode() { printf '%s\n' "$encoded" } +# strip_game_name <name> +# - strips region/version tags and returns cleaned name +strip_game_name() { + echo "$1" | sed -e 's/ ([^()]*)//g' -e 's/ [[A-z0-9!+]*]//g' -e 's/([^()]*)//g' -e 's/[[A-z0-9!+]*]//g' +} + # read_cookie [verbose] # - parses /mnt/SDCARD/RetroArch/retroarch.cookie.client into core/rom/checksum vars # - sets: core_url, rom_url, romdirname, romName, romNameNoExtension, Img_path @@ -233,8 +251,6 @@ read_cookie() { # - sync_type: -o overwrite if different, -f force, -b backup, -c check only # - mandatory: -m to cleanup on failure sync_file() { - MAX_FILE_CHKSUM_SIZE=26214400 - MAX_FILE_DL_SIZE=104857600 file_type="$1" # Used in displayed message and some custom actions file_path="$2" # Local file path @@ -312,10 +328,10 @@ sync_file() { ########################## exception : max file size check on the remote if echo "$remote_file_size" | grep -q "^[0-9][0-9]*$"; then - if [ "$remote_file_size" -le "$MAX_FILE_DL_SIZE" ]; then - log "Remote file size ok: $remote_file_size bytes (<= $MAX_FILE_DL_SIZE bytes)" + if [ "$remote_file_size" -le "$NETPLAY_SYNC_MAX_FILE_DL_SIZE" ]; then + log "Remote file size ok: $remote_file_size bytes (<= $NETPLAY_SYNC_MAX_FILE_DL_SIZE bytes)" else - log "Remote file size too big: $remote_file_size bytes (> $MAX_FILE_DL_SIZE bytes)" + log "Remote file size too big: $remote_file_size bytes (> $NETPLAY_SYNC_MAX_FILE_DL_SIZE bytes)" run_sync=0 fi else @@ -438,7 +454,7 @@ sync_file() { mv "${file_path}_old" "$file_path" log "backup restored" fi - sleep 2 + sleep "$NETPLAY_SYNC_FAIL_DELAY" if [ "$file_mandatory" = "-m" ]; then if [ "$file_type" != "Img" ]; then if type notify_peer >/dev/null 2>&1; then @@ -474,7 +490,7 @@ sync_file() { mv "${file_path}_old" "$file_path" log "backup restored" fi - sleep 2 + sleep "$NETPLAY_SYNC_FAIL_DELAY" if [ "$file_mandatory" = "-m" ]; then if type notify_peer >/dev/null 2>&1; then notify_peer "$remote_ip" "stop_now" @@ -493,7 +509,6 @@ sync_file() { # - writes core/rom/checksum/cpuspeed into retroarch.cookie create_cookie_info() { COOKIE_FILE="/mnt/SDCARD/RetroArch/retroarch.cookie" - MAX_FILE_SIZE_BYTES=26214400 echo "[core]: $netplaycore" >"$COOKIE_FILE" echo "[rom]: $cookie_rom_path" >>"$COOKIE_FILE" @@ -501,7 +516,7 @@ create_cookie_info() { if [ -s "$netplaycore" ]; then log "Writing core size" core_size=$(stat -c%s "$netplaycore") - if [ "$core_size" -gt "$MAX_FILE_SIZE_BYTES" ]; then + if [ "$core_size" -gt "$NETPLAY_COOKIE_MAX_FILE_SIZE" ]; then echo "[corechksum]: 0" >>"$COOKIE_FILE" else echo "[corechksum]: $(xcrc "$netplaycore")" >>"$COOKIE_FILE" @@ -511,7 +526,7 @@ create_cookie_info() { if [ -s "$cookie_rom_path" ]; then rom_size=$(stat -c%s "$cookie_rom_path") log "Cookie local rom size : $rom_size" - if [ "$rom_size" -gt "$MAX_FILE_SIZE_BYTES" ]; then + if [ "$rom_size" -gt "$NETPLAY_COOKIE_MAX_FILE_SIZE" ]; then echo "[romchksum]: 0" >>"$COOKIE_FILE" else echo "[romchksum]: $(xcrc "$cookie_rom_path")" >>"$COOKIE_FILE" @@ -542,7 +557,7 @@ start_ftp() { log "Starting FTP server" fi check_ftp_local - sleep 0.5 + sleep "$NETPLAY_FTP_START_DELAY" } # check_ftp_local [port] @@ -589,9 +604,9 @@ check_wifi() { build_infoPanel_and_log "WIFI" "Wifi disabled, starting..." /customer/app/axp_test wifion - sleep 2 + sleep "$NETPLAY_WIFI_POWER_ON_DELAY" ifconfig wlan0 up - sleep 1 + sleep "$NETPLAY_WIFI_UP_DELAY" $miyoodir/app/wpa_supplicant -B -D nl80211 -iwlan0 -c /appconfigs/wpa_supplicant.conf if [ "$use_udhcpc" -eq 1 ]; then @@ -605,10 +620,10 @@ check_wifi() { if [ "$hard_fail" -eq 1 ]; then notify_stop else - sleep 1 + sleep "$NETPLAY_WIFI_SOFT_FAIL_DELAY" fi fi - sleep 2 + sleep "$NETPLAY_WIFI_POST_START_DELAY" fi } diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh index ac7d8dd8e5..f558aca788 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh @@ -11,7 +11,7 @@ logfile=pokemon_link # Source scripts . $sysdir/script/log.sh -# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp, sync_file +# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, strip_game_name, check_wifi, start_ftp, sync_file . $sysdir/script/netplay/easy-netplay_common.sh # easy-netplay_signalling.sh: wait_for_client, ready_up, notify_peer, check_stop, notify_stop . $sysdir/script/netplay/easy-netplay_signalling.sh @@ -359,11 +359,10 @@ confirm_join_panel() { } stripped_game_names() { - host_game_name="$(basename "${host_rom%.*}")" - host_game_name="$(echo "$host_game_name" | sed -e 's/ ([^()]*)//g' -e 's/ [[A-z0-9!+]*]//g' -e 's/([^()]*)//g' -e 's/[[A-z0-9!+]*]//g')" + host_game_name="$(strip_game_name "$(basename "${host_rom%.*}")")" host_game_name="Host (me): \n$host_game_name" - client_rom_trimmed="$(basename "${client_rom%.*}" | sed -e 's/ ([^()]*)//g' -e 's/ [[A-z0-9!+]*]//g' -e 's/([^()]*)//g' -e 's/[[A-z0-9!+]*]//g')" + client_rom_trimmed="$(strip_game_name "$(basename "${client_rom%.*}")")" client_game_name="\n Client: \n$client_rom_trimmed" } diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh index 908a925636..a2a5a1b48c 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh @@ -11,7 +11,7 @@ logfile=pokemon_link # Source scripts . $sysdir/script/log.sh -# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp +# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, strip_game_name, check_wifi, start_ftp . $sysdir/script/netplay/easy-netplay_common.sh # easy-netplay_signalling.sh: wait_for_client, ready_up, notify_peer, check_stop, notify_stop . $sysdir/script/netplay/easy-netplay_signalling.sh @@ -116,8 +116,7 @@ confirm_join_panel() { # stripped_game_names: format local ROM display name stripped_game_names() { - host_game_name="$(basename "${host_rom%.*}")" - host_game_name="$(echo "$host_game_name" | sed -e 's/ ([^()]*)//g' -e 's/ [[A-z0-9!+]*]//g' -e 's/([^()]*)//g' -e 's/[[A-z0-9!+]*]//g')" + host_game_name="$(strip_game_name "$(basename "${host_rom%.*}")")" host_game_name="Host (me): \n$host_game_name" } From ee3aa5365390bd5092c30b18139868c12f8dda53 Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Tue, 20 Jan 2026 22:26:54 +0000 Subject: [PATCH 16/32] gate client confirm on host game start --- .../.tmp_update/script/netplay/easy-netplay_client_pokemon.sh | 4 +--- .../.tmp_update/script/netplay/easy-netplay_server_pokemon.sh | 3 --- .../.tmp_update/script/netplay/easy-netplay_signalling.sh | 2 +- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh index a21e37e668..dd59262c8a 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh @@ -101,7 +101,6 @@ start_retroarch() { echo -n $cpuspeed >"/mnt/SDCARD/Saves/CurrentProfile/config/${core_config_folder}/cpuclock.txt" fi - wait_for_host # we wait a second flag triggered from the host once RA is running cd /mnt/SDCARD/RetroArch log "Starting RetroArch loaded with $rom and $client_rom" HOME=/mnt/SDCARD/RetroArch ./retroarch --appendconfig=./.retroarch/easynetplay_override.cfg -C $hostip -L "$core" --subsystem "gb_link_2p" "$rom" "$client_rom" @@ -219,7 +218,6 @@ confirm_join_panel() { fi fi - # TO DO : allow to confirm only once the host has started infoPanel -t "$title" -m "$message" retcode=$? @@ -276,7 +274,7 @@ lets_go() { wait_for_host # Confirm join with host/client info - confirm_join_panel "Join now?" "Start the game on the host first! \n $game_name \n $game_name_client" + confirm_join_panel "Join now?" "$game_name \n $game_name_client" # Stop menu watcher before launch pkill -9 pressMenu2Kill diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh index f558aca788..aad034d4c3 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh @@ -417,9 +417,6 @@ lets_go() { sync_file "Rom" "$client_rom" 1 "$romchecksum" -b -m client_rom_rename - # Signal client that host is ready - ready_up - # Sync client image for confirmation display sync_file "Img" "$client_Img_path" 0 0 -o diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_signalling.sh b/static/build/.tmp_update/script/netplay/easy-netplay_signalling.sh index f477f36cb1..ce76d7b092 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_signalling.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_signalling.sh @@ -148,7 +148,7 @@ wait_for_client() { wait_for_host() { local counter=0 - build_infoPanel_and_log "Ready" "Waiting for host to ready up" + build_infoPanel_and_log "Ready" "Waiting for host to start game" while true; do sync # check_stop: host reported a setup issue From d75fd2aae35441dbea3690fa7cd5d01dadab3eba Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Tue, 20 Jan 2026 22:30:04 +0000 Subject: [PATCH 17/32] align comments to functions --- .../build/.tmp_update/script/netplay/easy-netplay_client.sh | 6 ++++-- .../script/netplay/easy-netplay_client_pokemon.sh | 4 +++- .../build/.tmp_update/script/netplay/easy-netplay_server.sh | 4 ++-- .../script/netplay/easy-netplay_server_pokemon.sh | 3 +++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh index ef45a3fc95..e5b4221d48 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh @@ -27,8 +27,7 @@ program=$(basename "$0" .sh) ##Setup.## ########## -# Read the cookie and store the paths and checksums into a var. - +# sync_file: download/verify remote file over ftp sync_file() { MAX_FILE_CHKSUM_SIZE=26214400 @@ -375,6 +374,7 @@ wifi_disabled() { [ $(/customer/app/jsonval wifi) -eq 0 ] } +# confirm_join_panel: show join confirmation UI with ROM image confirm_join_panel() { local title="$1" local message="$2" @@ -396,10 +396,12 @@ confirm_join_panel() { fi } +# stripped_game_name: format game name for display stripped_game_name() { game_name=$(awk -F'/' '/\[rom\]:/ {print $NF}' /mnt/SDCARD/RetroArch/retroarch.cookie.client | sed 's/\(.*\)\..*/\1/') } +# cleanup: restore wifi/ftp and remove session temp files cleanup() { build_infoPanel_and_log "Cleanup" "Cleaning up after netplay session..." diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh index dd59262c8a..e9a97d3095 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh @@ -164,6 +164,7 @@ wait_for_save_return() { fi } +# cleanup: restore wifi/ftp and remove session temp files cleanup() { build_infoPanel_and_log "Cleanup" "Cleaning up after Pokemon session\n Do not power off!" @@ -199,7 +200,7 @@ cleanup() { #Utilities# ########### -# Create a cookie with all the required info for the client. (client will use this cookie) +# confirm_join_panel: show join confirmation UI with host/client images confirm_join_panel() { local title="$1" local message="$2" @@ -228,6 +229,7 @@ confirm_join_panel() { fi } +# stripped_game_names: format host/client display names stripped_game_names() { host_name_trimmed="$(strip_game_name "$(basename "${rom%.*}")")" game_name="Host: \n$host_name_trimmed" diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh index c05e375f1e..e60b62d111 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh @@ -50,8 +50,7 @@ Get_NetplayCore() { } -# Create a cookie with all the required info for the client. (client will use this cookie) -# We'll start Retroarch in host mode with -H with the core and rom paths loaded in. +# start_retroarch: launch RetroArch host with selected core and ROM start_retroarch() { log "RetroArch" "Starting RetroArch..." echo "*****************************************" @@ -82,6 +81,7 @@ start_retroarch() { fi } +# cleanup: restore wifi/ftp and remove session temp files cleanup() { build_infoPanel_and_log "Cleanup" "Cleaning up after netplay session..." diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh index aad034d4c3..80d9a571cc 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh @@ -322,6 +322,7 @@ remove_client_save_suffix() { fi } +# confirm_join_panel: show host confirmation UI with host/client images confirm_join_panel() { local title="$1" local message="$2" @@ -358,6 +359,7 @@ confirm_join_panel() { fi } +# stripped_game_names: format host/client display names stripped_game_names() { host_game_name="$(strip_game_name "$(basename "${host_rom%.*}")")" host_game_name="Host (me): \n$host_game_name" @@ -366,6 +368,7 @@ stripped_game_names() { client_game_name="\n Client: \n$client_rom_trimmed" } +# unpack_rom: extract archive into its folder unpack_rom() { file="$1" folder=$(dirname "$file") From 01df136beeb86d6ebc96dd87b6670979f8c55a3b Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Tue, 20 Jan 2026 22:34:32 +0000 Subject: [PATCH 18/32] align gba join gating with host start --- .../script/netplay/easy-netplay_client_pokemon_GBA.sh | 4 +--- .../script/netplay/easy-netplay_server_pokemon_GBA.sh | 3 --- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh index 888caafa05..db0802e0a2 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh @@ -49,7 +49,6 @@ start_retroarch() { echo -n $cpuspeed >"/mnt/SDCARD/Saves/CurrentProfile/config/${core_config_folder}/cpuclock.txt" fi - wait_for_host # we wait a second flag triggered from the host once RA is running cd /mnt/SDCARD/RetroArch log "Starting RetroArch loaded with $client_rom" HOME=/mnt/SDCARD/RetroArch ./retroarch --appendconfig=./.retroarch/easynetplay_override.cfg -C $hostip -L "$netplaycore" "$client_rom" @@ -102,7 +101,6 @@ confirm_join_panel() { fi fi - # TO DO : allow to confirm only once the host has started infoPanel -t "$title" -m "$message" retcode=$? @@ -146,7 +144,7 @@ lets_go() { wait_for_host # Confirm join with local ROM display - confirm_join_panel "Join now?" "Start the game on the host first! \n $game_name_client" + confirm_join_panel "Join now?" "$game_name_client" # Stop menu watcher before launch pkill -9 pressMenu2Kill diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh index a2a5a1b48c..e3ce0b1bcb 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh @@ -144,9 +144,6 @@ lets_go() { # Wait for client connection wait_for_client - # Signal client that host is ready - ready_up - # Build display names for confirmation prompt stripped_game_names From 48765228851335480e3b06c919d0ee73ebcb3773 Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Tue, 20 Jan 2026 22:41:24 +0000 Subject: [PATCH 19/32] dedupe netplay helpers and fix client comments --- .../script/netplay/easy-netplay_client.sh | 320 +----------------- .../script/netplay/easy-netplay_common.sh | 12 + 2 files changed, 13 insertions(+), 319 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh index e5b4221d48..11b7732063 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh @@ -18,7 +18,7 @@ logfile=easy_netplay # Source scripts . $sysdir/script/log.sh -# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, read_cookie, check_wifi, start_ftp +# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, strip_game_name, wifi_disabled, stripped_game_name, read_cookie, check_wifi, start_ftp, sync_file . $sysdir/script/netplay/easy-netplay_common.sh program=$(basename "$0" .sh) @@ -27,313 +27,6 @@ program=$(basename "$0" .sh) ##Setup.## ########## -# sync_file: download/verify remote file over ftp -sync_file() { - - MAX_FILE_CHKSUM_SIZE=26214400 - MAX_FILE_DL_SIZE=104857600 - - file_type="$1" # Used in displayed message and some custom actions - file_path="$2" # Local file path - file_check_size="$3" # 0 or 1 to indicate if we have to check the file size - remote_file_checksum="$4" # 0 to skip , real checksum value to check - sync_type="$5" # -o overwrite if different (require file_size or/and checksum != 0) , (if file_size & checksum = 0 then the file is never overwritted, only copied if not present) - # -f overwrite all the time (whatever the value of file_size and checksum) (if file_size & checksum = 0 then the file is overwritted, even if already present ) - # -b if different, backup local file before copying remote file - # -c check only, allows to check the presence of a file, to check its CRC or size and to quit or not the script - file_mandatory="$6" # -m , exit the script on failed sync_success - - #examples : - # sync_file archive /mnt/SDCARD/test.zip 1 5AFC442 -b -m # backup and replace if different file - # sync_file archive /mnt/SDCARD/test.zip 0 0 -f -m # the local file will be systematically replaced - # sync_file archive /mnt/SDCARD/test.zip 0 0 -o -m # the local file will be copied if not exist - # sync_file archive /mnt/SDCARD/test.zip 0 5AFC442 -c -m # exit if the file doesn't have the right checksum - # sync_file archive /mnt/SDCARD/test.zip 1 5AFC442 -o -m # the local file will be replaced if the size or the checksum is different - - # some useful vars - dir_path=$(dirname "$file_path") - file_url="ftp://${hostip}/$(url_encode "${file_path#*/}")" - remote_ip="$hostip" - - echo "############################ DEBUGGING #######################################" - echo file_type $file_type - echo file_path $file_path - echo file_check_size $file_check_size - echo remote_file_checksum $remote_file_checksum - echo sync_type $sync_type - echo file_mandatory $file_mandatory - echo - echo dir_path $dir_path - echo romdirname $romdirname - echo romName $romName - echo romNameNoExtension $romNameNoExtension - echo Img_path $Img_path - echo file_url $file_url - echo "##############################################################################" - - # state vars - same_size= - same_chksum= - sync_success= - run_sync= # tell if the sync task must be done or not - - if ! ensure_ftp_head "$file_url" "$remote_ip" "$file_mandatory"; then - same_size=0 - run_sync=0 - sync_success=0 - fi - RequestResult="$ftp_head_result" - - if [[ $RequestResult == *"The file does not exist"* ]]; then - log "The remote file does not exist." - msg="The remote file does not exist." - build_infoPanel_and_log "Syncing" "The remote file does not exist." - run_sync=0 - sync_success=0 - same_size=0 - else - remote_file_size=$(echo "$RequestResult" | grep -i "Content-Length" | awk '{print $2}') - if ! echo "$remote_file_size" | grep -q "^[0-9][0-9]*$"; then # check if the remote file size is a numeric value - log "Non-numeric remote file size: '$remote_file_size'" - log "HEAD response: $RequestResult" - same_size=0 - else - log "remote_file_size: $remote_file_size" - fi - - fi - - if [ -e "$file_path" ]; then - - ########################## File checksum check : same_chksum = 0 different, 1 identical , 2 unknown - checksum_func "$file_path" "$remote_file_checksum" - - ########################## File size check same_size = 0 different, 1 identical , 2 unknown - if [ "$file_check_size" -eq 1 ]; then # file_checksum=0 means skip the difference check = always replace - checksize_func "$file_path" "$remote_file_size" - else - log "Skipping file size check." - same_size=1 # fake same size for skipping - fi - - else - log "The local file does not exist." - same_size=0 - same_chksum=0 - fi - - ########################## exception : max file size check on the remote - if echo "$remote_file_size" | grep -q "^[0-9][0-9]*$"; then - if [ "$remote_file_size" -le "$MAX_FILE_DL_SIZE" ]; then - log "Remote file size ok: $remote_file_size bytes (<= $MAX_FILE_DL_SIZE bytes)" - else - log "Remote file size too big: $remote_file_size bytes (> $MAX_FILE_DL_SIZE bytes)" - run_sync=0 - fi - else - log "Skipping max file size check due to non-numeric remote size: '$remote_file_size'" - fi - - ########################## We have all the required information, depending the choosen option we run the copy or not - - if [ "$sync_type" == "-o" ]; then # we overwrite the file if different - log "option -o selected : we overwrite the file if different." - if [ "$same_size" -ne 1 ] || [ "$same_chksum" -ne 1 ]; then - [ -z "$run_sync" ] && run_sync=1 - fi - fi - - if [ "$sync_type" == "-b" ]; then # backup - log "option -b selected : we backup before overwrite." - if { [ "$remote_file_checksum" != "0" ] && [ "$same_chksum" -ne 1 ]; } || [ "$remote_file_checksum" == "0" ]; then # if (we don't skip CRC and CRC is not identical) or (if we skip CRC) then we sync -> in other words we only skip the copy when we have an identical CRC - [ -z "$run_sync" ] && run_sync=1 - fi - fi - - if [ "$sync_type" == "-f" ]; then # we overwrite the file if different - log "option -f selected : forced file syncing." - if { [ "$remote_file_checksum" != "0" ] && [ "$same_chksum" -ne 1 ]; } || [ "$remote_file_checksum" == "0" ]; then # if (we don't skip CRC and CRC is not identical) or (if we skip CRC) then we sync -> in other words we only skip the copy when we have an identical CRC - [ -z "$run_sync" ] && run_sync=1 - fi - - fi - - if [ "$sync_type" == "-c" ]; then # we overwrite the file if different - log "option -c selected : no file copy, only check." - run_sync=0 - - if [ "$same_size" -ne 1 ]; then - msg="Files doesn't have the same size." - sync_success=0 - [ "$file_mandatory" = "-m" ] && cleanup - - fi - if [ "$same_chksum" -ne 1 ]; then - msg="$msg\nFiles doesn't have the same checksum." - sync_success=0 - [ "$file_mandatory" = "-m" ] && cleanup - - fi - if [ "$same_size" -eq 1 ] && [ "$same_chksum" -eq 1 ]; then - msg="Remote and local files are identical." - sync_success=1 - fi - build_infoPanel_and_log "File check" "$msg" - - fi - - log "############################ DEBUGGING #######################################" - echo sync_type $sync_type - echo remote_file_checksum $remote_file_checksum - echo same_chksum $same_chksum - echo run_sync $run_sync - echo file_type $file_type - echo - echo - echo "##############################################################################" - - ########################## COPY Operation ########################## - - if [ "$run_sync" -eq 1 ]; then - - if [ $file_type == "Cookie" ]; then # exception for cookies : we don't download with the same target name - file_path="${file_path}.client" - fi - # let's make a backup first whatever the case - if [ -e "$file_path" ]; then - if [ $file_type == "Rom" ]; then - # if rom already here and different file then we create a rom_neplay to avoid to override user games - - # oldpath="$file_path" - # file_path_without_extension="${file_path%.*}" - # file_path="${file_path_without_extension}_netplay.${file_path##*.}" - # if [ -e "$Img_path" ]; then - # cp "$Img_path" "/mnt/SDCARD/Roms/$romdirname/Imgs/${romNameNoExtension}_netplay.png" - # Img_path="/mnt/SDCARD/Roms/$romdirname/Imgs/${romNameNoExtension}_netplay.png" - # fi - - Netplay_Rom_Folder="$(dirname "$file_path")/.netplay" - mkdir -p "$Netplay_Rom_Folder" - file_path="$Netplay_Rom_Folder/$(basename "$file_path")" - rom=$file_path - - elif [ $file_type == "Core" ]; then - # oldpath="$file_path" - # file_path_without_extension="${file_path%.*}" - # file_path="${file_path_without_extension}_netplay.${file_path##*.}" - - Netplay_Core_Folder="$(dirname "$file_path")/.netplay" - mkdir -p "$Netplay_Core_Folder" - file_path="$Netplay_Core_Folder/$(basename "$file_path")" - core=$file_path - else - mv "$file_path" "${file_path}_old" - log "Existing $file_type file moved to ${file_path}_old" - fi - fi - - if [ ! -d "$dir_path" ]; then - mkdir -p "$dir_path" - fi - - log "Starting to download $file_type from $file_url" - download_attempt=1 - while [ $download_attempt -le $NETPLAY_FTP_DOWNLOAD_RETRIES ]; do - curl_output=$(curl -S -o "$file_path" "$file_url" 2>&1) - curl_exit=$? - - if [ $curl_exit -eq 0 ]; then - log "$file_type download completed" - break - fi - - log "$file_type download failed (curl exit=$curl_exit, attempt $download_attempt/$NETPLAY_FTP_DOWNLOAD_RETRIES)" - log "curl error: $curl_output" - if [ $curl_exit -eq 9 ] || [ $curl_exit -eq 78 ]; then - log "FTP path denied for $file_url" - break - fi - - download_attempt=$((download_attempt + 1)) - sleep "$NETPLAY_FTP_DOWNLOAD_DELAY" - done - - fi - - ###################### FINAL CHECK RESULT ######################### - - if [ ! -e "$file_path" ]; then - if [ "$file_type" = "Img" ]; then - log "Image not found on peer; continuing without image." - else - build_infoPanel_and_log "Sync Failed" "Failed to download the $file_type file." - fi - - # copy has failed : restoring the original file - if [ $file_type != "Rom" ] && [ $file_type != "Core" ]; then - mv "${file_path}_old" "$file_path" - log "backup restored" - fi - sleep 2 - if [ "$file_mandatory" = "-m" ]; then - if [ "$file_type" != "Img" ]; then - cleanup - fi - fi - - else - - checksum_func "$file_path" "$remote_file_checksum" - - if [ "$file_check_size" -eq 1 ]; then # file_checksum=0 means skip the difference check = always replace - checksize_func "$file_path" "$remote_file_size" - else - log "Skipping file size check." - same_size=1 # fake same size for skipping - fi - - if [ "$same_size" -eq 1 ] && [ "$same_chksum" -eq 1 ]; then - build_infoPanel_and_log "Syncing" "$file_type synced." - if [ $file_type == "Rom" ]; then - log "Refreshing roms list ${rom%/*}/${romdirname}_cache6.db" - rm "${rom%/*}/${romdirname}_cache6.db" - fi - - else - build_infoPanel_and_log "Sync Failed" "Failed to download the $file_type file." - - # copy has failed : restoring the original file - if [ $file_type != "Rom" ] && [ $file_type != "Core" ]; then - mv "${file_path}_old" "$file_path" - log "backup restored" - fi - sleep 2 - [ "$file_mandatory" = "-m" ] && cleanup - fi - #####" - - fi - ###################### FINAL RESULT DISPLAY######################### - - # if [ "$sync_success" -ne 1 ]; then - # build_infoPanel_and_log "Sync Failed" "Failed to download the $file_type file." - # sleep 2 - # cleanup - # else - # build_infoPanel_and_log "Syncing" "$file_type synced." - # fi - - # build_infoPanel_and_log "Syncing" "$file_type checksums don't match, syncing" - # build_infoPanel_and_log "Sync Failed" "Failed to download the $file_type file." - # build_infoPanel_and_log "Syncing" "$file_type synced." - # build_infoPanel_and_log "Syncing" "$file_type doesn't exist locally; syncing with host." - # build_infoPanel_and_log "Sync Failed" "Failed to download the $file_type file." - # build_infoPanel_and_log "Syncing" "$file_type synced." - - ################### END ########################## - -} - # Start retroarch with -C in client mode if everything's gone to plan start_retroarch() { build_infoPanel_and_log "Starting RA" "Starting RetroArch" @@ -368,12 +61,6 @@ start_retroarch() { #Utilities# ########### -# URL encode helper - -wifi_disabled() { - [ $(/customer/app/jsonval wifi) -eq 0 ] -} - # confirm_join_panel: show join confirmation UI with ROM image confirm_join_panel() { local title="$1" @@ -396,11 +83,6 @@ confirm_join_panel() { fi } -# stripped_game_name: format game name for display -stripped_game_name() { - game_name=$(awk -F'/' '/\[rom\]:/ {print $NF}' /mnt/SDCARD/RetroArch/retroarch.cookie.client | sed 's/\(.*\)\..*/\1/') -} - # cleanup: restore wifi/ftp and remove session temp files cleanup() { build_infoPanel_and_log "Cleanup" "Cleaning up after netplay session..." diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_common.sh b/static/build/.tmp_update/script/netplay/easy-netplay_common.sh index 96c371a85f..024bda6dbd 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_common.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_common.sh @@ -193,6 +193,18 @@ strip_game_name() { echo "$1" | sed -e 's/ ([^()]*)//g' -e 's/ [[A-z0-9!+]*]//g' -e 's/([^()]*)//g' -e 's/[[A-z0-9!+]*]//g' } +# wifi_disabled +# - returns 0 if wifi is disabled +wifi_disabled() { + [ $(/customer/app/jsonval wifi) -eq 0 ] +} + +# stripped_game_name +# - reads rom name from retroarch.cookie.client and strips extension +stripped_game_name() { + game_name=$(awk -F'/' '/\\[rom\\]:/ {print $NF}' /mnt/SDCARD/RetroArch/retroarch.cookie.client | sed 's/\\(.*\\)\\..*/\\1/') +} + # read_cookie [verbose] # - parses /mnt/SDCARD/RetroArch/retroarch.cookie.client into core/rom/checksum vars # - sets: core_url, rom_url, romdirname, romName, romNameNoExtension, Img_path From b8f6c358e43029a1d6344306fab521da8feaebee Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Tue, 20 Jan 2026 22:48:52 +0000 Subject: [PATCH 20/32] Get_NetplayCore - function name -> snake_case --- .../build/.tmp_update/script/netplay/easy-netplay_server.sh | 4 ++-- static/build/.tmp_update/script/netplay/standard-netplay.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh index e60b62d111..86f3164829 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh @@ -25,7 +25,7 @@ program=$(basename "$0" .sh) ########## # Find the recommended core for the current system. -Get_NetplayCore() { +get_netplay_core() { platform=$(echo "$cookie_rom_path" | grep -o '/Roms/[^/]*' | cut -d'/' -f3) netplaycore_info=$(grep "^${platform};" "$sysdir/config/netplay_cores.conf") @@ -116,7 +116,7 @@ lets_go() { start_ftp # Determine netplay core based on ROM/core config - Get_NetplayCore + get_netplay_core # Write cookie with core/rom metadata create_cookie_info diff --git a/static/build/.tmp_update/script/netplay/standard-netplay.sh b/static/build/.tmp_update/script/netplay/standard-netplay.sh index aa73b931c5..efbd078a0a 100644 --- a/static/build/.tmp_update/script/netplay/standard-netplay.sh +++ b/static/build/.tmp_update/script/netplay/standard-netplay.sh @@ -33,7 +33,7 @@ program=$(basename "$0" .sh) # We'll need wifi up for this. Lets try and start it.. # Find the recommended core for the current system. -Get_NetplayCore() { +get_netplay_core() { platform="$1" netplaycore_info=$(grep "^${platform};" "$sysdir/config/netplay_cores.conf") @@ -122,7 +122,7 @@ lets_go() { check_wifi 0 0 1 # Determine netplay core based on platform - Get_NetplayCore "$CurrentSystem" + get_netplay_core "$CurrentSystem" if [ $? -eq 0 ]; then echo "*****************************************" echo "romfullpath: $romfullpath" From b4ba8b12e2eb533b2aadab0701cf54ed644fb13f Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Tue, 20 Jan 2026 22:55:20 +0000 Subject: [PATCH 21/32] dedupe netplay env setup and helpers --- .../.tmp_update/script/netplay/easy-netplay_client.sh | 7 ++----- .../script/netplay/easy-netplay_client_pokemon.sh | 6 +----- .../script/netplay/easy-netplay_client_pokemon_GBA.sh | 6 +----- .../.tmp_update/script/netplay/easy-netplay_env.sh | 11 +++++++++++ .../.tmp_update/script/netplay/easy-netplay_server.sh | 5 ++--- .../script/netplay/easy-netplay_server_pokemon.sh | 4 +--- .../script/netplay/easy-netplay_server_pokemon_GBA.sh | 4 +--- .../.tmp_update/script/netplay/standard-netplay.sh | 4 +--- 8 files changed, 20 insertions(+), 27 deletions(-) create mode 100644 static/build/.tmp_update/script/netplay/easy-netplay_env.sh diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh index 11b7732063..0b360b7c67 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh @@ -8,11 +8,8 @@ # Used within GLO as an addon script. # Env setup -sysdir=/mnt/SDCARD/.tmp_update -miyoodir=/mnt/SDCARD/miyoo -export LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/parasyte" -export hostip="192.168.100.100" # This should be the default unless the user has changed it.. -peer_ip="$hostip" +# easy-netplay_env.sh: sysdir, miyoodir, LD_LIBRARY_PATH, hostip, peer_ip +. /mnt/SDCARD/.tmp_update/script/netplay/easy-netplay_env.sh logfile=easy_netplay diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh index e9a97d3095..63771588c2 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh @@ -2,12 +2,8 @@ # Used within GLO as an addon script. # Env setup -sysdir=/mnt/SDCARD/.tmp_update -miyoodir=/mnt/SDCARD/miyoo -LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/parasyte" +. /mnt/SDCARD/.tmp_update/script/netplay/easy-netplay_env.sh WPACLI=/customer/app/wpa_cli -hostip="192.168.100.100" # This should be the default unless the user has changed it.. -peer_ip="$hostip" # Runtime vars rm /tmp/stop_now diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh index db0802e0a2..15b60586f7 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh @@ -2,11 +2,7 @@ # Used within GLO as an addon script. # Env setup -sysdir=/mnt/SDCARD/.tmp_update -miyoodir=/mnt/SDCARD/miyoo -LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/parasyte" -hostip="192.168.100.100" # This should be the default unless the user has changed it.. -peer_ip="$hostip" +. /mnt/SDCARD/.tmp_update/script/netplay/easy-netplay_env.sh # Runtime vars rm /tmp/stop_now diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_env.sh b/static/build/.tmp_update/script/netplay/easy-netplay_env.sh new file mode 100644 index 0000000000..ec377812e3 --- /dev/null +++ b/static/build/.tmp_update/script/netplay/easy-netplay_env.sh @@ -0,0 +1,11 @@ +# Shared netplay environment setup + +sysdir=/mnt/SDCARD/.tmp_update +miyoodir=/mnt/SDCARD/miyoo + +LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/parasyte" +export LD_LIBRARY_PATH + +hostip="${hostip:-192.168.100.100}" # default unless overridden by caller +peer_ip="${peer_ip:-$hostip}" +export hostip peer_ip diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh index 86f3164829..88a3a7eb19 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh @@ -7,9 +7,8 @@ # Used within GLO as an addon script. # Env setup -sysdir=/mnt/SDCARD/.tmp_update -miyoodir=/mnt/SDCARD/miyoo -export LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/parasyte" +# easy-netplay_env.sh: sysdir, miyoodir, LD_LIBRARY_PATH, hostip, peer_ip +. /mnt/SDCARD/.tmp_update/script/netplay/easy-netplay_env.sh logfile=easy_netplay diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh index 80d9a571cc..bca8bf289c 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh @@ -2,9 +2,7 @@ # Used within GLO as an addon script. # Env setup -sysdir=/mnt/SDCARD/.tmp_update -miyoodir=/mnt/SDCARD/miyoo -LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/parasyte" +. /mnt/SDCARD/.tmp_update/script/netplay/easy-netplay_env.sh INFOPANEL_SLEEP=0.5 logfile=pokemon_link diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh index e3ce0b1bcb..7c3fde3868 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh @@ -2,9 +2,7 @@ # Used within GLO as an addon script. # Env setup -sysdir=/mnt/SDCARD/.tmp_update -miyoodir=/mnt/SDCARD/miyoo -LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/parasyte" +. /mnt/SDCARD/.tmp_update/script/netplay/easy-netplay_env.sh INFOPANEL_SLEEP=0.5 logfile=pokemon_link diff --git a/static/build/.tmp_update/script/netplay/standard-netplay.sh b/static/build/.tmp_update/script/netplay/standard-netplay.sh index efbd078a0a..a1be4c68dd 100644 --- a/static/build/.tmp_update/script/netplay/standard-netplay.sh +++ b/static/build/.tmp_update/script/netplay/standard-netplay.sh @@ -5,9 +5,7 @@ # Used within GLO as an addon script. # Env setup -sysdir=/mnt/SDCARD/.tmp_update -miyoodir=/mnt/SDCARD/miyoo -export LD_LIBRARY_PATH="/lib:/config/lib:$miyoodir/lib:$sysdir/lib:$sysdir/lib/parasyte" +. /mnt/SDCARD/.tmp_update/script/netplay/easy-netplay_env.sh INFOPANEL_SLEEP=0.5 # Runtime vars From 649150d66a24dfc372ad17cbfbf892705c59d26b Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Tue, 20 Jan 2026 23:15:48 +0000 Subject: [PATCH 22/32] centralize netplay cleanup and log removed files --- .../script/netplay/easy-netplay_client.sh | 27 +++------- .../netplay/easy-netplay_client_pokemon.sh | 43 ++++++---------- .../easy-netplay_client_pokemon_GBA.sh | 29 +++-------- .../script/netplay/easy-netplay_common.sh | 49 +++++++++++++++++++ .../script/netplay/easy-netplay_env.sh | 2 + .../script/netplay/easy-netplay_server.sh | 20 ++------ .../netplay/easy-netplay_server_pokemon.sh | 32 +++++------- .../easy-netplay_server_pokemon_GBA.sh | 25 +++------- 8 files changed, 103 insertions(+), 124 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh index 0b360b7c67..326f742b02 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh @@ -15,7 +15,8 @@ logfile=easy_netplay # Source scripts . $sysdir/script/log.sh -# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, strip_game_name, wifi_disabled, stripped_game_name, read_cookie, check_wifi, start_ftp, sync_file +# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, +# udhcpc_control, url_encode, strip_game_name, wifi_disabled, stripped_game_name, read_cookie, check_wifi, start_ftp, sync_file . $sysdir/script/netplay/easy-netplay_common.sh program=$(basename "$0" .sh) @@ -82,25 +83,11 @@ confirm_join_panel() { # cleanup: restore wifi/ftp and remove session temp files cleanup() { - build_infoPanel_and_log "Cleanup" "Cleaning up after netplay session..." - - pkill -9 pressMenu2Kill - - if is_running infoPanel; then - killall -9 infoPanel - fi - rm /tmp/dismiss_info_panel - - sync - - # restore_wifi_state - . "$sysdir/script/network/hotspot_cleanup.sh" - - rm "/mnt/SDCARD/RetroArch/retroarch.cookie.client" - - log "Cleanup done" - sync - exit + netplay_cleanup \ + "Cleaning up after netplay session..." \ + 1 0 1 0 \ + "/tmp/dismiss_info_panel" \ + "/mnt/SDCARD/RetroArch/retroarch.cookie.client" } ######### diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh index 63771588c2..3556995ab3 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh @@ -17,7 +17,8 @@ logfile=pokemon_link # Source scripts . $sysdir/script/log.sh -# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, strip_game_name, read_cookie, check_wifi, start_ftp, sync_file +# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, +# restore_ftp, udhcpc_control, url_encode, strip_game_name, read_cookie, check_wifi, start_ftp, sync_file . $sysdir/script/netplay/easy-netplay_common.sh # easy-netplay_signalling.sh: check_stop, notify_peer, notify_stop, wait_for_host . $sysdir/script/netplay/easy-netplay_signalling.sh @@ -162,34 +163,20 @@ wait_for_save_return() { # cleanup: restore wifi/ftp and remove session temp files cleanup() { - build_infoPanel_and_log "Cleanup" "Cleaning up after Pokemon session\n Do not power off!" - - pkill -9 pressMenu2Kill - - if is_running infoPanel; then - killall -9 infoPanel - fi - - # restore_wifi_state - . "$sysdir/script/network/hotspot_cleanup.sh" - restore_ftp - - # Remove some files we prepared and received log "Removing stale files" - rm "/tmp/host_ready" - rm "/tmp/ready_to_send" - rm "/tmp/ready_to_receive" - rm "${save_file_matched}_rcvd" - rm "/tmp/MISSING.srm" - rm "/tmp/stop_now" - rm "/tmp/wpa_supplicant.conf_bk" - rm "/mnt/SDCARD/RetroArch/retroarch.cookie.client" - rm "/mnt/SDCARD/RetroArch/retroarch.cookie" - rm "/tmp/dismiss_info_panel" - sync - - log "Cleanup done" - exit + netplay_cleanup \ + "Cleaning up after Pokemon session\n Do not power off!" \ + 1 1 1 0 \ + "/tmp/host_ready" \ + "/tmp/ready_to_send" \ + "/tmp/ready_to_receive" \ + "${save_file_matched}_rcvd" \ + "/tmp/MISSING.srm" \ + "/tmp/stop_now" \ + "/tmp/wpa_supplicant.conf_bk" \ + "/mnt/SDCARD/RetroArch/retroarch.cookie.client" \ + "/mnt/SDCARD/RetroArch/retroarch.cookie" \ + "/tmp/dismiss_info_panel" } ########### diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh index 15b60586f7..6be023e8a3 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh @@ -59,29 +59,14 @@ start_retroarch() { # cleanup: restore network/ftp and clean temp files cleanup() { - build_infoPanel_and_log "Cleanup" "Cleaning up after Pokemon session\n Do not power off!" - - pkill -9 pressMenu2Kill - - if is_running infoPanel; then - killall -9 infoPanel - fi - - # restore_wifi_state - . "$sysdir/script/network/hotspot_cleanup.sh" - restore_ftp - - # Remove some files we prepared and received log "Removing stale files" - rm "/tmp/host_ready" - rm "/tmp/stop_now" - rm "/tmp/wpa_supplicant.conf_bk" - rm "/tmp/dismiss_info_panel" - sync - - log "Cleanup done" - - exit + netplay_cleanup \ + "Cleaning up after Pokemon session\n Do not power off!" \ + 1 1 1 0 \ + "/tmp/host_ready" \ + "/tmp/stop_now" \ + "/tmp/wpa_supplicant.conf_bk" \ + "/tmp/dismiss_info_panel" } # confirm_join_panel: show join confirmation UI with local ROM image diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_common.sh b/static/build/.tmp_update/script/netplay/easy-netplay_common.sh index 024bda6dbd..bee6fb6b78 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_common.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_common.sh @@ -193,6 +193,55 @@ strip_game_name() { echo "$1" | sed -e 's/ ([^()]*)//g' -e 's/ [[A-z0-9!+]*]//g' -e 's/([^()]*)//g' -e 's/[[A-z0-9!+]*]//g' } +# remove_files +# - removes files if they exist +remove_files() { + local f + for f in "$@"; do + if [ -n "$f" ] && [ -e "$f" ]; then + echo "Removing: $f" + rm -f "$f" + fi + done +} + +# netplay_cleanup <message> <hotspot_cleanup> <restore_ftp> <kill_infopanel> <disable_hotspot_flag> [files...] +# - runs common cleanup steps and exits +netplay_cleanup() { + local message="$1" + local do_hotspot_cleanup="$2" + local do_restore_ftp="$3" + local do_kill_infopanel="$4" + local do_disable_hotspot="$5" + shift 5 + + build_infoPanel_and_log "Cleanup" "$message" + + pkill -9 pressMenu2Kill + + if [ "$do_kill_infopanel" -eq 1 ] && is_running infoPanel; then + killall -9 infoPanel + fi + + if [ "$do_hotspot_cleanup" -eq 1 ]; then + . "$sysdir/script/network/hotspot_cleanup.sh" + fi + + if [ "$do_restore_ftp" -eq 1 ]; then + restore_ftp + fi + + remove_files "$@" + + if [ "$do_disable_hotspot" -eq 1 ]; then + disable_flag hotspotState + fi + + sync + log "Cleanup done" + exit +} + # wifi_disabled # - returns 0 if wifi is disabled wifi_disabled() { diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_env.sh b/static/build/.tmp_update/script/netplay/easy-netplay_env.sh index ec377812e3..7f522fd120 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_env.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_env.sh @@ -9,3 +9,5 @@ export LD_LIBRARY_PATH hostip="${hostip:-192.168.100.100}" # default unless overridden by caller peer_ip="${peer_ip:-$hostip}" export hostip peer_ip + +iw wlan0 set power_save off \ No newline at end of file diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh index 88a3a7eb19..fb2fb407e8 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh @@ -82,22 +82,12 @@ start_retroarch() { # cleanup: restore wifi/ftp and remove session temp files cleanup() { - build_infoPanel_and_log "Cleanup" "Cleaning up after netplay session..." - - pkill -9 pressMenu2Kill - - . "$sysdir/script/network/hotspot_cleanup.sh" - - restore_ftp - - # Remove some files we prepared and received log "Removing stale files" - rm "/mnt/SDCARD/RetroArch/retroarch.cookie" - rm "/tmp/dismiss_info_panel" - sync - log "Cleanup done" - exit - + netplay_cleanup \ + "Cleaning up after netplay session..." \ + 1 1 0 0 \ + "/mnt/SDCARD/RetroArch/retroarch.cookie" \ + "/tmp/dismiss_info_panel" } ######### diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh index bca8bf289c..d70e71f613 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh @@ -283,27 +283,17 @@ client_save_send() { # Cleanup. If you don't call this you don't retransfer the saves - Users cannot under any circumstances miss this function. cleanup() { - build_infoPanel_and_log "Cleanup" "Cleaning up after Pokemon session\n Do not power off!" - - pkill -9 pressMenu2Kill - - . "$sysdir/script/network/hotspot_cleanup.sh" - - restore_ftp - - # Remove some files we prepared and received - rm "/tmp/host_ready" - rm "$save_new_path" - rm "$client_rom_clone" - rm "/tmp/ready_to_send" - rm "/tmp/ready_to_receive" - rm "/tmp/MISSING.srm" - rm "/tmp/stop_now" - disable_flag hotspotState - rm "/tmp/dismiss_info_panel" - sync - log "Cleanup done" - exit + netplay_cleanup \ + "Cleaning up after Pokemon session\n Do not power off!" \ + 1 1 0 1 \ + "/tmp/host_ready" \ + "$save_new_path" \ + "$client_rom_clone" \ + "/tmp/ready_to_send" \ + "/tmp/ready_to_receive" \ + "/tmp/MISSING.srm" \ + "/tmp/stop_now" \ + "/tmp/dismiss_info_panel" } ########### diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh index 7c3fde3868..9cbf4294ba 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh @@ -59,26 +59,15 @@ start_retroarch() { # cleanup: restore network/ftp and clean temp files cleanup() { - build_infoPanel_and_log "Cleanup" "Cleaning up after Pokemon session\n Do not power off!" - - pkill -9 pressMenu2Kill - - . "$sysdir/script/network/hotspot_cleanup.sh" - - restore_ftp - - # Remove some files we prepared and received - rm "/tmp/host_ready" - rm "/tmp/stop_now" - disable_flag hotspotState - rm "/tmp/dismiss_info_panel" - sync - log "Cleanup done" - - #Rename savestate_auto_load so savestate doesn't overwrite next loadsave + # Rename savestate_auto_load so savestate doesn't overwrite next loadsave mv -f "/mnt/SDCARD/Saves/CurrentProfile/states/gpSP/$host_rom_filename_NoExt.state.auto" "/mnt/SDCARD/Saves/CurrentProfile/states/gpSP/$host_rom_filename_NoExt.state.auto_$CurDate" - exit + netplay_cleanup \ + "Cleaning up after Pokemon session\n Do not power off!" \ + 1 1 0 1 \ + "/tmp/host_ready" \ + "/tmp/stop_now" \ + "/tmp/dismiss_info_panel" } # confirm_join_panel: show host confirmation UI with local ROM image From f54149835686bcc0b11b2301ebbb6b87e0939737 Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Tue, 20 Jan 2026 23:24:12 +0000 Subject: [PATCH 23/32] comments --- static/build/.tmp_update/script/netplay/easy-netplay_client.sh | 3 +++ .../.tmp_update/script/netplay/easy-netplay_client_pokemon.sh | 3 +++ .../script/netplay/easy-netplay_client_pokemon_GBA.sh | 3 +++ static/build/.tmp_update/script/netplay/easy-netplay_server.sh | 3 +++ .../.tmp_update/script/netplay/easy-netplay_server_pokemon.sh | 3 +++ .../script/netplay/easy-netplay_server_pokemon_GBA.sh | 3 +++ 6 files changed, 18 insertions(+) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh index 326f742b02..8b214b8794 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh @@ -83,6 +83,9 @@ confirm_join_panel() { # cleanup: restore wifi/ftp and remove session temp files cleanup() { + # message: cleanup infoPanel text + # args: hotspot_cleanup restore_ftp kill_infopanel disable_hotspot_flag + # remove files netplay_cleanup \ "Cleaning up after netplay session..." \ 1 0 1 0 \ diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh index 3556995ab3..00a53ebcc4 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh @@ -164,6 +164,9 @@ wait_for_save_return() { # cleanup: restore wifi/ftp and remove session temp files cleanup() { log "Removing stale files" + # message: cleanup infoPanel text + # args: hotspot_cleanup restore_ftp kill_infopanel disable_hotspot_flag + # remove files netplay_cleanup \ "Cleaning up after Pokemon session\n Do not power off!" \ 1 1 1 0 \ diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh index 6be023e8a3..5df77f221e 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh @@ -60,6 +60,9 @@ start_retroarch() { # cleanup: restore network/ftp and clean temp files cleanup() { log "Removing stale files" + # message: cleanup infoPanel text + # args: hotspot_cleanup restore_ftp kill_infopanel disable_hotspot_flag + # remove files netplay_cleanup \ "Cleaning up after Pokemon session\n Do not power off!" \ 1 1 1 0 \ diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh index fb2fb407e8..456a5c7362 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh @@ -83,6 +83,9 @@ start_retroarch() { # cleanup: restore wifi/ftp and remove session temp files cleanup() { log "Removing stale files" + # message: cleanup infoPanel text + # args: hotspot_cleanup restore_ftp kill_infopanel disable_hotspot_flag + # remove files netplay_cleanup \ "Cleaning up after netplay session..." \ 1 1 0 0 \ diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh index d70e71f613..d0d8e2132f 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh @@ -283,6 +283,9 @@ client_save_send() { # Cleanup. If you don't call this you don't retransfer the saves - Users cannot under any circumstances miss this function. cleanup() { + # message: cleanup infoPanel text + # args: hotspot_cleanup restore_ftp kill_infopanel disable_hotspot_flag + # remove files netplay_cleanup \ "Cleaning up after Pokemon session\n Do not power off!" \ 1 1 0 1 \ diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh index 9cbf4294ba..451b502408 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh @@ -62,6 +62,9 @@ cleanup() { # Rename savestate_auto_load so savestate doesn't overwrite next loadsave mv -f "/mnt/SDCARD/Saves/CurrentProfile/states/gpSP/$host_rom_filename_NoExt.state.auto" "/mnt/SDCARD/Saves/CurrentProfile/states/gpSP/$host_rom_filename_NoExt.state.auto_$CurDate" + # message: cleanup infoPanel text + # args: hotspot_cleanup restore_ftp kill_infopanel disable_hotspot_flag + # remove files netplay_cleanup \ "Cleaning up after Pokemon session\n Do not power off!" \ 1 1 0 1 \ From bd263d12c61d39a4b8af9cc770fe5b62e7ef84ec Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Tue, 20 Jan 2026 23:26:02 +0000 Subject: [PATCH 24/32] duplicate vars --- .../build/.tmp_update/script/netplay/easy-netplay_common.sh | 6 +++--- .../script/netplay/easy-netplay_server_pokemon.sh | 1 - .../script/netplay/easy-netplay_server_pokemon_GBA.sh | 1 - static/build/.tmp_update/script/netplay/standard-netplay.sh | 1 - 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_common.sh b/static/build/.tmp_update/script/netplay/easy-netplay_common.sh index bee6fb6b78..55bfed8cbe 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_common.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_common.sh @@ -18,7 +18,7 @@ NETPLAY_SYNC_MAX_FILE_CHKSUM_SIZE=26214400 # max file size to allow checksum NETPLAY_SYNC_MAX_FILE_DL_SIZE=104857600 # max file size to allow download NETPLAY_COOKIE_MAX_FILE_SIZE=26214400 # max file size for cookie checksum entries NETPLAY_SYNC_FAIL_DELAY=2 # delay after sync failures before cleanup -NETPLAY_INFOPANEL_SLEEP_DEFAULT=0.3 # default infoPanel delay when INFOPANEL_SLEEP is unset +NETPLAY_INFOPANEL_SLEEP=0.5 # infoPanel delay # checksize_func <file_path> <remote_size> # - sets: same_size (0 different, 1 identical, 2 unknown) @@ -104,12 +104,12 @@ is_running() { } # build_infoPanel_and_log <title> <message> -# - uses: INFOPANEL_SLEEP or NETPLAY_INFOPANEL_SLEEP_DEFAULT +# - uses: NETPLAY_INFOPANEL_SLEEP # - shows persistent infoPanel and logs message build_infoPanel_and_log() { local title="$1" local message="$2" - local delay="${INFOPANEL_SLEEP:-$NETPLAY_INFOPANEL_SLEEP_DEFAULT}" + local delay="$NETPLAY_INFOPANEL_SLEEP" log "Info Panel: \n\tStage: $title\n\tMessage: $message" if is_running infoPanel; then diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh index d0d8e2132f..55b32a0250 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh @@ -3,7 +3,6 @@ # Env setup . /mnt/SDCARD/.tmp_update/script/netplay/easy-netplay_env.sh -INFOPANEL_SLEEP=0.5 logfile=pokemon_link diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh index 451b502408..eef71ce1de 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh @@ -3,7 +3,6 @@ # Env setup . /mnt/SDCARD/.tmp_update/script/netplay/easy-netplay_env.sh -INFOPANEL_SLEEP=0.5 logfile=pokemon_link diff --git a/static/build/.tmp_update/script/netplay/standard-netplay.sh b/static/build/.tmp_update/script/netplay/standard-netplay.sh index a1be4c68dd..26b7915879 100644 --- a/static/build/.tmp_update/script/netplay/standard-netplay.sh +++ b/static/build/.tmp_update/script/netplay/standard-netplay.sh @@ -6,7 +6,6 @@ # Env setup . /mnt/SDCARD/.tmp_update/script/netplay/easy-netplay_env.sh -INFOPANEL_SLEEP=0.5 # Runtime vars romfullpath="$1" From 9af5fa41e319fb311dab5a1c3b6592367770e8bf Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Wed, 21 Jan 2026 10:01:27 +0000 Subject: [PATCH 25/32] block was unreachable, added some comments --- .../script/netplay/easy-netplay_client_pokemon.sh | 10 +++++++--- .../script/netplay/easy-netplay_server_pokemon.sh | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh index 00a53ebcc4..9a5767ec80 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh @@ -62,8 +62,9 @@ backup_and_send_save() { cp -f "$save_tgbdual" "${save_tgbdual}_$CurDate" save_file_matched="$save_tgbdual" else - touch "/tmp/MISSING.srm" - save_file_matched="/tmp/MISSING.srm" + missing=1 + touch "/tmp/missing_save.srm" + save_file_matched="/tmp/missing_save.srm" fi save_file_stripped="${save_file_matched##*/}" @@ -73,6 +74,8 @@ backup_and_send_save() { curl -T "$save_file_matched" "ftp://$hostip/tmp/$encoded_save_file" if [ "$missing" = "1" ]; then + # hitting this block means we cannot send a save to the host + # in some games, such as pokemon this means the host would start a blank save build_infoPanel_and_log "Save not found" "You don't have a save for this game, \n or we failed to find it. Cannot continue \n Notified host." notify_stop fi @@ -131,6 +134,7 @@ wait_for_save_return() { counter=$((counter + 1)) if [ $counter -ge 30 ]; then + # if we've hit this block the save won't be retransferred, if this happens progress during this session is lost. build_infoPanel_and_log "Error" "The Host didn't ready up, cannot continue..." log "We ran out of time waiting for the host to ready up, possibly due to host->client connecitivity" sleep 1 @@ -174,7 +178,7 @@ cleanup() { "/tmp/ready_to_send" \ "/tmp/ready_to_receive" \ "${save_file_matched}_rcvd" \ - "/tmp/MISSING.srm" \ + "/tmp/missing_save.srm" \ "/tmp/stop_now" \ "/tmp/wpa_supplicant.conf_bk" \ "/mnt/SDCARD/RetroArch/retroarch.cookie.client" \ diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh index 55b32a0250..39b24cebf4 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh @@ -89,7 +89,7 @@ client_save_get() { sync for file in /tmp/*.srm; do if [ -f "$file" ]; then - if [ "$(basename "$file")" = "MISSING.srm" ]; then + if [ "$(basename "$file")" = "missing_save.srm" ]; then build_infoPanel_and_log "Sync error" "Client advises they don't have a save file. \n Cannot continue." notify_stop else @@ -293,7 +293,7 @@ cleanup() { "$client_rom_clone" \ "/tmp/ready_to_send" \ "/tmp/ready_to_receive" \ - "/tmp/MISSING.srm" \ + "/tmp/missing_save.srm" \ "/tmp/stop_now" \ "/tmp/dismiss_info_panel" } From 9404407820b35c5732956dfe60ebdf29c60bfbec Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Wed, 21 Jan 2026 10:02:54 +0000 Subject: [PATCH 26/32] comment for pwr save --- static/build/.tmp_update/script/netplay/easy-netplay_common.sh | 3 +++ static/build/.tmp_update/script/netplay/easy-netplay_env.sh | 1 + 2 files changed, 4 insertions(+) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_common.sh b/static/build/.tmp_update/script/netplay/easy-netplay_common.sh index 55bfed8cbe..1eb3c2f020 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_common.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_common.sh @@ -237,6 +237,9 @@ netplay_cleanup() { disable_flag hotspotState fi + # reset power save on the wifi + iw wlan0 set power_save on + sync log "Cleanup done" exit diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_env.sh b/static/build/.tmp_update/script/netplay/easy-netplay_env.sh index 7f522fd120..ec3002873f 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_env.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_env.sh @@ -10,4 +10,5 @@ hostip="${hostip:-192.168.100.100}" # default unless overridden by caller peer_ip="${peer_ip:-$hostip}" export hostip peer_ip +# turn off power save on the wifi - this is turned back on in the netplay_cleanup function iw wlan0 set power_save off \ No newline at end of file From 6c5a4321ca3998ea03adc5b0e5d486929fd7a9d8 Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Wed, 21 Jan 2026 10:08:05 +0000 Subject: [PATCH 27/32] formatting --- .../script/netplay/easy-netplay_client_pokemon.sh | 2 +- .../.tmp_update/script/netplay/easy-netplay_server.sh | 7 +++---- .../script/netplay/easy-netplay_server_pokemon.sh | 1 - 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh index 9a5767ec80..af17e292d3 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh @@ -134,7 +134,7 @@ wait_for_save_return() { counter=$((counter + 1)) if [ $counter -ge 30 ]; then - # if we've hit this block the save won't be retransferred, if this happens progress during this session is lost. + # if we've hit this block the save won't be re-transferred, if this happens progress during this session is lost. build_infoPanel_and_log "Error" "The Host didn't ready up, cannot continue..." log "We ran out of time waiting for the host to ready up, possibly due to host->client connecitivity" sleep 1 diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh index 456a5c7362..574a6fd8c8 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh @@ -25,17 +25,16 @@ program=$(basename "$0" .sh) # Find the recommended core for the current system. get_netplay_core() { - platform=$(echo "$cookie_rom_path" | grep -o '/Roms/[^/]*' | cut -d'/' -f3) netplaycore_info=$(grep "^${platform};" "$sysdir/config/netplay_cores.conf") - if [ -n "$netplaycore_info" ]; then -# Runtime vars + if [ -n "$netplaycore_info" ]; then netplaycore=$(echo "$netplaycore_info" | cut -d ';' -f 2) netplaycore="/mnt/SDCARD/RetroArch/.retroarch/cores/$netplaycore" core_config_folder=$(echo "$netplaycore_info" | cut -d ';' -f 3) cpuspeed=$(echo "$netplaycore_info" | cut -d ';' -f 4) fi + if [ -n "$netplaycore" ]; then if [ "$netplaycore" = "none" ]; then build_infoPanel_and_log "Netplay impossible" "$platform not compatible with Netplay" @@ -45,8 +44,8 @@ get_netplay_core() { else netplaycore="$cookie_core_path" fi + return 0 - } # start_retroarch: launch RetroArch host with selected core and ROM diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh index 39b24cebf4..b9d03262df 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh @@ -189,7 +189,6 @@ client_rom_rename() { # We'll start Retroarch in host mode with -H with the core and rom paths loaded in. start_retroarch() { - log "\n############################ RETROARCH DEBUGGING ############################" log "host_rom: $host_rom" log "client_rom_clone: ${client_rom_clone}" From dfe26d4fe7b591eb3903b7b1cfd9cca94983d544 Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Wed, 21 Jan 2026 10:26:56 +0000 Subject: [PATCH 28/32] move source of the log.sh into common --- static/build/.tmp_update/script/netplay/easy-netplay_client.sh | 1 - .../.tmp_update/script/netplay/easy-netplay_client_pokemon.sh | 1 - .../script/netplay/easy-netplay_client_pokemon_GBA.sh | 1 - static/build/.tmp_update/script/netplay/easy-netplay_common.sh | 3 +++ static/build/.tmp_update/script/netplay/easy-netplay_server.sh | 1 - .../.tmp_update/script/netplay/easy-netplay_server_pokemon.sh | 1 - .../script/netplay/easy-netplay_server_pokemon_GBA.sh | 1 - .../.tmp_update/script/netplay/easy-netplay_signalling.sh | 1 + static/build/.tmp_update/script/netplay/standard-netplay.sh | 1 - 9 files changed, 4 insertions(+), 7 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh index 8b214b8794..03ffde614a 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh @@ -14,7 +14,6 @@ logfile=easy_netplay # Source scripts -. $sysdir/script/log.sh # easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, # udhcpc_control, url_encode, strip_game_name, wifi_disabled, stripped_game_name, read_cookie, check_wifi, start_ftp, sync_file . $sysdir/script/netplay/easy-netplay_common.sh diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh index af17e292d3..f1e05f0514 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh @@ -16,7 +16,6 @@ SaveFromGambatte=0 logfile=pokemon_link # Source scripts -. $sysdir/script/log.sh # easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, # restore_ftp, udhcpc_control, url_encode, strip_game_name, read_cookie, check_wifi, start_ftp, sync_file . $sysdir/script/netplay/easy-netplay_common.sh diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh index 5df77f221e..ba920cc1e4 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh @@ -15,7 +15,6 @@ netplaycore="/mnt/SDCARD/RetroArch/.retroarch/cores/gpsp_libretro.so" logfile=pokemon_link # Source scripts -. $sysdir/script/log.sh # easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, strip_game_name, check_wifi, start_ftp . $sysdir/script/netplay/easy-netplay_common.sh # easy-netplay_signalling.sh: wait_for_host, check_stop, notify_stop diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_common.sh b/static/build/.tmp_update/script/netplay/easy-netplay_common.sh index 1eb3c2f020..80b3ab9a65 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_common.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_common.sh @@ -1,5 +1,8 @@ # Shared netplay helpers +# logging (needed by helpers in this file) +. $sysdir/script/log.sh + # Tunables # seconds unless stated otherwise; bytes unless stated otherwise NETPLAY_FTP_CHECK_RETRIES=3 # ftp head retry count for preflight checks diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh index 574a6fd8c8..956798d99e 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh @@ -13,7 +13,6 @@ logfile=easy_netplay # Source scripts -. $sysdir/script/log.sh # easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp . $sysdir/script/netplay/easy-netplay_common.sh diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh index b9d03262df..4bf6c4ac64 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh @@ -7,7 +7,6 @@ logfile=pokemon_link # Source scripts -. $sysdir/script/log.sh # easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, strip_game_name, check_wifi, start_ftp, sync_file . $sysdir/script/netplay/easy-netplay_common.sh # easy-netplay_signalling.sh: wait_for_client, ready_up, notify_peer, check_stop, notify_stop diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh index eef71ce1de..7d99651ac6 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh @@ -7,7 +7,6 @@ logfile=pokemon_link # Source scripts -. $sysdir/script/log.sh # easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, strip_game_name, check_wifi, start_ftp . $sysdir/script/netplay/easy-netplay_common.sh # easy-netplay_signalling.sh: wait_for_client, ready_up, notify_peer, check_stop, notify_stop diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_signalling.sh b/static/build/.tmp_update/script/netplay/easy-netplay_signalling.sh index ce76d7b092..a893a6032f 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_signalling.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_signalling.sh @@ -132,6 +132,7 @@ wait_for_client() { sleep 0.5 counter=$((counter + 1)) + # wait for 15 seconds, then bail if [ $counter -ge 30 ]; then log "No client has connected" build_infoPanel_and_log "Hotspot error" "No client has connected. Exiting..." diff --git a/static/build/.tmp_update/script/netplay/standard-netplay.sh b/static/build/.tmp_update/script/netplay/standard-netplay.sh index 26b7915879..07ee3ea204 100644 --- a/static/build/.tmp_update/script/netplay/standard-netplay.sh +++ b/static/build/.tmp_update/script/netplay/standard-netplay.sh @@ -17,7 +17,6 @@ NetplayAction="$3" # host or join logfile=netplay # Source scripts -. $sysdir/script/log.sh # easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, check_wifi, start_ftp . $sysdir/script/netplay/easy-netplay_common.sh From 4cc0da560160271344c82716b6bd95ee3af94486 Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Wed, 21 Jan 2026 11:14:10 +0000 Subject: [PATCH 29/32] show client IP after hotspot join, remove client wait timeout, and centralize cookie/name handling --- .../script/netplay/easy-netplay_client.sh | 11 ++++--- .../netplay/easy-netplay_client_pokemon.sh | 21 +++++-------- .../easy-netplay_client_pokemon_GBA.sh | 10 ++---- .../script/netplay/easy-netplay_common.sh | 31 +++++++++++++------ .../script/netplay/easy-netplay_server.sh | 2 +- .../netplay/easy-netplay_server_pokemon.sh | 18 +++-------- .../easy-netplay_server_pokemon_GBA.sh | 10 ++---- .../script/netplay/easy-netplay_signalling.sh | 8 ----- 8 files changed, 45 insertions(+), 66 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh index 03ffde614a..82ce245275 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client.sh @@ -14,8 +14,8 @@ logfile=easy_netplay # Source scripts -# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, -# udhcpc_control, url_encode, strip_game_name, wifi_disabled, stripped_game_name, read_cookie, check_wifi, start_ftp, sync_file +# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, +# udhcpc_control, url_encode, strip_game_name, format_game_name, wifi_disabled, read_cookie, check_wifi, start_ftp, sync_file . $sysdir/script/netplay/easy-netplay_common.sh program=$(basename "$0" .sh) @@ -89,7 +89,7 @@ cleanup() { "Cleaning up after netplay session..." \ 1 0 1 0 \ "/tmp/dismiss_info_panel" \ - "/mnt/SDCARD/RetroArch/retroarch.cookie.client" + "$COOKIE_CLIENT_PATH" } ######### @@ -102,9 +102,10 @@ lets_go() { # Join host hotspot . "$sysdir/script/network/hotspot_join.sh" + build_infoPanel_and_log "Connected" "Client IP: ${IP:-unknown}\nHost IP: $hostip" # Fetch cookie from host - sync_file "Cookie" "/mnt/SDCARD/RetroArch/retroarch.cookie" 0 0 -f -m + sync_file "Cookie" "$COOKIE_FILE" 0 0 -f -m # Read host cookie and parse paths/checksums read_cookie @@ -115,7 +116,7 @@ lets_go() { sync_file "Img" "$Img_path" 0 0 -o # Build display name for confirmation prompt - stripped_game_name + game_name=$(format_game_name "$(basename "${rom%.*}")") # Stop menu watcher before launch pkill -9 pressMenu2Kill diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh index f1e05f0514..76b86053cd 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh @@ -17,7 +17,7 @@ logfile=pokemon_link # Source scripts # easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, -# restore_ftp, udhcpc_control, url_encode, strip_game_name, read_cookie, check_wifi, start_ftp, sync_file +# restore_ftp, udhcpc_control, url_encode, strip_game_name, format_game_name, read_cookie, check_wifi, start_ftp, sync_file . $sysdir/script/netplay/easy-netplay_common.sh # easy-netplay_signalling.sh: check_stop, notify_peer, notify_stop, wait_for_host . $sysdir/script/netplay/easy-netplay_signalling.sh @@ -180,8 +180,8 @@ cleanup() { "/tmp/missing_save.srm" \ "/tmp/stop_now" \ "/tmp/wpa_supplicant.conf_bk" \ - "/mnt/SDCARD/RetroArch/retroarch.cookie.client" \ - "/mnt/SDCARD/RetroArch/retroarch.cookie" \ + "$COOKIE_CLIENT_PATH" \ + "$COOKIE_FILE" \ "/tmp/dismiss_info_panel" } @@ -218,15 +218,6 @@ confirm_join_panel() { fi } -# stripped_game_names: format host/client display names -stripped_game_names() { - host_name_trimmed="$(strip_game_name "$(basename "${rom%.*}")")" - game_name="Host: \n$host_name_trimmed" - - client_rom_trimmed="$(strip_game_name "$client_rom_filename_NoExt")" - game_name_client="\n Client (me): \n$client_rom_trimmed" -} - ######### ##Main.## ######### @@ -240,12 +231,13 @@ lets_go() { # Join host hotspot . "$sysdir/script/network/hotspot_join.sh" + build_infoPanel_and_log "Connected" "Client IP: ${IP:-unknown}\nHost IP: $hostip" # start_ftp: start FTP without preflight start_ftp # Send cookie to host - sync_file "Cookie" "/mnt/SDCARD/RetroArch/retroarch.cookie" 0 0 -f -m + sync_file "Cookie" "$COOKIE_FILE" 0 0 -f -m # Read host cookie and parse paths/checksums (verbose logging) read_cookie 1 @@ -259,7 +251,8 @@ lets_go() { sync_file "Img" "$Img_path" 0 0 -o # Build display names for confirmation prompt - stripped_game_names + game_name=$(format_game_name "$(basename "${rom%.*}")" "Host") + game_name_client=$(format_game_name "$client_rom_filename_NoExt" "Client (me)" "\n ") # Wait for host ready signal wait_for_host diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh index ba920cc1e4..1231f54dc4 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh @@ -15,7 +15,7 @@ netplaycore="/mnt/SDCARD/RetroArch/.retroarch/cores/gpsp_libretro.so" logfile=pokemon_link # Source scripts -# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, strip_game_name, check_wifi, start_ftp +# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, strip_game_name, format_game_name, check_wifi, start_ftp . $sysdir/script/netplay/easy-netplay_common.sh # easy-netplay_signalling.sh: wait_for_host, check_stop, notify_stop . $sysdir/script/netplay/easy-netplay_signalling.sh @@ -94,11 +94,6 @@ confirm_join_panel() { fi } -# stripped_game_names: format local ROM display name -stripped_game_names() { - client_rom_trimmed="$(strip_game_name "$client_rom_filename_NoExt")" - game_name_client="Client (me): \n$client_rom_trimmed" -} ######### ##Main.## ######### @@ -116,12 +111,13 @@ lets_go() { # Join host hotspot . "$sysdir/script/network/hotspot_join.sh" + build_infoPanel_and_log "Connected" "Client IP: ${IP:-unknown}\nHost IP: $hostip" # Start FTP for lightweight signaling start_ftp # Build display names for confirmation prompt - stripped_game_names + game_name_client=$(format_game_name "$client_rom_filename_NoExt" "Client (me)") # Wait for host ready signal wait_for_host diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_common.sh b/static/build/.tmp_update/script/netplay/easy-netplay_common.sh index 80b3ab9a65..5f6a7b2346 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_common.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_common.sh @@ -22,6 +22,8 @@ NETPLAY_SYNC_MAX_FILE_DL_SIZE=104857600 # max file size to allow download NETPLAY_COOKIE_MAX_FILE_SIZE=26214400 # max file size for cookie checksum entries NETPLAY_SYNC_FAIL_DELAY=2 # delay after sync failures before cleanup NETPLAY_INFOPANEL_SLEEP=0.5 # infoPanel delay +COOKIE_CLIENT_PATH="/mnt/SDCARD/RetroArch/retroarch.cookie.client" +COOKIE_FILE="/mnt/SDCARD/RetroArch/retroarch.cookie" # checksize_func <file_path> <remote_size> # - sets: same_size (0 different, 1 identical, 2 unknown) @@ -196,6 +198,23 @@ strip_game_name() { echo "$1" | sed -e 's/ ([^()]*)//g' -e 's/ [[A-z0-9!+]*]//g' -e 's/([^()]*)//g' -e 's/[[A-z0-9!+]*]//g' } +# format_game_name <name> [label] [prefix] +# - label adds "<label>: \n" before the name +# - prefix allows leading newline/spacing (e.g. "\n ") +format_game_name() { + local name="$1" + local label="$2" + local prefix="$3" + local trimmed + + trimmed=$(strip_game_name "$name") + if [ -n "$label" ]; then + printf '%s%s: \n%s' "$prefix" "$label" "$trimmed" + else + printf '%s%s' "$prefix" "$trimmed" + fi +} + # remove_files # - removes files if they exist remove_files() { @@ -254,14 +273,8 @@ wifi_disabled() { [ $(/customer/app/jsonval wifi) -eq 0 ] } -# stripped_game_name -# - reads rom name from retroarch.cookie.client and strips extension -stripped_game_name() { - game_name=$(awk -F'/' '/\\[rom\\]:/ {print $NF}' /mnt/SDCARD/RetroArch/retroarch.cookie.client | sed 's/\\(.*\\)\\..*/\\1/') -} - # read_cookie [verbose] -# - parses /mnt/SDCARD/RetroArch/retroarch.cookie.client into core/rom/checksum vars +# - parses "$COOKIE_CLIENT_PATH" into core/rom/checksum vars # - sets: core_url, rom_url, romdirname, romName, romNameNoExtension, Img_path read_cookie() { local verbose="$1" @@ -291,7 +304,7 @@ read_cookie() { ;; esac log "$core $rom $coresize $corechksum $romsize $romchksum" - done <"/mnt/SDCARD/RetroArch/retroarch.cookie.client" + done <"$COOKIE_CLIENT_PATH" # url encode or curl complains export core_url=$(url_encode "$core") @@ -575,8 +588,6 @@ sync_file() { # create_cookie_info # - writes core/rom/checksum/cpuspeed into retroarch.cookie create_cookie_info() { - COOKIE_FILE="/mnt/SDCARD/RetroArch/retroarch.cookie" - echo "[core]: $netplaycore" >"$COOKIE_FILE" echo "[rom]: $cookie_rom_path" >>"$COOKIE_FILE" diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh index 956798d99e..4288fa1767 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server.sh @@ -87,7 +87,7 @@ cleanup() { netplay_cleanup \ "Cleaning up after netplay session..." \ 1 1 0 0 \ - "/mnt/SDCARD/RetroArch/retroarch.cookie" \ + "$COOKIE_FILE" \ "/tmp/dismiss_info_panel" } diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh index 4bf6c4ac64..bf58140a39 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh @@ -7,7 +7,7 @@ logfile=pokemon_link # Source scripts -# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, strip_game_name, check_wifi, start_ftp, sync_file +# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, strip_game_name, format_game_name, check_wifi, start_ftp, sync_file . $sysdir/script/netplay/easy-netplay_common.sh # easy-netplay_signalling.sh: wait_for_client, ready_up, notify_peer, check_stop, notify_stop . $sysdir/script/netplay/easy-netplay_signalling.sh @@ -154,7 +154,7 @@ client_read_cookie() { ;; esac log "$core $rom $coresize $corechksum $romsize $romchksum" - done <"/mnt/SDCARD/RetroArch/retroarch.cookie.client" + done <"$COOKIE_CLIENT_PATH" #url encode or curl complains export core_url=$(url_encode "$core") @@ -347,15 +347,6 @@ confirm_join_panel() { fi } -# stripped_game_names: format host/client display names -stripped_game_names() { - host_game_name="$(strip_game_name "$(basename "${host_rom%.*}")")" - host_game_name="Host (me): \n$host_game_name" - - client_rom_trimmed="$(strip_game_name "$(basename "${client_rom%.*}")")" - client_game_name="\n Client: \n$client_rom_trimmed" -} - # unpack_rom: extract archive into its folder unpack_rom() { file="$1" @@ -394,7 +385,7 @@ lets_go() { wait_for_client # Send cookie to client (downloaded as retroarch.cookie.client) - sync_file "Cookie" "/mnt/SDCARD/RetroArch/retroarch.cookie" 0 0 -f -m + sync_file "Cookie" "$COOKIE_FILE" 0 0 -f -m # Read client cookie for display and params client_read_cookie @@ -412,7 +403,8 @@ lets_go() { sync_file "Img" "$client_Img_path" 0 0 -o # Build display names for confirmation prompt - stripped_game_names + host_game_name=$(format_game_name "$(basename "${host_rom%.*}")" "Host (me)") + client_game_name=$(format_game_name "$(basename "${client_rom%.*}")" "Client" "\n ") # Confirm host start with host/client info confirm_join_panel "Host now?" "$host_game_name \n $client_game_name" diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh index 7d99651ac6..ce3f950f83 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon_GBA.sh @@ -7,7 +7,7 @@ logfile=pokemon_link # Source scripts -# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, strip_game_name, check_wifi, start_ftp +# easy-netplay_common.sh: build_infoPanel_and_log, checksize_func, checksum_func, enable_flag, disable_flag, flag_enabled, is_running, restore_ftp, udhcpc_control, url_encode, strip_game_name, format_game_name, check_wifi, start_ftp . $sysdir/script/netplay/easy-netplay_common.sh # easy-netplay_signalling.sh: wait_for_client, ready_up, notify_peer, check_stop, notify_stop . $sysdir/script/netplay/easy-netplay_signalling.sh @@ -102,12 +102,6 @@ confirm_join_panel() { fi } -# stripped_game_names: format local ROM display name -stripped_game_names() { - host_game_name="$(strip_game_name "$(basename "${host_rom%.*}")")" - host_game_name="Host (me): \n$host_game_name" -} - ######### ##Main.## ######### @@ -133,7 +127,7 @@ lets_go() { wait_for_client # Build display names for confirmation prompt - stripped_game_names + host_game_name=$(format_game_name "$(basename "${host_rom%.*}")" "Host (me)") # Confirm host start with local ROM display confirm_join_panel "Host now?" "$host_game_name" diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_signalling.sh b/static/build/.tmp_update/script/netplay/easy-netplay_signalling.sh index a893a6032f..757ca67630 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_signalling.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_signalling.sh @@ -147,8 +147,6 @@ wait_for_client() { # wait_for_host # - waits for /tmp/host_ready signal wait_for_host() { - local counter=0 - build_infoPanel_and_log "Ready" "Waiting for host to start game" while true; do sync @@ -163,11 +161,5 @@ wait_for_host() { done sleep 1 - counter=$((counter + 1)) - - if [ $counter -ge 25 ]; then - build_infoPanel_and_log "Error" "The host didn't ready up, cannot continue..." - notify_stop - fi done } From 516f6fa20035c9cff5e511a1724d8d4a1812af70 Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Wed, 21 Jan 2026 19:25:03 +0000 Subject: [PATCH 30/32] add save logging, client network wait, and hotspot ip tweaks --- .../netplay/easy-netplay_client_pokemon.sh | 13 +++++++--- .../easy-netplay_client_pokemon_GBA.sh | 2 -- .../script/netplay/easy-netplay_common.sh | 15 +++++++++++ .../netplay/easy-netplay_server_pokemon.sh | 26 +++++++++++++++++++ .../script/netplay/easy-netplay_signalling.sh | 17 ++++++++++++ .../script/network/hotspot_join.sh | 8 +++--- 6 files changed, 73 insertions(+), 8 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh index 76b86053cd..292ebf2e37 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon.sh @@ -44,9 +44,9 @@ backup_and_send_save() { if [ -f "$save_gambatte" ]; then SaveFromGambatte=1 - log "Gambatte save file detected." - log "Backing up Gambatte save file to: $client_rom_filename_NoExt.srm_$Curdate" + log "Gambatte save file detected. Backing up Gambatte save file to: $client_rom_filename_NoExt.srm_$Curdate" cp -f "$save_gambatte" "${save_gambatte}_$CurDate" + log_file_state "Gambatte save (backed up)" "$save_gambatte" if [ -f "$save_tgbdual" ]; then confirm_join_panel "Continue ?" "There is a local save for\n$client_rom_filename_NoExt\nfor TGB Dual and for Gambatte.\n Gambatte save will be used by default." log "Existing TGB Dual save file detected. Continue with Gambatte save." @@ -56,9 +56,10 @@ backup_and_send_save() { cp -f "$save_gambatte" "$save_tgbdual" save_file_matched="$save_gambatte" elif [ -f "$save_tgbdual" ]; then - log "No Gambatte save file detected, using TGB Dual save file instead." + log "No Gambatte save file detected, using TGB Dual" log "Backing up current TGB Dual save file to: $client_rom_filename_NoExt.srm_$Curdate" cp -f "$save_tgbdual" "${save_tgbdual}_$CurDate" + log_file_state "TGB Dual save (backed up)" "$save_tgbdual" save_file_matched="$save_tgbdual" else missing=1 @@ -69,8 +70,10 @@ backup_and_send_save() { save_file_stripped="${save_file_matched##*/}" encoded_save_file=$(url_encode "$save_file_stripped") log "encoded_save_file: $encoded_save_file" + log_file_state "Save selected for upload" "$save_file_matched" curl -T "$save_file_matched" "ftp://$hostip/tmp/$encoded_save_file" + log "curl exit status (upload save)=$?" if [ "$missing" = "1" ]; then # hitting this block means we cannot send a save to the host @@ -92,6 +95,7 @@ start_retroarch() { log "core_config_folder: $core_config_folder" log "cpuspeed: $cpuspeed" log "hostip: $hostip" + log_file_state "Client save (pre-RA)" "$save_file_matched" log "###############################################################################" if [ -n "$cpuspeed" ]; then @@ -146,11 +150,14 @@ wait_for_save_return() { received_save="/tmp/$(basename "$save_file_matched")_rcvd" + log_file_state "Received save (raw)" "$received_save" + log_file_state "Local save before merge" "$save_file_matched" log "cp -f \"$received_save\" \"$save_file_matched\"" cp -f "${received_save}" "$save_file_matched" cp_exit_status=$? if [ $cp_exit_status -eq 0 ]; then + log_file_state "Local save after merge" "$save_file_matched" if [ $SaveFromGambatte -eq 1 ]; then mv -f "/mnt/SDCARD/Saves/CurrentProfile/states/Gambatte/$client_rom_filename_NoExt.state.auto" "/mnt/SDCARD/Saves/CurrentProfile/states/Gambatte/$client_rom_filename_NoExt.state.auto_$CurDate" else diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh index 1231f54dc4..921fd35108 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_client_pokemon_GBA.sh @@ -5,7 +5,6 @@ . /mnt/SDCARD/.tmp_update/script/netplay/easy-netplay_env.sh # Runtime vars -rm /tmp/stop_now client_rom="$1" romdirname=$(echo "$client_rom" | grep -o '/Roms/[^/]*' | cut -d'/' -f3) client_rom_filename=$(basename "$client_rom") @@ -66,7 +65,6 @@ cleanup() { "Cleaning up after Pokemon session\n Do not power off!" \ 1 1 1 0 \ "/tmp/host_ready" \ - "/tmp/stop_now" \ "/tmp/wpa_supplicant.conf_bk" \ "/tmp/dismiss_info_panel" } diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_common.sh b/static/build/.tmp_update/script/netplay/easy-netplay_common.sh index 5f6a7b2346..430b639b41 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_common.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_common.sh @@ -705,3 +705,18 @@ check_wifi() { sleep "$NETPLAY_WIFI_POST_START_DELAY" fi } + +# capture quick state of a file for debugging save/rom transfer issues. +log_file_state() { + local label="$1" + local path="$2" + if [ -f "$path" ]; then + local size + size=$(stat -c%s "$path" 2>/dev/null || wc -c <"$path") + local md5 + md5=$(md5sum "$path" 2>/dev/null | awk '{print $1}') + log "$label: exists size=${size} md5=${md5:-N/A} path=$path" + else + log "$label: missing path=$path" + fi +} diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh index bf58140a39..791cce7349 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_server_pokemon.sh @@ -26,6 +26,22 @@ netplaycore="/mnt/SDCARD/RetroArch/.retroarch/cores/tgbdual_libretro.so" SaveFromGambatte=0 export CurDate=$(date +%Y%m%d_%H%M%S) log "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* Easy Netplay Pokemon Host -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\ndate : $CurDate" + +# Helper: capture quick state of a file for debugging save/rom transfer issues. +log_file_state() { + local label="$1" + local path="$2" + if [ -f "$path" ]; then + # Prefer stat, fall back to wc -c for size + local size + size=$(stat -c%s "$path" 2>/dev/null || wc -c <"$path") + local md5 + md5=$(md5sum "$path" 2>/dev/null | awk '{print $1}') + log "$label: exists size=${size} md5=${md5:-N/A} path=$path" + else + log "$label: missing path=$path" + fi +} ########## ##Setup.## ########## @@ -58,11 +74,13 @@ host_save_backup() { log "Gambatte save file detected." log "Backing up Gambatte save file to: $host_rom_filename_NoExt.srm_$Curdate" cp -f "$save_gambatte" "${save_gambatte}_$CurDate" + log_file_state "Gambatte save (backed up)" "$save_gambatte" SaveFromGambatte=1 if [ -f "$save_tgbdual" ]; then confirm_join_panel "Continue ?" "There is a local save for\n$host_rom_filename_NoExt\nfor TGB Dual and for Gambatte.\n Gambatte save will be used by default." log "Backing up the existing TGB Dual save file to: $host_rom_filename_NoExt.srm_$Curdate" cp -f "$save_tgbdual" "${save_tgbdual}_$CurDate" + log_file_state "Existing TGB Dual save (backed up)" "$save_tgbdual" fi # copy save from Gambatte to TGB Dual cp -f "$save_gambatte" "$save_tgbdual" @@ -70,6 +88,7 @@ host_save_backup() { log "No Gambatte save file detected, using TGB Dual save file instead." log "Backing up current TGB Dual save file to: $host_rom_filename_NoExt.srm_$Curdate" cp -f "$save_tgbdual" "${save_tgbdual}_$CurDate" + log_file_state "TGB Dual save (backed up)" "$save_tgbdual" fi sync @@ -88,6 +107,7 @@ client_save_get() { sync for file in /tmp/*.srm; do if [ -f "$file" ]; then + log_file_state "Incoming client save candidate" "$file" if [ "$(basename "$file")" = "missing_save.srm" ]; then build_infoPanel_and_log "Sync error" "Client advises they don't have a save file. \n Cannot continue." notify_stop @@ -119,6 +139,7 @@ client_save_rename() { save_new_path="/mnt/SDCARD/Saves/CurrentProfile/saves/TGB Dual/$save_new_name" mv "$client_save_file" "$save_new_path" log "Save file found and processed - old save path:$client_save_file, new save path:$save_new_path " + log_file_state "Client save after move" "$save_new_path" sync else build_infoPanel_and_log "Syncing" "Save file not found, cannot continue" @@ -193,6 +214,8 @@ start_retroarch() { log "client_rom_clone: ${client_rom_clone}" log "netplaycore: $netplaycore" log "cpuspeed: $cpuspeed" + log_file_state "Host save (pre-RA)" "$save_tgbdual" + log_file_state "Client save (pre-RA)" "$save_new_path" log "###############################################################################" if [ -n "$cpuspeed" ]; then @@ -273,8 +296,10 @@ client_save_send() { if [ $curl_exit_status -eq 0 ]; then build_infoPanel_and_log "Syncing" "Client save returned!" + log_file_state "Save returned to client (local copy)" "$save_new_path" else build_infoPanel_and_log "Syncing" "Failed to return the client save \n Progress has likely been lost \n Curl exit code: $curl_exit_status" + log "curl exit status while returning client save: $curl_exit_status" fi } @@ -383,6 +408,7 @@ lets_go() { # Wait for client connection wait_for_client + wait_for_client_network # Send cookie to client (downloaded as retroarch.cookie.client) sync_file "Cookie" "$COOKIE_FILE" 0 0 -f -m diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_signalling.sh b/static/build/.tmp_update/script/netplay/easy-netplay_signalling.sh index 757ca67630..eb6df9ea9b 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_signalling.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_signalling.sh @@ -144,6 +144,23 @@ wait_for_client() { log "$client_ip has joined the hotspot" } +# wait_for_client_network: ensure client responds to ping before transfers +wait_for_client_network() { + local counter=0 + build_infoPanel_and_log "Hotspot" "Client connected.\nWaiting for client network..." + while true; do + if ping -c 1 -W 1 "$client_ip" >/dev/null 2>&1; then + log "Client network reachable at $client_ip" + break + fi + sleep 1 + counter=$((counter + 1)) + if [ $((counter % 10)) -eq 0 ]; then + build_infoPanel_and_log "Hotspot" "Still waiting for client network...\nIP: $client_ip" + fi + done +} + # wait_for_host # - waits for /tmp/host_ready signal wait_for_host() { diff --git a/static/build/.tmp_update/script/network/hotspot_join.sh b/static/build/.tmp_update/script/network/hotspot_join.sh index 3814f256b6..80f8fd9271 100644 --- a/static/build/.tmp_update/script/network/hotspot_join.sh +++ b/static/build/.tmp_update/script/network/hotspot_join.sh @@ -103,18 +103,20 @@ wait_for_ip() { ip addr flush dev wlan0 while [ -z "$IP" ]; do - IP=$(ip route get 1 2>/dev/null | awk '{print $NF;exit}') + # prefer direct interface address (works even if route not set yet) + IP=$(ip -4 addr show wlan0 2>/dev/null | awk '/inet /{sub(/\\/.*$/,"",$2);print $2;exit}') + [ -z "$IP" ] && IP=$(ip route get 1 2>/dev/null | awk '{print $NF;exit}') sleep 0.5 counter=$((counter + 1)) - if [ $counter -eq 20 ]; then + if [ $counter -eq 40 ]; then $display_func "Fallback" "Using static IP..." killall -9 udhcpc ip addr flush dev wlan0 RAND_IP=$((101 + RANDOM % 150)) ip addr add 192.168.100.$RAND_IP/24 dev wlan0 ip route add default via 192.168.100.100 - elif [ $counter -ge 40 ]; then + elif [ $counter -ge 80 ]; then $display_func "Failed to connect!" "Could not get an IP in 20 seconds.\n Try again" sleep 1 $cleanup_func From eee340f4e968c4d5049d4229a26293953fb09da5 Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Wed, 21 Jan 2026 19:32:22 +0000 Subject: [PATCH 31/32] only FTP head the first time, not every time we're syncing a file --- .../.tmp_update/script/netplay/easy-netplay_common.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_common.sh b/static/build/.tmp_update/script/netplay/easy-netplay_common.sh index 430b639b41..6c0dff1f05 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_common.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_common.sh @@ -22,6 +22,7 @@ NETPLAY_SYNC_MAX_FILE_DL_SIZE=104857600 # max file size to allow download NETPLAY_COOKIE_MAX_FILE_SIZE=26214400 # max file size for cookie checksum entries NETPLAY_SYNC_FAIL_DELAY=2 # delay after sync failures before cleanup NETPLAY_INFOPANEL_SLEEP=0.5 # infoPanel delay +NETPLAY_FTP_HEAD_READY=0 # flag to avoid repeated FTP warmup delays COOKIE_CLIENT_PATH="/mnt/SDCARD/RetroArch/retroarch.cookie.client" COOKIE_FILE="/mnt/SDCARD/RetroArch/retroarch.cookie" @@ -656,10 +657,15 @@ check_ftp_local() { # - give peer time to start FTP before first transfer, then do a quick HEAD # - sets: ftp_head_result, ftp_head_exit ensure_ftp_head() { - # wait for peer tcpsvd to be ready (reduces race on first FTP request) - sleep "$NETPLAY_FTP_READY_DELAY" + # wait for peer tcpsvd only on the first HEAD; subsequent calls skip delay once ready + if [ "${NETPLAY_FTP_HEAD_READY:-0}" -eq 0 ]; then + sleep "$NETPLAY_FTP_READY_DELAY" + fi ftp_head_result=$(curl -sS -I --connect-timeout "$NETPLAY_FTP_HEAD_TIMEOUT" "$1" 2>&1) ftp_head_exit=$? + if [ $ftp_head_exit -eq 0 ]; then + NETPLAY_FTP_HEAD_READY=1 + fi return 0 } From 6cea84fe9c8e96b2d60412f8d1944733f032fca9 Mon Sep 17 00:00:00 2001 From: XK9274 <47260768+XK9274@users.noreply.github.com> Date: Wed, 21 Jan 2026 20:12:05 +0000 Subject: [PATCH 32/32] power save control on both ints --- static/build/.tmp_update/script/netplay/easy-netplay_common.sh | 3 ++- static/build/.tmp_update/script/netplay/easy-netplay_env.sh | 3 ++- static/build/.tmp_update/script/network/hotspot_create.sh | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_common.sh b/static/build/.tmp_update/script/netplay/easy-netplay_common.sh index 6c0dff1f05..9bd047d521 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_common.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_common.sh @@ -260,8 +260,9 @@ netplay_cleanup() { disable_flag hotspotState fi - # reset power save on the wifi + # reset power save on the wifi ints iw wlan0 set power_save on + iw wlan1 set power_save on sync log "Cleanup done" diff --git a/static/build/.tmp_update/script/netplay/easy-netplay_env.sh b/static/build/.tmp_update/script/netplay/easy-netplay_env.sh index ec3002873f..158b8ab5c2 100644 --- a/static/build/.tmp_update/script/netplay/easy-netplay_env.sh +++ b/static/build/.tmp_update/script/netplay/easy-netplay_env.sh @@ -11,4 +11,5 @@ peer_ip="${peer_ip:-$hostip}" export hostip peer_ip # turn off power save on the wifi - this is turned back on in the netplay_cleanup function -iw wlan0 set power_save off \ No newline at end of file +iw wlan0 set power_save off +iw wlan1 set power_save off \ No newline at end of file diff --git a/static/build/.tmp_update/script/network/hotspot_create.sh b/static/build/.tmp_update/script/network/hotspot_create.sh index 592defc821..f2dfb90abd 100644 --- a/static/build/.tmp_update/script/network/hotspot_create.sh +++ b/static/build/.tmp_update/script/network/hotspot_create.sh @@ -78,6 +78,7 @@ start_hotspot() { $sysdir/bin/hostapd -P /var/run/hostapd.pid -B -i wlan1 $sysdir/config/hostapd.conf & $sysdir/bin/dnsmasq --conf-file=$sysdir/config/dnsmasq.conf -u root & ip route add default via $gateway0addr + iw wlan1 set power_save off if pgrep "hostapd" >/dev/null; then $log_func "Started with IP of: $hotspot0addr, subnet of: $subnetmask"