Merge pull request #17756 from hrydgard/alert-on-retroachievement-server-error

Improve handling of RetroAchievements login errors
This commit is contained in:
Henrik Rydgård 2023-07-23 12:41:06 +02:00 committed by GitHub
commit 68c124d779
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 3 deletions

View File

@ -77,6 +77,7 @@ std::string s_game_hash;
std::set<uint32_t> g_activeChallenges;
bool g_isIdentifying = false;
bool g_isLoggingIn = false;
int g_loginResult;
// rc_client implementation
static rc_client_t *g_rcClient;
@ -320,15 +321,20 @@ static void login_token_callback(int result, const char *error_message, rc_clien
g_OSD.Show(OSDType::MESSAGE_WARNING, di->T("Failed to connect to server, check your internet connection."));
break;
}
case RC_INVALID_STATE:
case RC_API_FAILURE:
case RC_INVALID_STATE:
case RC_MISSING_VALUE:
case RC_INVALID_JSON:
default:
{
auto ac = GetI18NCategory(I18NCat::ACHIEVEMENTS);
ERROR_LOG(ACHIEVEMENTS, "Failure logging in via token: %d, %s", result, error_message);
g_OSD.Show(OSDType::MESSAGE_WARNING, ac->T("Failed logging in to RetroAchievements"));
OnAchievementsLoginStateChange();
break;
}
}
g_loginResult = result;
g_isLoggingIn = false;
}
@ -356,6 +362,19 @@ void Initialize() {
rc_client_set_event_handler(g_rcClient, event_handler_callback);
TryLoginByToken();
}
bool HasToken() {
return !NativeLoadSecret(RA_TOKEN_SECRET_NAME).empty();
}
bool LoginProblems(std::string *errorString) {
// TODO: Set error string.
return g_loginResult != RC_OK;
}
void TryLoginByToken() {
std::string api_token = NativeLoadSecret(RA_TOKEN_SECRET_NAME);
if (!api_token.empty()) {
g_isLoggingIn = true;
@ -398,6 +417,7 @@ static void login_password_callback(int result, const char *error_message, rc_cl
}
g_OSD.RemoveProgressBar("cheevos_async_login", true, 0.1f);
g_loginResult = RC_OK; // For these, we don't want the "permanence" of the login-by-token failure, this prevents LoginProblems from returning true.
g_isLoggingIn = false;
}
@ -420,7 +440,7 @@ void Logout() {
NativeSaveSecret(RA_TOKEN_SECRET_NAME, "");
g_Config.Save("Achievements logout");
g_activeChallenges.clear();
g_loginResult = RC_OK; // Allow trying again
OnAchievementsLoginStateChange();
}

View File

@ -82,6 +82,10 @@ rc_client_t *GetClient();
void Initialize();
void UpdateSettings();
bool LoginProblems(std::string *errorString);
bool HasToken();
void TryLoginByToken();
/// Called when the system is being shut down. If Shutdown() returns false, the shutdown should be aborted if possible.
bool Shutdown();

View File

@ -290,7 +290,20 @@ void RetroAchievementsSettingsScreen::CreateAccountTab(UI::ViewGroup *viewGroup)
return UI::EVENT_DONE;
});
} else {
if (System_GetPropertyBool(SYSPROP_HAS_LOGIN_DIALOG)) {
std::string errorMessage;
if (Achievements::LoginProblems(&errorMessage)) {
viewGroup->Add(new NoticeView(NoticeLevel::WARN, ac->T("Failed logging in to RetroAchievements"), errorMessage));
if (Achievements::HasToken()) {
viewGroup->Add(new Choice(di->T("Retry")))->OnClick.Add([=](UI::EventParams &) -> UI::EventReturn {
Achievements::TryLoginByToken();
return UI::EVENT_DONE;
});
}
viewGroup->Add(new Choice(di->T("Log out")))->OnClick.Add([=](UI::EventParams &) -> UI::EventReturn {
Achievements::Logout();
return UI::EVENT_DONE;
});
} else if (System_GetPropertyBool(SYSPROP_HAS_LOGIN_DIALOG)) {
viewGroup->Add(new Choice(ac->T("Log in")))->OnClick.Add([=](UI::EventParams &) -> UI::EventReturn {
System_AskUsernamePassword(ac->T("Log in"), [](const std::string &value, int) {
std::vector<std::string> parts;

View File

@ -30,6 +30,7 @@ Account = Account
Achievement Unlocked = Achievement Unlocked
Achievements = Achievements
Achievements are disabled = Achievements are disabled
Can't log in to RetroAchievements right now = Can't log in to RetroAchievements right now
Challenge Mode = Challenge Mode
Challenge Mode (no savestates) = Challenge Mode (no savestates)
Contacting RetroAchievements server... = Contacting RetroAchievements server...