Duckstation/dep/rcheevos/include/rc_api_user.h

150 lines
5 KiB
C
Raw Normal View History

2022-07-18 12:46:12 +00:00
#ifndef RC_API_USER_H
#define RC_API_USER_H
#include "rc_api_request.h"
2023-11-06 09:41:10 +00:00
#include <stdint.h>
2023-09-06 12:37:42 +00:00
#include <time.h>
2024-01-13 04:24:04 +00:00
RC_BEGIN_C_DECLS
2022-07-18 12:46:12 +00:00
/* --- Login --- */
/**
* API parameters for a login request.
* If both password and api_token are provided, api_token will be ignored.
*/
typedef struct rc_api_login_request_t {
/* The username of the player being logged in */
const char* username;
/* The API token from a previous login */
const char* api_token;
/* The player's password */
const char* password;
}
rc_api_login_request_t;
/**
* Response data for a login request.
*/
typedef struct rc_api_login_response_t {
/* The case-corrected username of the player */
const char* username;
/* The API token to use for all future requests */
const char* api_token;
/* The current score of the player */
2023-11-06 09:41:10 +00:00
uint32_t score;
/* The current softcore score of the player */
2023-11-06 09:41:10 +00:00
uint32_t score_softcore;
2022-07-18 12:46:12 +00:00
/* The number of unread messages waiting for the player on the web site */
2023-11-06 09:41:10 +00:00
uint32_t num_unread_messages;
2022-07-18 12:46:12 +00:00
/* The preferred name to display for the player */
const char* display_name;
/* Common server-provided response information */
rc_api_response_t response;
}
rc_api_login_response_t;
2024-01-13 04:24:04 +00:00
RC_EXPORT int RC_CCONV rc_api_init_login_request(rc_api_request_t* request, const rc_api_login_request_t* api_params);
RC_EXPORT int RC_CCONV rc_api_process_login_response(rc_api_login_response_t* response, const char* server_response);
RC_EXPORT int RC_CCONV rc_api_process_login_server_response(rc_api_login_response_t* response, const rc_api_server_response_t* server_response);
RC_EXPORT void RC_CCONV rc_api_destroy_login_response(rc_api_login_response_t* response);
2022-07-18 12:46:12 +00:00
/* --- Start Session --- */
/**
* API parameters for a start session request.
*/
typedef struct rc_api_start_session_request_t {
/* The username of the player */
const char* username;
/* The API token from the login request */
const char* api_token;
/* The unique identifier of the game */
2023-11-06 09:41:10 +00:00
uint32_t game_id;
2024-01-13 04:24:04 +00:00
/* (recommended) The hash associated to the game being played */
const char* game_hash;
/* Non-zero if hardcore is currently enabled (ignored if game_hash is null) */
uint32_t hardcore;
2022-07-18 12:46:12 +00:00
}
rc_api_start_session_request_t;
2023-09-06 12:37:42 +00:00
/**
* Response data for an achievement unlock.
*/
typedef struct rc_api_unlock_entry_t {
/* The unique identifier of the unlocked achievement */
2023-11-06 09:41:10 +00:00
uint32_t achievement_id;
2023-09-06 12:37:42 +00:00
/* When the achievement was unlocked */
time_t when;
}
rc_api_unlock_entry_t;
2022-07-18 12:46:12 +00:00
/**
* Response data for a start session request.
*/
typedef struct rc_api_start_session_response_t {
2023-09-06 12:37:42 +00:00
/* An array of hardcore user unlocks */
rc_api_unlock_entry_t* hardcore_unlocks;
/* An array of user unlocks */
rc_api_unlock_entry_t* unlocks;
/* The number of items in the hardcore_unlocks array */
2023-11-06 09:41:10 +00:00
uint32_t num_hardcore_unlocks;
2023-09-06 12:37:42 +00:00
/* The number of items in the unlocks array */
2023-11-06 09:41:10 +00:00
uint32_t num_unlocks;
2023-09-06 12:37:42 +00:00
/* The server timestamp when the response was generated */
time_t server_now;
2022-07-18 12:46:12 +00:00
/* Common server-provided response information */
rc_api_response_t response;
}
rc_api_start_session_response_t;
2024-01-13 04:24:04 +00:00
RC_EXPORT int RC_CCONV rc_api_init_start_session_request(rc_api_request_t* request, const rc_api_start_session_request_t* api_params);
RC_EXPORT int RC_CCONV rc_api_process_start_session_response(rc_api_start_session_response_t* response, const char* server_response);
RC_EXPORT int RC_CCONV rc_api_process_start_session_server_response(rc_api_start_session_response_t* response, const rc_api_server_response_t* server_response);
RC_EXPORT void RC_CCONV rc_api_destroy_start_session_response(rc_api_start_session_response_t* response);
2022-07-18 12:46:12 +00:00
/* --- Fetch User Unlocks --- */
/**
* API parameters for a fetch user unlocks request.
*/
typedef struct rc_api_fetch_user_unlocks_request_t {
/* The username of the player */
const char* username;
/* The API token from the login request */
const char* api_token;
/* The unique identifier of the game */
2023-11-06 09:41:10 +00:00
uint32_t game_id;
2022-07-18 12:46:12 +00:00
/* Non-zero to fetch hardcore unlocks, 0 to fetch non-hardcore unlocks */
2023-11-06 09:41:10 +00:00
uint32_t hardcore;
2022-07-18 12:46:12 +00:00
}
rc_api_fetch_user_unlocks_request_t;
/**
* Response data for a fetch user unlocks request.
*/
typedef struct rc_api_fetch_user_unlocks_response_t {
/* An array of achievement IDs previously unlocked by the user */
2023-11-06 09:41:10 +00:00
uint32_t* achievement_ids;
2022-07-18 12:46:12 +00:00
/* The number of items in the achievement_ids array */
2023-11-06 09:41:10 +00:00
uint32_t num_achievement_ids;
2022-07-18 12:46:12 +00:00
/* Common server-provided response information */
rc_api_response_t response;
}
rc_api_fetch_user_unlocks_response_t;
2024-01-13 04:24:04 +00:00
RC_EXPORT int RC_CCONV rc_api_init_fetch_user_unlocks_request(rc_api_request_t* request, const rc_api_fetch_user_unlocks_request_t* api_params);
RC_EXPORT int RC_CCONV rc_api_process_fetch_user_unlocks_response(rc_api_fetch_user_unlocks_response_t* response, const char* server_response);
RC_EXPORT int RC_CCONV rc_api_process_fetch_user_unlocks_server_response(rc_api_fetch_user_unlocks_response_t* response, const rc_api_server_response_t* server_response);
RC_EXPORT void RC_CCONV rc_api_destroy_fetch_user_unlocks_response(rc_api_fetch_user_unlocks_response_t* response);
2022-07-18 12:46:12 +00:00
2024-01-13 04:24:04 +00:00
RC_END_C_DECLS
2022-07-18 12:46:12 +00:00
#endif /* RC_API_H */