sgdk
gamejolt.h
Go to the documentation of this file.
00001 /************************************************************************/
00024 #ifndef _GAMEJOLT_H_
00025 #define _GAMEJOLT_H_
00026 
00027 #include "types.h"
00028 
00029 #if (MODULE_MEGAWIFI != 0)
00030 
00036 enum gj_error {
00037         GJ_ERR_NONE      =  0,  
00038         GJ_ERR_PARAM     = -1,  
00039         GJ_ERR_REQUEST   = -2,  
00040         GJ_ERR_RECEPTION = -3,  
00041         GJ_ERR_RESPONSE  = -4,  
00042         GJ_ERR_PARSE     = -5   
00043 };
00044 
00046 enum gj_trophy_difficulty {
00047         GJ_TROPHY_TYPE_BRONZE = 0,      
00048         GJ_TROPHY_TYPE_SILVER,          
00049         GJ_TROPHY_TYPE_GOLD,            
00050         GJ_TROPHY_TYPE_PLATINUM,        
00051         GJ_TROPHY_TYPE_UNKNOWN          
00052 };
00053 
00055 enum gj_data_store_update_operation {
00056         GJ_OP_ADD = 0,  
00057         GJ_OP_SUBTRACT, 
00058         GJ_OP_MULTIPLY, 
00059         GJ_OP_DIVIDE,   
00060         GJ_OP_APPEND,   
00061         GJ_OP_PREPEND,  
00062         GJ_OP_MAX       
00063 };
00064 
00066 #define GJ_TROPHY_RESPONSE_TABLE(X_MACRO) \
00067         X_MACRO(id,          string,            char*) \
00068         X_MACRO(title,       string,            char*) \
00069         X_MACRO(difficulty,  trophy_difficulty, enum gj_trophy_difficulty) \
00070         X_MACRO(description, string,            char*) \
00071         X_MACRO(image_url,   string,            char*) \
00072         X_MACRO(achieved,    string,            char*)
00073 
00075 #define GJ_TIME_RESPONSE_TABLE(X_MACRO) \
00076         X_MACRO(timestamp, string, char*) \
00077         X_MACRO(timezone,  string, char*) \
00078         X_MACRO(day,       string, char*) \
00079         X_MACRO(hour,      string, char*) \
00080         X_MACRO(minute,    string, char*) \
00081         X_MACRO(second,    string, char*)
00082 
00084 #define GJ_SCORE_RESPONSE_TABLE(X_MACRO) \
00085         X_MACRO(score,            string, char*) \
00086         X_MACRO(sort,             string, char*) \
00087         X_MACRO(extra_data,       string, char*) \
00088         X_MACRO(user,             string, char*) \
00089         X_MACRO(user_id,          string, char*) \
00090         X_MACRO(guest,            string, char*) \
00091         X_MACRO(stored,           string, char*) \
00092         X_MACRO(stored_timestamp, string, char*)
00093 
00095 #define GJ_SCORE_TABLE_RESPONSE_TABLE(X_MACRO) \
00096         X_MACRO(id,          string, char*) \
00097         X_MACRO(name,        string, char*) \
00098         X_MACRO(description, string, char*) \
00099         X_MACRO(primary,     bool_num, bool)
00100 
00102 #define GJ_SCORE_GETRANK_RESPONSE_TABLE(X_MACRO) \
00103         X_MACRO(message, string, char*) \
00104         X_MACRO(rank,    string, char*)
00105 
00107 #define GJ_USER_RESPONSE_TABLE(X_MACRO) \
00108         X_MACRO(id,                       string, char*) \
00109         X_MACRO(type,                     string, char*) \
00110         X_MACRO(username,                 string, char*) \
00111         X_MACRO(avatar_url,               string, char*) \
00112         X_MACRO(signed_up,                string, char*) \
00113         X_MACRO(signed_up_timestamp,      string, char*) \
00114         X_MACRO(last_logged_in,           string, char*) \
00115         X_MACRO(last_logged_in_timestamp, string, char*) \
00116         X_MACRO(status,                   string, char*) \
00117         X_MACRO(developer_name,           string, char*) \
00118         X_MACRO(developer_website,        string, char*) \
00119         X_MACRO(developer_description,    string, char*)
00120 
00122 #define X_AS_STRUCT(field, decoder, type) \
00123         type field;
00124 
00126 struct gj_trophy {
00127         GJ_TROPHY_RESPONSE_TABLE(X_AS_STRUCT);
00128         bool secret;    
00129 };
00130 
00132 struct gj_time {
00133         GJ_TIME_RESPONSE_TABLE(X_AS_STRUCT);
00134 };
00135 
00137 struct gj_score {
00138         GJ_SCORE_RESPONSE_TABLE(X_AS_STRUCT);
00139 };
00140 
00142 struct gj_score_table {
00143         GJ_SCORE_TABLE_RESPONSE_TABLE(X_AS_STRUCT);
00144 };
00145 
00147 struct gj_user {
00148         GJ_USER_RESPONSE_TABLE(X_AS_STRUCT);
00149 };
00150 
00151 /************************************************************************/
00174 bool gj_init(const char *endpoint, const char *game_id, const char *private_key,
00175                 const char *username, const char *user_token, char *reply_buf,
00176                 uint16_t buf_len, uint16_t tout_frames);
00177 
00178 /************************************************************************/
00186 enum gj_error gj_get_error(void);
00187 
00188 /************************************************************************/
00198 char *gj_trophies_fetch(bool achieved, const char *trophy_id);
00199 
00200 /************************************************************************/
00214 char *gj_trophy_get_next(char *pos, struct gj_trophy *trophy);
00215 
00216 /************************************************************************/
00223 bool gj_trophy_add_achieved(const char *trophy_id);
00224 
00225 /************************************************************************/
00232 bool gj_trophy_remove_achieved(const char *trophy_id);
00233 
00234 /************************************************************************/
00242 const char *gj_trophy_difficulty_str(enum gj_trophy_difficulty difficulty);
00243 
00244 /************************************************************************/
00251 bool gj_time(struct gj_time *time);
00252 
00253 /************************************************************************/
00268 char *gj_scores_fetch(const char *limit, const char *table_id,
00269                 const char *guest, const char *better_than,
00270                 const char *worse_than, bool only_user);
00271 
00272 /************************************************************************/
00286 char *gj_score_get_next(char *pos, struct gj_score *score);
00287 
00288 /************************************************************************/
00294 char *gj_scores_tables_fetch(void);
00295 
00296 /************************************************************************/
00310 char *gj_score_table_get_next(char *pos, struct gj_score_table *score_table);
00311 
00312 /************************************************************************/
00320 char *gj_scores_get_rank(const char *sort, const char *table_id);
00321 
00322 /************************************************************************/
00333 bool gj_scores_add(const char *score, const char *sort, const char *table_id,
00334                 const char *guest, const char *extra_data);
00335 
00336 /************************************************************************/
00346 bool gj_data_store_set(const char *key, const char *data, bool user_store);
00347 
00348 /************************************************************************/
00359 char *gj_data_store_keys_fetch(const char *pattern, bool user_store);
00360 
00361 /************************************************************************/
00375 char *gj_data_store_key_next(char *pos, char **key);
00376 
00377 /************************************************************************/
00387 char *data_store_fetch(const char *key, bool user_store);
00388 
00389 /************************************************************************/
00400 char *gj_data_store_update(const char *key,
00401                 enum gj_data_store_update_operation operation,
00402                 const char *value, bool user_store);
00403 
00404 /************************************************************************/
00413 bool gj_data_store_remove(const char *key, bool user_store);
00414 
00415 /************************************************************************/
00420 bool gj_sessions_open(void);
00421 
00422 /************************************************************************/
00430 bool gj_sessions_ping(bool active);
00431 
00432 /************************************************************************/
00446 bool gj_sessions_check(const char *username, const char *user_token);
00447 
00448 /************************************************************************/
00453 bool gj_sessions_close(void);
00454 
00455 /************************************************************************/
00468 char *gj_users_fetch(const char *username, const char *user_id);
00469 
00470 /************************************************************************/
00484 char *gj_user_get_next(char *pos, struct gj_user *user);
00485 
00486 /************************************************************************/
00495 bool gj_users_auth(void);
00496 
00497 /************************************************************************/
00503 char *gj_friends_fetch(void);
00504 
00505 /************************************************************************/
00519 char *gj_friend_get_next(char *pos, char **user_id);
00520 
00521 /************************************************************************/
00537 char *gj_request(const char **path, uint8_t num_paths, const char **key,
00538                 const char **value, uint8_t num_kv_pairs, uint32_t *out_len);
00539 
00540 #endif // MODULE_MEGAWIFI
00541 
00542 #endif /*_GAMEJOLT_H_*/
00543 
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines