NETPLAY: added flags + various bugfxies

This commit is contained in:
XargonWan 2024-06-18 14:55:11 +09:00
parent 2da412bb65
commit f2f12fb568

View file

@ -1,5 +1,258 @@
#!/bin/bash
# Mapping of country codes to flag emojis
declare -A country_flags=(
["af"]="🇦🇫"
["ax"]="🇦🇽"
["al"]="🇦🇱"
["dz"]="🇩🇿"
["as"]="🇦🇸"
["ad"]="🇦🇩"
["ao"]="🇦🇴"
["ai"]="🇦🇮"
["aq"]="🇦🇶"
["ag"]="🇦🇬"
["ar"]="🇦🇷"
["am"]="🇦🇲"
["aw"]="🇦🇼"
["au"]="🇦🇺"
["at"]="🇦🇹"
["az"]="🇦🇿"
["bs"]="🇧🇸"
["bh"]="🇧🇭"
["bd"]="🇧🇩"
["bb"]="🇧🇧"
["by"]="🇧🇾"
["be"]="🇧🇪"
["bz"]="🇧🇿"
["bj"]="🇧🇯"
["bm"]="🇧🇲"
["bt"]="🇧🇹"
["bo"]="🇧🇴"
["bq"]="🇧🇶"
["ba"]="🇧🇦"
["bw"]="🇧🇼"
["bv"]="🇧🇻"
["br"]="🇧🇷"
["io"]="🇮🇴"
["bn"]="🇧🇳"
["bg"]="🇧🇬"
["bf"]="🇧🇫"
["bi"]="🇧🇮"
["kh"]="🇰🇭"
["cm"]="🇨🇲"
["ca"]="🇨🇦"
["cv"]="🇨🇻"
["ky"]="🇰🇾"
["cf"]="🇨🇫"
["td"]="🇹🇩"
["cl"]="🇨🇱"
["cn"]="🇨🇳"
["cx"]="🇨🇽"
["cc"]="🇨🇨"
["co"]="🇨🇴"
["km"]="🇰🇲"
["cd"]="🇨🇩"
["cg"]="🇨🇬"
["ck"]="🇨🇰"
["cr"]="🇨🇷"
["ci"]="🇨🇮"
["hr"]="🇭🇷"
["cu"]="🇨🇺"
["cw"]="🇨🇼"
["cy"]="🇨🇾"
["cz"]="🇨🇿"
["dk"]="🇩🇰"
["dj"]="🇩🇯"
["dm"]="🇩🇲"
["do"]="🇩🇴"
["ec"]="🇪🇨"
["eg"]="🇪🇬"
["sv"]="🇸🇻"
["gq"]="🇬🇶"
["er"]="🇪🇷"
["ee"]="🇪🇪"
["et"]="🇪🇹"
["fk"]="🇫🇰"
["fo"]="🇫🇴"
["fj"]="🇫🇯"
["fi"]="🇫🇮"
["fr"]="🇫🇷"
["gf"]="🇬🇫"
["pf"]="🇵🇫"
["tf"]="🇹🇫"
["ga"]="🇬🇦"
["gm"]="🇬🇲"
["ge"]="🇬🇪"
["de"]="🇩🇪"
["gh"]="🇬🇭"
["gi"]="🇬🇮"
["gr"]="🇬🇷"
["gl"]="🇬🇱"
["gd"]="🇬🇩"
["gp"]="🇬🇵"
["gu"]="🇬🇺"
["gt"]="🇬🇹"
["gg"]="🇬🇬"
["gn"]="🇬🇳"
["gw"]="🇬🇼"
["gy"]="🇬🇾"
["ht"]="🇭🇹"
["hm"]="🇭🇲"
["va"]="🇻🇦"
["hn"]="🇭🇳"
["hk"]="🇭🇰"
["hu"]="🇭🇺"
["is"]="🇮🇸"
["in"]="🇮🇳"
["id"]="🇮🇩"
["ir"]="🇮🇷"
["iq"]="🇮🇶"
["ie"]="🇮🇪"
["im"]="🇮🇲"
["il"]="🇮🇱"
["it"]="🇮🇹"
["jm"]="🇯🇲"
["jp"]="🇯🇵"
["je"]="🇯🇪"
["jo"]="🇯🇴"
["kz"]="🇰🇿"
["ke"]="🇰🇪"
["ki"]="🇰🇮"
["kp"]="🇰🇵"
["kr"]="🇰🇷"
["kw"]="🇰🇼"
["kg"]="🇰🇬"
["la"]="🇱🇦"
["lv"]="🇱🇻"
["lb"]="🇱🇧"
["ls"]="🇱🇸"
["lr"]="🇱🇷"
["ly"]="🇱🇾"
["li"]="🇱🇮"
["lt"]="🇱🇹"
["lu"]="🇱🇺"
["mo"]="🇲🇴"
["mg"]="🇲🇬"
["mw"]="🇲🇼"
["my"]="🇲🇾"
["mv"]="🇲🇻"
["ml"]="🇲🇱"
["mt"]="🇲🇹"
["mh"]="🇲🇭"
["mq"]="🇲🇶"
["mr"]="🇲🇷"
["mu"]="🇲🇺"
["yt"]="🇾🇹"
["mx"]="🇲🇽"
["fm"]="🇫🇲"
["md"]="🇲🇩"
["mc"]="🇲🇨"
["mn"]="🇲🇳"
["me"]="🇲🇪"
["ms"]="🇲🇸"
["ma"]="🇲🇦"
["mz"]="🇲🇿"
["mm"]="🇲🇲"
["na"]="🇳🇦"
["nr"]="🇳🇷"
["np"]="🇳🇵"
["nl"]="🇳🇱"
["nc"]="🇳🇨"
["nz"]="🇳🇿"
["ni"]="🇳🇮"
["ne"]="🇳🇪"
["ng"]="🇳🇬"
["nu"]="🇳🇺"
["nf"]="🇳🇫"
["mk"]="🇲🇰"
["mp"]="🇲🇵"
["no"]="🇳🇴"
["om"]="🇴🇲"
["pk"]="🇵🇰"
["pw"]="🇵🇼"
["ps"]="🇵🇸"
["pa"]="🇵🇦"
["pg"]="🇵🇬"
["py"]="🇵🇾"
["pe"]="🇵🇪"
["ph"]="🇵🇭"
["pn"]="🇵🇳"
["pl"]="🇵🇱"
["pt"]="🇵🇹"
["pr"]="🇵🇷"
["qa"]="🇶🇦"
["re"]="🇷🇪"
["ro"]="🇷🇴"
["ru"]="🇷🇺"
["rw"]="🇷🇼"
["bl"]="🇧🇱"
["sh"]="🇸🇭"
["kn"]="🇰🇳"
["lc"]="🇱🇨"
["mf"]="🇲🇫"
["pm"]="🇵🇲"
["vc"]="🇻🇨"
["ws"]="🇼🇸"
["sm"]="🇸🇲"
["st"]="🇸🇹"
["sa"]="🇸🇦"
["sn"]="🇸🇳"
["rs"]="🇷🇸"
["sc"]="🇸🇨"
["sl"]="🇸🇱"
["sg"]="🇸🇬"
["sx"]="🇸🇽"
["sk"]="🇸🇰"
["si"]="🇸🇮"
["sb"]="🇸🇧"
["so"]="🇸🇴"
["za"]="🇿🇦"
["gs"]="🇬🇸"
["ss"]="🇸🇸"
["es"]="🇪🇸"
["lk"]="🇱🇰"
["sd"]="🇸🇩"
["sr"]="🇸🇷"
["sj"]="🇸🇯"
["se"]="🇸🇪"
["ch"]="🇨🇭"
["sy"]="🇸🇾"
["tw"]="🇹🇼"
["tj"]="🇹🇯"
["tz"]="🇹🇿"
["th"]="🇹🇭"
["tl"]="🇹🇱"
["tg"]="🇹🇬"
["tk"]="🇹🇰"
["to"]="🇹🇴"
["tt"]="🇹🇹"
["tn"]="🇹🇳"
["tr"]="🇹🇷"
["tm"]="🇹🇲"
["tc"]="🇹🇨"
["tv"]="🇹🇻"
["ug"]="🇺🇬"
["ua"]="🇺🇦"
["ae"]="🇦🇪"
["gb"]="🇬🇧"
["um"]="🇺🇲"
["us"]="🇺🇸"
["uy"]="🇺🇾"
["uz"]="🇺🇿"
["vu"]="🇻🇺"
["ve"]="🇻🇪"
["vn"]="🇻🇳"
["vg"]="🇻🇬"
["vi"]="🇻🇮"
["wf"]="🇼🇫"
["eh"]="🇪🇭"
["ye"]="🇾🇪"
["zm"]="🇿🇲"
["zw"]="🇿🇼"
)
populate_table() {
# URL of the RetroArch lobby API
url="http://lobby.libretro.com/list"
@ -14,14 +267,14 @@ populate_table() {
fi
# Parse the JSON response using jq
rooms=$(echo "$response" | jq -r '.[] | .fields | [.username, .game_name, .core_name, .has_password, .retroarch_version, .created, .game_crc, .ip, .port] | @tsv')
rooms=$(echo "$response" | jq -r '.[] | .fields | [.country, .username, .game_name, .core_name, .has_password, .retroarch_version, .created, .game_crc, .ip, .port] | @tsv')
# Initialize the results for the Zenity table
results=()
room_details=()
# Process each room
while IFS=$'\t' read -r username game_name core_name has_password retroarch_version created game_crc ip port; do
while IFS=$'\t' read -r country username game_name core_name has_password retroarch_version created game_crc ip port; do
# Convert boolean to human-readable format
if [ "$has_password" = "true" ]; then
has_password="Yes"
@ -29,9 +282,12 @@ populate_table() {
has_password="No"
fi
# Get the flag emoji for the country
flag="${country_flags[$country]}"
# Add the extracted data to the results array
results+=("$username" "$game_name" "$core_name" "$has_password" "$retroarch_version" "$created")
room_details+=("$username,$game_name,$core_name,$has_password,$retroarch_version,$created,$game_crc,$ip,$port")
results+=("$flag" "$username" "$game_name" "$core_name" "$has_password" "$retroarch_version" "$created")
room_details+=("$country,$username,$game_name,$core_name,$has_password,$retroarch_version,$created,$game_crc,$ip,$port")
done <<< "$rooms"
# Check if results array is populated
@ -41,8 +297,9 @@ populate_table() {
fi
# Display the results using Zenity in a table and get the selected row
selected=$(zenity --list \
selected=$(zenity --list --width="1280" --height="800" \
--title="Available Netplay Rooms" \
--column="Loc" \
--column="User" \
--column="Game" \
--column="Core" \
@ -65,17 +322,22 @@ start_game() {
fi
# Extract the details of the selected room
selected_username=$(echo "$selected" | awk -F'|' '{print $1}')
selected_game_name=$(echo "$selected" | awk -F'|' '{print $2}')
selected_core_name=$(echo "$selected" | awk -F'|' '{print $3}')
selected_has_password=$(echo "$selected" | awk -F'|' '{print $4}')
selected_version=$(echo "$selected" | awk -F'|' '{print $5}')
selected_created=$(echo "$selected" | awk -F'|' '{print $6}')
selected_flag=$(echo "$selected" | awk -F'|' '{print $1}')
selected_username=$(echo "$selected" | awk -F'|' '{print $2}')
selected_game_name=$(echo "$selected" | awk -F'|' '{print $3}')
selected_core_name=$(echo "$selected" | awk -F'|' '{print $4}')
selected_has_password=$(echo "$selected" | awk -F'|' '{print $5}')
selected_version=$(echo "$selected" | awk -F'|' '{print $6}')
raw_dates=$(echo "$selected" | awk -F'|' '{print $7}')
# Convert ISO 8601 format to human-readable format
selected_created=$(date -d "$raw_dates" +"%Y-%m-%d %H:%M:%S")
# Find the matching room details
for room in "${room_details[@]}"; do
IFS=',' read -r username game_name core_name has_password retroarch_version created game_crc ip port <<< "$room"
if [ "$username" = "$selected_username" ] && [ "$game_name" = "$selected_game_name" ] && [ "$core_name" = "$selected_core_name" ] && [ "$has_password" = "$selected_has_password" ] && [ "$retroarch_version" = "$selected_version" ] && [ "$created" = "$selected_created" ]; then
IFS=',' read -r country username game_name core_name has_password retroarch_version created game_crc ip port <<< "$room"
flag="${country_flags[$country]}"
if [ "$flag" = "$selected_flag" ] && [ "$username" = "$selected_username" ] && [ "$game_name" = "$selected_game_name" ] && [ "$core_name" = "$selected_core_name" ] && [ "$has_password" = "$selected_has_password" ] && [ "$retroarch_version" = "$selected_version" ] && [ "$created" = "$selected_created" ]; then
selected_game_crc="$game_crc"
selected_ip="$ip"
selected_port="$port"
@ -107,8 +369,19 @@ start_game() {
zenity --warning --text="CRC mismatch! The game may not work correctly."
fi
# Launch RetroArch with the selected game and netplay room details
retroarch -L "/path/to/cores/${selected_core_name}.so" "$found_rom" --connect "$selected_ip:$selected_port"
# If the room has a password, ask for it
if [ "$selected_has_password" = "Yes" ]; then
password=$(zenity --entry --title="Password Required" --text="Enter the password for the netplay room:")
if [ -z "$password" ]; then
zenity --error --text="Password required to join the room."
exit 1
fi
# Launch RetroArch with the selected game and netplay room details, including password
retroarch -L "/app/share/libretro/cores/${selected_core_name}.so" "$found_rom" --connect "$selected_ip:$selected_port" --password "$password"
else
# Launch RetroArch without password
retroarch -L "/app/share/libretro/cores/${selected_core_name}.so" "$found_rom" --connect "$selected_ip:$selected_port"
fi
}
# Call the function to populate the table