MegaWiFi 1.5
MegaWiFi API documentation
|
GameJolt Game API implementation for MegaWiFi. More...
Data Structures | |
struct | gj_trophy |
Holds the data of a single trophy. More... | |
struct | gj_time |
Holds the date/time from server. More... | |
struct | gj_score |
Holds data of a single score. More... | |
struct | gj_score_table |
Holds data of a single score table. More... | |
struct | gj_user |
Holds user data. More... | |
Macros | |
#define | GJ_TROPHY_RESPONSE_TABLE(X_MACRO) |
Reply fields to a trophy fetch request. More... | |
#define | GJ_TIME_RESPONSE_TABLE(X_MACRO) |
Reply fields to a time fetch request. More... | |
#define | GJ_SCORE_RESPONSE_TABLE(X_MACRO) |
Reply field to a scores fetch request. More... | |
#define | GJ_SCORE_TABLE_RESPONSE_TABLE(X_MACRO) |
Reply fields to a scores tables request. More... | |
#define | GJ_SCORE_GETRANK_RESPONSE_TABLE(X_MACRO) |
Reply fields to a scores get-rank request. More... | |
#define | GJ_USER_RESPONSE_TABLE(X_MACRO) |
Reply fields to a users fetch request. More... | |
#define | X_AS_STRUCT(field, decoder, type) type field; |
Expands a response table as a structure with its fields. More... | |
Enumerations | |
enum | gj_error |
Module error codes. More... | |
enum | gj_trophy_difficulty |
Difficulty to achieve the trophy. More... | |
enum | gj_data_store_update_operation |
Operations supported by gj_data_store_update() function. More... | |
Functions | |
bool | gj_init (const char *endpoint, const char *game_id, const char *private_key, const char *username, const char *user_token, char *reply_buf, uint16_t buf_len, uint16_t tout_frames) |
Initialize the GameJolt API. More... | |
enum gj_error | gj_get_error (void) |
Return the last error code. More... | |
char * | gj_trophies_fetch (bool achieved, const char *trophy_id) |
Fetch player trophies. More... | |
char * | gj_trophy_get_next (char *pos, struct gj_trophy *trophy) |
Decode the trophy raw data for the next entry. More... | |
bool | gj_trophy_add_achieved (const char *trophy_id) |
Mark a trophy as achieved. More... | |
bool | gj_trophy_remove_achieved (const char *trophy_id) |
Mark a trophy as not achieved. More... | |
const char * | gj_trophy_difficulty_str (enum gj_trophy_difficulty difficulty) |
Get the string corresponding to a trophy difficulty. More... | |
bool | gj_time (struct gj_time *time) |
Get the date and time from server. More... | |
char * | gj_scores_fetch (const char *limit, const char *table_id, const char *guest, const char *better_than, const char *worse_than, bool only_user) |
Fetch scores data. More... | |
char * | gj_score_get_next (char *pos, struct gj_score *score) |
Decode the score raw data for the next entry. More... | |
char * | gj_scores_tables_fetch (void) |
Fetch score tables. More... | |
char * | gj_score_table_get_next (char *pos, struct gj_score_table *score_table) |
Decode the score tables raw data for the next entry. More... | |
char * | gj_scores_get_rank (const char *sort, const char *table_id) |
Get ranking corresponding to a sort parameter. More... | |
bool | gj_scores_add (const char *score, const char *sort, const char *table_id, const char *guest, const char *extra_data) |
Add a score to a scoreboard. More... | |
bool | gj_data_store_set (const char *key, const char *data, bool user_store) |
Sets a key/value pair in the data store. More... | |
char * | gj_data_store_keys_fetch (const char *pattern, bool user_store) |
Fetch data store keys. More... | |
char * | gj_data_store_key_next (char *pos, char **key) |
Decode the key data from a gj_data_store_keys_fetch() call. More... | |
char * | data_store_fetch (const char *key, bool user_store) |
Retrieve data from the data store. More... | |
char * | gj_data_store_update (const char *key, enum gj_data_store_update_operation operation, const char *value, bool user_store) |
Update data in the data store. More... | |
bool | gj_data_store_remove (const char *key, bool user_store) |
Remove data from the data store. More... | |
bool | gj_sessions_open (void) |
Open a game session for the player. More... | |
bool | gj_sessions_ping (bool active) |
Ping a session, and allow setting it as active or idle. More... | |
bool | gj_sessions_check (const char *username, const char *user_token) |
Checks if a user session is active in the game. More... | |
bool | gj_sessions_close (void) |
Close a previously opened session. More... | |
char * | gj_users_fetch (const char *username, const char *user_id) |
Get user data. More... | |
char * | gj_user_get_next (char *pos, struct gj_user *user) |
Decode the user raw data for the next entry. More... | |
bool | gj_users_auth (void) |
Check user credentials. More... | |
char * | gj_friends_fetch (void) |
Get friends list. More... | |
char * | gj_friend_get_next (char *pos, char **user_id) |
Decode the friend raw data for the next entry. More... | |
char * | gj_request (const char **path, uint8_t num_paths, const char **key, const char **value, uint8_t num_kv_pairs, uint32_t *out_len) |
Generic GameJolt Game API request. More... | |
GameJolt Game API implementation for MegaWiFi.
Implementation of the version 1.2 of the GameJolt Game API, supporting scoreboards, trophies, friends, etc. For more information, read the original GameJolt Game API documentation: https://gamejolt.com/game-api/doc
#define GJ_SCORE_GETRANK_RESPONSE_TABLE | ( | X_MACRO | ) |
Reply fields to a scores get-rank request.
Definition at line 99 of file gamejolt.h.
#define GJ_SCORE_RESPONSE_TABLE | ( | X_MACRO | ) |
Reply field to a scores fetch request.
Definition at line 81 of file gamejolt.h.
#define GJ_SCORE_TABLE_RESPONSE_TABLE | ( | X_MACRO | ) |
Reply fields to a scores tables request.
Definition at line 92 of file gamejolt.h.
#define GJ_TIME_RESPONSE_TABLE | ( | X_MACRO | ) |
Reply fields to a time fetch request.
Definition at line 72 of file gamejolt.h.
#define GJ_TROPHY_RESPONSE_TABLE | ( | X_MACRO | ) |
Reply fields to a trophy fetch request.
Definition at line 63 of file gamejolt.h.
#define GJ_USER_RESPONSE_TABLE | ( | X_MACRO | ) |
Reply fields to a users fetch request.
Definition at line 104 of file gamejolt.h.
#define X_AS_STRUCT | ( | field, | |
decoder, | |||
type | |||
) | type field; |
Expands a response table as a structure with its fields.
Definition at line 119 of file gamejolt.h.
Operations supported by gj_data_store_update() function.
Definition at line 52 of file gamejolt.h.
enum gj_error |
Module error codes.
On success value is 0. On error all values are negative, with the exception of the HTTP status error. In this case, the value reported is the HTTP status code obtained (e.g. 500).
Definition at line 33 of file gamejolt.h.
enum gj_trophy_difficulty |
Difficulty to achieve the trophy.
Definition at line 43 of file gamejolt.h.
char * data_store_fetch | ( | const char * | key, |
bool | user_store | ||
) |
Retrieve data from the data store.
[in] | key | Key to use for data retrieval. |
[in] | user_store | When true, data is retrieved from user storage. Otherwise it will be retrieved from the game global store. |
char * gj_data_store_key_next | ( | char * | pos, |
char ** | key | ||
) |
Decode the key data from a gj_data_store_keys_fetch() call.
On first call, set pos to the value returned by gj_data_store_keys_fetch(). On successive calls, set pos to the last non-NULL returned value by this function.
[in,out] | pos | Position of the key to extract. Note that input raw data is modified to add null terminations. |
[out] | key | Decoded key data. |
char * gj_data_store_keys_fetch | ( | const char * | pattern, |
bool | user_store | ||
) |
Fetch data store keys.
[in] | pattern | Optional. If set, match returned keys with pattern. |
[in] | user_store | When true, data is retrieved from user storage. Otherwise it will be retrieved from the game global store. |
bool gj_data_store_remove | ( | const char * | key, |
bool | user_store | ||
) |
Remove data from the data store.
[in] | key | Key to use for data removal. |
[in] | user_store | When true, data is removed from user storage. Otherwise it will be removed in the game global store. |
bool gj_data_store_set | ( | const char * | key, |
const char * | data, | ||
bool | user_store | ||
) |
Sets a key/value pair in the data store.
[in] | key | Key to set. |
[in] | data | Value to set. |
[in] | user_store | When true, data is saved in user storage. Otherwise it will be saved in the game global store. |
char * gj_data_store_update | ( | const char * | key, |
enum gj_data_store_update_operation | operation, | ||
const char * | value, | ||
bool | user_store | ||
) |
Update data in the data store.
[in] | key | Key to use for the data to be updated. |
[in] | operation | Operation to apply to the data to update. |
[in] | value | Value to use in the update operation. |
[in] | user_store | When true, data is updated from user storage. Otherwise it will be updated in the game global store. |
char * gj_friend_get_next | ( | char * | pos, |
char ** | user_id | ||
) |
Decode the friend raw data for the next entry.
On first call, set pos to the value returned by gj_friends_fetch(). On successive calls, set pos to the last non-NULL returned value of this function.
[in,out] | pos | Position of the friend to extract. Note that input raw data is modified to add null terminations for fields |
[out] | user_id | Decoded friend user_id. |
char * gj_friends_fetch | ( | void | ) |
Get friends list.
enum gj_error gj_get_error | ( | void | ) |
Return the last error code.
If any other of the functions in the module return with error, call this function immediately after the error, to get the error code.
bool gj_init | ( | const char * | endpoint, |
const char * | game_id, | ||
const char * | private_key, | ||
const char * | username, | ||
const char * | user_token, | ||
char * | reply_buf, | ||
uint16_t | buf_len, | ||
uint16_t | tout_frames | ||
) |
Initialize the GameJolt API.
This function sets the API endpoint, game credentials and user credentials. Call this function before using any other function in the module.
[in] | endpoint | Endpoint for the Game API. Most likely you want to use "https://api.gamejolt.com/api/game/v1_2/" here. |
[in] | game_id | Game identifier. E.g. "123456" |
[in] | private_key | Game private key. Keep it safe! |
[in] | username | Username of the player. |
[in] | user_token | Token corresponding to username. |
[in] | reply_buf | Pre-allocated buffer to use for data reception. |
[in] | buf_len | Length of reply_buf buffer. |
[in] | tout_frames | Number of frames to wait for requests before timing out. |
char * gj_request | ( | const char ** | path, |
uint8_t | num_paths, | ||
const char ** | key, | ||
const char ** | value, | ||
uint8_t | num_kv_pairs, | ||
uint32_t * | out_len | ||
) |
Generic GameJolt Game API request.
Usually you do not need to use this function directly. Use more specific API calls that do the hard work of filling parameters and decoding the response.
[in] | path | Array of paths for the request. |
[in] | num_paths | Number of elements in path array. |
[in] | key | Array of keys for key/value parameters. |
[in] | value | Array of values for key/value parameters. |
[in] | num_kv_pairs | Number of elements in key and value arrays. |
[out] | out_len | Length of the received reply to request. |
char * gj_score_get_next | ( | char * | pos, |
struct gj_score * | score | ||
) |
Decode the score raw data for the next entry.
On first call, set pos to the value returned by gj_scores_fetch(). On successive calls, set pos to the last non-NULL returned value of this function.
[in,out] | pos | Position of the score to extract. Note that input raw data is modified to add null terminations for fields |
[out] | score | Decoded score data. |
char * gj_score_table_get_next | ( | char * | pos, |
struct gj_score_table * | score_table | ||
) |
Decode the score tables raw data for the next entry.
On first call, set pos to the value returned by gj_scores_tables_fetch(). On successive calls, set pos to the last non-NULL returned value by this function.
[in,out] | pos | Position of the score table to extract. Note that input raw data is modified to add null terminations for fields |
[out] | score_table | Decoded score table data. |
bool gj_scores_add | ( | const char * | score, |
const char * | sort, | ||
const char * | table_id, | ||
const char * | guest, | ||
const char * | extra_data | ||
) |
Add a score to a scoreboard.
[in] | score | Score in textual format (e.g. "500 torreznos") |
[in] | sort | Number used to sort the score (e.g. "500") |
[in] | table_id | Table id, or NULL for the main game table. |
[in] | guest | Name of the guest player, or NULL for user player. |
[in] | extra_data | Extra data to save with score, NULL for none. |
char * gj_scores_fetch | ( | const char * | limit, |
const char * | table_id, | ||
const char * | guest, | ||
const char * | better_than, | ||
const char * | worse_than, | ||
bool | only_user | ||
) |
Fetch scores data.
[in] | limit | Number of scores to return (defaults to 10). |
[in] | table_id | Table id, or NULL for the main game table. |
[in] | guest | Set if you want to get score only from guest player. |
[in] | better_than | Get only scores better than this sort value. |
[in] | worse_than | Get only scores worse than this sort value. |
[in] | only_user | Set to true if you want to get only the user scores. |
char * gj_scores_get_rank | ( | const char * | sort, |
const char * | table_id | ||
) |
Get ranking corresponding to a sort parameter.
[in] | sort | Score sort value to get ranking position from table. |
[in] | table_id | Score table id, or NULL for the main table. |
char * gj_scores_tables_fetch | ( | void | ) |
Fetch score tables.
bool gj_sessions_check | ( | const char * | username, |
const char * | user_token | ||
) |
Checks if a user session is active in the game.
[in] | username | (Optional) username to check for open session. |
[in] | user_token | (Optional) user token to check for open session. |
bool gj_sessions_close | ( | void | ) |
Close a previously opened session.
bool gj_sessions_open | ( | void | ) |
Open a game session for the player.
bool gj_sessions_ping | ( | bool | active | ) |
Ping a session, and allow setting it as active or idle.
[in] | active | If true, session is marked as active. Otherwise, session is marked as idle. |
Get the date and time from server.
[out] | time | Date and time from the server. |
char * gj_trophies_fetch | ( | bool | achieved, |
const char * | trophy_id | ||
) |
Fetch player trophies.
[in] | achieved | If true, only achieved trophies are get. |
[in] | trophy_id | If not NULL, a single trophy with specified id is retrieved. |
bool gj_trophy_add_achieved | ( | const char * | trophy_id | ) |
Mark a trophy as achieved.
[in] | trophy_id | Identifier of the trophy to mark as achieved. |
const char * gj_trophy_difficulty_str | ( | enum gj_trophy_difficulty | difficulty | ) |
Get the string corresponding to a trophy difficulty.
[in] | difficulty | Difficulty value to be translated to a string. |
char * gj_trophy_get_next | ( | char * | pos, |
struct gj_trophy * | trophy | ||
) |
Decode the trophy raw data for the next entry.
On first call, set pos to the value returned by gj_trophies_fetch(). On successive calls, set pos to the last non-NULL returned value of this function.
[in,out] | pos | Position of the trophy to extract. Note that input raw data is modified to add null terminations for fields |
[out] | trophy | Decoded trophy data. |
bool gj_trophy_remove_achieved | ( | const char * | trophy_id | ) |
Mark a trophy as not achieved.
[in] | trophy_id | Identifier of the trophy to mark as not achieved. |
char * gj_user_get_next | ( | char * | pos, |
struct gj_user * | user | ||
) |
Decode the user raw data for the next entry.
On first call, set pos to the value returned by gj_users_fetch(). On successive calls, set pos to the last non-NULL returned value of this function.
[in,out] | pos | Position of the user to extract. Note that input raw data is modified to add null terminations for fields |
[out] | user | Decoded user data |
bool gj_users_auth | ( | void | ) |
Check user credentials.
char * gj_users_fetch | ( | const char * | username, |
const char * | user_id | ||
) |
Get user data.
[in] | username | (Optional) User name to get data from. |
[in] | user_id | (Optional) user token to check for open session. |