diff --git a/cheevos-new/cheevos.c b/cheevos-new/cheevos.c index de043f4455..cb57a1bec9 100644 --- a/cheevos-new/cheevos.c +++ b/cheevos-new/cheevos.c @@ -462,7 +462,16 @@ static int rcheevos_parse(const char* json) if (res != 0) { - RARCH_ERR(RCHEEVOS_TAG "Error parsing cheevos"); + char* ptr = buffer + snprintf(buffer, sizeof(buffer), "Error retrieving achievement data: "); + + /* extract the Error field from the JSON. if not found, remove the colon from the message */ + if (rcheevos_get_json_error(json, ptr, sizeof(buffer) - (ptr - buffer)) == -1) + ptr[-2] = '\0'; + + runloop_msg_queue_push(buffer, 0, 5 * 60, false, NULL, + MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_WARNING); + + RARCH_ERR(RCHEEVOS_TAG "%s", buffer); return -1; } @@ -1251,6 +1260,7 @@ bool rcheevos_unload(void) { bool running = false; unsigned i = 0, count = 0; + settings_t* settings = config_get_ptr(); CHEEVOS_LOCK(rcheevos_locals.task_lock); running = rcheevos_locals.task != NULL; @@ -1307,6 +1317,10 @@ bool rcheevos_unload(void) rcheevos_state_loaded_flag = false; } + /* if the config-level token has been cleared, we need to re-login on loading the next game */ + if (!settings->arrays.cheevos_token[0]) + rcheevos_locals.token[0] = '\0'; + return true; } diff --git a/cheevos-new/parser.c b/cheevos-new/parser.c index 78af214108..cb6c4aedf8 100644 --- a/cheevos-new/parser.c +++ b/cheevos-new/parser.c @@ -141,7 +141,7 @@ static int rcheevos_get_value(const char* json, unsigned key_hash, } /***************************************************************************** -Returns the token of the error message +Returns the token or the error message *****************************************************************************/ int rcheevos_get_token(const char* json, char* token, size_t length) @@ -154,6 +154,11 @@ int rcheevos_get_token(const char* json, char* token, size_t length) return rcheevos_get_value(json, CHEEVOS_JSON_KEY_TOKEN, token, length); } +int rcheevos_get_json_error(const char* json, char* token, size_t length) +{ + return rcheevos_get_value(json, CHEEVOS_JSON_KEY_ERROR, token, length); +} + /***************************************************************************** Count number of achievements in a JSON file *****************************************************************************/ @@ -162,6 +167,7 @@ typedef struct { int in_cheevos; int in_lboards; + int has_error; uint32_t field_hash; unsigned core_count; unsigned unofficial_count; @@ -185,9 +191,11 @@ static int rcheevos_count_key(void* userdata, ud->field_hash = rcheevos_djb2(name, length); if (ud->field_hash == CHEEVOS_JSON_KEY_ACHIEVEMENTS) - ud->in_cheevos = 1; + ud->in_cheevos = 1; else if (ud->field_hash == CHEEVOS_JSON_KEY_LEADERBOARDS) - ud->in_lboards = 1; + ud->in_lboards = 1; + else if (ud->field_hash == CHEEVOS_JSON_KEY_ERROR) + ud->has_error = 1; return 0; } @@ -214,7 +222,7 @@ static int rcheevos_count_number(void* userdata, static int rcheevos_count_cheevos(const char* json, unsigned* core_count, unsigned* unofficial_count, - unsigned* lboard_count) + unsigned* lboard_count, int* has_error) { static const jsonsax_handlers_t handlers = { @@ -236,6 +244,7 @@ static int rcheevos_count_cheevos(const char* json, rcheevos_countud_t ud; ud.in_cheevos = 0; ud.in_lboards = 0; + ud.has_error = 0; ud.core_count = 0; ud.unofficial_count = 0; ud.lboard_count = 0; @@ -245,6 +254,7 @@ static int rcheevos_count_cheevos(const char* json, *core_count = ud.core_count; *unofficial_count = ud.unofficial_count; *lboard_count = ud.lboard_count; + *has_error = ud.has_error; return res; } @@ -582,12 +592,13 @@ int rcheevos_get_patchdata(const char* json, rcheevos_rapatchdata_t* patchdata) rcheevos_readud_t ud; int res; + int has_error; /* Count the number of achievements in the JSON file. */ res = rcheevos_count_cheevos(json, &patchdata->core_count, - &patchdata->unofficial_count, &patchdata->lboard_count); + &patchdata->unofficial_count, &patchdata->lboard_count, &has_error); - if (res != JSONSAX_OK) + if (res != JSONSAX_OK || has_error) return -1; /* Allocate the achievements. */ diff --git a/cheevos-new/parser.h b/cheevos-new/parser.h index 29aa0a3e3e..5f5c3c6692 100644 --- a/cheevos-new/parser.h +++ b/cheevos-new/parser.h @@ -58,6 +58,7 @@ typedef struct { typedef void (*rcheevos_unlock_cb_t)(unsigned id, void* userdata); +int rcheevos_get_json_error(const char* json, char* token, size_t length); int rcheevos_get_token(const char* json, char* token, size_t length); int rcheevos_get_patchdata(const char* json, rcheevos_rapatchdata_t* patchdata); diff --git a/menu/cbs/menu_cbs_get_value.c b/menu/cbs/menu_cbs_get_value.c index 9852278698..bb9ab16fd4 100644 --- a/menu/cbs/menu_cbs_get_value.c +++ b/menu/cbs/menu_cbs_get_value.c @@ -1854,7 +1854,7 @@ int menu_cbs_init_bind_get_string_representation(menu_file_list_cbs_t *cbs, } } - if (cbs->setting) + if (cbs->setting && !cbs->setting->get_string_representation) { switch (setting_get_type(cbs->setting)) { diff --git a/menu/menu_setting.c b/menu/menu_setting.c index be1a64aebd..87cb4c2424 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -2828,7 +2828,13 @@ static void setting_get_string_representation_cheevos_password( if (!string_is_empty(setting->value.target.string)) strlcpy(s, "********", len); else - *setting->value.target.string = '\0'; + { + settings_t *settings = config_get_ptr(); + if (settings->arrays.cheevos_token[0]) + strlcpy(s, "********", len); + else + *setting->value.target.string = '\0'; + } } #endif @@ -6808,6 +6814,15 @@ void general_write_handler(rarch_setting_t *setting) break; } break; + case MENU_ENUM_LABEL_CHEEVOS_USERNAME: + /* when changing the username, clear out the password and token */ + settings->arrays.cheevos_password[0] = '\0'; + settings->arrays.cheevos_token[0] = '\0'; + break; + case MENU_ENUM_LABEL_CHEEVOS_PASSWORD: + /* when changing the password, clear out the token */ + settings->arrays.cheevos_token[0] = '\0'; + break; default: break; }