Skip to content

Commit

Permalink
Merge branch 'ZAP-98-en-tant-que-graphic-je-veux-recevoir-les-eveneme…
Browse files Browse the repository at this point in the history
…nts' into SERVER-various-fix
  • Loading branch information
Saverio976 committed Jun 19, 2023
2 parents 0b7c634 + b2502fc commit 388e687
Show file tree
Hide file tree
Showing 65 changed files with 1,671 additions and 98 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -1007,3 +1007,5 @@ vgcore.*
!src/GUI/.clang-format
*.vscode/
*.idea
*.gcno
*.gcda
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ $(TARGET_server)_fclean: $(TARGET_server)_clean
$(MAKE) -C $(TARGET_server_DIR) fclean

$(TARGET_gui)_fclean: $(TARGET_gui)_clean
$(RM) $(TARGET_gui_DIR)/$(TARGET_gui)

$(TARGET_ai)_fclean: $(TARGET_ai)_clean
$(MAKE) -C $(TARGET_ai_DIR) fclean
Expand Down
9 changes: 6 additions & 3 deletions src/AI/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,16 @@ clean:
fclean: clean
pip uninstall --break-system-packages -y $(PIP_TARGET) || \
pip uninstall -y $(PIP_TARGET)
$(RM) $(LOCAL_DEPS)/requirements.txt
$(RM) $(TARGET)

fclean-simple: fclean
$(RM) $(LOCAL_DEPS)/requirements.txt
$(RM) -r $(LOCAL_DEPS)/simple
$(RM) $(LOCAL_DEPS)/*.whl

re: fclean all
re: fclean
re: all

re-simple: fclean-simple $(LOCAL_DEPS)/simple all
re-simple: fclean-simple
re-simple: $(LOCAL_DEPS)/simple
re-simple: all
19 changes: 17 additions & 2 deletions src/SERVER/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ SRC_LOOP_GRCMD = \
cmd_pin.c \
cmd_sgt.c \
cmd_sst.c \
cmd_pnw.c \
cmd_pex.c \
cmd_pbc.c \
cmd_pfk.c \
cmd_pdr.c \
cmd_pgt.c \
cmd_pdi.c \
cmd_enw.c \
cmd_ebo.c \
cmd_edi.c \
cmd_seg.c \
cmd_smg.c \
cmd_suc.c \
cmd_sbp.c \
update_graphic_cmd.c
SRC_LOOP_GRCMD := $(addprefix graphic_cmd/, $(SRC_LOOP_GRCMD))

Expand Down Expand Up @@ -186,6 +200,7 @@ SRC := \
get_id.c \
main.c \
on_new_conn.c \
zappy_check_end.c \
zappy_create_initial_egg.c \
zappy_destroy.c \
zappy_find_trantorien_by_id.c \
Expand All @@ -201,7 +216,7 @@ CC = gcc

TTARGET := bin_test

T_DIR := tests
T_DIR := ../../tests/SERVER

T_SRC := $(shell find $(T_DIR)/ -name '*.c' -type f) \
$(filter-out src/main.c, $(SRC))
Expand Down Expand Up @@ -268,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
Expand Down
125 changes: 125 additions & 0 deletions src/SERVER/include/broadcast_events.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
** EPITECH PROJECT, 2023
** ZappyCulteur
** File description:
** broadcast_events
*/

#ifndef BROADCAST_EVENTS_H_
#define BROADCAST_EVENTS_H_

/**
** @brief broadcast event pnw (new player)
** @param zappy
** @param cl
** @return bool
**/
bool cmd_pnw(ntw_t *ntw, ntw_client_t *cl);

/**
** @brief broadcast event pex (player expulse)
** @param ntw
** @param cl
** @return bool
**/
bool cmd_pex(ntw_t *ntw, ntw_client_t *cl, trantorien_t *tr);

/**
** @brief broadcast event pbc (player broadcast)
** @param ntw
** @param cl
** @param action
** @return bool
**/
bool cmd_pbc(ntw_t *ntw, ntw_client_t *cl, action_t *action);

