MegaWiFi 1.5
MegaWiFi API documentation
gamejolt.h
Go to the documentation of this file.
1/************************************************************************/
22#ifndef _GAMEJOLT_H_
23#define _GAMEJOLT_H_
24
25#include <stdbool.h>
26#include <stdint.h>
27
39 GJ_ERR_PARSE = -5
40};
41
49};
50
60};
61
63#define GJ_TROPHY_RESPONSE_TABLE(X_MACRO) \
64 X_MACRO(id, string, char*) \
65 X_MACRO(title, string, char*) \
66 X_MACRO(difficulty, trophy_difficulty, enum gj_trophy_difficulty) \
67 X_MACRO(description, string, char*) \
68 X_MACRO(image_url, string, char*) \
69 X_MACRO(achieved, string, char*)
70
72#define GJ_TIME_RESPONSE_TABLE(X_MACRO) \
73 X_MACRO(timestamp, string, char*) \
74 X_MACRO(timezone, string, char*) \
75 X_MACRO(day, string, char*) \
76 X_MACRO(hour, string, char*) \
77 X_MACRO(minute, string, char*) \
78 X_MACRO(second, string, char*)
79
81#define GJ_SCORE_RESPONSE_TABLE(X_MACRO) \
82 X_MACRO(score, string, char*) \
83 X_MACRO(sort, string, char*) \
84 X_MACRO(extra_data, string, char*) \
85 X_MACRO(user, string, char*) \
86 X_MACRO(user_id, string, char*) \
87 X_MACRO(guest, string, char*) \
88 X_MACRO(stored, string, char*) \
89 X_MACRO(stored_timestamp, string, char*)
90
92#define GJ_SCORE_TABLE_RESPONSE_TABLE(X_MACRO) \
93 X_MACRO(id, string, char*) \
94 X_MACRO(name, string, char*) \
95 X_MACRO(description, string, char*) \
96 X_MACRO(primary, bool_num, bool)
97
99#define GJ_SCORE_GETRANK_RESPONSE_TABLE(X_MACRO) \
100 X_MACRO(message, string, char*) \
101 X_MACRO(rank, string, char*)
102
104#define GJ_USER_RESPONSE_TABLE(X_MACRO) \
105 X_MACRO(id, string, char*) \
106 X_MACRO(type, string, char*) \
107 X_MACRO(username, string, char*) \
108 X_MACRO(avatar_url, string, char*) \
109 X_MACRO(signed_up, string, char*) \
110 X_MACRO(signed_up_timestamp, string, char*) \
111 X_MACRO(last_logged_in, string, char*) \
112 X_MACRO(last_logged_in_timestamp, string, char*) \
113 X_MACRO(status, string, char*) \
114 X_MACRO(developer_name, string, char*) \
115 X_MACRO(developer_website, string, char*) \
116 X_MACRO(developer_description, string, char*)
117
119#define X_AS_STRUCT(field, decoder, type) \
120 type field;
121
123struct gj_trophy {
125 bool secret;
126};
127
129struct gj_time {
131};
132
134struct gj_score {
136};
137
141};
142
144struct gj_user {
146};
147
148/************************************************************************/
171bool gj_init(const char *endpoint, const char *game_id, const char *private_key,
172 const char *username, const char *user_token, char *reply_buf,
173 uint16_t buf_len, uint16_t tout_frames);
174
175/************************************************************************/
184
185/************************************************************************/
195char *gj_trophies_fetch(bool achieved, const char *trophy_id);
196
197/************************************************************************/
211char *gj_trophy_get_next(char *pos, struct gj_trophy *trophy);
212
213/************************************************************************/
220bool gj_trophy_add_achieved(const char *trophy_id);
221
222/************************************************************************/
229bool gj_trophy_remove_achieved(const char *trophy_id);
230
231/************************************************************************/
240
241/************************************************************************/
248bool gj_time(struct gj_time *time);
249
250/************************************************************************/
265char *gj_scores_fetch(const char *limit, const char *table_id,
266 const char *guest, const char *better_than,
267 const char *worse_than, bool only_user);
268
269/************************************************************************/
283char *gj_score_get_next(char *pos, struct gj_score *score);
284
285/************************************************************************/
292
293/************************************************************************/
307char *gj_score_table_get_next(char *pos, struct gj_score_table *score_table);
308
309/************************************************************************/
317char *gj_scores_get_rank(const char *sort, const char *table_id);
318
319/************************************************************************/
330bool gj_scores_add(const char *score, const char *sort, const char *table_id,
331 const char *guest, const char *extra_data);
332
333/************************************************************************/
343bool gj_data_store_set(const char *key, const char *data, bool user_store);
344
345/************************************************************************/
356char *gj_data_store_keys_fetch(const char *pattern, bool user_store);
357
358/************************************************************************/
372char *gj_data_store_key_next(char *pos, char **key);
373
374/************************************************************************/
384char *data_store_fetch(const char *key, bool user_store);
385
386/************************************************************************/
397char *gj_data_store_update(const char *key,
398 enum gj_data_store_update_operation operation,
399 const char *value, bool user_store);
400
401/************************************************************************/
410bool gj_data_store_remove(const char *key, bool user_store);
411
412/************************************************************************/
418
419/************************************************************************/
427bool gj_sessions_ping(bool active);
428
429/************************************************************************/
443bool gj_sessions_check(const char *username, const char *user_token);
444
445/************************************************************************/
451
452/************************************************************************/
465char *gj_users_fetch(const char *username, const char *user_id);
466
467/************************************************************************/
481char *gj_user_get_next(char *pos, struct gj_user *user);
482
483/************************************************************************/
492bool gj_users_auth(void);
493
494/************************************************************************/
501
502/************************************************************************/
516char *gj_friend_get_next(char *pos, char **user_id);
517
518/************************************************************************/
534char *gj_request(const char **path, uint8_t num_paths, const char **key,
535 const char **value, uint8_t num_kv_pairs, uint32_t *out_len);
536
537#endif /*_GAMEJOLT_H_*/
538
char * gj_friend_get_next(char *pos, char **user_id)
Decode the friend raw data for the next entry.
bool gj_time(struct gj_time *time)
Get the date and time from server.
char * gj_data_store_key_next(char *pos, char **key)
Decode the key data from a gj_data_store_keys_fetch() call.
char * gj_friends_fetch(void)
Get friends list.
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.
const char * gj_trophy_difficulty_str(enum gj_trophy_difficulty difficulty)
Get the string corresponding to a trophy difficulty.
bool gj_sessions_ping(bool active)
Ping a session, and allow setting it as active or idle.
bool gj_sessions_check(const char *username, const char *user_token)
Checks if a user session is active in the game.
char * data_store_fetch(const char *key, bool user_store)
Retrieve data from the data store.
enum gj_error gj_get_error(void)
Return the last error code.
bool gj_users_auth(void)
Check user credentials.
#define GJ_SCORE_RESPONSE_TABLE(X_MACRO)
Reply field to a scores fetch request.
Definition: gamejolt.h:81
bool gj_data_store_remove(const char *key, bool user_store)
Remove data from the data store.
char * gj_users_fetch(const char *username, const char *user_id)
Get user data.
#define GJ_USER_RESPONSE_TABLE(X_MACRO)
Reply fields to a users fetch request.
Definition: gamejolt.h:104
char * gj_data_store_keys_fetch(const char *pattern, bool user_store)
Fetch data store keys.
gj_data_store_update_operation
Operations supported by gj_data_store_update() function.
Definition: gamejolt.h:52
#define GJ_SCORE_TABLE_RESPONSE_TABLE(X_MACRO)
Reply fields to a scores tables request.
Definition: gamejolt.h:92
#define GJ_TIME_RESPONSE_TABLE(X_MACRO)
Reply fields to a time fetch request.
Definition: gamejolt.h:72
#define GJ_TROPHY_RESPONSE_TABLE(X_MACRO)
Reply fields to a trophy fetch request.
Definition: gamejolt.h:63
char * gj_trophy_get_next(char *pos, struct gj_trophy *trophy)
Decode the trophy raw data for the next entry.
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.
gj_error
Module error codes.
Definition: gamejolt.h:33
#define X_AS_STRUCT(field, decoder, type)
Expands a response table as a structure with its fields.
Definition: gamejolt.h:119
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.
char * gj_scores_tables_fetch(void)
Fetch score tables.
bool gj_trophy_remove_achieved(const char *trophy_id)
Mark a trophy as not achieved.
char * gj_trophies_fetch(bool achieved, const char *trophy_id)
Fetch player trophies.
char * gj_scores_get_rank(const char *sort, const char *table_id)
Get ranking corresponding to a sort parameter.
char * gj_score_table_get_next(char *pos, struct gj_score_table *score_table)
Decode the score tables raw data for the next entry.
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.
bool gj_sessions_open(void)
Open a game session for the player.
gj_trophy_difficulty
Difficulty to achieve the trophy.
Definition: gamejolt.h:43
bool gj_trophy_add_achieved(const char *trophy_id)
Mark a trophy as achieved.
char * gj_score_get_next(char *pos, struct gj_score *score)
Decode the score raw data for the next entry.
bool gj_sessions_close(void)
Close a previously opened session.
char * gj_user_get_next(char *pos, struct gj_user *user)
Decode the user raw data for the next entry.
bool gj_data_store_set(const char *key, const char *data, bool user_store)
Sets a key/value pair in the data store.
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.
@ GJ_OP_APPEND
Appends value to the data store.
Definition: gamejolt.h:57
@ GJ_OP_ADD
Adds the value to item.
Definition: gamejolt.h:53
@ GJ_OP_DIVIDE
Divides the item by value.
Definition: gamejolt.h:56
@ GJ_OP_MAX
Maximum enum value, do not use for operation.
Definition: gamejolt.h:59
@ GJ_OP_SUBTRACT
Subtracs the value from item.
Definition: gamejolt.h:54
@ GJ_OP_MULTIPLY
Multiplies value by item.
Definition: gamejolt.h:55
@ GJ_OP_PREPEND
Prepends value to the data store.
Definition: gamejolt.h:58
@ GJ_ERR_RESPONSE
Response has no success:"true" head.
Definition: gamejolt.h:38
@ GJ_ERR_REQUEST
Request failed (network or server down?)
Definition: gamejolt.h:36
@ GJ_ERR_PARAM
Missing or invalid parameter.
Definition: gamejolt.h:35
@ GJ_ERR_RECEPTION
Failed to receive response data.
Definition: gamejolt.h:37
@ GJ_ERR_PARSE
Error while parsing response data.
Definition: gamejolt.h:39
@ GJ_ERR_NONE
No error.
Definition: gamejolt.h:34
@ GJ_TROPHY_TYPE_SILVER
Silver trophy (medium)
Definition: gamejolt.h:45
@ GJ_TROPHY_TYPE_PLATINUM
Platinum trophy (hardest)
Definition: gamejolt.h:47
@ GJ_TROPHY_TYPE_GOLD
Gold trophy (hard)
Definition: gamejolt.h:46
@ GJ_TROPHY_TYPE_UNKNOWN
Unknown, just for errors.
Definition: gamejolt.h:48
@ GJ_TROPHY_TYPE_BRONZE
Bronze trophy (easiest)
Definition: gamejolt.h:44
Holds data of a single score table.
Definition: gamejolt.h:139
Holds data of a single score.
Definition: gamejolt.h:134
Holds the date/time from server.
Definition: gamejolt.h:129
Holds the data of a single trophy.
Definition: gamejolt.h:123
bool secret
If true, trophy is secret.
Definition: gamejolt.h:124
Holds user data.
Definition: gamejolt.h:144