Update Cheevos login/logout process

This commit is contained in:
icenine451 2025-04-01 13:34:23 -04:00
parent e25361a5b0
commit 4f695f96d4
3 changed files with 30 additions and 21 deletions

View file

@ -194,7 +194,7 @@ changelog_dialog() {
}
get_cheevos_token_dialog() {
# This function will return a RetroAchvievements token from a valid username and password, will return "login failed" otherwise
# This function will return a RetroAchvievements token from a valid username and password, will return an error code otherwise
# USAGE: get_cheevos_token_dialog
local cheevos_info=$(rd_zenity --forms --title="Cheevos" \
@ -204,14 +204,12 @@ get_cheevos_token_dialog() {
--add-password="Password")
IFS='^' read -r cheevos_username cheevos_password < <(printf '%s\n' "$cheevos_info")
local cheevos_response=$(curl --silent --data "r=login&u=$cheevos_username&p=$cheevos_password" "$RA_API_URL")
local cheevos_success=$(echo "$cheevos_response" | jq .Success | tr -d '"')
local cheevos_token=$(echo "$cheevos_response" | jq .Token | tr -d '"')
local cheevos_login_timestamp=$(date +%s)
if [[ "$cheevos_success" == "true" ]]; then
echo "$cheevos_username,$cheevos_token,$cheevos_login_timestamp"
else
echo "failed"
if cheevos_info=$(get_cheevos_token "$cheevos_username" "$cheevos_password"); then
log d "Cheevos login succeeded"
echo "$cheevos_info"
else # login failed
log d "Cheevos login failed"
return 1
fi
}

View file

@ -1448,3 +1448,18 @@ sanitize() {
# Replace sequences of underscores with a single space
echo "$1" | sed -e 's/_\{2,\}/ /g' -e 's/_/ /g' -e 's/:/ -/g' -e 's/&/and/g' -e 's%/%and%g' -e 's/ / /g'
}
get_cheevos_token() {
# This function will attempt to authenticate with the RA API with the supplied credentials and will return a JSON object if successful
# USAGE get_cheevos_token $username $password
local cheevos_api_response=$(curl --silent --data "r=login&u=$1&p=$2" "$RA_API_URL")
local cheevos_success=$(echo "$cheevos_api_response" | jq -r '.Success')
if [[ "$cheevos_success" == "true" ]]; then
log d "login succeeded"
echo "$cheevos_api_response"
else
log d "login failed"
return 1
fi
}

View file

@ -191,7 +191,7 @@ configurator_global_presets_and_settings_dialog() {
"Rewind" "Enable / Disable: the rewind function in supported systems." \
"Swap A/B and X/Y Buttons" "Enable / Disable: Swapped A/B and X/Y button layout in supported systems." \
"RetroAchievements: Login" "Login the RetroAchievements in supported systems." \
"RetroAchievements: Logout" "Logout RetroAchievements service in ALL supported systems" \
"RetroAchievements: Logout" "Logout RetroAchievements service in supported systems" \
"RetroAchievements: Hardcore Mode" "Enable / Disable: RetroAchievements Hardcore Mode (no cheats, rewind, save states, etc.) in supported systems." \
"Universal Dynamic Input Textures: Dolphin" "Enable / Disable: Universal Dynamic Input Textures for Dolphin." \
"Universal Dynamic Input Textures: Primehack" "Enable / Disable: Universal Dynamic Input Textures for Primehack." \
@ -233,10 +233,11 @@ configurator_global_presets_and_settings_dialog() {
;;
"RetroAchievements: Login" )
local cheevos_creds=$(get_cheevos_token_dialog)
if [[ ! "$cheevos_creds" == "failed" ]]; then
if cheevos_response=$(get_cheevos_token_dialog); then
configurator_generic_dialog "RetroDECK Configurator Utility - RetroAchievements" "RetroAchievements login successful, please select systems you would like to enable achievements for in the next dialog."
IFS=',' read -r cheevos_username cheevos_token cheevos_login_timestamp < <(printf '%s\n' "$cheevos_creds")
cheevos_username=$(echo "$cheevos_response" | jq -r '.User')
cheevos_token=$(echo "$cheevos_response" | jq -r '.Token')
cheevos_login_timestamp=$(date +%s)
change_preset_dialog "cheevos"
else
configurator_generic_dialog "RetroDECK Configurator Utility - RetroAchievements" "RetroAchievements login failed, please verify your username and password and try the process again."
@ -244,14 +245,9 @@ configurator_global_presets_and_settings_dialog() {
configurator_global_presets_and_settings_dialog
;;
"RetroAchievements: Logout" ) # This is a workaround to allow disabling cheevos without having to enter login credentials
local cheevos_emulators=$(sed -n '/\[cheevos\]/, /\[/{ /\[cheevos\]/! { /\[/! p } }' "$rd_conf" | sed '/^$/d')
for setting_line in $cheevos_emulators; do
emulator=$(get_setting_name "$setting_line" "retrodeck")
set_setting_value "$rd_conf" "$emulator" "false" "retrodeck" "cheevos"
build_preset_config "$emulator" "cheevos"
done
configurator_generic_dialog "RetroDECK Configurator Utility - RetroAchievements" "RetroAchievements has been disabled in all supported systems."
"RetroAchievements: Logout" )
# This is a workaround to allow disabling cheevos without having to enter login credentials
change_preset_dialog "cheevos"
configurator_global_presets_and_settings_dialog
;;