diff --git a/src/SERVER/Makefile b/src/SERVER/Makefile index 44f583d3..305420ed 100644 --- a/src/SERVER/Makefile +++ b/src/SERVER/Makefile @@ -283,7 +283,7 @@ tests_run: fclean $(T_OBJ) tests_run: $(LIBS_DIR)/tinylibc/libtinylibc.a tests_run: $(LIBS_DIR)/circularbuffer/libcircularbuffer.a $(CC) $(T_OBJ) -o $(TTARGET) $(LDFLAGS) $(CFLAGS) - ./$(TTARGET) || exit 1 + ./$(TTARGET) -j1 || exit 1 gcovr --exclude-directories tests || true gcovr --exclude-directories tests --branch || true true diff --git a/src/SERVER/include/broadcast_events.h b/src/SERVER/include/broadcast_events.h index d2d3f906..a33c24d2 100644 --- a/src/SERVER/include/broadcast_events.h +++ b/src/SERVER/include/broadcast_events.h @@ -62,10 +62,10 @@ bool cmd_pgt(ntw_t *ntw, ntw_client_t *cl, action_t *action); /** ** @brief broadcast event pdi (player died) ** @param ntw -** @param cl +** @param id ** @return **/ -bool cmd_pdi(ntw_t *ntw, ntw_client_t *cl); +bool cmd_pdi(ntw_t *ntw, int id); /** ** @brief broadcast event enw (new egg) @@ -87,10 +87,10 @@ bool cmd_ebo(ntw_t *ntw, ntw_client_t *cl); /** ** @brief broadcast event edi (egg died) ** @param ntw -** @param cl +** @param id ** @return **/ -bool cmd_edi(ntw_t *ntw, ntw_client_t *cl); +bool cmd_edi(ntw_t *ntw, int id); /** ** @brief broadcast event smg (server message) diff --git a/src/SERVER/src/loop/loop.c b/src/SERVER/src/loop/loop.c index b5df95b7..a15156ae 100644 --- a/src/SERVER/src/loop/loop.c +++ b/src/SERVER/src/loop/loop.c @@ -83,9 +83,7 @@ static void update_trantoriens_available_food(ntw_t *ntw, if (trantorien == NULL) { continue; } - if (new_freq == true) { - update_food(ntw, trantorien, NULL, true); - } + update_food(ntw, trantorien, NULL, true); } } @@ -102,9 +100,9 @@ bool loop(zappy_t *zappy, bool new_freq) } status = update_client(zappy, cl, new_freq) & status; update_clients_connections(zappy->ntw); - if (L_DATAT(client_t *, client)->type == AI && new_freq == true) { + if (L_DATAT(client_t *, cl)->type == AI && new_freq == true) { update_food(zappy->ntw, - L_DATAT(client_t *, client)->cl.ai.trantorien, cl, false); + L_DATAT(client_t *, cl)->cl.ai.trantorien, cl, false); } } update_trantoriens_available_food(zappy->ntw, diff --git a/src/SERVER/src/loop/state_connected/graphic_cmd/cmd_edi.c b/src/SERVER/src/loop/state_connected/graphic_cmd/cmd_edi.c index 6b0fea63..613cd7dc 100644 --- a/src/SERVER/src/loop/state_connected/graphic_cmd/cmd_edi.c +++ b/src/SERVER/src/loop/state_connected/graphic_cmd/cmd_edi.c @@ -12,19 +12,14 @@ #include "internal.h" #include "client.h" -bool cmd_edi(ntw_t *ntw, ntw_client_t *cl) +bool cmd_edi(ntw_t *ntw, int id) { - client_t *client = NULL; char buff[512] = {0}; - if (ntw == NULL || cl == NULL) { + if (ntw == NULL) { return false; } - client = L_DATA(cl); - if (client == NULL) { - return false; - } - snprintf(buff, 511, "edi %d\n", client->id); - circular_buffer_write(cl->write_to_outside, buff); + snprintf(buff, 511, "edi %d\n", id); + broadcast_graphic(ntw, buff); return true; } diff --git a/src/SERVER/src/loop/state_connected/graphic_cmd/cmd_pdi.c b/src/SERVER/src/loop/state_connected/graphic_cmd/cmd_pdi.c index ab50939b..a44f75c1 100644 --- a/src/SERVER/src/loop/state_connected/graphic_cmd/cmd_pdi.c +++ b/src/SERVER/src/loop/state_connected/graphic_cmd/cmd_pdi.c @@ -12,16 +12,14 @@ #include "internal.h" #include "client.h" -bool cmd_pdi(ntw_t *ntw, ntw_client_t *cl) +bool cmd_pdi(ntw_t *ntw, int id) { char buff[512] = {0}; - client_t *client = NULL; - if (ntw == NULL || cl == NULL) { + if (ntw == NULL) { return false; } - client = L_DATA(cl); - snprintf(buff, 511, "pdi %d\n", client->id); + snprintf(buff, 511, "pdi %d\n", id); broadcast_graphic(ntw, buff); return true; } diff --git a/src/SERVER/src/loop/update_food.c b/src/SERVER/src/loop/update_food.c index 68e9dc13..8ee793a6 100644 --- a/src/SERVER/src/loop/update_food.c +++ b/src/SERVER/src/loop/update_food.c @@ -9,28 +9,25 @@ #include "client.h" #include "broadcast_events.h" -static void send_event_death(ntw_t *ntw, ntw_client_t *cl, bool is_an_egg) +static void send_event_death(ntw_t *ntw, int id, bool is_an_egg) { if (is_an_egg) { - cmd_edi(ntw, cl); + cmd_edi(ntw, id); } else { - cmd_pdi(ntw, cl); + cmd_pdi(ntw, id); } } void update_food(ntw_t *ntw, trantorien_t *trantorien, ntw_client_t *cl, bool is_an_egg) { - puts("update food");j if (trantorien == NULL || trantorien->alive == false) { return; } trantorien->food_stack_freq += 1; - printf("food stack freq: %d\n", trantorien->food_stack_freq); if (trantorien->food_stack_freq < MAX_FOOD_FREQ) { return; } - printf("ca update la food\n"); trantorien->food_stack_freq = 0; if (trantorien->ressources[FOOD] > 0) { trantorien->ressources[FOOD]--; @@ -38,7 +35,7 @@ ntw_client_t *cl, bool is_an_egg) trantorien->alive = false; if (cl) { circular_buffer_write(cl->write_to_outside, "dead\n"); - send_event_death(ntw, cl, is_an_egg); } + send_event_death(ntw, trantorien->id, is_an_egg); } } diff --git a/tests/SERVER/loop/events/event_edi_pdi.c b/tests/SERVER/loop/events/event_edi_pdi.c index 032b5d77..9a38552a 100644 --- a/tests/SERVER/loop/events/event_edi_pdi.c +++ b/tests/SERVER/loop/events/event_edi_pdi.c @@ -23,13 +23,13 @@ static void set_up_tests(zappy_t **zappy, int nb_client, int port, ntw_client_t **graphic) { static args_t args = { - .clients_per_teams = 0, - .teams_name = NULL, - .freq = 1000, - .height = 10, - .width = 10, - .is_ok = true, - .port = 0, + .clients_per_teams = 0, + .teams_name = NULL, + .freq = 1000, + .height = 10, + .width = 10, + .is_ok = true, + .port = 0, }; args.port = port; args.teams_name = list_create(); @@ -92,13 +92,13 @@ Test(loop_event_pdi, basic_pdi) while (circular_buffer_is_read_ready(client_e->write_to_outside) == false) { cr_assert_eq(loop(zappy, true), false); } - printf("result incantation = '%s'\n", circular_buffer_read(client_e->write_to_outside)); + cr_assert_str_eq(circular_buffer_read(client_e->write_to_outside), "Elevation underway\n"); snprintf(res, 511, "pic %d %d %d %d\n", c_e->cl.ai.trantorien->x, c_e->cl.ai.trantorien->y, c_e->cl.ai.trantorien->level, c_e->cl.ai.trantorien->id); cr_assert_str_eq(circular_buffer_read(graph->write_to_outside), res); while (circular_buffer_is_read_ready(client_e->write_to_outside) == false) { cr_assert_eq(loop(zappy, true), false); } - printf("result incantation = '%s'\n", circular_buffer_read(client_e->write_to_outside)); + cr_assert_str_eq(circular_buffer_read(client_e->write_to_outside), "dead\n"); memset(res, 0, 512); snprintf(res, 511, "pdi %d\n", c_e->cl.ai.trantorien->id); cr_assert_str_eq(circular_buffer_read(graph->write_to_outside), res); @@ -115,7 +115,7 @@ Test(loop_event_edi_pdi, basic_edi) cr_assert_not_null(client_e); client_t *c_e = L_DATA(client_e); cr_assert_not_null(c_e); - c_e->cl.ai.trantorien->ressources[FOOD] = 1; + c_e->cl.ai.trantorien->ressources[FOOD] = 10000; zappy->map->tiles[0].ressources[LINEMATE] = 1; c_e->cl.ai.trantorien->x = 0; c_e->cl.ai.trantorien->y = 0; @@ -123,10 +123,9 @@ Test(loop_event_edi_pdi, basic_edi) while (circular_buffer_is_read_ready(client_e->write_to_outside) == false) { cr_assert_eq(loop(zappy, true), false); } - printf("result fork = '%s'\n", circular_buffer_read(client_e->write_to_outside)); + cr_assert_str_eq(circular_buffer_read(client_e->write_to_outside), "ok\n"); snprintf(res, 511, "pfk %d\n", c_e->cl.ai.trantorien->id); cr_assert_str_eq(circular_buffer_read(graph->write_to_outside), res); - printf("len trantoriens available = %d\n", zappy->trantoriens_available->len); trantorien_t *trantorien = L_DATA(zappy->trantoriens_available->end); cr_assert_not_null(trantorien); memset(res, 0, 512); @@ -137,18 +136,18 @@ Test(loop_event_edi_pdi, basic_edi) while (circular_buffer_is_read_ready(client_e->write_to_outside) == false) { cr_assert_eq(loop(zappy, true), false); } - printf("result incantation = '%s'\n", circular_buffer_read(client_e->write_to_outside)); + cr_assert_str_eq(circular_buffer_read(client_e->write_to_outside), "Elevation underway\n"); memset(res, 0, 512); snprintf(res, 511, "pic %d %d %d %d\n", c_e->cl.ai.trantorien->x, c_e->cl.ai.trantorien->y, c_e->cl.ai.trantorien->level, c_e->cl.ai.trantorien->id); cr_assert_str_eq(circular_buffer_read(graph->write_to_outside), res); while (circular_buffer_is_read_ready(client_e->write_to_outside) == false) { cr_assert_eq(loop(zappy, true), false); } - printf("result incantation = '%s'\n", circular_buffer_read(client_e->write_to_outside)); + cr_assert_str_eq(circular_buffer_read(client_e->write_to_outside), "Current level: 2\n"); memset(res, 0, 512); - snprintf(res, 511, "pdi %d\n", c_e->cl.ai.trantorien->id); + snprintf(res, 511, "edi %d\n", trantorien->id); cr_assert_str_eq(circular_buffer_read(graph->write_to_outside), res); memset(res, 0, 512); - snprintf(res, 511, "edi %d\n", trantorien->id); + snprintf(res, 511, "pie %d %d %d\n", c_e->cl.ai.trantorien->x, c_e->cl.ai.trantorien->y, c_e->cl.ai.trantorien->level); cr_assert_str_eq(circular_buffer_read(graph->write_to_outside), res); }