reset token when username or password changes

This commit is contained in:
Jamiras 2020-02-22 20:58:11 -07:00
parent 8d6c7d6753
commit 4e27394b87
5 changed files with 50 additions and 9 deletions

View File

@ -462,7 +462,16 @@ static int rcheevos_parse(const char* json)
if (res != 0) 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; return -1;
} }
@ -1251,6 +1260,7 @@ bool rcheevos_unload(void)
{ {
bool running = false; bool running = false;
unsigned i = 0, count = 0; unsigned i = 0, count = 0;
settings_t* settings = config_get_ptr();
CHEEVOS_LOCK(rcheevos_locals.task_lock); CHEEVOS_LOCK(rcheevos_locals.task_lock);
running = rcheevos_locals.task != NULL; running = rcheevos_locals.task != NULL;
@ -1307,6 +1317,10 @@ bool rcheevos_unload(void)
rcheevos_state_loaded_flag = false; 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; return true;
} }

View File

@ -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) 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); 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 Count number of achievements in a JSON file
*****************************************************************************/ *****************************************************************************/
@ -162,6 +167,7 @@ typedef struct
{ {
int in_cheevos; int in_cheevos;
int in_lboards; int in_lboards;
int has_error;
uint32_t field_hash; uint32_t field_hash;
unsigned core_count; unsigned core_count;
unsigned unofficial_count; unsigned unofficial_count;
@ -185,9 +191,11 @@ static int rcheevos_count_key(void* userdata,
ud->field_hash = rcheevos_djb2(name, length); ud->field_hash = rcheevos_djb2(name, length);
if (ud->field_hash == CHEEVOS_JSON_KEY_ACHIEVEMENTS) 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) 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; return 0;
} }
@ -214,7 +222,7 @@ static int rcheevos_count_number(void* userdata,
static int rcheevos_count_cheevos(const char* json, static int rcheevos_count_cheevos(const char* json,
unsigned* core_count, unsigned* unofficial_count, unsigned* core_count, unsigned* unofficial_count,
unsigned* lboard_count) unsigned* lboard_count, int* has_error)
{ {
static const jsonsax_handlers_t handlers = static const jsonsax_handlers_t handlers =
{ {
@ -236,6 +244,7 @@ static int rcheevos_count_cheevos(const char* json,
rcheevos_countud_t ud; rcheevos_countud_t ud;
ud.in_cheevos = 0; ud.in_cheevos = 0;
ud.in_lboards = 0; ud.in_lboards = 0;
ud.has_error = 0;
ud.core_count = 0; ud.core_count = 0;
ud.unofficial_count = 0; ud.unofficial_count = 0;
ud.lboard_count = 0; ud.lboard_count = 0;
@ -245,6 +254,7 @@ static int rcheevos_count_cheevos(const char* json,
*core_count = ud.core_count; *core_count = ud.core_count;
*unofficial_count = ud.unofficial_count; *unofficial_count = ud.unofficial_count;
*lboard_count = ud.lboard_count; *lboard_count = ud.lboard_count;
*has_error = ud.has_error;
return res; return res;
} }
@ -582,12 +592,13 @@ int rcheevos_get_patchdata(const char* json, rcheevos_rapatchdata_t* patchdata)
rcheevos_readud_t ud; rcheevos_readud_t ud;
int res; int res;
int has_error;
/* Count the number of achievements in the JSON file. */ /* Count the number of achievements in the JSON file. */
res = rcheevos_count_cheevos(json, &patchdata->core_count, 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; return -1;
/* Allocate the achievements. */ /* Allocate the achievements. */

View File

@ -58,6 +58,7 @@ typedef struct {
typedef void (*rcheevos_unlock_cb_t)(unsigned id, void* userdata); 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_token(const char* json, char* token, size_t length);
int rcheevos_get_patchdata(const char* json, rcheevos_rapatchdata_t* patchdata); int rcheevos_get_patchdata(const char* json, rcheevos_rapatchdata_t* patchdata);

View File

@ -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)) switch (setting_get_type(cbs->setting))
{ {

View File

@ -2828,7 +2828,13 @@ static void setting_get_string_representation_cheevos_password(
if (!string_is_empty(setting->value.target.string)) if (!string_is_empty(setting->value.target.string))
strlcpy(s, "********", len); strlcpy(s, "********", len);
else 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 #endif
@ -6808,6 +6814,15 @@ void general_write_handler(rarch_setting_t *setting)
break; break;
} }
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: default:
break; break;
} }