Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/dep/rcheevos/include/rc_api_user.h
4246 views
1
#ifndef RC_API_USER_H
2
#define RC_API_USER_H
3
4
#include "rc_api_request.h"
5
6
#include <stdint.h>
7
#include <time.h>
8
9
RC_BEGIN_C_DECLS
10
11
/* --- Login --- */
12
13
/**
14
* API parameters for a login request.
15
* If both password and api_token are provided, api_token will be ignored.
16
*/
17
typedef struct rc_api_login_request_t {
18
/* The username of the player being logged in */
19
const char* username;
20
/* The API token from a previous login */
21
const char* api_token;
22
/* The player's password */
23
const char* password;
24
}
25
rc_api_login_request_t;
26
27
/**
28
* Response data for a login request.
29
*/
30
typedef struct rc_api_login_response_t {
31
/* The case-corrected username of the player */
32
const char* username;
33
/* The API token to use for all future requests */
34
const char* api_token;
35
/* The current score of the player */
36
uint32_t score;
37
/* The current softcore score of the player */
38
uint32_t score_softcore;
39
/* The number of unread messages waiting for the player on the web site */
40
uint32_t num_unread_messages;
41
/* The preferred name to display for the player */
42
const char* display_name;
43
/* A URL to the user's avatar image */
44
const char* avatar_url;
45
46
/* Common server-provided response information */
47
rc_api_response_t response;
48
}
49
rc_api_login_response_t;
50
51
RC_EXPORT int RC_CCONV rc_api_init_login_request(rc_api_request_t* request, const rc_api_login_request_t* api_params);
52
RC_EXPORT int RC_CCONV rc_api_init_login_request_hosted(rc_api_request_t* request, const rc_api_login_request_t* api_params, const rc_api_host_t* host);
53
/* [deprecated] use rc_api_process_login_server_response instead */
54
RC_EXPORT int RC_CCONV rc_api_process_login_response(rc_api_login_response_t* response, const char* server_response);
55
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);
56
RC_EXPORT void RC_CCONV rc_api_destroy_login_response(rc_api_login_response_t* response);
57
58
/* --- Start Session --- */
59
60
/**
61
* API parameters for a start session request.
62
*/
63
typedef struct rc_api_start_session_request_t {
64
/* The username of the player */
65
const char* username;
66
/* The API token from the login request */
67
const char* api_token;
68
/* The unique identifier of the game */
69
uint32_t game_id;
70
/* (recommended) The hash associated to the game being played */
71
const char* game_hash;
72
/* Non-zero if hardcore is currently enabled (ignored if game_hash is null) */
73
uint32_t hardcore;
74
}
75
rc_api_start_session_request_t;
76
77
/**
78
* Response data for an achievement unlock.
79
*/
80
typedef struct rc_api_unlock_entry_t {
81
/* The unique identifier of the unlocked achievement */
82
uint32_t achievement_id;
83
/* When the achievement was unlocked */
84
time_t when;
85
}
86
rc_api_unlock_entry_t;
87
88
/**
89
* Response data for a start session request.
90
*/
91
typedef struct rc_api_start_session_response_t {
92
/* An array of hardcore user unlocks */
93
rc_api_unlock_entry_t* hardcore_unlocks;
94
/* An array of user unlocks */
95
rc_api_unlock_entry_t* unlocks;
96
97
/* The number of items in the hardcore_unlocks array */
98
uint32_t num_hardcore_unlocks;
99
/* The number of items in the unlocks array */
100
uint32_t num_unlocks;
101
102
/* The server timestamp when the response was generated */
103
time_t server_now;
104
105
/* Common server-provided response information */
106
rc_api_response_t response;
107
}
108
rc_api_start_session_response_t;
109
110
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);
111
RC_EXPORT int RC_CCONV rc_api_init_start_session_request_hosted(rc_api_request_t* request, const rc_api_start_session_request_t* api_params, const rc_api_host_t* host);
112
/* [deprecated] use rc_api_process_start_session_server_response instead */
113
RC_EXPORT int RC_CCONV rc_api_process_start_session_response(rc_api_start_session_response_t* response, const char* server_response);
114
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);
115
RC_EXPORT void RC_CCONV rc_api_destroy_start_session_response(rc_api_start_session_response_t* response);
116
117
/* --- Fetch User Unlocks --- */
118
119
/**
120
* API parameters for a fetch user unlocks request.
121
*/
122
typedef struct rc_api_fetch_user_unlocks_request_t {
123
/* The username of the player */
124
const char* username;
125
/* The API token from the login request */
126
const char* api_token;
127
/* The unique identifier of the game */
128
uint32_t game_id;
129
/* Non-zero to fetch hardcore unlocks, 0 to fetch non-hardcore unlocks */
130
uint32_t hardcore;
131
}
132
rc_api_fetch_user_unlocks_request_t;
133
134
/**
135
* Response data for a fetch user unlocks request.
136
*/
137
typedef struct rc_api_fetch_user_unlocks_response_t {
138
/* An array of achievement IDs previously unlocked by the user */
139
uint32_t* achievement_ids;
140
/* The number of items in the achievement_ids array */
141
uint32_t num_achievement_ids;
142
143
/* Common server-provided response information */
144
rc_api_response_t response;
145
}
146
rc_api_fetch_user_unlocks_response_t;
147
148
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);
149
RC_EXPORT int RC_CCONV rc_api_init_fetch_user_unlocks_request_hosted(rc_api_request_t* request, const rc_api_fetch_user_unlocks_request_t* api_params, const rc_api_host_t* host);
150
/* [deprecated] use rc_api_process_fetch_user_unlocks_server_response instead */
151
RC_EXPORT int RC_CCONV rc_api_process_fetch_user_unlocks_response(rc_api_fetch_user_unlocks_response_t* response, const char* server_response);
152
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);
153
RC_EXPORT void RC_CCONV rc_api_destroy_fetch_user_unlocks_response(rc_api_fetch_user_unlocks_response_t* response);
154
155
/* --- Fetch Followed Users --- */
156
157
/**
158
* API parameters for a fetch followed users request.
159
*/
160
typedef struct rc_api_fetch_followed_users_request_t {
161
/* The username of the player */
162
const char* username;
163
/* The API token from the login request */
164
const char* api_token;
165
}
166
rc_api_fetch_followed_users_request_t;
167
168
typedef struct rc_api_followed_user_activity_t {
169
/* The record associated to the activity */
170
const char* context;
171
/* The image of the record associated to the activity */
172
const char* context_image_url;
173
/* The description of the activity */
174
const char* description;
175
/* The time of the activity */
176
time_t when;
177
/* The unique identifier of the record associated to the activity */
178
uint32_t context_id;
179
}
180
rc_api_followed_user_activity_t;
181
182
/**
183
* Response data for a followed user.
184
*/
185
typedef struct rc_api_followed_user_t {
186
/* The preferred name to display for the player */
187
const char* display_name;
188
/* A URL to the user's avatar image */
189
const char* avatar_url;
190
/* The player's last registered activity */
191
rc_api_followed_user_activity_t recent_activity;
192
/* The current score of the player */
193
uint32_t score;
194
}
195
rc_api_followed_user_t;
196
197
/**
198
* Response data for a fetch followed users request.
199
*/
200
typedef struct rc_api_fetch_followed_users_response_t {
201
/* An array of followed user information */
202
rc_api_followed_user_t* users;
203
/* The number of items in the users array */
204
uint32_t num_users;
205
206
/* Common server-provided response information */
207
rc_api_response_t response;
208
}
209
rc_api_fetch_followed_users_response_t;
210
211
RC_EXPORT int RC_CCONV rc_api_init_fetch_followed_users_request(rc_api_request_t* request, const rc_api_fetch_followed_users_request_t* api_params);
212
RC_EXPORT int RC_CCONV rc_api_init_fetch_followed_users_request_hosted(rc_api_request_t* request, const rc_api_fetch_followed_users_request_t* api_params, const rc_api_host_t* host);
213
RC_EXPORT int RC_CCONV rc_api_process_fetch_followed_users_server_response(rc_api_fetch_followed_users_response_t* response, const rc_api_server_response_t* server_response);
214
RC_EXPORT void RC_CCONV rc_api_destroy_fetch_followed_users_response(rc_api_fetch_followed_users_response_t* response);
215
216
/* --- Fetch All Progress --- */
217
218
/**
219
* API parameters for a fetch all user progress request.
220
*/
221
typedef struct rc_api_fetch_all_user_progress_request_t {
222
/* The username of the player */
223
const char* username;
224
/* The API token from the login request */
225
const char* api_token;
226
/* The unique identifier of the console to query */
227
uint32_t console_id;
228
} rc_api_fetch_all_user_progress_request_t;
229
230
/* An all-user-progress entry */
231
typedef struct rc_api_all_user_progress_entry_t {
232
/* The unique identifier of the game */
233
uint32_t game_id;
234
/* The total number of achievements for this game */
235
uint32_t num_achievements;
236
/* The total number of unlocked achievements for this game in softcore mode */
237
uint32_t num_unlocked_achievements;
238
/* The total number of unlocked achievements for this game in hardcore mode */
239
uint32_t num_unlocked_achievements_hardcore;
240
} rc_api_all_user_progress_entry_t;
241
242
/**
243
* Response data for a fetch all user progress request.
244
*/
245
typedef struct rc_api_fetch_all_user_progress_response_t {
246
/* An array of entries, one per game */
247
rc_api_all_user_progress_entry_t* entries;
248
/* The number of items in the entries array */
249
uint32_t num_entries;
250
251
/* Common server-provided response information */
252
rc_api_response_t response;
253
} rc_api_fetch_all_user_progress_response_t;
254
255
RC_EXPORT int RC_CCONV rc_api_init_fetch_all_user_progress_request(rc_api_request_t* request, const rc_api_fetch_all_user_progress_request_t* api_params);
256
RC_EXPORT int RC_CCONV rc_api_init_fetch_all_user_progress_request_hosted(rc_api_request_t* request, const rc_api_fetch_all_user_progress_request_t* api_params, const rc_api_host_t* host);
257
RC_EXPORT int RC_CCONV rc_api_process_fetch_all_user_progress_server_response(rc_api_fetch_all_user_progress_response_t* response, const rc_api_server_response_t* server_response);
258
RC_EXPORT void RC_CCONV rc_api_destroy_fetch_all_user_progress_response(rc_api_fetch_all_user_progress_response_t* response);
259
260
RC_END_C_DECLS
261
262
#endif /* RC_API_H */
263
264