NETPLAY: outsourced flags, added placeholder logics for pretendo, pcsx2, rpcs3 and dolphin

This commit is contained in:
XargonWan 2024-06-18 15:17:48 +09:00
parent 3adb696922
commit 1115fcab3e

View file

@ -1,279 +1,59 @@
#!/bin/bash #!/bin/bash
# Mapping of country codes to flag emojis source functions/flags.sh # TODO: set it in the real folder for flatpak enviro
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() { populate_table() {
# URL of the RetroArch lobby API # URL of the RetroArch lobby API
url="http://lobby.libretro.com/list" retroarch_url="http://lobby.libretro.com/list"
# Fetch the list of netplay rooms in JSON format # Fetch the list of netplay rooms in JSON format
response=$(curl -s "$url") retroarch_response=$(curl -s "$retroarch_url")
# Check if the response is empty or if there are errors # Fetch Pretendo netplay rooms (Example URL)
if [ -z "$response" ]; then pretendo_url="https://pretendo.network/api/rooms"
zenity --error --text="Error connecting to the RetroArch Netplay server." pretendo_response=$(curl -s "$pretendo_url")
exit 1
# Fetch PCSX2 netplay rooms (Example URL)
pcsx2_url="https://pcsx2.netplay.api/rooms"
pcsx2_response=$(curl -s "$pcsx2_url")
# Fetch RPCS3 netplay rooms (Example URL)
rpcs3_url="https://rpcn.rpc3.net/v1/rooms"
rpcs3_response=$(curl -s "$rpcs3_url")
# Fetch Dolphin netplay rooms (Example URL)
dolphin_url="https://dolphin-emu.org/netplay/rooms"
dolphin_response=$(curl -s "$dolphin_url")
# Check if the responses are empty or if there are errors
if [ -z "$retroarch_response" ]; then
log e "Error connecting to the RetroArch Netplay server."
fi
if [ -z "$pretendo_response" ]; then
log e "Error connecting to the Pretendo Netplay server."
fi
if [ -z "$pcsx2_response" ]; then
log e "Error connecting to the PCSX2 Netplay server."
fi
if [ -z "$rpcs3_response" ]; then
log e "Error connecting to the RPCS3 Netplay server."
fi
if [ -z "$dolphin_response" ]; then
log e "Error connecting to the Dolphin Netplay server."
fi fi
# Parse the JSON response using jq # Parse the JSON responses using jq
rooms=$(echo "$response" | jq -r '.[] | .fields | [.country, .username, .game_name, .core_name, .has_password, .retroarch_version, .created, .game_crc, .ip, .port] | @tsv') retroarch_rooms=$(echo "$retroarch_response" | jq -r '.[] | .fields | [.country, .username, .game_name, .core_name, .has_password, .retroarch_version, .created, .game_crc, .ip, .port] | @tsv')
pretendo_rooms=$(echo "$pretendo_response" | jq -r '.rooms[] | [.game, .host, .status] | @tsv')
pcsx2_rooms=$(echo "$pcsx2_response" | jq -r '.rooms[] | [.game, .host, .status] | @tsv')
rpcs3_rooms=$(echo "$rpcs3_response" | jq -r '.rooms[] | [.game, .host, .status] | @tsv')
dolphin_rooms=$(echo "$dolphin_response" | jq -r '.rooms[] | [.game, .host, .status] | @tsv')
# Initialize the results for the Zenity table # Initialize the results for the Zenity table
results=() results=()
room_details=() room_details=()
# Process each room # Process each room from RetroArch
while IFS=$'\t' read -r country 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 # Convert boolean to human-readable format
if [ "$has_password" = "true" ]; then if [ "$has_password" = "true" ]; then
@ -288,7 +68,31 @@ populate_table() {
# Add the extracted data to the results array # Add the extracted data to the results array
results+=("$flag" "$username" "$game_name" "$core_name" "$has_password" "$retroarch_version" "$created") 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") room_details+=("$country,$username,$game_name,$core_name,$has_password,$retroarch_version,$created,$game_crc,$ip,$port")
done <<< "$rooms" done <<< "$retroarch_rooms"
# Process each room from Pretendo
while IFS=$'\t' read -r game host status; do
results+=("Pretendo" "$host" "$game" "Pretendo" "$status" "N/A" "N/A")
room_details+=("Pretendo,$host,$game,Pretendo,$status,N/A,N/A,N/A,N/A,N/A")
done <<< "$pretendo_rooms"
# Process each room from PCSX2
while IFS=$'\t' read -r game host status; do
results+=("PCSX2" "$host" "$game" "PCSX2" "$status" "N/A" "N/A")
room_details+=("PCSX2,$host,$game,PCSX2,$status,N/A,N/A,N/A,N/A,N/A")
done <<< "$pcsx2_rooms"
# Process each room from RPCS3
while IFS=$'\t' read -r game host status; do
results+=("RPCS3" "$host" "$game" "RPCS3" "$status" "N/A" "N/A")
room_details+=("RPCS3,$host,$game,RPCS3,$status,N/A,N/A,N/A,N/A,N/A")
done <<< "$rpcs3_rooms"
# Process each room from Dolphin
while IFS=$'\t' read -r game host status; do
results+=("Dolphin" "$host" "$game" "Dolphin" "$status" "N/A" "N/A")
room_details+=("Dolphin,$host,$game,Dolphin,$status,N/A,N/A,N/A,N/A,N/A")
done <<< "$dolphin_rooms"
# Check if results array is populated # Check if results array is populated
if [ ${#results[@]} -eq 0 ]; then if [ ${#results[@]} -eq 0 ]; then
@ -312,32 +116,25 @@ populate_table() {
echo "$selected" echo "$selected"
} }
# Call the function to populate the table
selected_room=$(populate_table)
# Parse the selected room details
IFS=',' read -r selected_country selected_username selected_game_name selected_core_name selected_has_password selected_version selected_created selected_game_crc selected_ip selected_port <<< "$selected_room"
# Implement the logic for launching the selected emulator with the selected game and netplay room details
start_game() { start_game() {
selected="$1" # Get the details of the selected room
room_details=("${@:2}") room_details=("$@")
# Check if the user selected a row selected_game_crc=""
if [ -z "$selected" ]; then selected_ip=""
exit 0 selected_port=""
fi
# Extract the details of the selected room for detail in "${room_details[@]}"; do
selected_flag=$(echo "$selected" | awk -F'|' '{print $1}') IFS=',' read -r country username game_name core_name has_password version created game_crc ip port <<< "$detail"
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")
if [ "$country" = "$selected_country" ] && [ "$username" = "$selected_username" ] && [ "$game_name" = "$selected_game_name" ] && [ "$core_name" = "$selected_core_name" ] && [ "$has_password" = "$selected_has_password" ] && [ "$version" = "$selected_version" ] && [ "$created" = "$selected_created" ]; then
# Find the matching room details
for room in "${room_details[@]}"; do
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_game_crc="$game_crc"
selected_ip="$ip" selected_ip="$ip"
selected_port="$port" selected_port="$port"
@ -369,23 +166,42 @@ start_game() {
zenity --warning --text="CRC mismatch! The game may not work correctly." zenity --warning --text="CRC mismatch! The game may not work correctly."
fi fi
# If the room has a password, ask for it # Launch the appropriate emulator with the selected game and netplay room details
case "$selected_core_name" in
"RetroArch")
if [ "$selected_has_password" = "Yes" ]; then if [ "$selected_has_password" = "Yes" ]; then
password=$(zenity --entry --title="Password Required" --text="Enter the password for the netplay room:") password=$(zenity --entry --title="Password Required" --text="Enter the password for the netplay room:")
if [ -z "$password" ]; then if [ -z "$password" ]; then
zenity --error --text="Password required to join the room." zenity --error --text="Password required to join the room."
exit 1 exit 1
fi 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" retroarch -L "/app/share/libretro/cores/${selected_core_name}.so" "$found_rom" --connect "$selected_ip:$selected_port" --password "$password"
else else
# Launch RetroArch without password
retroarch -L "/app/share/libretro/cores/${selected_core_name}.so" "$found_rom" --connect "$selected_ip:$selected_port" retroarch -L "/app/share/libretro/cores/${selected_core_name}.so" "$found_rom" --connect "$selected_ip:$selected_port"
fi fi
;;
"Pretendo")
# Pretendo-specific launch command (example, replace with actual)
pretendoclient --connect "$selected_ip:$selected_port" --game "$found_rom"
;;
"PCSX2")
# PCSX2-specific launch command (example, replace with actual)
pcsx2 --netplay --host "$selected_ip" --port "$selected_port" "$found_rom"
;;
"RPCS3")
# RPCS3-specific launch command (example, replace with actual)
rpcs3 --netplay --host "$selected_ip" --port "$selected_port" "$found_rom"
;;
"Dolphin")
# Dolphin-specific launch command (example, replace with actual)
dolphin-emu --netplay --host "$selected_ip" --port "$selected_port" "$found_rom"
;;
*)
zenity --error --text="Unsupported core: $selected_core_name"
exit 1
;;
esac
} }
# Call the function to populate the table
selected_room=$(populate_table)
# Call the function to start the game # Call the function to start the game
start_game "$selected_room" "${room_details[@]}" start_game "$selected_room" "${room_details[@]}"