C / C++ (any engine)Tested
A small C99 library for proprietary and custom engines. It starts no threads, allocates little, and lets you bring your own HTTP stack.
Design
- No threads: call
rean_tick()every frame (or every 50–100 ms). All callbacks run inside it, on your thread. - Pluggable HTTP: a non-blocking libcurl transport is included (
rean_transport_curl()). On consoles or with your engine's HTTP, implement the 3-functionrean_transportinstead. - No other dependencies: JSON parsing is built in.
- Tested end to end against the REAN API over real HTTP, with AddressSanitizer and UBSan, on gcc and clang; the header also compiles as C++.
Build
Download rean-sdk-c-0.1.0.zip, then:
cmake -S rean-sdk-c -B build -DREAN_WITH_CURL=ON
cmake --build build
# or just add src/*.c and include/ to your engine's buildUsage
#include <rean/rean.h>
static void on_signed_in(void *ud, rean_result r, const rean_user *user, const char *msg) {
if (r == REAN_OK) printf("Hi %s\n", user->display_name);
else printf("Sign-in failed: %s (%s)\n", msg, rean_result_string(r));
}
static void show_code(void *ud, const char *code, const char *uri, const char *uri_full, int expires) {
printf("Go to %s and enter %s\n", uri, code);
}
static void save_session(void *ud, const char *refresh_token) {
secure_store_put("rean", refresh_token); /* NULL = signed out: delete it */
}
int main(int argc, char **argv) {
curl_global_init(CURL_GLOBAL_DEFAULT);
rean_config cfg = {0};
cfg.client_id = "rean_xxxxxxxxxxxxxxxxxxxxxxxx";
cfg.transport = rean_transport_curl();
rean_client *rean = rean_create(&cfg);
rean_set_session_callback(rean, save_session, NULL);
const char *launcher = rean_launcher_code_from_args(argc, argv);
const char *saved = secure_store_get("rean");
if (launcher) rean_sign_in_with_launcher(rean, launcher, on_signed_in, NULL);
else if (saved) rean_sign_in_with_refresh_token(rean, saved, on_signed_in, NULL);
else rean_sign_in_with_device(rean, show_code, on_signed_in, NULL);
while (game_running()) {
rean_tick(rean);
/* … your frame … */
}
rean_destroy(rean);
}rean_activity a;
rean_activity_init(&a); /* party sizes = -1 (not set) */
a.details = "Ranked";
a.state = "Round 3";
a.party_id = lobby_id;
a.party_size = 2; a.party_max = 5; a.joinable = 1;
rean_set_activity(rean, &a); /* kept alive by rean_tick */
rean_get_friends(rean, on_friends, NULL);
rean_set_event_callback(rean, on_event, NULL, 0); /* invites, every 10 s */
rean_send_invite(rean, friend_id, lobby_id, "Join me", on_sent, NULL);
rean_respond_to_invite(rean, invite_id, 1, on_join, NULL);Your own HTTP
typedef struct rean_transport {
void *user;
int (*send)(void *user, const rean_http_request *req, rean_http_complete complete, void *context);
void (*poll)(void *user); /* called from rean_tick: call complete() for finished requests */
void (*destroy)(void *user); /* drop pending requests without calling complete() */
} rean_transport;Call complete(context, status, body, length) exactly once per request, with status 0 for a network error, and never from inside send.