/**
** @brief broadcast event pfk (player fork)
** @param ntw
** @param cl
** @return bool
**/
bool cmd_pfk(ntw_t *ntw, ntw_client_t *cl);

/**
** @brief broadcast event pdr (player drop ressource)
** @param ntw
** @param cl
** @param action
** @return bool
**/
bool cmd_pdr(ntw_t *ntw, ntw_client_t *cl, action_t *action);

/**
* @brief broadcast event pgt (player take ressource)
* @param ntw
* @param cl
* @param action
* @return
*/
bool cmd_pgt(ntw_t *ntw, ntw_client_t *cl, action_t *action);

/**
** @brief broadcast event pdi (player died)
** @param ntw
** @param id
** @return
**/
bool cmd_pdi(ntw_t *ntw, int id);

/**
** @brief broadcast event enw (new egg)
** @param ntw
** @param tr (trantorien)
** @param parent (parent trantorien)
** @return bool
**/
bool cmd_enw(ntw_t *ntw, trantorien_t *tr, trantorien_t *parent);

/**
** @brief broadcast event eht (egg hatched)
** @param ntw
** @param cl
** @return
**/
bool cmd_ebo(ntw_t *ntw, ntw_client_t *cl);

/**
** @brief broadcast event edi (egg died)
** @param ntw
** @param id
** @return
**/
bool cmd_edi(ntw_t *ntw, int id);

/**
** @brief broadcast event smg (server message)
** @param ntw
** @param smg
** @return
**/
bool cmd_smg(ntw_t *ntw, const char *smg);

/**
** @brief broadcast event seg (end game)
** @param ntw
** @param cl
** @return
**/
bool cmd_seg(ntw_t *ntw, client_t *cl);

/**
** @brief broadcast event suc (success)
** @param cl
** @return
**/
bool cmd_suc(ntw_client_t *cl);

/**
** @brief broadcast event sbp (error)
** @param cl
** @return
**/
bool cmd_sbp(ntw_client_t *cl);

#endif // BROADCAST_EVENTS_H_
5 changes: 5 additions & 0 deletions src/SERVER/include/trantorien.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ typedef struct zappy_s zappy_t;
void trantorien_reduce_freq(trantorien_t *trantorien, zappy_t *zappy,
ntw_client_t *cl);

/**
** @brief Destroy an action
** @param action
**/
void action_destroy(action_t *action);

/**
** @brief Get the min case for the look around wiht substration
Expand Down
8 changes: 8 additions & 0 deletions src/SERVER/include/zappy.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct zappy_s {
size_t cur_tick;
size_t before_add_resources;
list_t *trantoriens_available;
bool is_end;
};
typedef struct zappy_s zappy_t;

Expand Down Expand Up @@ -95,4 +96,11 @@ bool broadcast_graphic(ntw_t *ntw, const char *msg);
**/
list_t *zappy_create_initial_egg(args_t *args);

/**
** @brief Check if the game is ended
** @param zappy
** @return true if the game is ended
**/
bool check_end(zappy_t *zappy, bool is_end);

#endif
2 changes: 1 addition & 1 deletion src/SERVER/src/broadcast_graphic.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#include <stdbool.h>
#include "circular_buffer.h"
#include "client.h"
#include "ntw.h"
#include "client.h"

bool broadcast_graphic(ntw_t *ntw, const char *msg)
{
Expand Down
6 changes: 4 additions & 2 deletions src/SERVER/src/loop/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ void send_id(client_t *cc, ntw_client_t *cl);

/**
** @brief update food for every trantoriens, associated or not with clients
** @param ntw
** @param trantorien
** @param cl
** @param new_freq
** @param is_and_egg
**/
void update_food(trantorien_t *trantorien, ntw_client_t *cl, bool new_freq);
void update_food(ntw_t *ntw, trantorien_t *trantorien,
ntw_client_t *cl, bool is_and_egg);

// Update in states

Expand Down
16 changes: 9 additions & 7 deletions src/SERVER/src/loop/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ static void check_ressources(zappy_t *zappy, bool new_freq)
}
}

