diff --git a/include/hunter.h b/include/hunter.h index 2d74cbe..192a556 100644 --- a/include/hunter.h +++ b/include/hunter.h @@ -15,6 +15,9 @@ #define AMMO_COUNT 3 #define FRAMERATE 144 #define MICRO_TO_SEC(time) time.microseconds / 1000000.0 + #define API_HOST "http://localhost" + #define API_PORT 3000 + #define API_TIMEOUT 2000000 typedef struct { sfTexture *texture; diff --git a/src/score_manager.c b/src/score_manager.c index 553d1e2..e50c90f 100644 --- a/src/score_manager.c +++ b/src/score_manager.c @@ -14,16 +14,17 @@ int get_score(hunterinfo_t *hf) sfHttp *http = sfHttp_create(); sfHttpRequest *req = sfHttpRequest_create(); sfHttpResponse *res; - sfTime timeout = (sfTime){ .microseconds = 0 }; + sfTime timeout = (sfTime){ .microseconds = API_TIMEOUT }; char const *body; sfHttpRequest_setMethod(req, sfHttpGet); sfHttpRequest_setUri(req, "/score"); - sfHttp_setHost(http, "http://localhost", 3000); + sfHttp_setHost(http, API_HOST, API_PORT); res = sfHttp_sendRequest(http, req, timeout); body = sfHttpResponse_getBody(res); hf->high_score = my_getnbr(body); - my_printf("%d\n", hf->high_score); + my_printf("Get score from %s:%d\nAPI response: %d\n", API_HOST, API_PORT, + hf->high_score); return EXIT_SUCCESS; } @@ -32,7 +33,7 @@ int post_score(hunterinfo_t *hf) sfHttp *http = sfHttp_create(); sfHttpRequest *req = sfHttpRequest_create(); sfHttpResponse *res; - sfTime timeout = (sfTime){ .microseconds = 0 }; + sfTime timeout = (sfTime){ .microseconds = API_TIMEOUT }; char score[10]; char *uri = "/score?score="; char const *body; @@ -41,9 +42,10 @@ int post_score(hunterinfo_t *hf) my_numstr(score, hf->score); sfHttpRequest_setUri(req, my_strcat(uri, score)); sfHttpRequest_setBody(req, score); - sfHttp_setHost(http, "http://localhost", 3000); + sfHttp_setHost(http, API_HOST, API_PORT); res = sfHttp_sendRequest(http, req, timeout); body = sfHttpResponse_getBody(res); - my_printf("%s\n", body); + my_printf("Post score to %s:%d\nAPI response: %s\n", API_HOST, API_PORT, + body); return EXIT_SUCCESS; }