static void update_trantoriens_available_food(list_t *trantoriens_available,
bool new_freq)
static void update_trantoriens_available_food(ntw_t *ntw,
list_t *trantoriens_available, bool new_freq)
{
trantorien_t *trantorien = NULL;

Expand All @@ -83,7 +83,7 @@ static void update_trantoriens_available_food(list_t *trantoriens_available,
if (trantorien == NULL) {
continue;
}
update_food(trantorien, NULL, new_freq);
update_food(ntw, trantorien, NULL, true);
}
}

Expand All @@ -100,11 +100,13 @@ 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) {
update_food(L_DATAT(client_t *, client)->cl.ai.trantorien,
cl, new_freq);
if (L_DATAT(client_t *, cl)->type == AI && new_freq == true) {
update_food(zappy->ntw,
L_DATAT(client_t *, cl)->cl.ai.trantorien, cl, false);
}
}
update_trantoriens_available_food(zappy->trantoriens_available, new_freq);
update_trantoriens_available_food(zappy->ntw,
zappy->trantoriens_available, new_freq);
check_end(zappy, status);
return !status;
}
4 changes: 3 additions & 1 deletion src/SERVER/src/loop/state_connected/ai_cmd/cmd_fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
#include "zappy.h"
#include "internal.h"
#include "trantorien.h"
#include "broadcast_events.h"

bool cmd_fork(__attribute__((unused)) zappy_t *zappy, ntw_client_t *cl,
bool cmd_fork(zappy_t *zappy, ntw_client_t *cl,
__attribute__((unused)) char **cmd_split)
{
client_t *cc = cl->data;

if (trantorien_add_act(cc->cl.ai.trantorien, FORK) == false) {
return false;
}
cmd_pfk(zappy->ntw, cl);
return true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "zappy.h"
#include "internal.h"
#include "trantorien.h"
#include "broadcast_events.h"

bool cmd_incantation(__attribute__((unused)) zappy_t *zappy, ntw_client_t *cl,
__attribute__((unused)) char **cmd_split)
Expand Down
3 changes: 1 addition & 2 deletions src/SERVER/src/loop/state_connected/graphic_cmd/cmd_bct.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ntw.h"
#include "circular_buffer.h"
#include "ntw.h"
#include "map.h"
#include "internal.h"
#include "zappy.h"

static bool send_pos(ntw_client_t *cl, int x, int y)
{
Expand Down
27 changes: 27 additions & 0 deletions src/SERVER/src/loop/state_connected/graphic_cmd/cmd_ebo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
** EPITECH PROJECT, 2023
** ZappyCulteur
** File description:
** cmd_ebo
*/

#include <stdbool.h>
#include <stdio.h>
#include "ntw.h"
#include "map.h"
#include "internal.h"
#include "client.h"

bool cmd_ebo(ntw_t *ntw, ntw_client_t *cl)
{
char buff[512] = {0};
client_t *client = NULL;

if (ntw == NULL || cl == NULL) {
return false;
}
client = L_DATA(cl);
snprintf(buff, 511, "ebo %d\n", client->id);
broadcast_graphic(ntw, buff);
return true;
}
25 changes: 25 additions & 0 deletions src/SERVER/src/loop/state_connected/graphic_cmd/cmd_edi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
** EPITECH PROJECT, 2023
** ZappyCulteur
** File description:
** cmd_edi
*/

#include <stdbool.h>
#include <stdio.h>
#include "ntw.h"
#include "map.h"
#include "internal.h"
#include "client.h"

bool cmd_edi(ntw_t *ntw, int id)
{
char buff[512] = {0};

if (ntw == NULL) {
return false;
}
snprintf(buff, 511, "edi %d\n", id);
broadcast_graphic(ntw, buff);
return true;
}
Loading

0 comments on commit 388e687

Please sign in to comment.