├── test.txt ├── client ├── graphic ├── server ├── font ├── font.ttf ├── test.ttf ├── BEBAS___.TTF └── font_gui.ttf ├── sprites ├── egg.bmp ├── gui.bmp ├── kik.bmp ├── lay.bmp ├── map.bmp ├── drop.bmp ├── items.bmp ├── link.bmp ├── moves.bmp └── incant.bmp ├── src_common ├── rw.o ├── stop.o ├── error.o ├── getline.o ├── getnbr.o ├── nbr_str.o ├── parse.o ├── select.o ├── circular.o ├── str_to_wordtab.o ├── getnbr.c ├── stop.c ├── error.c ├── getline.c ├── select.c ├── rw.c ├── nbr_str.c ├── circular.c ├── str_to_wordtab.c └── parse.c ├── src_server ├── map.o ├── read.o ├── action.o ├── connect.o ├── server.o ├── signal.o ├── update.o ├── write.o ├── check_fds.o ├── exec_bct.o ├── exec_ebo.o ├── exec_edi.o ├── exec_eht.o ├── exec_enw.o ├── exec_fork.o ├── exec_left.o ├── exec_look.o ├── exec_mct.o ├── exec_msz.o ├── exec_pbc.o ├── exec_pdi.o ├── exec_pdr.o ├── exec_pex.o ├── exec_pfk.o ├── exec_pgt.o ├── exec_pic.o ├── exec_pie.o ├── exec_pin.o ├── exec_plv.o ├── exec_pnw.o ├── exec_ppo.o ├── exec_push.o ├── exec_put.o ├── exec_sbp.o ├── exec_seg.o ├── exec_sgt.o ├── exec_sst.o ├── exec_suc.o ├── exec_take.o ├── exec_tna.o ├── list_egg.o ├── list_team.o ├── check_action.o ├── check_cmds.o ├── check_fork.o ├── close_server.o ├── exec_forward.o ├── exec_right.o ├── get_params.o ├── list_client.o ├── orientation.o ├── check_graphic.o ├── exec_broadcast.o ├── exec_elevation.o ├── exec_inventory.o ├── check_elevation.o ├── exec_connect_nbr.o ├── open_to_clients.o ├── check_fork.c ├── exec_fork.c ├── exec_sbp.c ├── exec_suc.c ├── exec_sgt.c ├── exec_sst.c ├── exec_connect_nbr.c ├── exec_right.c ├── exec_left.c ├── exec_pdi.c ├── exec_pex.c ├── exec_pfk.c ├── exec_ebo.c ├── exec_edi.c ├── exec_eht.c ├── exec_msz.c ├── exec_seg.c ├── exec_pdr.c ├── exec_pgt.c ├── exec_elevation.c ├── exec_pbc.c ├── exec_pie.c ├── signal.c ├── close_server.c ├── exec_mct.c ├── check_action.c ├── exec_put.c ├── exec_forward.c ├── open_to_clients.c ├── exec_pnw.c ├── exec_plv.c ├── exec_tna.c ├── get_params_fct.c ├── exec_bct.c ├── exec_inventory.c ├── read.c ├── check_graphic.c ├── exec_enw.c ├── list_team.c ├── exec_broadcast.c ├── exec_pic.c ├── exec_ppo.c ├── exec_take.c ├── connect.c ├── orientation.c ├── exec_pin.c ├── write.c ├── map.c ├── exec_push.c ├── list_egg.c ├── list_client.c ├── get_params.c ├── server.c ├── check_elevation.c ├── check_cmds.c ├── exec_look.c └── action.c ├── src_client ├── client.o ├── signal.o ├── check_fds.o ├── send_cmd.o ├── check_cmds.o ├── close_client.o ├── get_params.o ├── list_action.o ├── manual_action.o ├── connect_to_server.o ├── termcaps_functions.o ├── manual_action.c~ ├── termcaps_functions.c~ ├── signal.c ├── close_client.c ├── connect_to_server.c ├── get_params.c ├── check_cmds.c ├── termcaps_functions.c ├── check_fds.c ├── client.c ├── send_cmd.c └── list_action.c ├── src_graphic ├── anim.o ├── event.o ├── signal.o ├── bct_cmd.o ├── disp_gui.o ├── disp_map.o ├── ebo_cmd.o ├── edi_cmd.o ├── eht_cmd.o ├── enw_cmd.o ├── graphic.o ├── init_sdl.o ├── is_anim.o ├── msz_cmd.o ├── pbc_cmd.o ├── pdi_cmd.o ├── pdr_cmd.o ├── pex_cmd.o ├── pfk_cmd.o ├── pgt_cmd.o ├── pic_cmd.o ├── pie_cmd.o ├── pin_cmd.o ├── plv_cmd.o ├── pnw_cmd.o ├── ppo_cmd.o ├── sbp_cmd.o ├── seg_cmd.o ├── sgt_cmd.o ├── smg_cmd.o ├── suc_cmd.o ├── tna_cmd.o ├── check_cmds.o ├── check_egg.o ├── check_fds.o ├── check_team.o ├── disp_eggs.o ├── disp_items.o ├── disp_player.o ├── display_sdl.o ├── get_params.o ├── list_eggs.o ├── map_update.o ├── check_player.o ├── close_graphic.o ├── list_clients.o ├── get_click_coord.o ├── get_team_by_name.o ├── connect_to_server.o ├── smg_cmd.c ├── sbp_cmd.c ├── suc_cmd.c ├── sgt_cmd.c ├── ebo_cmd.c ├── seg_cmd.c ├── pdi_cmd.c ├── is_anim.c ├── edi_cmd.c ├── pbc_cmd.c ├── get_team_by_name.c ├── check_egg.c ├── eht_cmd.c ├── check_player.c ├── pex_cmd.c ├── pfk_cmd.c ├── pdr_cmd.c ├── pgt_cmd.c ├── check_team.c ├── plv_cmd.c ├── signal.c ├── get_click_coord.c ├── bct_cmd.c ├── connect_to_server.c ├── disp_eggs.c ├── pin_cmd.c ├── map_update.c ├── pie_cmd.c ├── get_params.c ├── pic_cmd.c ├── event.c ├── close_graphic.c ├── tna_cmd.c ├── ppo_cmd.c ├── enw_cmd.c ├── disp_map.c ├── pnw_cmd.c ├── display_sdl.c ├── msz_cmd.c ├── list_eggs.c ├── graphic.c ├── disp_player.c ├── check_fds.c ├── list_clients.c ├── check_cmds.c ├── disp_items.c ├── init_sdl.c ├── anim.c └── disp_gui.c ├── .gitattributes ├── inc ├── pointer_to_func.h ├── error.h ├── gui.h ├── common.h ├── protocol.h └── client.h └── .gitignore /test.txt: -------------------------------------------------------------------------------- 1 | test 2 | ok 3 | -------------------------------------------------------------------------------- /client: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/client -------------------------------------------------------------------------------- /graphic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/graphic -------------------------------------------------------------------------------- /server: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/server -------------------------------------------------------------------------------- /font/font.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/font/font.ttf -------------------------------------------------------------------------------- /font/test.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/font/test.ttf -------------------------------------------------------------------------------- /sprites/egg.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/sprites/egg.bmp -------------------------------------------------------------------------------- /sprites/gui.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/sprites/gui.bmp -------------------------------------------------------------------------------- /sprites/kik.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/sprites/kik.bmp -------------------------------------------------------------------------------- /sprites/lay.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/sprites/lay.bmp -------------------------------------------------------------------------------- /sprites/map.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/sprites/map.bmp -------------------------------------------------------------------------------- /src_common/rw.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_common/rw.o -------------------------------------------------------------------------------- /font/BEBAS___.TTF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/font/BEBAS___.TTF -------------------------------------------------------------------------------- /font/font_gui.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/font/font_gui.ttf -------------------------------------------------------------------------------- /sprites/drop.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/sprites/drop.bmp -------------------------------------------------------------------------------- /sprites/items.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/sprites/items.bmp -------------------------------------------------------------------------------- /sprites/link.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/sprites/link.bmp -------------------------------------------------------------------------------- /sprites/moves.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/sprites/moves.bmp -------------------------------------------------------------------------------- /src_common/stop.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_common/stop.o -------------------------------------------------------------------------------- /src_server/map.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/map.o -------------------------------------------------------------------------------- /src_server/read.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/read.o -------------------------------------------------------------------------------- /sprites/incant.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/sprites/incant.bmp -------------------------------------------------------------------------------- /src_client/client.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_client/client.o -------------------------------------------------------------------------------- /src_client/signal.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_client/signal.o -------------------------------------------------------------------------------- /src_common/error.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_common/error.o -------------------------------------------------------------------------------- /src_common/getline.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_common/getline.o -------------------------------------------------------------------------------- /src_common/getnbr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_common/getnbr.o -------------------------------------------------------------------------------- /src_common/nbr_str.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_common/nbr_str.o -------------------------------------------------------------------------------- /src_common/parse.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_common/parse.o -------------------------------------------------------------------------------- /src_common/select.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_common/select.o -------------------------------------------------------------------------------- /src_graphic/anim.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/anim.o -------------------------------------------------------------------------------- /src_graphic/event.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/event.o -------------------------------------------------------------------------------- /src_graphic/signal.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/signal.o -------------------------------------------------------------------------------- /src_server/action.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/action.o -------------------------------------------------------------------------------- /src_server/connect.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/connect.o -------------------------------------------------------------------------------- /src_server/server.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/server.o -------------------------------------------------------------------------------- /src_server/signal.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/signal.o -------------------------------------------------------------------------------- /src_server/update.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/update.o -------------------------------------------------------------------------------- /src_server/write.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/write.o -------------------------------------------------------------------------------- /src_client/check_fds.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_client/check_fds.o -------------------------------------------------------------------------------- /src_client/send_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_client/send_cmd.o -------------------------------------------------------------------------------- /src_common/circular.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_common/circular.o -------------------------------------------------------------------------------- /src_graphic/bct_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/bct_cmd.o -------------------------------------------------------------------------------- /src_graphic/disp_gui.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/disp_gui.o -------------------------------------------------------------------------------- /src_graphic/disp_map.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/disp_map.o -------------------------------------------------------------------------------- /src_graphic/ebo_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/ebo_cmd.o -------------------------------------------------------------------------------- /src_graphic/edi_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/edi_cmd.o -------------------------------------------------------------------------------- /src_graphic/eht_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/eht_cmd.o -------------------------------------------------------------------------------- /src_graphic/enw_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/enw_cmd.o -------------------------------------------------------------------------------- /src_graphic/graphic.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/graphic.o -------------------------------------------------------------------------------- /src_graphic/init_sdl.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/init_sdl.o -------------------------------------------------------------------------------- /src_graphic/is_anim.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/is_anim.o -------------------------------------------------------------------------------- /src_graphic/msz_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/msz_cmd.o -------------------------------------------------------------------------------- /src_graphic/pbc_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/pbc_cmd.o -------------------------------------------------------------------------------- /src_graphic/pdi_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/pdi_cmd.o -------------------------------------------------------------------------------- /src_graphic/pdr_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/pdr_cmd.o -------------------------------------------------------------------------------- /src_graphic/pex_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/pex_cmd.o -------------------------------------------------------------------------------- /src_graphic/pfk_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/pfk_cmd.o -------------------------------------------------------------------------------- /src_graphic/pgt_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/pgt_cmd.o -------------------------------------------------------------------------------- /src_graphic/pic_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/pic_cmd.o -------------------------------------------------------------------------------- /src_graphic/pie_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/pie_cmd.o -------------------------------------------------------------------------------- /src_graphic/pin_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/pin_cmd.o -------------------------------------------------------------------------------- /src_graphic/plv_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/plv_cmd.o -------------------------------------------------------------------------------- /src_graphic/pnw_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/pnw_cmd.o -------------------------------------------------------------------------------- /src_graphic/ppo_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/ppo_cmd.o -------------------------------------------------------------------------------- /src_graphic/sbp_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/sbp_cmd.o -------------------------------------------------------------------------------- /src_graphic/seg_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/seg_cmd.o -------------------------------------------------------------------------------- /src_graphic/sgt_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/sgt_cmd.o -------------------------------------------------------------------------------- /src_graphic/smg_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/smg_cmd.o -------------------------------------------------------------------------------- /src_graphic/suc_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/suc_cmd.o -------------------------------------------------------------------------------- /src_graphic/tna_cmd.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/tna_cmd.o -------------------------------------------------------------------------------- /src_server/check_fds.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/check_fds.o -------------------------------------------------------------------------------- /src_server/exec_bct.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_bct.o -------------------------------------------------------------------------------- /src_server/exec_ebo.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_ebo.o -------------------------------------------------------------------------------- /src_server/exec_edi.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_edi.o -------------------------------------------------------------------------------- /src_server/exec_eht.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_eht.o -------------------------------------------------------------------------------- /src_server/exec_enw.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_enw.o -------------------------------------------------------------------------------- /src_server/exec_fork.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_fork.o -------------------------------------------------------------------------------- /src_server/exec_left.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_left.o -------------------------------------------------------------------------------- /src_server/exec_look.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_look.o -------------------------------------------------------------------------------- /src_server/exec_mct.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_mct.o -------------------------------------------------------------------------------- /src_server/exec_msz.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_msz.o -------------------------------------------------------------------------------- /src_server/exec_pbc.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_pbc.o -------------------------------------------------------------------------------- /src_server/exec_pdi.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_pdi.o -------------------------------------------------------------------------------- /src_server/exec_pdr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_pdr.o -------------------------------------------------------------------------------- /src_server/exec_pex.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_pex.o -------------------------------------------------------------------------------- /src_server/exec_pfk.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_pfk.o -------------------------------------------------------------------------------- /src_server/exec_pgt.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_pgt.o -------------------------------------------------------------------------------- /src_server/exec_pic.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_pic.o -------------------------------------------------------------------------------- /src_server/exec_pie.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_pie.o -------------------------------------------------------------------------------- /src_server/exec_pin.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_pin.o -------------------------------------------------------------------------------- /src_server/exec_plv.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_plv.o -------------------------------------------------------------------------------- /src_server/exec_pnw.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_pnw.o -------------------------------------------------------------------------------- /src_server/exec_ppo.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_ppo.o -------------------------------------------------------------------------------- /src_server/exec_push.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_push.o -------------------------------------------------------------------------------- /src_server/exec_put.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_put.o -------------------------------------------------------------------------------- /src_server/exec_sbp.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_sbp.o -------------------------------------------------------------------------------- /src_server/exec_seg.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_seg.o -------------------------------------------------------------------------------- /src_server/exec_sgt.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_sgt.o -------------------------------------------------------------------------------- /src_server/exec_sst.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_sst.o -------------------------------------------------------------------------------- /src_server/exec_suc.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_suc.o -------------------------------------------------------------------------------- /src_server/exec_take.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_take.o -------------------------------------------------------------------------------- /src_server/exec_tna.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_tna.o -------------------------------------------------------------------------------- /src_server/list_egg.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/list_egg.o -------------------------------------------------------------------------------- /src_server/list_team.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/list_team.o -------------------------------------------------------------------------------- /src_client/check_cmds.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_client/check_cmds.o -------------------------------------------------------------------------------- /src_client/close_client.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_client/close_client.o -------------------------------------------------------------------------------- /src_client/get_params.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_client/get_params.o -------------------------------------------------------------------------------- /src_client/list_action.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_client/list_action.o -------------------------------------------------------------------------------- /src_graphic/check_cmds.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/check_cmds.o -------------------------------------------------------------------------------- /src_graphic/check_egg.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/check_egg.o -------------------------------------------------------------------------------- /src_graphic/check_fds.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/check_fds.o -------------------------------------------------------------------------------- /src_graphic/check_team.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/check_team.o -------------------------------------------------------------------------------- /src_graphic/disp_eggs.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/disp_eggs.o -------------------------------------------------------------------------------- /src_graphic/disp_items.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/disp_items.o -------------------------------------------------------------------------------- /src_graphic/disp_player.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/disp_player.o -------------------------------------------------------------------------------- /src_graphic/display_sdl.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/display_sdl.o -------------------------------------------------------------------------------- /src_graphic/get_params.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/get_params.o -------------------------------------------------------------------------------- /src_graphic/list_eggs.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/list_eggs.o -------------------------------------------------------------------------------- /src_graphic/map_update.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/map_update.o -------------------------------------------------------------------------------- /src_server/check_action.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/check_action.o -------------------------------------------------------------------------------- /src_server/check_cmds.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/check_cmds.o -------------------------------------------------------------------------------- /src_server/check_fork.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/check_fork.o -------------------------------------------------------------------------------- /src_server/close_server.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/close_server.o -------------------------------------------------------------------------------- /src_server/exec_forward.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_forward.o -------------------------------------------------------------------------------- /src_server/exec_right.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_right.o -------------------------------------------------------------------------------- /src_server/get_params.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/get_params.o -------------------------------------------------------------------------------- /src_server/list_client.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/list_client.o -------------------------------------------------------------------------------- /src_server/orientation.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/orientation.o -------------------------------------------------------------------------------- /src_client/manual_action.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_client/manual_action.o -------------------------------------------------------------------------------- /src_common/str_to_wordtab.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_common/str_to_wordtab.o -------------------------------------------------------------------------------- /src_graphic/check_player.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/check_player.o -------------------------------------------------------------------------------- /src_graphic/close_graphic.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/close_graphic.o -------------------------------------------------------------------------------- /src_graphic/list_clients.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/list_clients.o -------------------------------------------------------------------------------- /src_server/check_graphic.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/check_graphic.o -------------------------------------------------------------------------------- /src_server/exec_broadcast.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_broadcast.o -------------------------------------------------------------------------------- /src_server/exec_elevation.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_elevation.o -------------------------------------------------------------------------------- /src_server/exec_inventory.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_inventory.o -------------------------------------------------------------------------------- /src_client/connect_to_server.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_client/connect_to_server.o -------------------------------------------------------------------------------- /src_graphic/get_click_coord.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/get_click_coord.o -------------------------------------------------------------------------------- /src_graphic/get_team_by_name.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/get_team_by_name.o -------------------------------------------------------------------------------- /src_server/check_elevation.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/check_elevation.o -------------------------------------------------------------------------------- /src_server/exec_connect_nbr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/exec_connect_nbr.o -------------------------------------------------------------------------------- /src_server/open_to_clients.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_server/open_to_clients.o -------------------------------------------------------------------------------- /src_client/termcaps_functions.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_client/termcaps_functions.o -------------------------------------------------------------------------------- /src_graphic/connect_to_server.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kefranabg/Zappy/master/src_graphic/connect_to_server.o -------------------------------------------------------------------------------- /src_client/manual_action.c~: -------------------------------------------------------------------------------- 1 | /* 2 | ** manual_action.c for manual_action.c in /home/acca_b/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by Baptiste Acca 5 | ** Login 6 | ** 7 | ** Started on Thu Jul 10 15:57:07 2014 Baptiste Acca 8 | ** Last update Thu Jul 10 15:57:10 2014 Baptiste Acca 9 | */ 10 | 11 | #include "projet.h" 12 | 13 | void projet_fonction() 14 | { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src_client/termcaps_functions.c~: -------------------------------------------------------------------------------- 1 | /* 2 | ** termcaps_functions.c for termcaps_functions.c in /home/acca_b/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by Baptiste Acca 5 | ** Login 6 | ** 7 | ** Started on Thu Jul 10 16:09:59 2014 Baptiste Acca 8 | ** Last update Thu Jul 10 16:10:11 2014 Baptiste Acca 9 | */ 10 | 11 | 12 | #include "client.h" 13 | 14 | void projet_fonction() 15 | { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src_server/check_fork.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** check_fork.c for check_fork.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Wed Jun 11 17:09:55 2014 LOEB Thomas 8 | ** Last update Thu Jun 12 15:59:15 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool check_fork(t_server *s) 14 | { 15 | exec_pfk(s); 16 | return (TRUE); 17 | } 18 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /src_graphic/smg_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** smg_cmd.c for smg_cmd.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Wed Jun 25 12:46:13 2014 abgral_f 8 | ** Last update Wed Jun 25 12:56:25 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int smg_cmd(char **args, 14 | __attribute__((unused))t_graphic *c) 15 | { 16 | printf("Server say : %s\n", args[0]); 17 | return (SUCCESS); 18 | } 19 | -------------------------------------------------------------------------------- /src_graphic/sbp_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** sbp_cmd.c for sbp_cmd.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Wed Jun 25 12:49:58 2014 abgral_f 8 | ** Last update Wed Jun 25 12:57:06 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int sbp_cmd(__attribute__((unused))char **args, 14 | __attribute__((unused))t_graphic *c) 15 | { 16 | printf("Wrong parameters\n"); 17 | return (SUCCESS); 18 | } 19 | -------------------------------------------------------------------------------- /src_server/exec_fork.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_forward.c for exec_forward.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Fri May 30 13:21:25 2014 LOEB Thomas 8 | ** Last update Thu Jun 12 16:00:57 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_fork(t_server *s) 14 | { 15 | add_egg(s); 16 | strcpy(s->tmp_clients->send, OK("\n")); 17 | exec_enw(s); 18 | return (FALSE); 19 | } 20 | -------------------------------------------------------------------------------- /src_graphic/suc_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** suc_cmd.c for suc_cmd.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Wed Jun 25 12:48:15 2014 abgral_f 8 | ** Last update Wed Jun 25 12:56:55 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int suc_cmd(__attribute__((unused))char **args, 14 | __attribute__((unused))t_graphic *c) 15 | { 16 | printf("Undefined command\n"); 17 | return (SUCCESS); 18 | } 19 | -------------------------------------------------------------------------------- /src_server/exec_sbp.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_sbp.c for exec_sbp.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Thu Jun 12 16:47:34 2014 LOEB Thomas 8 | ** Last update Thu Jun 12 16:47:54 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_sbp(t_server *s) 14 | { 15 | if (write_graphic(s) == FAILURE) 16 | return (FALSE); 17 | strcpy(s->graphic->send, (SBP"\n")); 18 | return (TRUE); 19 | } 20 | -------------------------------------------------------------------------------- /src_server/exec_suc.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_suc.c for exec_suc.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Thu Jun 12 16:46:26 2014 LOEB Thomas 8 | ** Last update Thu Jun 12 16:47:22 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_suc(t_server *s) 14 | { 15 | if (write_graphic(s) == FAILURE) 16 | return (FALSE); 17 | strcpy(s->graphic->send, (SUC"\n")); 18 | return (TRUE); 19 | } 20 | -------------------------------------------------------------------------------- /src_server/exec_sgt.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_sgt.c for exec_sgt.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Mon Jun 9 13:13:04 2014 LOEB Thomas 8 | ** Last update Tue Jun 10 14:17:45 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_sgt(t_server *s) 14 | { 15 | if (write_graphic(s) == FAILURE) 16 | return (FALSE); 17 | sprintf(s->graphic->send, "sgt %f\n", s->delay); 18 | return (TRUE); 19 | } 20 | -------------------------------------------------------------------------------- /src_server/exec_sst.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_sst.c for exec_sst.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Mon Jun 9 13:13:04 2014 LOEB Thomas 8 | ** Last update Fri Jun 13 13:56:19 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_sst(t_server *s) 14 | { 15 | if (write_graphic(s) == FAILURE) 16 | return (FALSE); 17 | s->delay = atof(s->p.cmd[1]); 18 | exec_sgt(s); 19 | return (TRUE); 20 | } 21 | -------------------------------------------------------------------------------- /src_common/getnbr.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** getnbr.c for getnbr.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Thu May 29 16:39:34 2014 LOEB Thomas 8 | ** Last update Thu May 29 16:41:17 2014 LOEB Thomas 9 | */ 10 | 11 | #include "common.h" 12 | 13 | int getnbr(char *s) 14 | { 15 | unsigned int i; 16 | 17 | i = -1; 18 | while (s[++i] != '\0') 19 | if (s[i] < '0' || s[i] > '9') 20 | return (-1); 21 | return (atoi(s)); 22 | } 23 | -------------------------------------------------------------------------------- /src_graphic/sgt_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** sgt_cmd.c for sgt_cmd.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Wed Jun 25 12:37:03 2014 abgral_f 8 | ** Last update Wed Jun 25 12:40:01 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int sgt_cmd(char **args, t_graphic *c) 14 | { 15 | if (atoi(args[0]) < 0) 16 | return (my_error("Time unity can't be negativ", FAILURE)); 17 | c->time = atoi(args[0]); 18 | return (SUCCESS); 19 | } 20 | -------------------------------------------------------------------------------- /src_server/exec_connect_nbr.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_forward.c for exec_forward.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Fri May 30 13:21:25 2014 LOEB Thomas 8 | ** Last update Wed Jun 11 16:03:45 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_connect_nbr(t_server *s) 14 | { 15 | nbr_to_str(s->tmp_teams->nb_remaining + s->tmp_teams->nb_egg_remaining, 16 | s->tmp_clients->send, "\n"); 17 | return (FALSE); 18 | } 19 | -------------------------------------------------------------------------------- /src_server/exec_right.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_forward.c for exec_forward.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Fri May 30 13:21:25 2014 LOEB Thomas 8 | ** Last update Fri Jun 13 14:31:45 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_right(t_server *s) 14 | { 15 | s->tmp_clients->direction = (s->tmp_clients->direction + 1) % 4; 16 | strcpy(s->tmp_clients->send, OK("\n")); 17 | exec_ppo(s); 18 | return (FALSE); 19 | } 20 | -------------------------------------------------------------------------------- /src_common/stop.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** stop.c for stop.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Wed May 7 14:54:20 2014 LOEB Thomas 8 | ** Last update Wed May 7 16:41:31 2014 LOEB Thomas 9 | */ 10 | 11 | #include "common.h" 12 | 13 | int stop(int value) 14 | { 15 | static int stopValue = STOP_VALUE; 16 | 17 | if (value != STOP_VALUE) 18 | stopValue = value; 19 | if (value == STOP_RESET) 20 | stopValue = STOP_VALUE; 21 | return (stopValue); 22 | } 23 | -------------------------------------------------------------------------------- /src_graphic/ebo_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** ebo_cmd.c for ebo_cmd.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Tue Jun 24 20:50:58 2014 abgral_f 8 | ** Last update Wed Jul 2 15:16:29 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int ebo_cmd(char **args, t_graphic *c) 14 | { 15 | if (check_egg(atoi(args[0] + 1), c) == FAILURE) 16 | return (my_error("Unknown egg id", FAILURE)); 17 | del_egg(c, atoi(args[0] + 1)); 18 | return (SUCCESS); 19 | } 20 | -------------------------------------------------------------------------------- /src_graphic/seg_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** seg_cmd.c for seg_cmd.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Wed Jun 25 12:42:29 2014 abgral_f 8 | ** Last update Wed Jun 25 12:49:36 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int seg_cmd(char **args, t_graphic *c) 14 | { 15 | if (check_team(c, args[0]) == FAILURE) 16 | return (my_error("This team does not exist", FAILURE)); 17 | printf("%s win!\n", args[0]); 18 | return (SUCCESS); 19 | } 20 | -------------------------------------------------------------------------------- /src_common/error.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** error.c for error.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Mon May 5 15:33:11 2014 LOEB Thomas 8 | ** Last update Mon May 5 15:55:59 2014 LOEB Thomas 9 | */ 10 | 11 | #include "error.h" 12 | 13 | int my_perror(char *message, int retVal) 14 | { 15 | perror(message); 16 | return (retVal); 17 | } 18 | 19 | int my_error(char *message, int retVal) 20 | { 21 | fprintf(stderr, "%s\n", message); 22 | return (retVal); 23 | } 24 | -------------------------------------------------------------------------------- /src_graphic/pdi_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** pdi_cmd.c for pdi_cmd.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Tue Jun 24 18:28:02 2014 abgral_f 8 | ** Last update Wed Jul 2 15:14:43 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int pdi_cmd(char **args, t_graphic *c) 14 | { 15 | if (check_player(atoi(args[0] + 1), c) == FAILURE) 16 | return (my_error("Unknown player id", FAILURE)); 17 | del_client(c, atoi(args[0] + 1)); 18 | return (SUCCESS); 19 | } 20 | -------------------------------------------------------------------------------- /src_common/getline.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** getline.c for getline.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Wed May 7 15:10:29 2014 LOEB Thomas 8 | ** Last update Wed May 14 12:27:01 2014 LOEB Thomas 9 | */ 10 | 11 | #include "common.h" 12 | 13 | int my_getline(t_line *l) 14 | { 15 | l->retGetline = getline(&l->line, &l->len, l->stream); 16 | if (l->retGetline > 0) 17 | l->len_line = strlen(l->line); 18 | else 19 | l->len_line = 0; 20 | return (l->retGetline); 21 | } 22 | -------------------------------------------------------------------------------- /src_graphic/is_anim.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** is_anim.c for is_anim.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Sat Jul 5 18:45:41 2014 abgral_f 8 | ** Last update Sat Jul 5 18:46:52 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | bool is_anim(t_graphic *c) 14 | { 15 | t_client *tmp; 16 | 17 | tmp = c->client; 18 | while (tmp != NULL) 19 | { 20 | if (tmp->anim != UNDEFINED) 21 | return (TRUE); 22 | tmp = tmp->next; 23 | } 24 | return (FALSE); 25 | } 26 | -------------------------------------------------------------------------------- /src_graphic/edi_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** edi_cmd.c for edi_cmd.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Tue Jun 24 20:53:22 2014 abgral_f 8 | ** Last update Wed Jul 2 15:16:51 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int edi_cmd(char **args, t_graphic *c) 14 | { 15 | if (check_egg(atoi(args[0] + 1), c) == FAILURE) 16 | return (my_error("Unknown egg id", FAILURE)); 17 | del_egg(c, atoi(args[0] + 1)); 18 | return (SUCCESS); 19 | } 20 | -------------------------------------------------------------------------------- /src_graphic/pbc_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** pbc_cmd.c for pbc_cmd.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Tue Jun 24 12:44:11 2014 abgral_f 8 | ** Last update Wed Jul 2 15:12:50 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int pbc_cmd(char **args, t_graphic *c) 14 | { 15 | if (check_player(atoi(args[0] + 1), c) == FAILURE) 16 | return (my_error("Unknown player id", FAILURE)); 17 | printf("Broadcast from player %d : <%s>\n", atoi(args[0] + 1), args[1]); 18 | return (SUCCESS); 19 | } 20 | -------------------------------------------------------------------------------- /src_server/exec_left.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_forward.c for exec_forward.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Fri May 30 13:21:25 2014 LOEB Thomas 8 | ** Last update Fri Jun 13 14:31:51 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_left(t_server *s) 14 | { 15 | --s->tmp_clients->direction; 16 | if ((int)s->tmp_clients->direction < 0) 17 | s->tmp_clients->direction = D_LEFT; 18 | strcpy(s->tmp_clients->send, OK("\n")); 19 | exec_ppo(s); 20 | return (FALSE); 21 | } 22 | -------------------------------------------------------------------------------- /src_server/exec_pdi.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_pdi.c for exec_pdi.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Wed Jun 11 17:03:13 2014 LOEB Thomas 8 | ** Last update Wed Jun 11 17:03:13 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_pdi(t_server *s) 14 | { 15 | if (write_graphic(s) == FAILURE) 16 | return (FALSE); 17 | strcpy(s->graphic->send, (PDI" #")); 18 | nbr_to_str(s->tmp_clients->id, 19 | s->graphic->send + strlen(s->graphic->send), "\n"); 20 | return (TRUE); 21 | } 22 | -------------------------------------------------------------------------------- /src_server/exec_pex.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_pex.c for exec_pex.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Tue Jun 10 14:19:39 2014 LOEB Thomas 8 | ** Last update Wed Jun 11 16:09:13 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_pex(t_server *s) 14 | { 15 | if (write_graphic(s) == FAILURE) 16 | return (FALSE); 17 | strcpy(s->graphic->send, (PEX" #")); 18 | nbr_to_str(s->tmp_clients->id, 19 | s->graphic->send + strlen(s->graphic->send), "\n"); 20 | return (TRUE); 21 | } 22 | -------------------------------------------------------------------------------- /src_server/exec_pfk.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_pfk.c for exec_pfk.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Wed Jun 11 15:31:59 2014 LOEB Thomas 8 | ** Last update Wed Jun 11 16:09:38 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_pfk(t_server *s) 14 | { 15 | if (write_graphic(s) == FAILURE) 16 | return (FALSE); 17 | strcpy(s->graphic->send, (PFK" #")); 18 | nbr_to_str(s->tmp_clients->id, 19 | s->graphic->send + strlen(s->graphic->send), "\n"); 20 | return (TRUE); 21 | } 22 | -------------------------------------------------------------------------------- /src_server/exec_ebo.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_ebo.c for exec_ebo.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Thu Jun 12 16:06:23 2014 LOEB Thomas 8 | ** Last update Thu Jun 12 16:06:30 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_ebo(t_server *s) 14 | { 15 | if (write_graphic(s) == FAILURE) 16 | return (FALSE); 17 | strcpy(s->graphic->send, (EBO" #")); 18 | nbr_to_str(s->tmp_teams->tmp_eggs->id, 19 | s->graphic->send + strlen(s->graphic->send), "\n"); 20 | return (TRUE); 21 | } 22 | -------------------------------------------------------------------------------- /src_server/exec_edi.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_edi.c for exec_edi.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Thu Jun 12 16:07:56 2014 LOEB Thomas 8 | ** Last update Thu Jun 12 16:08:02 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_edi(t_server *s) 14 | { 15 | if (write_graphic(s) == FAILURE) 16 | return (FALSE); 17 | strcpy(s->graphic->send, (EDI" #")); 18 | nbr_to_str(s->tmp_teams->tmp_eggs->id, 19 | s->graphic->send + strlen(s->graphic->send), "\n"); 20 | return (TRUE); 21 | } 22 | -------------------------------------------------------------------------------- /src_server/exec_eht.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_eht.c for exec_eht.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Thu Jun 12 15:54:54 2014 LOEB Thomas 8 | ** Last update Thu Jun 12 15:56:07 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_eht(t_server *s) 14 | { 15 | if (write_graphic(s) == FAILURE) 16 | return (FALSE); 17 | strcpy(s->graphic->send, (EHT" #")); 18 | nbr_to_str(s->tmp_teams->tmp_eggs->id, 19 | s->graphic->send + strlen(s->graphic->send), "\n"); 20 | return (TRUE); 21 | } 22 | -------------------------------------------------------------------------------- /src_graphic/get_team_by_name.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** get_team_by_name.c for get_team_by_name.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Mon Jun 23 19:40:06 2014 abgral_f 8 | ** Last update Mon Jun 23 19:43:15 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | t_team *get_team_by_name(t_graphic *c, char *name) 14 | { 15 | t_team *ret; 16 | 17 | ret = c->teams; 18 | while (ret != NULL && strcmp(name, ret->name) != 0) 19 | ret = ret->next; 20 | if (ret == NULL) 21 | return (NULL); 22 | return (ret); 23 | } 24 | -------------------------------------------------------------------------------- /src_graphic/check_egg.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** check_egg.c for check_egg.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Tue Jun 24 18:47:56 2014 abgral_f 8 | ** Last update Tue Jun 24 18:48:50 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int check_egg(unsigned int id, t_graphic *c) 14 | { 15 | t_egg *tmp; 16 | 17 | tmp = c->eggs; 18 | while (tmp != NULL && 19 | tmp->id != id) 20 | tmp = tmp-> next; 21 | if (tmp == NULL) 22 | return (FAILURE); 23 | if (tmp->id == id) 24 | return (SUCCESS); 25 | return (FAILURE); 26 | } 27 | -------------------------------------------------------------------------------- /src_server/exec_msz.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_msz.c for exec_msz.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Mon Jun 9 13:13:04 2014 LOEB Thomas 8 | ** Last update Wed Jun 11 16:09:57 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_msz(t_server *s) 14 | { 15 | if (write_graphic(s) == FAILURE) 16 | return (FALSE); 17 | strcpy(s->graphic->send, (MSZ" ")); 18 | nbr_to_str(s->x, s->graphic->send + strlen(s->graphic->send), " "); 19 | nbr_to_str(s->y, s->graphic->send + strlen(s->graphic->send), "\n"); 20 | return (TRUE); 21 | } 22 | -------------------------------------------------------------------------------- /src_server/exec_seg.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_seg.c for exec_seg.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Thu Jun 12 16:21:06 2014 LOEB Thomas 8 | ** Last update Thu Jun 12 16:24:59 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_seg(t_server *s) 14 | { 15 | if (write_graphic(s) == FAILURE) 16 | return (FALSE); 17 | strcpy(s->graphic->send, (SEG" #")); 18 | strcpy(s->graphic->send + strlen(s->graphic->send), 19 | s->tmp_clients->team->name); 20 | s->graphic->send[strlen(s->graphic->send)] = '\n'; 21 | return (TRUE); 22 | } 23 | -------------------------------------------------------------------------------- /src_graphic/eht_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** eht_cmd.c for eht_cmd.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Tue Jun 24 20:40:21 2014 abgral_f 8 | ** Last update Wed Jul 2 15:16:10 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int eht_cmd(char **args, t_graphic *c) 14 | { 15 | t_egg *tmp; 16 | 17 | if (check_egg(atoi(args[0] + 1), c) == FAILURE) 18 | return (my_error("Unknown egg id", FAILURE)); 19 | tmp = c->eggs; 20 | while (tmp->id != (unsigned int)atoi(args[0] + 1)) 21 | tmp = tmp->next; 22 | tmp->isHatched = TRUE; 23 | return (SUCCESS); 24 | } 25 | -------------------------------------------------------------------------------- /inc/pointer_to_func.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** pointer_to_func.h for pointer_to_func.h in /home/chauch_a/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by CHAUCHET Alan 5 | ** Login 6 | ** 7 | ** Started on Mon Jul 7 10:32:58 2014 CHAUCHET Alan 8 | ** Last update Thu Jul 10 16:01:15 2014 CHAUCHET Alan 9 | */ 10 | 11 | #ifndef POINTER_TO_FUNC_H_ 12 | # define POINTER_TO_FUNC_H_ 13 | 14 | # include "client.h" 15 | 16 | typedef int (*send_cmd_func)(t_client *, char *, char *); 17 | 18 | typedef struct s_send_cmd 19 | { 20 | char *cmd; 21 | send_cmd_func func; 22 | } t_send_cmd; 23 | 24 | typedef void (*direction_move)(t_client *c, e_direction); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src_server/exec_pdr.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_pdr.c for exec_pdr.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Wed Jun 11 15:39:50 2014 LOEB Thomas 8 | ** Last update Wed Jun 11 16:03:57 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_pdr(t_server *s, char c) 14 | { 15 | if (write_graphic(s) == FAILURE) 16 | return (FALSE); 17 | strcpy(s->graphic->send, (PDR" #")); 18 | nbr_to_str(s->tmp_clients->id, 19 | s->graphic->send + strlen(s->graphic->send), " "); 20 | nbr_to_str(c, s->graphic->send + strlen(s->graphic->send), "\n"); 21 | return (TRUE); 22 | } 23 | -------------------------------------------------------------------------------- /src_server/exec_pgt.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_pgt.c for exec_pgt.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Wed Jun 11 15:46:27 2014 LOEB Thomas 8 | ** Last update Wed Jun 11 16:05:07 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_pgt(t_server *s, char c) 14 | { 15 | if (write_graphic(s) == FAILURE) 16 | return (FALSE); 17 | strcpy(s->graphic->send, (PGT" #")); 18 | nbr_to_str(s->tmp_clients->id, 19 | s->graphic->send + strlen(s->graphic->send), " "); 20 | nbr_to_str(c, s->graphic->send + strlen(s->graphic->send), "\n"); 21 | return (TRUE); 22 | } 23 | -------------------------------------------------------------------------------- /src_common/select.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** select.c for select.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Wed May 7 14:50:19 2014 LOEB Thomas 8 | ** Last update Thu May 8 13:31:45 2014 LOEB Thomas 9 | */ 10 | 11 | #include "common.h" 12 | 13 | int my_select(t_select *s, e_mode flag) 14 | { 15 | if (flag == R) 16 | s->retSelect = select(s->maxfd, &s->rdfds, NULL, NULL, &s->tv); 17 | else if (flag == W) 18 | s->retSelect = select(s->maxfd, NULL, &s->wrfds, NULL, &s->tv); 19 | else if (flag == RW) 20 | s->retSelect = select(s->maxfd, &s->rdfds, &s->wrfds, NULL, &s->tv); 21 | return (s->retSelect); 22 | } 23 | -------------------------------------------------------------------------------- /src_graphic/check_player.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** check_if_player_exist.c for check_if_player_exist.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Fri Jun 20 12:34:30 2014 abgral_f 8 | ** Last update Wed Jul 2 15:08:28 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int check_player(unsigned int id, t_graphic *c) 14 | { 15 | t_client *tmp; 16 | 17 | tmp = c->client; 18 | while (tmp != NULL && 19 | tmp->id != id) 20 | tmp = tmp-> next; 21 | if (tmp == NULL) 22 | return (FAILURE); 23 | if (tmp->id == id) 24 | return (SUCCESS); 25 | return (FAILURE); 26 | } 27 | -------------------------------------------------------------------------------- /src_graphic/pex_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** pex_cmd.c for pex_cmd.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Tue Jun 24 12:40:54 2014 abgral_f 8 | ** Last update Sat Jul 5 18:23:46 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int pex_cmd(char **args, t_graphic *c) 14 | { 15 | t_client *tmp; 16 | 17 | if (check_player(atoi(args[0] + 1), c) == FAILURE) 18 | return (my_error("Unknown player id", FAILURE)); 19 | tmp = c->client; 20 | while (tmp->id != (unsigned int)atoi(args[0] + 1)) 21 | tmp = tmp->next; 22 | tmp->anim = KIK; 23 | tmp->count_anim = 0; 24 | return (SUCCESS); 25 | } 26 | -------------------------------------------------------------------------------- /src_graphic/pfk_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** pfk_cmd.c for pfk_cmd.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Tue Jun 24 17:07:50 2014 abgral_f 8 | ** Last update Sat Jul 5 18:27:16 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int pfk_cmd(char **args, t_graphic *c) 14 | { 15 | t_client *tmp; 16 | 17 | if (check_player(atoi(args[0] + 1), c) == FAILURE) 18 | return (my_error("Unknown player id", FAILURE)); 19 | tmp = c->client; 20 | while (tmp->id != (unsigned int)atoi(args[0] + 1)) 21 | tmp = tmp->next; 22 | tmp->anim = LAY; 23 | tmp->count_anim = 0; 24 | return (SUCCESS); 25 | } 26 | -------------------------------------------------------------------------------- /src_graphic/pdr_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** pdr_cmd.c for pdr_cmd.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Tue Jun 24 17:10:49 2014 abgral_f 8 | ** Last update Sat Jul 5 18:26:03 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int pdr_cmd(char **args, t_graphic *c) 14 | { 15 | t_client *tmp; 16 | 17 | if (check_player(atoi(args[0] + 1), c) == FAILURE) 18 | return (my_error("Unknown player id", FAILURE)); 19 | tmp = c->client; 20 | while (tmp->id != (unsigned int)atoi(args[0] + 1)) 21 | tmp = tmp->next; 22 | tmp->anim = DROP; 23 | tmp->count_anim = 0; 24 | return (SUCCESS); 25 | } 26 | -------------------------------------------------------------------------------- /src_graphic/pgt_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** pgt_cmd.c for pgt_cmd.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Tue Jun 24 17:12:12 2014 abgral_f 8 | ** Last update Sat Jul 5 18:27:05 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int pgt_cmd(char **args, t_graphic *c) 14 | { 15 | t_client *tmp; 16 | 17 | if (check_player(atoi(args[0] + 1), c) == FAILURE) 18 | return (my_error("Unknown player id", FAILURE)); 19 | tmp = c->client; 20 | while (tmp->id != (unsigned int)atoi(args[0] + 1)) 21 | tmp = tmp->next; 22 | tmp->anim = DROP; 23 | tmp->count_anim = 0; 24 | return (SUCCESS); 25 | } 26 | -------------------------------------------------------------------------------- /src_graphic/check_team.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** check_if_team_exist.c for check_if_team_exist.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Fri Jun 20 12:41:09 2014 abgral_f 8 | ** Last update Wed Jun 25 13:03:45 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int check_team(t_graphic *c, char *team) 14 | { 15 | t_team *tmp; 16 | 17 | tmp = c->teams; 18 | while (tmp != NULL && 19 | strcmp(tmp->name, team) != 0) 20 | tmp = tmp->next; 21 | if (tmp == NULL) 22 | return (FAILURE); 23 | if (strcmp(tmp->name, team) == 0) 24 | return (SUCCESS); 25 | return (FAILURE); 26 | } 27 | -------------------------------------------------------------------------------- /src_server/exec_elevation.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_forward.c for exec_forward.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Fri May 30 13:21:25 2014 LOEB Thomas 8 | ** Last update Fri Jun 13 15:02:31 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_elevation(t_server *s) 14 | { 15 | strcpy(s->tmp_clients->send, ELEVATION_DONE); 16 | s->tmp_clients->send[16] = s->tmp_clients->level + 49; 17 | ++s->tmp_clients->level; 18 | s->tmp_clients->isAscending = -1; 19 | exec_pie(s, 1); 20 | exec_plv(s); 21 | exec_bct(s); 22 | if (s->tmp_clients->level == MAX_LEVEL) 23 | exec_seg(s); 24 | return (FALSE); 25 | } 26 | -------------------------------------------------------------------------------- /src_server/exec_pbc.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_pbc.c for exec_pbc.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Tue Jun 10 14:25:34 2014 LOEB Thomas 8 | ** Last update Wed Jun 11 16:48:25 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_pbc(t_server *s) 14 | { 15 | if (write_graphic(s) == FAILURE) 16 | return (FALSE); 17 | strcpy(s->graphic->send, (PBC" #")); 18 | nbr_to_str(s->tmp_clients->id, 19 | s->graphic->send + strlen(s->graphic->send), " "); 20 | strcpy(s->graphic->send + strlen(s->graphic->send), 21 | s->tmp_clients->action.param); 22 | s->graphic->send[strlen(s->graphic->send)] = '\n'; 23 | return (TRUE); 24 | } 25 | -------------------------------------------------------------------------------- /src_server/exec_pie.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_pie.c for exec_pie.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Wed Jun 11 15:10:20 2014 LOEB Thomas 8 | ** Last update Wed Jun 11 16:09:27 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_pie(t_server *s, char c) 14 | { 15 | if (write_graphic(s) == FAILURE) 16 | return (FALSE); 17 | strcpy(s->graphic->send, (PIE" ")); 18 | nbr_to_str(s->tmp_clients->x, 19 | s->graphic->send + strlen(s->graphic->send), " "); 20 | nbr_to_str(s->tmp_clients->y, 21 | s->graphic->send + strlen(s->graphic->send), " "); 22 | nbr_to_str(c, s->graphic->send + strlen(s->graphic->send), "\n"); 23 | return (TRUE); 24 | } 25 | -------------------------------------------------------------------------------- /src_graphic/plv_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** plv_cmd.c for plv_cmd.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Mon Jun 23 18:25:57 2014 abgral_f 8 | ** Last update Wed Jul 2 15:11:30 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int plv_cmd(char **args, t_graphic *c) 14 | { 15 | t_client *tmp; 16 | 17 | if (check_player(atoi(args[0] + 1), c) == FAILURE) 18 | return (my_error("Unknown player id", FAILURE)); 19 | if (atoi(args[1]) > 8 || atoi(args[1]) < 1) 20 | return (my_error("Invalid lvl", FAILURE)); 21 | tmp = c->client; 22 | while (tmp->id != (unsigned int)atoi(args[0] + 1)) 23 | tmp = tmp->next; 24 | tmp->lvl = atoi(args[1]); 25 | return (SUCCESS); 26 | } 27 | -------------------------------------------------------------------------------- /src_server/signal.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** signal.c for signal.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Thu May 8 12:49:53 2014 LOEB Thomas 8 | ** Last update Sat Jul 12 12:17:00 2014 abgral_f 9 | */ 10 | 11 | #include "server.h" 12 | 13 | static void my_signal_handler(int sig) 14 | { 15 | signal(SIGINT, &my_signal_handler); 16 | signal(SIGTERM, &my_signal_handler); 17 | signal(SIGPIPE, &my_signal_handler); 18 | if (sig == SIGINT || sig == SIGTERM) 19 | stop(STOP_QUIT); 20 | else if (sig == SIGPIPE) 21 | stop(STOP_BRK_PIPE); 22 | } 23 | 24 | void my_signal(void) 25 | { 26 | signal(SIGINT, &my_signal_handler); 27 | signal(SIGTERM, &my_signal_handler); 28 | signal(SIGPIPE, &my_signal_handler); 29 | } 30 | -------------------------------------------------------------------------------- /src_client/signal.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** signal.c for signal.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Wed May 7 16:02:45 2014 LOEB Thomas 8 | ** Last update Wed May 7 18:10:28 2014 LOEB Thomas 9 | */ 10 | 11 | #include "client.h" 12 | 13 | static void my_signal_handler(int sig) 14 | { 15 | signal(SIGINT, &my_signal_handler); 16 | signal(SIGTERM, &my_signal_handler); 17 | signal(SIGPIPE, &my_signal_handler); 18 | if (sig == SIGINT || sig == SIGTERM) 19 | my_error(BAD_WAY_QUIT, CONTINUE); 20 | else if (sig == SIGPIPE) 21 | stop(STOP_BRK_PIPE); 22 | } 23 | 24 | void my_signal(void) 25 | { 26 | signal(SIGINT, &my_signal_handler); 27 | signal(SIGTERM, &my_signal_handler); 28 | signal(SIGPIPE, &my_signal_handler); 29 | } 30 | -------------------------------------------------------------------------------- /src_graphic/signal.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** signal.c for signal.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Wed May 7 16:02:45 2014 LOEB Thomas 8 | ** Last update Thu Jun 12 17:49:57 2014 LOEB Thomas 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | static void my_signal_handler(int sig) 14 | { 15 | signal(SIGINT, &my_signal_handler); 16 | signal(SIGTERM, &my_signal_handler); 17 | signal(SIGPIPE, &my_signal_handler); 18 | if (sig == SIGINT || sig == SIGTERM) 19 | my_error(BAD_WAY_QUIT, CONTINUE); 20 | else if (sig == SIGPIPE) 21 | stop(STOP_BRK_PIPE); 22 | } 23 | 24 | void my_signal(void) 25 | { 26 | signal(SIGINT, &my_signal_handler); 27 | signal(SIGTERM, &my_signal_handler); 28 | signal(SIGPIPE, &my_signal_handler); 29 | } 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /src_graphic/get_click_coord.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** get_click_coord.c for get_click_coord.c in /home/abgral_f/backups/zappy7 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Thu Jul 10 20:15:06 2014 abgral_f 8 | ** Last update Fri Jul 11 13:43:34 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int get_click_coord(t_graphic *c) 14 | { 15 | if (c->display.event.type == SDL_MOUSEBUTTONDOWN) 16 | { 17 | if (c->display.event.button.x / SPRITE_SIZE < c->x 18 | && c->display.event.button.y / SPRITE_SIZE < c->y 19 | && c->display.event.button.x < MAP_X) 20 | { 21 | c->display.coord_x = c->display.event.button.x 22 | / SPRITE_SIZE + c->display.cursor_x; 23 | c->display.coord_y = c->display.event.button.y 24 | / SPRITE_SIZE + c->display.cursor_y; 25 | } 26 | } 27 | return (SUCCESS); 28 | } 29 | -------------------------------------------------------------------------------- /src_graphic/bct_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** bct_cmd.c for bct_cmd.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Thu Jun 19 15:45:35 2014 abgral_f 8 | ** Last update Fri Jul 4 22:20:12 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int bct_cmd(char **args, t_graphic *c) 14 | { 15 | int count; 16 | 17 | if (atoi(args[0]) < 0 || (unsigned int)atoi(args[0]) >= c->x 18 | || atoi(args[1]) < 0 || (unsigned int)atoi(args[1]) >= c->y) 19 | return (my_error("Unknown coordinates", FAILURE)); 20 | c->map[atoi(args[0]) + atoi(args[1]) * c->x].isUpdate = TRUE; 21 | c->map[atoi(args[0]) + atoi(args[1]) * c->x].b.food = atoi(args[2]); 22 | count = -1; 23 | while (++count != NB_STONE) 24 | { 25 | c->map[atoi(args[0]) + atoi(args[1]) 26 | * c->x].b.stone[count] = atoi(args[3 + count]); 27 | } 28 | return (SUCCESS); 29 | } 30 | -------------------------------------------------------------------------------- /src_server/close_server.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** close_server.c for close_server.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Wed May 7 17:44:22 2014 LOEB Thomas 8 | ** Last update Fri May 30 15:02:22 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | int close_server(t_server *s, int retVal) 14 | { 15 | if (stop(STOP_VALUE) < STOP_VALUE) 16 | fprintf(stderr, "ERROR: server did not quit correctly (%d)\n", 17 | stop(STOP_VALUE)); 18 | else if (stop(STOP_VALUE) > STOP_VALUE) 19 | fprintf(stderr, "SUCCESS: server quitted correctly (%d)\n", 20 | stop(STOP_VALUE)); 21 | if (s->map != NULL) 22 | free(s->map); 23 | if (s->p.cmd != NULL) 24 | free_words(&s->p); 25 | free_clients(s); 26 | free_teams(s); 27 | if (s->socket != -1 && close(s->socket) == -1) 28 | my_perror(SYSCALL("close"), CONTINUE); 29 | return (retVal); 30 | } 31 | -------------------------------------------------------------------------------- /src_client/close_client.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** close_client.c for close_client.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Wed May 7 13:22:05 2014 LOEB Thomas 8 | ** Last update Fri Jul 11 19:18:20 2014 Baptiste Acca 9 | */ 10 | 11 | #include "client.h" 12 | 13 | int close_client(t_client *c, int retVal) 14 | { 15 | if (stop(STOP_VALUE) < STOP_VALUE) 16 | fprintf(stderr, "ERROR: client did not quit correctly (%d)\n", 17 | stop(STOP_VALUE)); 18 | else if (stop(STOP_VALUE) > STOP_VALUE) 19 | fprintf(stderr, "SUCCESS: client quitted correctly (%d)\n", 20 | stop(STOP_VALUE)); 21 | if (c->p.cmd != NULL) 22 | free_words(&c->p); 23 | if (c->l.line != NULL) 24 | free(c->l.line); 25 | if (c->socket != -1 && close(c->socket) == -1) 26 | my_perror(SYSCALL("close"), CONTINUE); 27 | if (raw_mode_exit(c) == FAILURE) 28 | return (retVal); 29 | return (retVal); 30 | } 31 | -------------------------------------------------------------------------------- /src_server/exec_mct.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_mct.c for exec_mct.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Mon Jun 9 13:13:04 2014 LOEB Thomas 8 | ** Last update Tue Jun 10 14:17:06 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_mct(t_server *s) 14 | { 15 | unsigned int i; 16 | t_client *tmp; 17 | 18 | if (write_graphic(s) == FAILURE) 19 | return (FALSE); 20 | i = -1; 21 | while (++i < (unsigned int)(s->x * s->y - 1)) 22 | { 23 | exec_bct_fill(s, i % s->x, i / s->x); 24 | if (rw(s->graphic->socket, s->graphic->send, 25 | strlen(s->graphic->send), W) == FAILURE) 26 | { 27 | tmp = s->tmp_clients; 28 | s->tmp_clients = s->graphic; 29 | del_client(s, TRUE); 30 | s->tmp_clients = tmp; 31 | return (FALSE); 32 | } 33 | memset(s->graphic->send, '\0', BUFF_LEN); 34 | } 35 | exec_bct_fill(s, s->x - 1, s->y - 1); 36 | return (TRUE); 37 | } 38 | -------------------------------------------------------------------------------- /src_client/connect_to_server.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** connect_to_server.c for connect_to_server.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Wed May 7 13:03:52 2014 LOEB Thomas 8 | ** Last update Thu May 29 16:47:10 2014 LOEB Thomas 9 | */ 10 | 11 | #include "client.h" 12 | 13 | int connect_to_server(t_client *c) 14 | { 15 | c->server.sin_family = AF_INET; 16 | c->server.sin_port = htons(c->port); 17 | if (((c->socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1 && 18 | my_perror(SYSCALL("socket"), FAILURE) == FAILURE) || 19 | (inet_aton(c->ip, IN_ADDR(&c->server.sin_addr.s_addr)) == -1 && 20 | my_perror(SYSCALL("inet_aton"), FAILURE) == FAILURE) || 21 | (connect(c->socket, C_SOCKADDR(&c->server), sizeof(c->server)) == -1 && 22 | my_perror(SYSCALL("connect"), FAILURE) == FAILURE)) 23 | return (close_client(c, FAILURE)); 24 | printf("Client trying to connect\n"); 25 | return (check_fds(c)); 26 | } 27 | -------------------------------------------------------------------------------- /src_server/check_action.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** check_action.c for check_action.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Fri May 30 12:34:17 2014 LOEB Thomas 8 | ** Last update Thu Jun 19 17:37:13 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | static char *g_objects[NB_STONE + 1] = 14 | { 15 | LINEMATE, 16 | DERAUMERE, 17 | SIBUR, 18 | MENDIANE, 19 | PHIRAS, 20 | THYSTAME, 21 | FOOD 22 | }; 23 | 24 | bool check_take(t_server *s) 25 | { 26 | unsigned int i; 27 | 28 | i = 0; 29 | while (i < NB_STONE + 1 && strcmp(s->p.cmd[1], g_objects[i]) != 0) 30 | ++i; 31 | if (i == NB_STONE + 1) 32 | return (FALSE); 33 | return (TRUE); 34 | } 35 | 36 | bool check_put(t_server *s) 37 | { 38 | unsigned int i; 39 | 40 | i = 0; 41 | while (i < NB_STONE && strcmp(s->p.cmd[1], g_objects[i]) != 0) 42 | ++i; 43 | if (i == NB_STONE) 44 | return (FALSE); 45 | return (TRUE); 46 | } 47 | -------------------------------------------------------------------------------- /src_graphic/connect_to_server.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** connect_to_server.c for connect_to_server.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Wed May 7 13:03:52 2014 LOEB Thomas 8 | ** Last update Thu Jun 12 17:51:00 2014 LOEB Thomas 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int connect_to_server(t_graphic *c) 14 | { 15 | c->server.sin_family = AF_INET; 16 | c->server.sin_port = htons(c->port); 17 | if (((c->socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1 && 18 | my_perror(SYSCALL("socket"), FAILURE) == FAILURE) || 19 | (inet_aton(c->ip, IN_ADDR(&c->server.sin_addr.s_addr)) == -1 && 20 | my_perror(SYSCALL("inet_aton"), FAILURE) == FAILURE) || 21 | (connect(c->socket, C_SOCKADDR(&c->server), sizeof(c->server)) == -1 && 22 | my_perror(SYSCALL("connect"), FAILURE) == FAILURE)) 23 | return (close_graphic(c, FAILURE)); 24 | printf("Graphic trying to connect\n"); 25 | return (check_fds(c)); 26 | } 27 | -------------------------------------------------------------------------------- /src_graphic/disp_eggs.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** disp_eggs.c for disp_eggs.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Fri Jul 4 15:19:37 2014 abgral_f 8 | ** Last update Wed Jul 9 15:21:45 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int display_eggs(t_graphic *c) 14 | { 15 | t_egg *tmp; 16 | 17 | tmp = c->eggs; 18 | c->display.sprite.y = 0; 19 | while (tmp != NULL) 20 | { 21 | if (tmp->isHatched == TRUE) 22 | c->display.sprite.x = SPRITE_SIZE; 23 | else 24 | c->display.sprite.x = 0; 25 | c->display.pos.x = (tmp->x - c->display.cursor_x) * SPRITE_SIZE; 26 | c->display.pos.y = (tmp->y - c->display.cursor_y) * SPRITE_SIZE; 27 | if (SDL_BlitSurface(c->display.list[EGG], 28 | &c->display.sprite, c->display.list[WINDOW], 29 | &c->display.pos) == -1) 30 | return (my_error(SDL_GetError(), FAILURE)); 31 | tmp = tmp->next; 32 | } 33 | return (SUCCESS); 34 | } 35 | -------------------------------------------------------------------------------- /src_graphic/pin_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** pin_cmd.c for pin_cmd.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Mon Jun 23 18:32:22 2014 abgral_f 8 | ** Last update Wed Jul 2 15:17:26 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int pin_cmd(char **args, t_graphic *c) 14 | { 15 | int count; 16 | int i; 17 | t_client *tmp; 18 | 19 | if (check_player(atoi(args[0] + 1), c) == FAILURE) 20 | return (my_error("Unknown player id", FAILURE)); 21 | tmp = c->client; 22 | while (tmp->id != (unsigned int)atoi(args[0] + 1)) 23 | tmp = tmp->next; 24 | count = 3; 25 | i = 0; 26 | while (count != 10) 27 | { 28 | if (atoi(args[count]) < 0) 29 | return (my_perror("Items number can't have a negativ value", FAILURE)); 30 | if (count == 3) 31 | tmp->inventory.food = atoi(args[count]); 32 | else 33 | tmp->inventory.stone[count - 4] = atoi(args[count]); 34 | count++; 35 | i++; 36 | } 37 | return (SUCCESS); 38 | } 39 | -------------------------------------------------------------------------------- /src_server/exec_put.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_forward.c for exec_forward.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Fri May 30 13:21:25 2014 LOEB Thomas 8 | ** Last update Fri Jun 13 14:33:56 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | static char *g_objects[NB_STONE] = 14 | { 15 | LINEMATE, 16 | DERAUMERE, 17 | SIBUR, 18 | MENDIANE, 19 | PHIRAS, 20 | THYSTAME 21 | }; 22 | 23 | bool exec_put(t_server *s) 24 | { 25 | unsigned int i; 26 | 27 | i = 0; 28 | while (i < NB_STONE && 29 | strcmp(s->tmp_clients->action.param, g_objects[i]) != 0) 30 | ++i; 31 | if (i == NB_STONE || s->tmp_clients->stone[i] == 0) 32 | { 33 | strcpy(s->tmp_clients->send, KO("\n")); 34 | return (FALSE); 35 | } 36 | --s->tmp_clients->stone[i]; 37 | ++s->map[s->tmp_clients->x + s->tmp_clients->y * s->x].stone[i]; 38 | strcpy(s->tmp_clients->send, OK("\n")); 39 | exec_pdr(s, i + 1); 40 | exec_pin(s); 41 | exec_bct(s); 42 | return (FALSE); 43 | } 44 | -------------------------------------------------------------------------------- /src_server/exec_forward.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_forward.c for exec_forward.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Fri May 30 13:21:25 2014 LOEB Thomas 8 | ** Last update Thu Jul 3 17:06:37 2014 abgral_f 9 | */ 10 | 11 | #include "server.h" 12 | 13 | static int g_x[4] = 14 | { 15 | 0, 16 | 1, 17 | 0, 18 | -1 19 | }; 20 | 21 | static int g_y[4] = 22 | { 23 | -1, 24 | 0, 25 | 1, 26 | 0 27 | }; 28 | 29 | bool exec_forward(t_server *s) 30 | { 31 | s->tmp_clients->x += g_x[s->tmp_clients->direction]; 32 | if ((int)s->tmp_clients->x < 0) 33 | s->tmp_clients->x = s->x - 1; 34 | else if (s->tmp_clients->x >= (unsigned int)s->x) 35 | s->tmp_clients->x = 0; 36 | s->tmp_clients->y += g_y[s->tmp_clients->direction]; 37 | if ((int)s->tmp_clients->y < 0) 38 | s->tmp_clients->y = s->y - 1; 39 | else if (s->tmp_clients->y >= (unsigned int)s->y) 40 | s->tmp_clients->y = 0; 41 | strcpy(s->tmp_clients->send, OK("\n")); 42 | exec_ppo(s); 43 | return (FALSE); 44 | } 45 | -------------------------------------------------------------------------------- /src_graphic/map_update.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** map_update.c for map_update.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Wed Jul 2 17:10:58 2014 abgral_f 8 | ** Last update Wed Jul 9 18:13:51 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int is_map_update(t_graphic *c) 14 | { 15 | unsigned int count; 16 | char *cmd; 17 | 18 | if (c->map == NULL) 19 | return (FAILURE); 20 | count = -1; 21 | while (++count != c->x * c->y) 22 | { 23 | if (c->map[count].isUpdate == FALSE) 24 | { 25 | if ((cmd = malloc(sizeof (*cmd) * (7 + nbrlen(count % c->x) 26 | + nbrlen(count / c->x)))) == NULL) 27 | return (my_perror(SYSCALL("malloc"), FAILURE)); 28 | memset(cmd, '\0', 7 + nbrlen(count % c->x) + nbrlen(count / c->x)); 29 | strcat(cmd, "bct "); 30 | nbr_to_str(count % c->x, &cmd[strlen(cmd)], " "); 31 | nbr_to_str(count / c->x, &cmd[strlen(cmd)], "\n"); 32 | write(c->socket, cmd, strlen(cmd)); 33 | free(cmd); 34 | return (FAILURE); 35 | } 36 | } 37 | return (SUCCESS); 38 | } 39 | -------------------------------------------------------------------------------- /src_server/open_to_clients.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** open_to_clients.c for open_to_clients.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Wed May 7 17:37:03 2014 LOEB Thomas 8 | ** Last update Mon Jun 2 17:16:56 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | int open_to_clients(t_server *s) 14 | { 15 | s->map = NULL; 16 | s->server.sin_family = AF_INET; 17 | s->server.sin_port = htons(s->port); 18 | s->server.sin_addr.s_addr = INADDR_ANY; 19 | if (((s->socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1 && 20 | my_perror(SYSCALL("socket"), FAILURE) == FAILURE) || 21 | (bind(s->socket, C_SOCKADDR(&s->server), sizeof(s->server)) == -1 && 22 | my_perror(SYSCALL("bind"), FAILURE) == FAILURE) || 23 | (listen(s->socket, WAITING_LIST) == -1 && 24 | my_perror(SYSCALL("listen"), FAILURE) == FAILURE)) 25 | return (close_server(s, FAILURE)); 26 | printf("Server online\n"); 27 | if (create_map(s) == FAILURE) 28 | return (close_server(s, FAILURE)); 29 | return (check_fds(s)); 30 | } 31 | -------------------------------------------------------------------------------- /src_graphic/pie_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** pie_cmd.c for pie_cmd.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Tue Jun 24 16:47:28 2014 abgral_f 8 | ** Last update Sat Jul 5 14:55:33 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int pie_cmd(char **args, t_graphic *c) 14 | { 15 | t_client *tmp; 16 | 17 | if (atoi(args[0]) < 0 || (unsigned int)atoi(args[0]) >= c->x 18 | || atoi(args[1]) < 0 || (unsigned int)atoi(args[1]) >= c->y) 19 | return (my_error("Unknown coordinates", FAILURE)); 20 | tmp = c->client; 21 | while (tmp != NULL) 22 | { 23 | if (tmp->x == (unsigned int)atoi(args[0]) 24 | && tmp->y == (unsigned int)atoi(args[1])) 25 | { 26 | tmp->anim = UNDEFINED; 27 | tmp->isAscending = -1; 28 | } 29 | tmp = tmp->next; 30 | } 31 | if (atoi(args[2]) != 0 && atoi(args[2]) != 1) 32 | return (my_error("Unknown incantion result", FAILURE)); 33 | if (atoi(args[2]) != 1) 34 | printf("Incantation in %d/%d failed", atoi(args[0]), atoi(args[1])); 35 | return (SUCCESS); 36 | } 37 | -------------------------------------------------------------------------------- /src_server/exec_pnw.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_pnw.c for exec_pnw.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Mon Jun 9 17:22:26 2014 LOEB Thomas 8 | ** Last update Thu Jul 3 17:06:16 2014 abgral_f 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_pnw(t_server *s) 14 | { 15 | if (write_graphic(s) == FAILURE) 16 | return (FALSE); 17 | strcpy(s->graphic->send, (PNW" #")); 18 | nbr_to_str(s->tmp_clients->id, 19 | s->graphic->send + strlen(s->graphic->send), " "); 20 | nbr_to_str(s->tmp_clients->x, 21 | s->graphic->send + strlen(s->graphic->send), " "); 22 | nbr_to_str(s->tmp_clients->y, 23 | s->graphic->send + strlen(s->graphic->send), " "); 24 | nbr_to_str(s->tmp_clients->direction + 1, 25 | s->graphic->send + strlen(s->graphic->send), " "); 26 | nbr_to_str(s->tmp_clients->level, 27 | s->graphic->send + strlen(s->graphic->send), " "); 28 | strcpy(s->graphic->send + strlen(s->graphic->send), 29 | s->tmp_clients->team->name); 30 | s->graphic->send[strlen(s->graphic->send)] = '\n'; 31 | return (TRUE); 32 | } 33 | -------------------------------------------------------------------------------- /src_graphic/get_params.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** get_params.c for get_params.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Tue May 6 10:31:40 2014 LOEB Thomas 8 | ** Last update Thu Jun 12 18:10:20 2014 LOEB Thomas 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | static int get_port(t_graphic *c, char **av, int *i) 14 | { 15 | unsigned int j; 16 | 17 | if (av[++(*i)] == NULL) 18 | return (my_error(BAD_VALUE_OPT, FAILURE)); 19 | j = -1; 20 | while (av[(*i)][++j] != '\0') 21 | if (av[(*i)][j] < '0' || av[(*i)][j] > '9') 22 | return (my_error(BAD_VALUE_OPT, FAILURE)); 23 | c->port = atoi(av[(*i)]); 24 | return (SUCCESS); 25 | } 26 | 27 | static int get_ip(t_graphic *c, char **av, int *i) 28 | { 29 | if ((c->ip = av[++(*i)]) == NULL) 30 | return (my_error(BAD_VALUE_OPT, FAILURE)); 31 | return (SUCCESS); 32 | } 33 | 34 | static int (*g_get[GRAPHIC_NB_OPT])(t_graphic *, char **, int *) = 35 | { 36 | &get_port, 37 | &get_ip 38 | }; 39 | 40 | int get_params(t_graphic *c, char **av, int *i, int pos) 41 | { 42 | return ((*g_get[pos])(c, av, i)); 43 | } 44 | -------------------------------------------------------------------------------- /src_graphic/pic_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** pic_cmd.c for pic_cmd.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Tue Jun 24 12:57:32 2014 abgral_f 8 | ** Last update Sat Jul 5 14:42:14 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int pic_cmd(char **args, t_graphic *c) 14 | { 15 | t_client *tmp; 16 | int count; 17 | 18 | if (atoi(args[0]) < 0 || (unsigned int)atoi(args[0]) >= c->x 19 | || atoi(args[1]) < 0 || (unsigned int)atoi(args[1]) >= c->y) 20 | return (my_error("Unknown coordinates", FAILURE)); 21 | if (atoi(args[2]) > 8 || atoi(args[2]) < 1) 22 | return (my_error("Invalid lvl", FAILURE)); 23 | count = 3; 24 | while (args[count] != NULL) 25 | { 26 | if (check_player(atoi(args[count] + 1), c) == FAILURE) 27 | return (my_error("Unknown player id", FAILURE)); 28 | tmp = c->client; 29 | while (tmp->id != (unsigned int)atoi(args[count] + 1)) 30 | tmp = tmp->next; 31 | tmp->isAscending = atoi(args[2]); 32 | tmp->anim = INCANT; 33 | tmp->count_anim = 0; 34 | count++; 35 | } 36 | return (SUCCESS); 37 | } 38 | -------------------------------------------------------------------------------- /src_graphic/event.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** event.c for event.c in /home/abgral_f/backups/zappy5 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Wed Jul 9 12:45:03 2014 abgral_f 8 | ** Last update Fri Jul 11 12:38:38 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int event(t_graphic *c) 14 | { 15 | if (c->display.event.type == SDL_KEYDOWN) 16 | { 17 | if (c->display.event.key.keysym.sym == SDLK_ESCAPE) 18 | return (FAILURE); 19 | if (c->display.event.key.keysym.sym == SDLK_LEFT 20 | && c->display.cursor_x > 0) 21 | c->display.cursor_x--; 22 | else 23 | if (c->display.event.key.keysym.sym == SDLK_RIGHT 24 | && MAP_X / SPRITE_SIZE + c->display.cursor_x + 1 <= c->x) 25 | c->display.cursor_x++; 26 | else 27 | if (c->display.event.key.keysym.sym == SDLK_UP 28 | && c->display.cursor_y > 0) 29 | c->display.cursor_y--; 30 | else 31 | if (c->display.event.key.keysym.sym == SDLK_DOWN 32 | && WIN_Y / SPRITE_SIZE + c->display.cursor_y + 1 <= c->y) 33 | c->display.cursor_y++; 34 | } 35 | return (get_click_coord(c)); 36 | } 37 | -------------------------------------------------------------------------------- /src_server/exec_plv.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_plv.c for exec_plv.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Mon Jun 9 13:13:04 2014 LOEB Thomas 8 | ** Last update Wed Jun 11 16:56:28 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_plv_manual(t_server *s) 14 | { 15 | t_client *tmp; 16 | int pos; 17 | 18 | if (write_graphic(s) == FAILURE) 19 | return (FALSE); 20 | pos = atoi(s->p.cmd[1] + 1); 21 | tmp = s->clients; 22 | while (tmp->id != (unsigned int)pos) 23 | tmp = tmp->next; 24 | strcpy(s->graphic->send, s->p.line); 25 | s->graphic->send[strlen(s->graphic->send)] = ' '; 26 | nbr_to_str(tmp->level, s->graphic->send + strlen(s->graphic->send), "\n"); 27 | return (TRUE); 28 | } 29 | 30 | bool exec_plv(t_server *s) 31 | { 32 | if (write_graphic(s) == FAILURE) 33 | return (FALSE); 34 | strcpy(s->graphic->send, (PLV" #")); 35 | nbr_to_str(s->tmp_clients->id, 36 | s->graphic->send + strlen(s->graphic->send), " "); 37 | nbr_to_str(s->tmp_clients->level, 38 | s->graphic->send + strlen(s->graphic->send), "\n"); 39 | return (TRUE); 40 | } 41 | -------------------------------------------------------------------------------- /src_server/exec_tna.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_tna.c for exec_tna.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Mon Jun 9 13:13:04 2014 LOEB Thomas 8 | ** Last update Wed Jun 11 16:42:35 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | static void exec_tna_fill(t_server *s) 14 | { 15 | strcpy(s->graphic->send + strlen(TNA) + 1, s->tmp_teams->name); 16 | s->graphic->send[strlen(s->graphic->send)] = '\n'; 17 | } 18 | 19 | bool exec_tna(t_server *s) 20 | { 21 | t_client *tmp; 22 | 23 | if (write_graphic(s) == FAILURE) 24 | return (FALSE); 25 | strcpy(s->graphic->send, (TNA" ")); 26 | s->tmp_teams = s->teams; 27 | while (s->tmp_teams != NULL && s->tmp_teams->next != NULL) 28 | { 29 | exec_tna_fill(s); 30 | if (rw(s->graphic->socket, s->graphic->send, 31 | strlen(s->graphic->send), W) == FAILURE) 32 | { 33 | tmp = s->tmp_clients; 34 | s->tmp_clients = s->graphic; 35 | del_client(s, TRUE); 36 | s->tmp_clients = tmp; 37 | return (FALSE); 38 | } 39 | s->tmp_teams = s->tmp_teams->next; 40 | } 41 | exec_tna_fill(s); 42 | return (TRUE); 43 | } 44 | -------------------------------------------------------------------------------- /src_graphic/close_graphic.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** close_graphic.c for close_graphic.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Wed May 7 13:22:05 2014 LOEB Thomas 8 | ** Last update Thu Jul 10 22:35:28 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int close_graphic(t_graphic *c, int retVal) 14 | { 15 | if (stop(STOP_VALUE) < STOP_VALUE) 16 | fprintf(stderr, "ERROR: graphic did not quit correctly (%d)\n", 17 | stop(STOP_VALUE)); 18 | else if (stop(STOP_VALUE) > STOP_VALUE) 19 | fprintf(stderr, "SUCCESS: graphic quitted correctly (%d)\n", 20 | stop(STOP_VALUE)); 21 | if (c->p.cmd != NULL) 22 | free_words(&c->p); 23 | if (c->l.line != NULL) 24 | free(c->l.line); 25 | if (c->map != NULL) 26 | free(c->map); 27 | if (c->socket != -1 && close(c->socket) == -1) 28 | my_perror(SYSCALL("close"), CONTINUE); 29 | if (c->teams != NULL) 30 | free_teams(c); 31 | if (c->eggs != NULL) 32 | free_eggs(c); 33 | if (c->client != NULL) 34 | free_clients(c); 35 | if (c->display.list != NULL) 36 | free_surfaces(c); 37 | SDL_Quit(); 38 | TTF_Quit(); 39 | return (retVal); 40 | } 41 | -------------------------------------------------------------------------------- /src_common/rw.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** rw.c for rw.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Wed May 7 15:16:42 2014 LOEB Thomas 8 | ** Last update Sat Jul 12 12:25:26 2014 abgral_f 9 | */ 10 | 11 | #include "common.h" 12 | 13 | static int read_simple(int fd, void *buf, size_t count) 14 | { 15 | if (read(fd, buf, count) <= 0) 16 | return (my_perror(SYSCALL("read"), FAILURE)); 17 | return (SUCCESS); 18 | } 19 | 20 | static int write_loop(int fd, const void *buf, size_t count) 21 | { 22 | unsigned int i; 23 | int ret; 24 | 25 | i = 0; 26 | while (i < count) 27 | { 28 | if ((ret = write(fd, buf + i, count - i)) <= 0) 29 | return (my_perror(SYSCALL("write"), FAILURE)); 30 | if (stop(STOP_VALUE) == STOP_BRK_PIPE) 31 | { 32 | stop(STOP_RESET); 33 | return (my_error(BRK_PIPE, FAILURE)); 34 | } 35 | i += ret; 36 | } 37 | return (SUCCESS); 38 | } 39 | 40 | int rw(int fd, void *buf, size_t count, e_mode flag) 41 | { 42 | if (flag == R) 43 | return (read_simple(fd, buf, count)); 44 | else if (flag == W) 45 | return (write_loop(fd, buf, count)); 46 | else 47 | return (FAILURE); 48 | } 49 | -------------------------------------------------------------------------------- /inc/error.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** error.h for error.h in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Mon May 5 15:33:04 2014 LOEB Thomas 8 | ** Last update Fri Jul 11 19:53:52 2014 Baptiste Acca 9 | */ 10 | 11 | #ifndef ERROR_H_ 12 | # define ERROR_H_ 13 | 14 | # include 15 | 16 | # define ERROR(error) ("ERROR: "error) 17 | # define WARNING(error) ("WARNING: "error) 18 | # define SYSCALL(syscall) ERROR("syscall '"syscall"' failed") 19 | 20 | # define WRONG_OPT ERROR("bad(s) option(s)") 21 | # define TOO_MANY_OPT WARNING("too many options -> using the last one") 22 | # define BAD_VALUE_OPT ERROR("bad value of option(s)") 23 | 24 | # define BAD_WAY_QUIT ERROR("can not quit this way") 25 | 26 | # define BRK_PIPE ERROR("client/server quitted during write") 27 | 28 | # define STOP_VALUE 0 29 | # define STOP_RESET 42 30 | 31 | # define STOP_BRK_PIPE -1 32 | # define STOP_QUIT 1 33 | 34 | # define TCGETATTR_FAIL SYSCALL("tcgetattr") 35 | # define TCSETATTR_FAIL SYSCALL("tcsetattr") 36 | # define READ_FAIL SYSCALL("Read") 37 | 38 | int my_perror(char *, int); 39 | int my_error(char *, int); 40 | 41 | #endif /* ERROR_H_ */ 42 | -------------------------------------------------------------------------------- /src_graphic/tna_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** tna_cmd.c for tna_cmd.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Thu Jun 19 16:41:03 2014 abgral_f 8 | ** Last update Thu Jul 3 16:44:03 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | void free_teams(t_graphic *c) 14 | { 15 | t_team *tmp; 16 | 17 | while (c->teams != NULL) 18 | { 19 | tmp = c->teams; 20 | c->teams = c->teams->next; 21 | free(tmp->name); 22 | free(tmp); 23 | } 24 | } 25 | 26 | static int add_team(t_graphic *c, char *name) 27 | { 28 | t_team *new; 29 | 30 | if ((new = malloc(sizeof(t_team))) == NULL) 31 | return (my_perror(SYSCALL("malloc"), FAILURE)); 32 | new->name = strdup(name); 33 | new->next = c->teams; 34 | new->prev = NULL; 35 | if (c->teams != NULL) 36 | c->teams->prev = new; 37 | c->teams = new; 38 | return (SUCCESS); 39 | } 40 | 41 | int tna_cmd(char **args, t_graphic *c) 42 | { 43 | if (check_team(c, args[0]) == SUCCESS) 44 | return (my_error("This team already exist", FAILURE)); 45 | if (add_team(c, args[0]) == FAILURE) 46 | return (FAILURE); 47 | return (SUCCESS); 48 | } 49 | -------------------------------------------------------------------------------- /src_server/get_params_fct.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** get_params_fct.c for get_params_fct.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Tue May 6 13:58:26 2014 LOEB Thomas 8 | ** Last update Mon Jun 23 18:45:56 2014 LOEB Thomas 9 | */ 10 | 11 | static int get_names(t_server *s, char **av, int *i) 12 | { 13 | free_teams(s); 14 | if (av[(*i) + 1] == NULL) 15 | return (my_error(BAD_VALUE_OPT, FAILURE)); 16 | while (av[++(*i)] != NULL && is_in_opts(av[(*i)]) == FAILURE) 17 | if (nb_space(av[(*i)]) != 0) 18 | return (my_error(BAD_VALUE_OPT, FAILURE)); 19 | else if (add_team(s, av[(*i)]) == FAILURE) 20 | { 21 | free_teams(s); 22 | return (FAILURE); 23 | } 24 | if (s->teams == NULL) 25 | return (my_error(BAD_VALUE_OPT, FAILURE)); 26 | --(*i); 27 | return (SUCCESS); 28 | } 29 | 30 | static int get_port(t_server *s, char **av, int *i) 31 | { 32 | unsigned int j; 33 | 34 | if (av[++(*i)] == NULL) 35 | return (my_error(BAD_VALUE_OPT, FAILURE)); 36 | j = -1; 37 | while (av[(*i)][++j] != '\0') 38 | if (av[(*i)][j] < '0' || av[(*i)][j] > '9') 39 | return (my_error(BAD_VALUE_OPT, FAILURE)); 40 | s->port = atoi(av[(*i)]); 41 | return (SUCCESS); 42 | } 43 | -------------------------------------------------------------------------------- /src_common/nbr_str.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** nbrlen.c for nbrlen.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Sun May 18 17:52:15 2014 LOEB Thomas 8 | ** Last update Wed Jun 25 14:01:47 2014 LOEB Thomas 9 | */ 10 | 11 | #include "common.h" 12 | 13 | int nbrlen(int nb) 14 | { 15 | int len; 16 | 17 | len = 1; 18 | while (nb / 10 != 0) 19 | { 20 | nb /= 10; 21 | ++len; 22 | } 23 | return (len); 24 | } 25 | 26 | int nbr_to_str(int nb, char *s, char *after_nb) 27 | { 28 | unsigned int idx; 29 | unsigned int after; 30 | int len; 31 | 32 | if (nb < 0) 33 | nb = 0; 34 | idx = -1; 35 | len = nbrlen(nb) - 1; 36 | while (nb / 10 != 0) 37 | { 38 | s[len - ++idx] = nb % 10 + 48; 39 | nb /= 10; 40 | } 41 | s[len - ++idx] = nb + 48; 42 | if (after_nb != NULL) 43 | { 44 | after = -1; 45 | while (after_nb[++after] != '\0') 46 | s[++idx] = after_nb[after]; 47 | s[++idx] = '\0'; 48 | } 49 | return (SUCCESS); 50 | } 51 | 52 | int nb_space(char *s) 53 | { 54 | unsigned int i; 55 | int ret; 56 | 57 | i = -1; 58 | ret = 0; 59 | while (s[++i] != '\0') 60 | if (s[i] == ' ') 61 | ++ret; 62 | return (ret); 63 | } 64 | -------------------------------------------------------------------------------- /src_server/exec_bct.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_bct.c for exec_bct.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Mon Jun 9 13:13:04 2014 LOEB Thomas 8 | ** Last update Wed Jun 11 16:52:57 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | void exec_bct_fill(t_server *s, int x, int y) 14 | { 15 | int p; 16 | unsigned int i; 17 | 18 | p = x + y * s->x; 19 | strcpy(s->graphic->send, (BCT" ")); 20 | nbr_to_str(x, s->graphic->send + strlen(s->graphic->send), " "); 21 | nbr_to_str(y, s->graphic->send + strlen(s->graphic->send), " "); 22 | nbr_to_str(s->map[p].food, s->graphic->send + strlen(s->graphic->send), " "); 23 | i = -1; 24 | while (++i < NB_STONE) 25 | nbr_to_str(s->map[p].stone[i], 26 | s->graphic->send + strlen(s->graphic->send), 27 | (i + 1 == NB_STONE) ? "\n" : " "); 28 | } 29 | 30 | bool exec_bct_manual(t_server *s) 31 | { 32 | if (write_graphic(s) == FAILURE) 33 | return (FALSE); 34 | exec_bct_fill(s, atoi(s->p.cmd[1]), atoi(s->p.cmd[2])); 35 | return (TRUE); 36 | } 37 | 38 | bool exec_bct(t_server *s) 39 | { 40 | if (write_graphic(s) == FAILURE) 41 | return (FALSE); 42 | exec_bct_fill(s, s->tmp_clients->x, s->tmp_clients->y); 43 | return (TRUE); 44 | } 45 | -------------------------------------------------------------------------------- /src_server/exec_inventory.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_forward.c for exec_forward.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Fri May 30 13:21:25 2014 LOEB Thomas 8 | ** Last update Wed Jun 11 16:10:58 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | static char *g_inventory[NB_STONE] = 14 | { 15 | (" "LINEMATE" "), 16 | (" "DERAUMERE" "), 17 | (" "SIBUR" "), 18 | (" "MENDIANE" "), 19 | (" "PHIRAS" "), 20 | (" "THYSTAME" ") 21 | }; 22 | 23 | bool exec_inventory(t_server *s) 24 | { 25 | unsigned int food; 26 | unsigned int i; 27 | 28 | strcpy(s->tmp_clients->send, ("{"FOOD" ")); 29 | food = FOOD_TIME * (s->tmp_clients->life - 1) 30 | + (FOOD_TIME - (s->tmp_clients->action_life.usec / SEC_TO_USEC)); 31 | nbr_to_str(food, s->tmp_clients->send + strlen(s->tmp_clients->send), ","); 32 | i = -1; 33 | while (++i < NB_STONE) 34 | { 35 | strcpy(s->tmp_clients->send + strlen(s->tmp_clients->send), 36 | g_inventory[i]); 37 | nbr_to_str(s->tmp_clients->stone[i], 38 | s->tmp_clients->send + strlen(s->tmp_clients->send), 39 | (i + 1 == NB_STONE) ? NULL : ","); 40 | } 41 | strcpy(s->tmp_clients->send + strlen(s->tmp_clients->send), "}\n"); 42 | return (FALSE); 43 | } 44 | -------------------------------------------------------------------------------- /src_graphic/ppo_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** ppo_cmd.c for ppo_cmd.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Mon Jun 23 17:55:07 2014 abgral_f 8 | ** Last update Wed Jul 9 15:46:35 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | int ppo_cmd(char **args, t_graphic *c) 14 | { 15 | t_client *tmp; 16 | 17 | if (check_player(atoi(args[0] + 1), c) == FAILURE) 18 | return (my_error("Unknown player id", FAILURE)); 19 | if (atoi(args[1]) < 0 || (unsigned int)atoi(args[1]) >= c->x 20 | || atoi(args[2]) < 0 || (unsigned int)atoi(args[2]) >= c->y) 21 | return (my_error("Unknown coordinates", FAILURE)); 22 | if (atoi(args[3]) < 1 || atoi(args[3]) > 4) 23 | return (my_error("Unknown direction", FAILURE)); 24 | tmp = c->client; 25 | while (tmp->id != (unsigned int)atoi(args[0] + 1)) 26 | tmp = tmp->next; 27 | tmp->direction = atoi(args[3]) - 1; 28 | if (args[4] == NULL && 29 | ((unsigned int)atoi(args[1]) != tmp->x 30 | || (unsigned int)atoi(args[2]) != tmp->y)) 31 | { 32 | tmp->last_coords[0] = tmp->x; 33 | tmp->last_coords[1] = tmp->y; 34 | tmp->anim = MOVES; 35 | tmp->count_anim = 0; 36 | } 37 | tmp->x = atoi(args[1]); 38 | tmp->y = atoi(args[2]); 39 | return (SUCCESS); 40 | } 41 | -------------------------------------------------------------------------------- /src_client/get_params.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** get_params.c for get_params.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Tue May 6 10:31:40 2014 LOEB Thomas 8 | ** Last update Fri Jul 11 19:18:33 2014 Baptiste Acca 9 | */ 10 | 11 | #include "client.h" 12 | 13 | static int get_name(t_client *c, char **av, int *i) 14 | { 15 | if ((c->name = av[++(*i)]) == NULL) 16 | return (my_error(BAD_VALUE_OPT, FAILURE)); 17 | return (SUCCESS); 18 | } 19 | 20 | static int get_port(t_client *c, char **av, int *i) 21 | { 22 | unsigned int j; 23 | 24 | if (av[++(*i)] == NULL) 25 | return (my_error(BAD_VALUE_OPT, FAILURE)); 26 | j = -1; 27 | while (av[(*i)][++j] != '\0') 28 | if (av[(*i)][j] < '0' || av[(*i)][j] > '9') 29 | return (my_error(BAD_VALUE_OPT, FAILURE)); 30 | c->port = atoi(av[(*i)]); 31 | return (SUCCESS); 32 | } 33 | 34 | static int get_ip(t_client *c, char **av, int *i) 35 | { 36 | if ((c->ip = av[++(*i)]) == NULL) 37 | return (my_error(BAD_VALUE_OPT, FAILURE)); 38 | return (SUCCESS); 39 | } 40 | 41 | static int (*g_get[CLIENT_NB_OPT])(t_client *, char **, int *) = 42 | { 43 | &get_name, 44 | &get_port, 45 | &get_ip, 46 | }; 47 | 48 | int get_params(t_client *c, char **av, int *i, int pos) 49 | { 50 | return ((*g_get[pos])(c, av, i)); 51 | } 52 | -------------------------------------------------------------------------------- /src_server/read.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** read.c for read.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Sun May 11 12:55:25 2014 LOEB Thomas 8 | ** Last update Mon Jun 9 11:51:58 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | static int nb_cmd(t_client *c) 14 | { 15 | unsigned int i; 16 | int ret; 17 | 18 | i = -1; 19 | ret = 0; 20 | while (++i < BUFF_LEN) 21 | if (c->b.circular[i] == '\n') 22 | ++ret; 23 | return (ret); 24 | } 25 | 26 | static void read_one_fd(t_server *s, t_select *sel) 27 | { 28 | if (nb_cmd(s->tmp_clients) < 10 && 29 | FD_ISSET(s->tmp_clients->socket, &sel->rdfds)) 30 | { 31 | memset(s->tmp_clients->b.tmp, '\0', BUFF_LEN); 32 | if (rw(s->tmp_clients->socket, 33 | s->tmp_clients->b.tmp, BUFF_LEN, R) == FAILURE) 34 | del_client(s, TRUE); 35 | else 36 | { 37 | buffer_to_circular(&s->tmp_clients->b); 38 | s->tmp_clients = s->tmp_clients->next; 39 | } 40 | } 41 | else 42 | s->tmp_clients = s->tmp_clients->next; 43 | } 44 | 45 | int read_from_fds(t_server *s, t_select *sel) 46 | { 47 | s->tmp_clients = s->clients; 48 | while (s->tmp_clients != NULL) 49 | read_one_fd(s, sel); 50 | if (s->graphic != NULL) 51 | { 52 | s->tmp_clients = s->graphic; 53 | read_one_fd(s, sel); 54 | } 55 | return (SUCCESS); 56 | } 57 | -------------------------------------------------------------------------------- /src_server/check_graphic.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** check_graphic.c for check_graphic.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Mon Jun 9 12:54:11 2014 LOEB Thomas 8 | ** Last update Mon Jun 9 17:39:13 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool check_bct(t_server *s) 14 | { 15 | int coord; 16 | 17 | if ((coord = getnbr(s->p.cmd[1])) < 0 || coord >= s->x || 18 | (coord = getnbr(s->p.cmd[2])) < 0 || coord >= s->y) 19 | return (FALSE); 20 | return (TRUE); 21 | } 22 | 23 | bool check_no_player(t_server *s) 24 | { 25 | int pos; 26 | t_client *tmp; 27 | 28 | if (s->p.cmd[1][0] != '#' || (pos = getnbr(s->p.cmd[1] + 1)) < 0) 29 | return (FALSE); 30 | tmp = s->clients; 31 | while (tmp != NULL && (unsigned int)pos != tmp->id) 32 | tmp = tmp->next; 33 | if (tmp == NULL) 34 | return (FALSE); 35 | return (TRUE); 36 | } 37 | 38 | bool check_sst(t_server *s) 39 | { 40 | unsigned int i; 41 | unsigned char comma; 42 | 43 | i = -1; 44 | comma = 0; 45 | while (s->p.cmd[1][++i] != '\0') 46 | if ((s->p.cmd[1][i] < '0' || s->p.cmd[1][i] > '9') && 47 | (comma == 1 || (comma == 0 && s->p.cmd[1][i] != '.'))) 48 | return (FALSE); 49 | else if (s->p.cmd[1][i] == '.') 50 | comma = 1; 51 | if (atoi(s->p.cmd[1]) <= 0) 52 | return (FALSE); 53 | return (TRUE); 54 | } 55 | -------------------------------------------------------------------------------- /src_server/exec_enw.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_enw.c for exec_enw.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Thu Jun 12 15:41:15 2014 LOEB Thomas 8 | ** Last update Fri Jun 13 13:49:50 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_enw(t_server *s) 14 | { 15 | if (write_graphic(s) == FAILURE) 16 | return (FALSE); 17 | strcpy(s->graphic->send, (ENW" #")); 18 | nbr_to_str(s->tmp_clients->team->eggs->id, 19 | s->graphic->send + strlen(s->graphic->send), " #"); 20 | nbr_to_str(s->tmp_clients->id, 21 | s->graphic->send + strlen(s->graphic->send), " "); 22 | nbr_to_str(s->tmp_clients->x, 23 | s->graphic->send + strlen(s->graphic->send), " "); 24 | nbr_to_str(s->tmp_clients->y, 25 | s->graphic->send + strlen(s->graphic->send), "\n"); 26 | return (TRUE); 27 | } 28 | 29 | bool exec_enw_manual(t_server *s, t_egg *e) 30 | { 31 | if (write_graphic(s) == FAILURE) 32 | return (FALSE); 33 | strcpy(s->graphic->send, (ENW" #")); 34 | nbr_to_str(e->id, s->graphic->send + strlen(s->graphic->send), " #"); 35 | nbr_to_str(e->id_client, s->graphic->send + strlen(s->graphic->send), " "); 36 | nbr_to_str(e->x, s->graphic->send + strlen(s->graphic->send), " "); 37 | nbr_to_str(e->y, s->graphic->send + strlen(s->graphic->send), "\n"); 38 | return (TRUE); 39 | } 40 | -------------------------------------------------------------------------------- /src_server/list_team.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** list_team.c for list_team.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Tue May 6 13:29:52 2014 LOEB Thomas 8 | ** Last update Fri May 16 13:20:43 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | int add_team(t_server *s, char *name) 14 | { 15 | t_team *new; 16 | 17 | if ((new = malloc(sizeof(t_team))) == NULL) 18 | return (my_perror(SYSCALL("malloc"), FAILURE)); 19 | new->name = name; 20 | new->eggs = NULL; 21 | new->nb_egg_remaining = 0; 22 | new->next = s->teams; 23 | new->prev = NULL; 24 | if (s->teams != NULL) 25 | s->teams->prev = new; 26 | s->teams = new; 27 | return (SUCCESS); 28 | } 29 | 30 | void init_teams(t_server *s) 31 | { 32 | if (s->teams == NULL) 33 | { 34 | add_team(s, STD_TEAM1); 35 | add_team(s, STD_TEAM2); 36 | } 37 | s->tmp_teams = s->teams; 38 | while (s->tmp_teams != NULL) 39 | { 40 | s->tmp_teams->nb_remaining = s->nb_per_team; 41 | s->tmp_teams = s->tmp_teams->next; 42 | } 43 | } 44 | 45 | void free_teams(t_server *s) 46 | { 47 | t_team *tmp; 48 | 49 | s->tmp_teams = s->teams; 50 | while (s->tmp_teams != NULL) 51 | { 52 | tmp = s->tmp_teams; 53 | free_eggs(s); 54 | s->tmp_teams = s->tmp_teams->next; 55 | free(tmp); 56 | } 57 | s->teams = NULL; 58 | } 59 | -------------------------------------------------------------------------------- /src_client/check_cmds.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** check_cmds.c for check_cmds.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Tue May 13 12:39:09 2014 LOEB Thomas 8 | ** Last update Fri Jul 11 15:33:18 2014 CHAUCHET Alan 9 | */ 10 | 11 | #include "client.h" 12 | 13 | static int check_connection(t_client *c) 14 | { 15 | if (strcmp(c->p.line, WELCOME_CLIENT("")) == 0) 16 | { 17 | if (rw(c->socket, c->name, strlen(c->name), W) == FAILURE || 18 | rw(c->socket, "\n", 1, W) == FAILURE) 19 | return (FAILURE); 20 | } 21 | else if (c->p.len == 1) 22 | { 23 | if ((c->remaining = getnbr(c->p.line)) <= 0) 24 | return (FAILURE); 25 | } 26 | else if (c->p.len == 2) 27 | { 28 | if ((c->x = getnbr(c->p.cmd[0])) <= 0 || 29 | (c->y = getnbr(c->p.cmd[1])) <= 0) 30 | return (FAILURE); 31 | c->connected = TRUE; 32 | } 33 | else 34 | return (FAILURE); 35 | return (SUCCESS); 36 | } 37 | 38 | int check_cmds(t_client *c) 39 | { 40 | int pos; 41 | 42 | if ((pos = pos_cmd(&c->b)) != -1) 43 | { 44 | get_cmd(&c->b, pos); 45 | if (parse_cmd(&c->p, c->b.tmp) == FAILURE) 46 | return (CONTINUE); 47 | printf("server : (%s)\n", c->p.line); 48 | if (c->connected == FALSE) 49 | return (check_connection(c)); 50 | else if (strcmp(c->p.line, DEATH("")) == 0) 51 | return (FAILURE); 52 | } 53 | return (SUCCESS); 54 | } 55 | -------------------------------------------------------------------------------- /src_graphic/enw_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** enw_cmd.c for enw_cmd.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Tue Jun 24 18:50:50 2014 abgral_f 8 | ** Last update Sat Jul 5 18:29:14 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | static void set_egg_position(char **args, t_graphic *c) 14 | { 15 | t_egg *tmp; 16 | 17 | tmp = c->eggs; 18 | while (tmp->id != (unsigned int)atoi(args[0] + 1)) 19 | tmp = tmp->next; 20 | tmp->x = atoi(args[2]); 21 | tmp->y = atoi(args[3]); 22 | } 23 | 24 | int enw_cmd(char **args, t_graphic *c) 25 | { 26 | t_client *tmp; 27 | 28 | if (check_egg(atoi(args[0] + 1), c) == SUCCESS) 29 | return (my_error("This egg's id already exist", FAILURE)); 30 | if (check_player(atoi(args[1] + 1), c) == FAILURE) 31 | return (my_error("This player's id does not exist", FAILURE)); 32 | tmp = c->client; 33 | while (tmp->id != (unsigned int)atoi(args[1] + 1)) 34 | tmp = tmp->next; 35 | if (add_egg(c, tmp->team->name, args[0] + 1) == FAILURE) 36 | return (FAILURE); 37 | if (atoi(args[2]) < 0 || (unsigned int)atoi(args[2]) >= c->x 38 | || atoi(args[3]) < 0 || (unsigned int)atoi(args[3]) >= c->y) 39 | { 40 | del_egg(c, atoi(args[0] + 1)); 41 | return (my_error("Unknown coordinates", FAILURE)); 42 | } 43 | set_egg_position(args, c); 44 | tmp->anim = UNDEFINED; 45 | return (SUCCESS); 46 | } 47 | -------------------------------------------------------------------------------- /src_server/exec_broadcast.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_forward.c for exec_forward.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Fri May 30 13:21:25 2014 LOEB Thomas 8 | ** Last update Thu Jun 12 16:00:48 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | static void exec_broadcast_delete(t_server *s, t_client **c) 14 | { 15 | t_client *tmp; 16 | 17 | tmp = *c; 18 | *c = s->tmp_clients; 19 | s->tmp_clients = tmp; 20 | tmp = tmp->next; 21 | del_client(s, TRUE); 22 | s->tmp_clients = *c; 23 | *c = tmp; 24 | } 25 | 26 | static void exec_broadcast_send(t_server *s, t_client **tmp, 27 | char *send, unsigned int len) 28 | { 29 | send[8] = get_orientation(s, (*tmp), s->tmp_clients); 30 | if (rw((*tmp)->socket, send, len, W) == FAILURE) 31 | exec_broadcast_delete(s, tmp); 32 | else 33 | (*tmp) = (*tmp)->next; 34 | } 35 | 36 | bool exec_broadcast(t_server *s) 37 | { 38 | t_client *tmp; 39 | char send[ARG_LEN + 12]; 40 | unsigned int len; 41 | 42 | tmp = s->clients; 43 | strcpy(send, MSG); 44 | strcpy(send + strlen(send), s->tmp_clients->action.param); 45 | send[strlen(send)] = '\n'; 46 | len = strlen(send); 47 | while (tmp != NULL) 48 | if (tmp != s->tmp_clients) 49 | exec_broadcast_send(s, &tmp, send, len); 50 | else 51 | tmp = tmp->next; 52 | strcpy(s->tmp_clients->send, OK("\n")); 53 | exec_pbc(s); 54 | return (FALSE); 55 | } 56 | -------------------------------------------------------------------------------- /src_server/exec_pic.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_pic.c for exec_pic.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Tue Jun 10 14:32:32 2014 LOEB Thomas 8 | ** Last update Mon Jun 30 16:01:39 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | static void exec_pic_clients(t_server *s) 14 | { 15 | t_client *tmp; 16 | 17 | tmp = s->clients; 18 | while (tmp != NULL) 19 | { 20 | if (tmp != s->tmp_clients && 21 | tmp->isAscending == (int)s->tmp_clients->id && 22 | strlen(s->graphic->send) + nbrlen(tmp->id) + 2 < BUFF_LEN) 23 | { 24 | s->graphic->send[strlen(s->graphic->send)] = '#'; 25 | nbr_to_str(tmp->id, 26 | s->graphic->send + strlen(s->graphic->send), " "); 27 | } 28 | tmp = tmp->next; 29 | } 30 | s->graphic->send[strlen(s->graphic->send) - 1] = '\n'; 31 | } 32 | 33 | bool exec_pic(t_server *s) 34 | { 35 | if (write_graphic(s) == FAILURE) 36 | return (FALSE); 37 | strcpy(s->graphic->send, (PIC" ")); 38 | nbr_to_str(s->tmp_clients->x, 39 | s->graphic->send + strlen(s->graphic->send), " "); 40 | nbr_to_str(s->tmp_clients->y, 41 | s->graphic->send + strlen(s->graphic->send), " "); 42 | nbr_to_str(s->tmp_clients->level + 1, 43 | s->graphic->send + strlen(s->graphic->send), " #"); 44 | nbr_to_str(s->tmp_clients->id, 45 | s->graphic->send + strlen(s->graphic->send), " "); 46 | exec_pic_clients(s); 47 | return (TRUE); 48 | } 49 | -------------------------------------------------------------------------------- /src_graphic/disp_map.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** disp_map.c for disp_map.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Fri Jul 4 15:07:15 2014 abgral_f 8 | ** Last update Thu Jul 10 19:44:06 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | static void set_sprite_size(t_graphic *c, int value) 14 | { 15 | c->display.sprite.w = SPRITE_SIZE + value; 16 | c->display.sprite.h = SPRITE_SIZE + value; 17 | } 18 | 19 | int display_map(t_graphic *c) 20 | { 21 | unsigned int count_x; 22 | unsigned int count_y; 23 | 24 | count_y = c->display.cursor_y - 1; 25 | set_sprite_size(c, -1); 26 | c->display.sprite.y = 0; 27 | while (++count_y != c->y && count_y != 28 | c->display.cursor_y + WIN_Y / SPRITE_SIZE) 29 | { 30 | count_x = c->display.cursor_x - 1; 31 | while (++count_x != c->x && count_x != 32 | c->display.cursor_x + MAP_X / SPRITE_SIZE) 33 | { 34 | if (c->map[count_x + count_y * c->x].sprite_one == FALSE) 35 | c->display.sprite.x = 0; 36 | else 37 | c->display.sprite.x = SPRITE_SIZE; 38 | c->display.pos.x = (count_x - c->display.cursor_x) * SPRITE_SIZE; 39 | c->display.pos.y = (count_y - c->display.cursor_y) * SPRITE_SIZE; 40 | if (SDL_BlitSurface(c->display.list[MAP], 41 | &c->display.sprite, c->display.list[WINDOW], 42 | &c->display.pos) == -1) 43 | return (my_error(SDL_GetError(), FAILURE)); 44 | } 45 | } 46 | set_sprite_size(c, 0); 47 | return (SUCCESS); 48 | } 49 | -------------------------------------------------------------------------------- /src_server/exec_ppo.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_ppo.c for exec_ppo.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Mon Jun 9 13:13:04 2014 LOEB Thomas 8 | ** Last update Wed Jun 11 16:55:11 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_ppo_manual(t_server *s) 14 | { 15 | t_client *tmp; 16 | int pos; 17 | 18 | if (write_graphic(s) == FAILURE) 19 | return (FALSE); 20 | pos = atoi(s->p.cmd[1] + 1); 21 | tmp = s->clients; 22 | while (tmp->id != (unsigned int)pos) 23 | tmp = tmp->next; 24 | strcpy(s->graphic->send, s->p.line); 25 | s->graphic->send[strlen(s->graphic->send)] = ' '; 26 | nbr_to_str(tmp->x, s->graphic->send + strlen(s->graphic->send), " "); 27 | nbr_to_str(tmp->y, s->graphic->send + strlen(s->graphic->send), " "); 28 | nbr_to_str(tmp->direction + 1, 29 | s->graphic->send + strlen(s->graphic->send), "\n"); 30 | return (TRUE); 31 | } 32 | 33 | bool exec_ppo(t_server *s) 34 | { 35 | if (write_graphic(s) == FAILURE) 36 | return (FALSE); 37 | strcpy(s->graphic->send, (PPO" #")); 38 | nbr_to_str(s->tmp_clients->id, 39 | s->graphic->send + strlen(s->graphic->send), " "); 40 | nbr_to_str(s->tmp_clients->x, 41 | s->graphic->send + strlen(s->graphic->send), " "); 42 | nbr_to_str(s->tmp_clients->y, 43 | s->graphic->send + strlen(s->graphic->send), " "); 44 | nbr_to_str(s->tmp_clients->direction + 1, 45 | s->graphic->send + strlen(s->graphic->send), "\n"); 46 | return (TRUE); 47 | } 48 | -------------------------------------------------------------------------------- /src_graphic/pnw_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** pnw_cmd.c for pnw_cmd.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Thu Jun 19 20:37:05 2014 abgral_f 8 | ** Last update Thu Jul 3 16:49:29 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | static void free_plv_arg(char **plv_args, 14 | bool free_case_one, bool free_case_two) 15 | { 16 | if (free_case_one == TRUE) 17 | free(plv_args[0]); 18 | if (free_case_two == TRUE) 19 | free(plv_args[1]); 20 | free(plv_args); 21 | } 22 | 23 | int pnw_cmd(char **args, t_graphic *c) 24 | { 25 | char **plv_args; 26 | 27 | if (check_player(atoi(args[0] + 1), c) == SUCCESS) 28 | return (my_error("This player's id already exist", FAILURE)); 29 | if (add_client(c, args[5], args[0] + 1) == FAILURE) 30 | return (FAILURE); 31 | else if ((plv_args = malloc(sizeof (*plv_args) * 2)) == NULL 32 | || (plv_args[0] = strdup(args[0])) == NULL 33 | || (plv_args[1] = strdup(args[4])) == NULL 34 | || plv_cmd(plv_args, c) == FAILURE 35 | || ppo_cmd(args, c) == FAILURE) 36 | { 37 | del_client(c, atoi(args[0] + 1)); 38 | if (plv_args != NULL) 39 | free(plv_args); 40 | else if (plv_args[0] == NULL) 41 | free_plv_arg(plv_args, TRUE, FALSE); 42 | else if (plv_args[1] == NULL) 43 | free_plv_arg(plv_args, TRUE, TRUE); 44 | else 45 | return (my_perror(SYSCALL("malloc"), FAILURE)); 46 | return (FAILURE); 47 | } 48 | free_plv_arg(plv_args, TRUE, TRUE); 49 | return (SUCCESS); 50 | } 51 | -------------------------------------------------------------------------------- /inc/gui.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** gui.h for gui.h in /home/manzan_m/Project/zappy_sdl 3 | ** 4 | ** Made by Maxime Manzano 5 | ** Login 6 | ** 7 | ** Started on Mon Jul 7 14:27:00 2014 Maxime Manzano 8 | ** Last update Fri Jul 11 14:02:04 2014 Maxime Manzano 9 | */ 10 | 11 | #ifndef GUI_H_ 12 | # define GUI_H_ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | # define POS_PLA 225 21 | # define POS_INV 65 22 | # define LI_INV 150 23 | # define DER_INV 210 24 | # define SIB_INV 270 25 | # define MEN_INV 330 26 | # define PHI_INV 390 27 | # define THY_INV 450 28 | # define LI_PLA 310 29 | # define DER_PLA 370 30 | # define SIB_PLA 430 31 | # define MEN_PLA 490 32 | # define PHI_PLA 550 33 | # define THY_PLA 610 34 | # define WIN_X 1024 35 | # define WIN_Y (WIN_X / 4 * 3) 36 | # define MAP_X (WIN_X - WIN_X / 4) 37 | # define MAP_Y WIN_Y 38 | # define GUI_X (WIN_X / 4) 39 | # define GUI_Y WIN_Y 40 | # define BPP 32 41 | # define SIZE_SPRITE (MAP_X / 24) 42 | # define POS_TAB(x, y, size) ((y) * size + (x)) 43 | # define SIZE_FONT 25 44 | # define FONT "font/font_gui.ttf" 45 | # define BACKGROUND "sprites/sprite_gui.bmp" 46 | 47 | 48 | typedef struct s_gui 49 | { 50 | TTF_Font *font; 51 | SDL_Surface *background; 52 | SDL_Surface *text; 53 | SDL_Color color; 54 | SDL_Rect conf; 55 | SDL_Rect conf_screen; 56 | SDL_Rect conf_background; 57 | int modx; 58 | int mody; 59 | int x; 60 | int y; 61 | 62 | } t_gui; 63 | 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /src_server/exec_take.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_forward.c for exec_forward.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Fri May 30 13:21:25 2014 LOEB Thomas 8 | ** Last update Fri Jun 13 14:33:10 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | static char *g_objects[NB_STONE + 1] = 14 | { 15 | LINEMATE, 16 | DERAUMERE, 17 | SIBUR, 18 | MENDIANE, 19 | PHIRAS, 20 | THYSTAME, 21 | FOOD 22 | }; 23 | 24 | static bool exec_take_sub(t_server *s, unsigned int i) 25 | { 26 | if (i == NB_STONE) 27 | { 28 | --s->map[s->tmp_clients->x + s->tmp_clients->y * s->x].food; 29 | ++s->tmp_clients->life; 30 | } 31 | else 32 | { 33 | --s->map[s->tmp_clients->x + s->tmp_clients->y * s->x].stone[i]; 34 | ++s->tmp_clients->stone[i]; 35 | } 36 | strcpy(s->tmp_clients->send, OK("\n")); 37 | exec_pgt(s, (i + 1) % (NB_STONE + 1)); 38 | exec_pin(s); 39 | exec_bct(s); 40 | return (FALSE); 41 | } 42 | 43 | bool exec_take(t_server *s) 44 | { 45 | unsigned int i; 46 | 47 | i = 0; 48 | while (i < NB_STONE + 1 && 49 | strcmp(s->tmp_clients->action.param, g_objects[i]) != 0) 50 | ++i; 51 | if (i == NB_STONE + 1 || 52 | (i == NB_STONE && 53 | s->map[s->tmp_clients->x + s->tmp_clients->y * s->x].food == 0) || 54 | s->map[s->tmp_clients->x + s->tmp_clients->y * s->x].stone[i] == 0) 55 | { 56 | strcpy(s->tmp_clients->send, KO("\n")); 57 | return (FALSE); 58 | } 59 | return (exec_take_sub(s, i)); 60 | } 61 | -------------------------------------------------------------------------------- /src_graphic/display_sdl.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** display_sdl.c for display_sdl.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Tue Jul 1 14:47:58 2014 abgral_f 8 | ** Last update Sat Jul 12 15:16:53 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | static t_anim cmp[NB_ANIMS] = 14 | { 15 | {MOVES, &anim_moves}, 16 | {KIK, &anim_kik}, 17 | {DROP, &anim_drop}, 18 | {LAY, &anim_lay}, 19 | {INCANT, &anim_incant} 20 | }; 21 | 22 | static int display_anims(t_graphic *c) 23 | { 24 | t_client *tmp; 25 | int count; 26 | 27 | tmp = c->client; 28 | while (tmp != NULL) 29 | { 30 | count = 0; 31 | while (count != NB_ANIMS) 32 | { 33 | if (tmp->anim == cmp[count].anim) 34 | if ((*(cmp[count].ptr_func))(c, tmp) == FAILURE) 35 | return (FAILURE); 36 | count++; 37 | } 38 | tmp = tmp->next; 39 | } 40 | return (SUCCESS); 41 | } 42 | 43 | int display_sdl(t_graphic *c) 44 | { 45 | if (SDL_FillRect(c->display.list[WINDOW], NULL, 0x000000) == -1) 46 | return (my_error(SDL_GetError(), FAILURE)); 47 | if (c->map != NULL && (display_map(c) == FAILURE || 48 | display_items(c) == FAILURE || 49 | display_eggs(c) == FAILURE || 50 | display_player(c) == FAILURE || 51 | display_anims(c) == FAILURE || 52 | display_gui(c) == FAILURE)) 53 | return (FAILURE); 54 | if (SDL_Flip(c->display.list[WINDOW]) == -1) 55 | return (my_error(SDL_GetError(), FAILURE)); 56 | if (SDL_PollEvent(&c->display.event) == -1) 57 | return (my_error((SDL_GetError()), FAILURE)); 58 | SDL_Delay(1000 * 7 / c->time / NB_SPRITES_ANIM); 59 | return (event(c)); 60 | } 61 | -------------------------------------------------------------------------------- /src_server/connect.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** connect.c for connect.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Mon Jun 9 11:21:27 2014 LOEB Thomas 8 | ** Last update Wed Jun 25 14:43:49 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | static void send_graphic(t_server *s) 14 | { 15 | t_client *tmp; 16 | 17 | tmp = s->tmp_clients; 18 | s->tmp_clients = s->clients; 19 | while (s->tmp_clients != NULL) 20 | { 21 | exec_pnw(s); 22 | s->tmp_clients = s->tmp_clients->next; 23 | } 24 | s->tmp_clients = tmp; 25 | s->tmp_teams = s->teams; 26 | while (s->tmp_teams != NULL) 27 | { 28 | s->tmp_teams->tmp_eggs = s->tmp_teams->eggs; 29 | while (s->tmp_teams->tmp_eggs != NULL) 30 | { 31 | exec_enw_manual(s, s->tmp_teams->tmp_eggs); 32 | s->tmp_teams->tmp_eggs = s->tmp_teams->tmp_eggs->next; 33 | } 34 | s->tmp_teams = s->tmp_teams->next; 35 | } 36 | } 37 | 38 | int connect_graphic(t_server *s) 39 | { 40 | if (s->graphic != NULL) 41 | { 42 | del_client(s, TRUE); 43 | return (SUCCESS); 44 | } 45 | s->graphic = s->tmp_clients; 46 | if (s->tmp_clients->prev != NULL) 47 | s->tmp_clients->prev->next = s->tmp_clients->next; 48 | if (s->tmp_clients->next != NULL) 49 | s->tmp_clients->next->prev = s->tmp_clients->prev; 50 | if (s->tmp_clients->prev == NULL) 51 | s->clients = s->clients->next; 52 | s->graphic->next = NULL; 53 | s->graphic->prev = NULL; 54 | exec_msz(s); 55 | exec_sgt(s); 56 | exec_mct(s); 57 | exec_tna(s); 58 | send_graphic(s); 59 | s->tmp_clients = s->tmp_clients->next; 60 | printf("Graphic connected\n"); 61 | return (SUCCESS); 62 | } 63 | -------------------------------------------------------------------------------- /src_common/circular.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** circular.c for circular.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Tue May 13 12:15:06 2014 LOEB Thomas 8 | ** Last update Fri Jun 13 14:10:53 2014 LOEB Thomas 9 | */ 10 | 11 | #include "common.h" 12 | 13 | int pos_cmd(t_buffer *b) 14 | { 15 | int ret; 16 | 17 | ret = -1; 18 | while (++ret < BUFF_LEN) 19 | if (b->circular[ret] == '\n') 20 | return (ret); 21 | return (-1); 22 | } 23 | 24 | void get_cmd(t_buffer *b, int pos) 25 | { 26 | if (pos == -1) 27 | return ; 28 | strncpy(b->tmp, b->circular, pos); 29 | b->tmp[pos] = '\0'; 30 | memmove(b->circular, b->circular + pos + 1, BUFF_LEN - (pos + 1)); 31 | memset(b->circular + BUFF_LEN - (pos + 1), '\0', pos + 1); 32 | b->idx -= (pos + 1); 33 | while ((int)b->idx < 0) 34 | b->idx += BUFF_LEN; 35 | } 36 | 37 | void buffer_to_circular(t_buffer *l) 38 | { 39 | unsigned int nbChar; 40 | 41 | if (l->tmp[BUFF_LEN - 1] == '\0') 42 | nbChar = strlen(l->tmp); 43 | else 44 | nbChar = BUFF_LEN; 45 | if (nbChar > BUFF_LEN - l->idx + 1) 46 | nbChar = BUFF_LEN - l->idx + 1; 47 | memmove(l->circular + l->idx, l->tmp, nbChar); 48 | l->idx = (l->idx + nbChar) % BUFF_LEN; 49 | if (l->tmp[BUFF_LEN - 1] != '\0' && nbChar != BUFF_LEN) 50 | { 51 | memmove(l->circular + l->idx, l->tmp + nbChar - 1, 52 | BUFF_LEN - nbChar); 53 | l->idx += (BUFF_LEN - nbChar); 54 | l->idx %= BUFF_LEN; 55 | } 56 | else if (l->tmp[BUFF_LEN - 1] == '\0' && nbChar != strlen(l->tmp)) 57 | { 58 | memmove(l->circular + l->idx, l->tmp + nbChar - 1, 59 | strlen(l->tmp) - nbChar); 60 | l->idx += (strlen(l->tmp) - nbChar); 61 | l->idx %= BUFF_LEN; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src_graphic/msz_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** msz_cmd.c for msz_cmd.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Thu Jun 19 14:52:01 2014 abgral_f 8 | ** Last update Thu Jul 10 23:42:19 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | static void set_items_pos(t_graphic *c) 14 | { 15 | unsigned int count; 16 | int count_stone; 17 | 18 | count = 0; 19 | while (count != c->x * c->y) 20 | { 21 | c->map[count].isUpdate = FALSE; 22 | c->map[count].sprite_one = (bool)rand() % 2; 23 | c->map[count].b.food_pos[0] = rand() 24 | % (SPRITE_SIZE - WIDTH_FOOD) - MARGE_HOR; 25 | c->map[count].b.food_pos[1] = rand() 26 | % (SPRITE_SIZE - HEIGHT_FOOD) - MARGE_VER + 1; 27 | count_stone = -1; 28 | while (++count_stone != NB_STONE) 29 | { 30 | c->map[count].b.stone_pos[count_stone][0] = MARGE_HOR * -1 31 | + rand() % (SPRITE_SIZE - WIDTH_STONE); 32 | c->map[count].b.stone_pos[count_stone][1] = MARGE_VER * -1 33 | + rand() % (SPRITE_SIZE - HEIGHT_STONE); 34 | } 35 | count++; 36 | } 37 | } 38 | 39 | int msz_cmd(char **args, t_graphic *c) 40 | { 41 | unsigned int count; 42 | int count_stones; 43 | 44 | if (c->map == NULL) 45 | { 46 | c->x = atoi(args[0]); 47 | c->y = atoi(args[1]); 48 | if ((c->map = malloc(sizeof (*c->map) * c->x * c->y)) == NULL) 49 | return (my_perror(SYSCALL("malloc"), CONTINUE)); 50 | set_items_pos(c); 51 | count = 0; 52 | while (count != c->x * c->y) 53 | { 54 | count_stones = 0; 55 | while (count_stones != NB_STONE) 56 | { 57 | c->map[count].b.stone[count_stones] = 0; 58 | c->map[count].b.food = 0; 59 | count_stones++; 60 | } 61 | count++; 62 | } 63 | } 64 | return (SUCCESS); 65 | } 66 | -------------------------------------------------------------------------------- /src_graphic/list_eggs.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** list_eggs.c for list_eggs.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Tue Jun 24 18:37:35 2014 abgral_f 8 | ** Last update Thu Jul 3 14:06:01 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | void free_eggs(t_graphic *c) 14 | { 15 | t_egg *tmp; 16 | 17 | tmp = c->eggs; 18 | while (c->eggs != NULL) 19 | { 20 | tmp = c->eggs; 21 | c->eggs = c->eggs->next; 22 | free(tmp); 23 | } 24 | } 25 | 26 | int add_egg(t_graphic *c, char *team, char *id) 27 | { 28 | t_egg *new; 29 | 30 | if ((new = malloc(sizeof(t_egg))) == NULL) 31 | return (my_perror(SYSCALL("malloc"), FAILURE)); 32 | new->next = c->eggs; 33 | new->prev = NULL; 34 | if (c->eggs != NULL) 35 | c->eggs->prev = new; 36 | c->eggs = new; 37 | if (check_team(c, team) == FAILURE) 38 | { 39 | del_egg(c, atoi(id)); 40 | return (my_error(strcat(team, " does not exist"), FAILURE)); 41 | } 42 | else 43 | new->team = get_team_by_name(c, team); 44 | new->id = atoi(id); 45 | new->isHatched = FALSE; 46 | return (SUCCESS); 47 | } 48 | 49 | int del_egg(t_graphic *c, unsigned int id) 50 | { 51 | t_egg *tmp; 52 | 53 | tmp = c->eggs; 54 | while (tmp != NULL && tmp->id != id) 55 | tmp = tmp->next; 56 | if (tmp == NULL) 57 | return (FAILURE); 58 | else if (tmp->next == NULL && tmp->prev == NULL) 59 | c->eggs = NULL; 60 | else if (tmp->prev == NULL) 61 | { 62 | c->eggs = tmp->next; 63 | c->eggs->prev = NULL; 64 | } 65 | else if (tmp->next == NULL) 66 | tmp->prev->next = tmp->next; 67 | else 68 | { 69 | tmp->prev->next = tmp->next; 70 | tmp->next->prev = tmp->prev; 71 | } 72 | free(tmp); 73 | return (SUCCESS); 74 | } 75 | -------------------------------------------------------------------------------- /src_server/orientation.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** orientation.c for orientation.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Sun Jun 1 17:39:29 2014 LOEB Thomas 8 | ** Last update Tue Jun 3 19:20:55 2014 LOEB Thomas 9 | */ 10 | 11 | #include 12 | #include "server.h" 13 | 14 | static int g_terminal[8][2] = 15 | { 16 | {-23, 22}, 17 | {22, 67}, 18 | {67, 112}, 19 | {112, 157}, 20 | {157, 202}, 21 | {202, 247}, 22 | {247, 292}, 23 | {292, 337} 24 | }; 25 | 26 | static int calc_orientation(double angle) 27 | { 28 | unsigned int i; 29 | 30 | i = -1; 31 | while (++i < 8) 32 | if (angle >= g_terminal[i][0] && angle < g_terminal[i][1]) 33 | return (i + 49); 34 | return (ORIENTATION[0]); 35 | } 36 | 37 | static int g_angle[4] = 38 | { 39 | 0, 40 | 90, 41 | 180, 42 | 270 43 | }; 44 | 45 | int get_orientation(t_server *s, t_client *c1, 46 | t_client *c2) 47 | { 48 | int x; 49 | int y; 50 | double angle; 51 | 52 | if (c2->x == c1->x && c2->y == c1->y) 53 | return ('0'); 54 | x = c2->x - c1->x; 55 | if (ABS((int)c1->x + (s->x - (int)c2->x)) < ABS(x)) 56 | x = -(c1->x + (s->x - c2->x)); 57 | if (ABS((int)c2->x + (s->x - (int)c1->x)) < ABS(x)) 58 | x = c2->x + (s->x - c1->x); 59 | y = c2->y - c1->y; 60 | if (ABS((int)c1->y + (s->y - (int)c2->y)) < ABS(y)) 61 | y = -(c1->y + (s->y - c2->y)); 62 | if (ABS((int)c2->y + (s->y - (int)c1->y)) < ABS(y)) 63 | y = c2->y + (s->y - c1->y); 64 | angle = atan((double)(-x) / (double)(-y)) * 180 / M_PI; 65 | if (y > 0) 66 | angle += 180; 67 | else if (y <= 0 && x > 0) 68 | angle += 360; 69 | angle = (int)(angle + g_angle[c1->direction]) % 360; 70 | if (angle >= 337) 71 | angle -= 360; 72 | return (calc_orientation(angle)); 73 | } 74 | -------------------------------------------------------------------------------- /src_client/termcaps_functions.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** termcaps_functions.c for termcaps_functions.c in /home/acca_b/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by Baptiste Acca 5 | ** Login 6 | ** 7 | ** Started on Thu Jul 10 16:09:59 2014 Baptiste Acca 8 | ** Last update Fri Jul 11 17:58:47 2014 Baptiste Acca 9 | */ 10 | 11 | #include "client.h" 12 | 13 | static char *cmds_desc[NB_TEXT_MANUAL] = 14 | { 15 | WELCOME_MANUAL, 16 | MANUAL_AV_CMDS, 17 | MANUAL_FORWARD_CMD, 18 | MANUAL_LEFT_CMD, 19 | MANUAL_RIGHT_CMD, 20 | MANUAL_ENTER_CMD, 21 | MANUAL_LOOK_CMD, 22 | M_TAKE, 23 | M_PUT, 24 | M_STONES_LINEMATE, 25 | M_STONES_DERAUMERE, 26 | M_STONES_SIBUR, 27 | M_STONES_MENDIANE, 28 | M_STONES_PHIRAS, 29 | M_STONES_THYSTAME, 30 | M_FOOD, 31 | MANUAL_INVENTORY, 32 | MANUAL_PUSH, 33 | MANUAL_BROADCAST, 34 | MANUAL_FORK, 35 | MANUAL_CONNECT_NBR 36 | }; 37 | 38 | void aff_cmds(void) 39 | { 40 | unsigned int i; 41 | 42 | i = 0; 43 | while (i < NB_TEXT_MANUAL) 44 | { 45 | printf("%s\n", cmds_desc[i]); 46 | ++i; 47 | } 48 | } 49 | 50 | int raw_mode_init(t_client *c) 51 | { 52 | if (tcgetattr(0, &c->termcaps) == -1) 53 | return (my_error(TCGETATTR_FAIL, FAILURE)); 54 | c->termcaps.c_lflag &= ~ICANON; 55 | c->termcaps.c_lflag &= ~ECHO; 56 | c->termcaps.c_cc[VMIN] = 1; 57 | c->termcaps.c_cc[VTIME] = 0; 58 | if (tcsetattr(0, 0, &c->termcaps) == -1) 59 | return (my_error(TCSETATTR_FAIL, FAILURE)); 60 | aff_cmds(); 61 | return (SUCCESS); 62 | } 63 | 64 | int raw_mode_exit(t_client *c) 65 | { 66 | c->termcaps.c_lflag |= ICANON; 67 | c->termcaps.c_lflag |= ECHO; 68 | c->termcaps.c_cc[VMIN] = 1; 69 | c->termcaps.c_cc[VTIME] = 0; 70 | if (tcsetattr(0, 0, &c->termcaps) == -1) 71 | return (my_error(TCSETATTR_FAIL, FAILURE)); 72 | return (SUCCESS); 73 | } 74 | -------------------------------------------------------------------------------- /src_server/exec_pin.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_pin.c for exec_pin.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Mon Jun 9 13:13:04 2014 LOEB Thomas 8 | ** Last update Wed Jun 11 16:58:56 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | bool exec_pin_manual(t_server *s) 14 | { 15 | t_client *tmp; 16 | int pos; 17 | unsigned int i; 18 | 19 | if (write_graphic(s) == FAILURE) 20 | return (FALSE); 21 | pos = atoi(s->p.cmd[1] + 1); 22 | tmp = s->clients; 23 | while (tmp->id != (unsigned int)pos) 24 | tmp = tmp->next; 25 | strcpy(s->graphic->send, s->p.line); 26 | s->graphic->send[strlen(s->graphic->send)] = ' '; 27 | nbr_to_str(tmp->x, s->graphic->send + strlen(s->graphic->send), " "); 28 | nbr_to_str(tmp->y, s->graphic->send + strlen(s->graphic->send), " "); 29 | nbr_to_str(tmp->life, s->graphic->send + strlen(s->graphic->send), " "); 30 | i = -1; 31 | while (++i < NB_STONE) 32 | nbr_to_str(tmp->stone[i], s->graphic->send + strlen(s->graphic->send), 33 | (i + 1 == NB_STONE) ? "\n" : " "); 34 | return (TRUE); 35 | } 36 | 37 | bool exec_pin(t_server *s) 38 | { 39 | unsigned int i; 40 | 41 | if (write_graphic(s) == FAILURE) 42 | return (FALSE); 43 | strcpy(s->graphic->send, (PIN" #")); 44 | nbr_to_str(s->tmp_clients->id, 45 | s->graphic->send + strlen(s->graphic->send), " "); 46 | nbr_to_str(s->tmp_clients->x, 47 | s->graphic->send + strlen(s->graphic->send), " "); 48 | nbr_to_str(s->tmp_clients->y, 49 | s->graphic->send + strlen(s->graphic->send), " "); 50 | nbr_to_str(s->tmp_clients->life, 51 | s->graphic->send + strlen(s->graphic->send), " "); 52 | i = -1; 53 | while (++i < NB_STONE) 54 | nbr_to_str(s->tmp_clients->stone[i], 55 | s->graphic->send + strlen(s->graphic->send), 56 | (i + 1 == NB_STONE) ? "\n" : " "); 57 | return (TRUE); 58 | } 59 | -------------------------------------------------------------------------------- /src_client/check_fds.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** check_fds.c for check_fds.c in /home/chauch_a/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by CHAUCHET Alan 5 | ** Login 6 | ** 7 | ** Started on Wed May 7 14:42:27 2014 LOEB Thomas 8 | <<<<<<< HEAD 9 | ** Last update Fri Jul 11 17:11:48 2014 abgral_f 10 | ======= 11 | ** Last update Fri Jul 11 19:35:40 2014 Baptiste Acca 12 | >>>>>>> 09b34583a1e8314459208570cd350de083b9db8a 13 | */ 14 | 15 | #include "client.h" 16 | 17 | static int nb_cmd(t_client *c) 18 | { 19 | unsigned int i; 20 | unsigned int ret; 21 | 22 | i = -1; 23 | ret = 0; 24 | while (++i < BUFF_LEN) 25 | if (c->b.circular[i] == '\n') 26 | ++ret; 27 | return (ret); 28 | } 29 | 30 | static int check_socket(t_client *c, t_select *sel) 31 | { 32 | if (nb_cmd(c) == 0 && FD_ISSET(c->socket, &sel->rdfds)) 33 | { 34 | memset(c->b.tmp, '\0', BUFF_LEN); 35 | if (rw(c->socket, c->b.tmp, BUFF_LEN, R) == FAILURE) 36 | return (FAILURE); 37 | buffer_to_circular(&c->b); 38 | } 39 | return (SUCCESS); 40 | } 41 | 42 | int check_fds(t_client *c) 43 | { 44 | t_select sel; 45 | 46 | if (raw_mode_init(c) == FAILURE) 47 | return (FAILURE); 48 | sel.tv.tv_usec = 0; 49 | while (stop(STOP_VALUE) == STOP_VALUE) 50 | { 51 | FD_ZERO(&sel.rdfds); 52 | FD_SET(c->socket, &sel.rdfds); 53 | FD_SET(STDIN_FILENO, &sel.rdfds); 54 | sel.maxfd = c->socket + 1; 55 | sel.tv.tv_sec = 1; 56 | if (my_select(&sel, R) == -1 && stop(STOP_VALUE) != STOP_VALUE) 57 | return (close_client(c, my_perror(SYSCALL("select"), FAILURE))); 58 | if ((sel.retSelect > 0 && check_socket(c, &sel) == FAILURE) 59 | || check_cmds(c) == FAILURE) 60 | return (close_client(c, FAILURE)); 61 | if (FD_ISSET(STDIN_FILENO, &sel.rdfds)) 62 | if (manual_action(c) == FAILURE) 63 | return (close_client(c, FAILURE)); 64 | if (c->list_action) 65 | exec_action(c); 66 | } 67 | return (close_client(c, SUCCESS)); 68 | } 69 | -------------------------------------------------------------------------------- /src_server/write.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** write.c for write.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Sun May 11 12:54:28 2014 LOEB Thomas 8 | ** Last update Sat Jul 12 15:39:57 2014 abgral_f 9 | */ 10 | 11 | #include "server.h" 12 | 13 | int write_nb_and_size(t_server *s) 14 | { 15 | nbr_to_str(s->tmp_teams->nb_remaining + s->tmp_teams->nb_egg_remaining, 16 | s->tmp_clients->send, "\n"); 17 | nbr_to_str(s->x, s->tmp_clients->send + strlen(s->tmp_clients->send), " "); 18 | nbr_to_str(s->y, s->tmp_clients->send + strlen(s->tmp_clients->send), "\n"); 19 | return (SUCCESS); 20 | } 21 | 22 | static void write_one_fd(t_server *s, t_select *sel) 23 | { 24 | if (s->tmp_clients->send[0] != '\0' && 25 | FD_ISSET(s->tmp_clients->socket, &sel->wrfds) && 26 | rw(s->tmp_clients->socket, s->tmp_clients->send, 27 | strlen(s->tmp_clients->send), W) == FAILURE) 28 | del_client(s, TRUE); 29 | else 30 | { 31 | memset(s->tmp_clients->send, '\0', BUFF_LEN); 32 | s->tmp_clients = s->tmp_clients->next; 33 | } 34 | } 35 | 36 | int write_on_fds(t_server *s, t_select *sel) 37 | { 38 | s->tmp_clients = s->clients; 39 | while (s->tmp_clients != NULL) 40 | write_one_fd(s, sel); 41 | if (s->graphic != NULL) 42 | { 43 | s->tmp_clients = s->graphic; 44 | write_one_fd(s, sel); 45 | } 46 | return (SUCCESS); 47 | } 48 | 49 | int write_graphic(t_server *s) 50 | { 51 | t_client *tmp; 52 | 53 | if (s->graphic == NULL) 54 | return (FAILURE); 55 | if (s->graphic->send[0] == '\0') 56 | return (SUCCESS); 57 | if (rw(s->graphic->socket, s->graphic->send, 58 | strlen(s->graphic->send), W) == FAILURE) 59 | { 60 | tmp = s->tmp_clients; 61 | s->tmp_clients = s->graphic; 62 | del_client(s, TRUE); 63 | s->tmp_clients = tmp; 64 | return (FAILURE); 65 | } 66 | memset(s->graphic->send, '\0', BUFF_LEN); 67 | return (SUCCESS); 68 | } 69 | -------------------------------------------------------------------------------- /src_common/str_to_wordtab.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** point_on_words.c for point_on_words.c in /home/chauch_a/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by CHAUCHET Alan 5 | ** Login 6 | ** 7 | ** Started on Tue Jun 24 16:40:54 2014 CHAUCHET Alan 8 | ** Last update Wed Jul 9 17:28:18 2014 CHAUCHET Alan 9 | */ 10 | 11 | #include "common.h" 12 | 13 | static bool is_delim(char c, char *delim) 14 | { 15 | unsigned int count; 16 | 17 | count = -1; 18 | while (delim[++count]) 19 | if (delim[count] == c) 20 | return (TRUE); 21 | return (FALSE); 22 | } 23 | 24 | static char **create_word_tab(char *str, unsigned int nb_words, 25 | unsigned int size) 26 | { 27 | unsigned int count; 28 | unsigned int count_tab; 29 | char **word_tab; 30 | 31 | if ((word_tab = malloc(sizeof(char *) * (nb_words + 1))) == NULL) 32 | { 33 | my_perror(SYSCALL("malloc"), FAILURE); 34 | return (NULL); 35 | } 36 | count = -1; 37 | count_tab = -1; 38 | while (++count < size) 39 | if (str[count] != '\0' && (count == 0 || str[count - 1] == '\0')) 40 | word_tab[++count_tab] = strdup(&(str[count])); 41 | word_tab[++count_tab] = NULL; 42 | free(str); 43 | return (word_tab); 44 | } 45 | 46 | char **str_to_wordtab(char *param, char *delim) 47 | { 48 | unsigned int count; 49 | unsigned int nb_words; 50 | unsigned int size; 51 | char *str; 52 | 53 | count = -1; 54 | size = strlen(param); 55 | nb_words = 0; 56 | if ((str = strdup(param)) == NULL) 57 | { 58 | my_perror(SYSCALL("malloc"), FAILURE); 59 | return (NULL); 60 | } 61 | while (++count < size) 62 | if (is_delim(str[count], delim)) 63 | str[count] = '\0'; 64 | else 65 | if (count == 0 || str[count - 1] == '\0') 66 | ++nb_words; 67 | return (create_word_tab(str, nb_words, size)); 68 | } 69 | 70 | void free_wordtab(char **wordtab) 71 | { 72 | unsigned int count; 73 | 74 | count = -1; 75 | while (wordtab[++count]) 76 | free(wordtab[count]); 77 | free(wordtab); 78 | } 79 | -------------------------------------------------------------------------------- /src_graphic/graphic.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** client.c for client.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Mon May 5 15:36:39 2014 LOEB Thomas 8 | ** Last update Thu Jul 3 21:41:27 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | static t_opt g_opt[GRAPHIC_NB_OPT + 1] = 14 | { 15 | {"-p", 0, 1}, 16 | {"-h", 0, 1}, 17 | {"--help", 0, 0} 18 | }; 19 | 20 | static int is_in_opts(char *s) 21 | { 22 | unsigned int i; 23 | 24 | i = 0; 25 | while (i < GRAPHIC_NB_OPT + 1 && strcmp(g_opt[i].s, s) != 0) 26 | ++i; 27 | if (i == GRAPHIC_NB_OPT + 1) 28 | return (FAILURE); 29 | return (i); 30 | } 31 | 32 | static int parse_params(t_graphic *c, char **av) 33 | { 34 | int i; 35 | int pos; 36 | 37 | i = 0; 38 | while (av[i] != NULL) 39 | { 40 | if ((pos = is_in_opts(av[i])) == FAILURE) 41 | return (my_error(WRONG_OPT, FAILURE)); 42 | else if (pos == GRAPHIC_NB_OPT) 43 | { 44 | printf("%s\n", GRAPHIC_USAGE); 45 | return (FAILURE); 46 | } 47 | else 48 | { 49 | ++g_opt[pos].occurrence; 50 | if (g_opt[pos].occurrence != g_opt[pos].occurrence_max) 51 | my_error(TOO_MANY_OPT, CONTINUE); 52 | if (get_params(c, av, &i, pos) == FAILURE) 53 | return (FAILURE); 54 | } 55 | if (av[i] != NULL) 56 | ++i; 57 | } 58 | return (SUCCESS); 59 | } 60 | 61 | static void display(t_graphic *c) 62 | { 63 | printf(("Graphic not yet connected\n" \ 64 | "\tPort: %d\n\tIp: %s\n"), 65 | c->port, c->ip); 66 | } 67 | 68 | int main(int ac __attribute__((__unused__)), char **av) 69 | { 70 | t_graphic c; 71 | 72 | srand(clock()); 73 | memset(&c, '\0', sizeof(t_graphic)); 74 | c.port = atoi(STD_PORT); 75 | c.ip = STD_IP; 76 | c.socket = -1; 77 | c.time = 100; 78 | c.l.stream = stdin; 79 | if (parse_params(&c, av + 1) == FAILURE 80 | || init_sdl(&c) == FAILURE) 81 | return (FAILURE); 82 | my_signal(); 83 | display(&c); 84 | return (connect_to_server(&c)); 85 | } 86 | -------------------------------------------------------------------------------- /src_client/client.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** client.c for client.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Mon May 5 15:36:39 2014 LOEB Thomas 8 | ** Last update Fri Jul 11 19:35:15 2014 Baptiste Acca 9 | */ 10 | 11 | #include "client.h" 12 | 13 | static t_opt g_opt[CLIENT_NB_OPT + 1] = 14 | { 15 | {"-n", 0, 1}, 16 | {"-p", 0, 1}, 17 | {"-h", 0, 1}, 18 | {"--help", 0, 0} 19 | }; 20 | 21 | static int is_in_opts(char *s) 22 | { 23 | unsigned int i; 24 | 25 | i = 0; 26 | while (i < CLIENT_NB_OPT + 1 && strcmp(g_opt[i].s, s) != 0) 27 | ++i; 28 | if (i == CLIENT_NB_OPT + 1) 29 | return (FAILURE); 30 | return (i); 31 | } 32 | 33 | static int parse_params(t_client *c, char **av) 34 | { 35 | int i; 36 | int pos; 37 | 38 | i = 0; 39 | while (av[i] != NULL) 40 | { 41 | if ((pos = is_in_opts(av[i])) == FAILURE) 42 | return (my_error(WRONG_OPT, FAILURE)); 43 | else if (pos == CLIENT_NB_OPT) 44 | { 45 | printf("%s\n", CLIENT_USAGE); 46 | return (FAILURE); 47 | } 48 | else 49 | { 50 | ++g_opt[pos].occurrence; 51 | if (g_opt[pos].occurrence != g_opt[pos].occurrence_max) 52 | my_error(TOO_MANY_OPT, CONTINUE); 53 | if (get_params(c, av, &i, pos) == FAILURE) 54 | return (FAILURE); 55 | } 56 | if (av[i] != NULL) 57 | ++i; 58 | } 59 | return (SUCCESS); 60 | } 61 | 62 | static void display(t_client *c) 63 | { 64 | printf(("Client not yet connected\n\tName of team: %s\n" \ 65 | "\tPort: %d\n\tIp: %s\n"), 66 | c->name, c->port, c->ip); 67 | } 68 | 69 | int main(int ac __attribute__((__unused__)), char **av) 70 | { 71 | t_client c; 72 | 73 | memset(&c, '\0', sizeof(t_client)); 74 | c.name = STD_TEAM1; 75 | c.port = atoi(STD_PORT); 76 | c.ip = STD_IP; 77 | c.socket = -1; 78 | c.l.stream = stdin; 79 | c.level = STD_LEVEL; 80 | if (parse_params(&c, av + 1) == FAILURE) 81 | return (FAILURE); 82 | my_signal(); 83 | display(&c); 84 | return (connect_to_server(&c)); 85 | } 86 | -------------------------------------------------------------------------------- /src_graphic/disp_player.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** disp_player.c for disp_player.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Fri Jul 4 15:20:58 2014 abgral_f 8 | ** Last update Wed Jul 9 18:19:17 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | static t_direction direction[NB_DIRECTIONS] = 14 | { 15 | {D_BOTTOM, 0, 0, (SPRITE_SIZE + 4) / 10}, 16 | {D_TOP, SPRITE_SIZE - 1, 0, (SPRITE_SIZE + 4) / 10 * -1}, 17 | {D_LEFT, SPRITE_SIZE * 2 - 2, (SPRITE_SIZE + 7) / 10 * -1, 0}, 18 | {D_RIGHT, SPRITE_SIZE * 3 - 2, (SPRITE_SIZE + 7) / 10, 0} 19 | }; 20 | 21 | void set_position(t_graphic *c, t_client *tmp) 22 | { 23 | int count; 24 | 25 | count = 0; 26 | while (count != NB_DIRECTIONS && tmp->direction 27 | != direction[count].direction) 28 | count++; 29 | c->display.sprite.y = direction[count].sprite_pos; 30 | c->display.sprite.x = SPRITE_SIZE * tmp->count_anim; 31 | c->display.pos.x = (tmp->x - c->display.cursor_x) * SPRITE_SIZE; 32 | c->display.pos.y = (tmp->y - c->display.cursor_y) * SPRITE_SIZE; 33 | } 34 | 35 | int display_player(t_graphic *c) 36 | { 37 | t_client *tmp; 38 | int count; 39 | 40 | tmp = c->client; 41 | c->display.sprite.y = 0; 42 | while (tmp != NULL) 43 | { 44 | count = 0; 45 | while (count != NB_DIRECTIONS) 46 | { 47 | if (tmp->direction == direction[count].direction) 48 | c->display.sprite.x = direction[count].sprite_pos; 49 | count++; 50 | } 51 | c->display.pos.x = (tmp->x - c->display.cursor_x) * SPRITE_SIZE; 52 | c->display.pos.y = (tmp->y - c->display.cursor_y) * SPRITE_SIZE; 53 | if (tmp->anim == UNDEFINED) 54 | if (SDL_BlitSurface(c->display.list[LINK], 55 | &c->display.sprite, c->display.list[WINDOW], 56 | &c->display.pos) == -1) 57 | return (my_error(SDL_GetError(), FAILURE)); 58 | tmp = tmp->next; 59 | } 60 | return (SUCCESS); 61 | } 62 | -------------------------------------------------------------------------------- /src_client/send_cmd.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** send_cmd.c for send_cmd.c in /home/chauch_a/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by CHAUCHET Alan 5 | ** Login 6 | ** 7 | ** Started on Wed Jun 25 15:08:07 2014 CHAUCHET Alan 8 | ** Last update Fri Jul 11 15:36:47 2014 CHAUCHET Alan 9 | */ 10 | 11 | #include "pointer_to_func.h" 12 | 13 | int send_with_param(t_client *c, char *cmd, char *param) 14 | { 15 | char *msg; 16 | 17 | if (param == NULL) 18 | return (2); 19 | if ((msg = malloc(strlen(cmd) + strlen(param) + 3)) == NULL) 20 | return (my_perror(SYSCALL("malloc"), FAILURE)); 21 | memset(msg, '\0', strlen(cmd) + strlen(param) + 3); 22 | strcpy(msg, cmd); 23 | msg[strlen(cmd)] = ' '; 24 | strcpy(&(msg[strlen(cmd) + 1]), param); 25 | msg[strlen(msg)] = '\n'; 26 | if (rw(c->socket, msg, strlen(msg), W) == FAILURE) 27 | { 28 | free(msg); 29 | return (FAILURE); 30 | } 31 | free(msg); 32 | return (SUCCESS); 33 | } 34 | 35 | int send_no_param(t_client *c, char *cmd, char *param) 36 | { 37 | (void)param; 38 | if (rw(c->socket, cmd, strlen(cmd), W) == FAILURE) 39 | return (FAILURE); 40 | return (rw(c->socket, "\n", 1, W)); 41 | } 42 | 43 | static t_send_cmd g_send_cmd[NB_CMD] = 44 | { 45 | {FORWARD, &send_no_param}, 46 | {RIGHT, &send_no_param}, 47 | {LEFT, &send_no_param}, 48 | {LOOK, &send_no_param}, 49 | {INVENTORY, &send_no_param}, 50 | {PUSH, &send_no_param}, 51 | {ELEVATION, &send_no_param}, 52 | {FORK, &send_no_param}, 53 | {CONNECT_NBR, &send_no_param}, 54 | {TAKE, &send_with_param}, 55 | {PUT, &send_with_param}, 56 | {BROADCAST, &send_with_param} 57 | }; 58 | 59 | int send_cmd(t_client *c, char *cmd, char *param) 60 | { 61 | unsigned int count; 62 | 63 | printf("client : (%s) (%s)\n", cmd, param); 64 | count = -1; 65 | if (cmd == NULL) 66 | return (2); 67 | while (++count < NB_CMD && strcmp(g_send_cmd[count].cmd, cmd)) 68 | ; 69 | if (count >= NB_CMD) 70 | return (2); 71 | if ((g_send_cmd[count].func)(c, cmd, param) == SUCCESS) 72 | return (SUCCESS); 73 | return (FAILURE); 74 | } 75 | -------------------------------------------------------------------------------- /src_server/map.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** map.c for map.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Fri May 30 14:54:59 2014 LOEB Thomas 8 | ** Last update Sat Jul 12 12:43:26 2014 abgral_f 9 | */ 10 | 11 | #include "server.h" 12 | 13 | int create_map(t_server *s) 14 | { 15 | unsigned int i; 16 | 17 | if ((s->map = malloc(s->x * s->y * sizeof(t_box))) == NULL) 18 | return (my_perror(SYSCALL("malloc"), FAILURE)); 19 | memset(s->map, '\0', s->x * s->y * sizeof(t_box)); 20 | i = -1; 21 | while (++i < (unsigned int)(s->x * s->y)) 22 | { 23 | s->map[i].stone[rand() % NB_STONE] = 1; 24 | s->map[i].stone[rand() % NB_STONE] = 1; 25 | s->map[i].food = 1; 26 | } 27 | return (SUCCESS); 28 | } 29 | 30 | bool is_empty_box(t_server *s, int x, int y) 31 | { 32 | t_client *tmp; 33 | unsigned int i; 34 | 35 | tmp = s->clients; 36 | while (tmp != NULL) 37 | if (tmp != s->tmp_clients && (int)tmp->x == x && (int)tmp->y == y) 38 | return (FALSE); 39 | else 40 | tmp = tmp->next; 41 | if (s->map[x + y * s->x].food != 0) 42 | return (FALSE); 43 | i = -1; 44 | while (++i < NB_STONE) 45 | if (s->map[x + y * s->x].stone[i] != 0) 46 | return (FALSE); 47 | return (TRUE); 48 | } 49 | 50 | static void inform_graphic(t_server *s, int x, int y) 51 | { 52 | if (write_graphic(s) == FAILURE) 53 | return ; 54 | exec_bct_fill(s, x, y); 55 | } 56 | 57 | void refill_map(t_server *s) 58 | { 59 | unsigned int i; 60 | int randVal; 61 | bool refill; 62 | 63 | if (rand() % 30 != 0) 64 | return ; 65 | i = -1; 66 | while (++i < (unsigned int)(s->x * s->y)) 67 | { 68 | refill = FALSE; 69 | if (s->map[i].food == 0 && rand() % 10 == 0) 70 | { 71 | refill = TRUE; 72 | s->map[i].food = 1; 73 | } 74 | randVal = rand() % NB_STONE; 75 | if (s->map[i].stone[randVal] == 0 && rand() % 100 == 0) 76 | { 77 | refill = TRUE; 78 | s->map[i].stone[randVal] = 1; 79 | } 80 | if (refill == TRUE) 81 | inform_graphic(s, i % s->x, i / s->x); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src_graphic/check_fds.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** check_fds.c for check_fds.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Wed May 7 14:42:27 2014 LOEB Thomas 8 | ** Last update Sat Jul 12 15:49:10 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | static int check_stdin(t_graphic *c, t_select *sel) 14 | { 15 | if (FD_ISSET(STDIN_FILENO, &sel->rdfds)) 16 | { 17 | if (my_getline(&c->l) > 0 && c->l.line[0] != '\0') 18 | { 19 | if (rw(c->socket, c->l.line, c->l.len_line, W) == FAILURE) 20 | return (FAILURE); 21 | memset(c->l.line, '\0', c->l.len_line); 22 | } 23 | } 24 | return (SUCCESS); 25 | } 26 | 27 | static int nb_cmd(t_graphic *c) 28 | { 29 | unsigned int i; 30 | unsigned int ret; 31 | 32 | i = -1; 33 | ret = 0; 34 | while (++i < BUFF_LEN) 35 | if (c->b.circular[i] == '\n') 36 | ++ret; 37 | return (ret); 38 | } 39 | 40 | static int check_socket(t_graphic *c, t_select *sel) 41 | { 42 | if (nb_cmd(c) == 0 && FD_ISSET(c->socket, &sel->rdfds)) 43 | { 44 | memset(c->b.tmp, '\0', BUFF_LEN); 45 | if (rw(c->socket, c->b.tmp, BUFF_LEN, R) == FAILURE) 46 | return (FAILURE); 47 | buffer_to_circular(&c->b); 48 | } 49 | return (SUCCESS); 50 | } 51 | 52 | int check_fds(t_graphic *c) 53 | { 54 | t_select sel; 55 | 56 | c->teams = NULL; 57 | sel.tv.tv_usec = 0; 58 | sel.tv.tv_sec = 0; 59 | while (stop(STOP_VALUE) == STOP_VALUE) 60 | { 61 | FD_ZERO(&sel.rdfds); 62 | FD_SET(STDIN_FILENO, &sel.rdfds); 63 | FD_SET(c->socket, &sel.rdfds); 64 | sel.maxfd = c->socket + 1; 65 | if (my_select(&sel, RW) == -1 && stop(STOP_VALUE) != STOP_VALUE) 66 | return (close_graphic(c, my_perror(SYSCALL("select"), FAILURE))); 67 | if ((sel.retSelect > 0 && 68 | (check_stdin(c, &sel) == FAILURE || 69 | check_socket(c, &sel) == FAILURE)) || check_cmds(c) == FAILURE) 70 | return (close_graphic(c, FAILURE)); 71 | if (c->teams != NULL) 72 | if (display_sdl(c) == FAILURE) 73 | return (close_graphic(c, FAILURE)); 74 | } 75 | return (close_graphic(c, SUCCESS)); 76 | } 77 | -------------------------------------------------------------------------------- /src_common/parse.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** parse.c for parse.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Tue May 13 12:55:52 2014 LOEB Thomas 8 | ** Last update Mon May 19 11:51:54 2014 LOEB Thomas 9 | */ 10 | 11 | #include "common.h" 12 | 13 | void free_words(t_parse *p) 14 | { 15 | unsigned int i; 16 | 17 | i = -1; 18 | while (++i < p->len) 19 | free(p->cmd[i]); 20 | free(p->cmd); 21 | memset(p, '\0', sizeof(t_parse)); 22 | } 23 | 24 | static int nb_words(char *s) 25 | { 26 | unsigned int i; 27 | unsigned int ret; 28 | 29 | i = -1; 30 | ret = 0; 31 | while (s[++i] != '\0') 32 | if (s[i] != ' ' && s[i] != '\t' && 33 | (i == 0 || s[i - 1] == ' ' || s[i - 1] == '\t')) 34 | ++ret; 35 | return (ret); 36 | } 37 | 38 | static int new_word(t_parse *p, char *s, unsigned int *i, 39 | unsigned int idx_word) 40 | { 41 | unsigned int len_word; 42 | unsigned int len_cpy; 43 | 44 | len_word = strlen(s + (*i)); 45 | len_cpy = len_word; 46 | if (len_word >= ARG_LEN - 1) 47 | len_cpy = ARG_LEN - 1; 48 | if ((p->cmd[idx_word] = malloc((len_cpy + 1) * sizeof(char))) == NULL) 49 | return (my_perror(SYSCALL("malloc"), FAILURE)); 50 | strncpy(p->cmd[idx_word], s + (*i), len_cpy); 51 | p->cmd[idx_word][len_cpy] = '\0'; 52 | (*i) += len_word; 53 | return (SUCCESS); 54 | } 55 | 56 | int parse_cmd(t_parse *p, char *s) 57 | { 58 | unsigned int len_tmp; 59 | unsigned int idx_word; 60 | unsigned int i; 61 | 62 | if (p->cmd != NULL) 63 | free_words(p); 64 | memcpy(p->line, s, BUFF_LEN); 65 | p->len = nb_words(s); 66 | if ((p->cmd = malloc((p->len + 1) * sizeof(char *))) == NULL) 67 | return (my_perror(SYSCALL("malloc"), FAILURE)); 68 | p->cmd[p->len] = NULL; 69 | len_tmp = strlen(s); 70 | i = -1; 71 | while (++i < len_tmp) 72 | if (s[i] == ' ' || s[i] == '\t') 73 | s[i] = '\0'; 74 | idx_word = -1; 75 | i = -1; 76 | while (++i < len_tmp) 77 | if (s[i] != '\0' && (i == 0 || s[i - 1] == '\0') && 78 | new_word(p, s, &i, ++idx_word) == FAILURE) 79 | return (FAILURE); 80 | return (SUCCESS); 81 | } 82 | -------------------------------------------------------------------------------- /src_graphic/list_clients.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** list_player.c for list_player.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Thu Jun 19 21:14:37 2014 abgral_f 8 | ** Last update Sat Jul 5 13:37:41 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | static void set_new_client(t_client *new) 14 | { 15 | int count; 16 | 17 | new->inventory.food = 10; 18 | count = -1; 19 | while (++count != 6) 20 | new->inventory.stone[count] = 0; 21 | new->isAscending = -1; 22 | new->anim = UNDEFINED; 23 | count = 0; 24 | } 25 | 26 | void free_clients(t_graphic *c) 27 | { 28 | t_client *tmp; 29 | 30 | tmp = c->client; 31 | while (c->client != NULL) 32 | { 33 | tmp = c->client; 34 | c->client = c->client->next; 35 | free(tmp); 36 | } 37 | } 38 | 39 | int add_client(t_graphic *c, char *team, char *id) 40 | { 41 | t_client *new; 42 | 43 | if ((new = malloc(sizeof(t_client))) == NULL) 44 | return (my_perror(SYSCALL("malloc"), FAILURE)); 45 | new->next = c->client; 46 | new->prev = NULL; 47 | if (c->client != NULL) 48 | c->client->prev = new; 49 | c->client = new; 50 | if (check_team(c, team) == FAILURE) 51 | { 52 | del_client(c, atoi(id)); 53 | return (my_error(strcat(team, " does not exist"), FAILURE)); 54 | } 55 | else 56 | new->team = get_team_by_name(c, team); 57 | new->id = atoi(id); 58 | set_new_client(new); 59 | return (SUCCESS); 60 | } 61 | 62 | int del_client(t_graphic *c, unsigned int id) 63 | { 64 | t_client *tmp; 65 | 66 | tmp = c->client; 67 | while (tmp != NULL && tmp->id != id) 68 | tmp = tmp->next; 69 | if (tmp == NULL) 70 | return (FAILURE); 71 | else if (tmp->next == NULL && tmp->prev == NULL) 72 | c->client = NULL; 73 | else if (tmp->prev == NULL) 74 | { 75 | c->client = tmp->next; 76 | c->client->prev = NULL; 77 | } 78 | else if (tmp->next == NULL) 79 | tmp->prev->next = tmp->next; 80 | else 81 | { 82 | tmp->prev->next = tmp->next; 83 | tmp->next->prev = tmp->prev; 84 | } 85 | free(tmp); 86 | return (SUCCESS); 87 | } 88 | -------------------------------------------------------------------------------- /src_server/exec_push.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_forward.c for exec_forward.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Fri May 30 13:21:25 2014 LOEB Thomas 8 | ** Last update Thu Jun 19 17:02:44 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | static void exec_push_delete(t_server *s, t_client **c) 14 | { 15 | t_client *tmp; 16 | 17 | tmp = *c; 18 | *c = s->tmp_clients; 19 | s->tmp_clients = tmp; 20 | tmp = tmp->next; 21 | del_client(s, TRUE); 22 | s->tmp_clients = *c; 23 | *c = tmp; 24 | } 25 | 26 | static void exec_push_graphic(t_server *s, t_client **tmp) 27 | { 28 | t_client *swap; 29 | 30 | swap = s->tmp_clients; 31 | s->tmp_clients = (*tmp); 32 | exec_ppo(s); 33 | if (s->tmp_clients->isAscending != -1) 34 | { 35 | exec_pie(s, 0); 36 | exec_plv(s); 37 | exec_bct(s); 38 | } 39 | s->tmp_clients = swap; 40 | } 41 | 42 | static int g_x[4] = 43 | { 44 | 0, 45 | 1, 46 | 0, 47 | -1 48 | }; 49 | 50 | static int g_y[4] = 51 | { 52 | -1, 53 | 0, 54 | 1, 55 | 0 56 | }; 57 | 58 | static void exec_push_send(t_server *s, t_client **tmp, char *send) 59 | { 60 | (*tmp)->x = ((*tmp)->x + g_x[s->tmp_clients->direction]) % s->x; 61 | if ((int)(*tmp)->x < 0) 62 | (*tmp)->x += s->x; 63 | (*tmp)->y = ((*tmp)->y + g_y[s->tmp_clients->direction]) % s->y; 64 | if ((int)(*tmp)->y < 0) 65 | (*tmp)->y += s->y; 66 | if (s->graphic != NULL) 67 | exec_push_graphic(s, tmp); 68 | (*tmp)->isAscending = -1; 69 | send[13] = get_orientation(s, (*tmp), s->tmp_clients); 70 | if (rw((*tmp)->socket, send, strlen(MOVE), W) == FAILURE) 71 | exec_push_delete(s, tmp); 72 | else 73 | (*tmp) = (*tmp)->next; 74 | } 75 | 76 | bool exec_push(t_server *s) 77 | { 78 | t_client *tmp; 79 | char send[17]; 80 | 81 | exec_pex(s); 82 | tmp = s->clients; 83 | strcpy(send, MOVE); 84 | while (tmp != NULL) 85 | if (tmp != s->tmp_clients && 86 | tmp->x == s->tmp_clients->x && 87 | tmp->y == s->tmp_clients->y) 88 | exec_push_send(s, &tmp, send); 89 | else 90 | tmp = tmp->next; 91 | strcpy(s->tmp_clients->send, OK("\n")); 92 | if (send[13] == ORIENTATION[0]) 93 | strcpy(s->tmp_clients->send, KO("\n")); 94 | return (FALSE); 95 | } 96 | -------------------------------------------------------------------------------- /src_server/list_egg.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** list_egg.c for list_egg.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Wed May 14 18:13:00 2014 LOEB Thomas 8 | ** Last update Thu Jul 10 14:16:21 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | void add_egg(t_server *s) 14 | { 15 | t_egg *new; 16 | 17 | if ((new = malloc(sizeof(t_egg))) == NULL && 18 | my_perror(SYSCALL("malloc"), CONTINUE) == CONTINUE) 19 | return ; 20 | new->id = 0; 21 | new->id_client = s->tmp_clients->id; 22 | new->life = STD_LIFE; 23 | new->action_life = action_life(s->delay); 24 | new->action = action_egg(s->delay); 25 | new->isThereAction = TRUE; 26 | new->x = s->tmp_clients->x; 27 | new->y = s->tmp_clients->y; 28 | new->direction = s->tmp_clients->direction; 29 | new->next = s->tmp_clients->team->eggs; 30 | new->prev = NULL; 31 | if (s->tmp_clients->team->eggs != NULL) 32 | { 33 | new->id = s->tmp_clients->team->eggs->id + 1; 34 | s->tmp_clients->team->eggs->prev = new; 35 | } 36 | s->tmp_clients->team->eggs = new; 37 | } 38 | 39 | void del_egg(t_server *s) 40 | { 41 | t_egg *tmp; 42 | 43 | --s->tmp_teams->nb_egg_remaining; 44 | if (s->tmp_teams->tmp_eggs->prev != NULL) 45 | s->tmp_teams->tmp_eggs->prev->next = s->tmp_teams->tmp_eggs->next; 46 | if (s->tmp_teams->tmp_eggs->next != NULL) 47 | s->tmp_teams->tmp_eggs->next->prev = s->tmp_teams->tmp_eggs->prev; 48 | if (s->tmp_teams->tmp_eggs->prev == NULL) 49 | s->tmp_teams->eggs = s->tmp_teams->eggs->next; 50 | tmp = s->tmp_teams->tmp_eggs; 51 | s->tmp_teams->tmp_eggs = s->tmp_teams->tmp_eggs->next; 52 | free(tmp); 53 | } 54 | 55 | void free_eggs(t_server *s) 56 | { 57 | s->tmp_teams->tmp_eggs = s->tmp_teams->eggs; 58 | while (s->tmp_teams->tmp_eggs != NULL) 59 | del_egg(s); 60 | s->tmp_teams->eggs = NULL; 61 | } 62 | 63 | void take_last_egg(t_server *s) 64 | { 65 | s->tmp_teams->tmp_eggs = s->tmp_teams->eggs; 66 | while (s->tmp_teams->tmp_eggs->next != NULL) 67 | s->tmp_teams->tmp_eggs = s->tmp_teams->tmp_eggs->next; 68 | s->tmp_clients->x = s->tmp_teams->tmp_eggs->x; 69 | s->tmp_clients->y = s->tmp_teams->tmp_eggs->y; 70 | s->tmp_clients->direction = s->tmp_teams->tmp_eggs->direction; 71 | s->tmp_clients->life = s->tmp_teams->tmp_eggs->life; 72 | exec_ebo(s); 73 | exec_pnw(s); 74 | del_egg(s); 75 | } 76 | -------------------------------------------------------------------------------- /src_server/list_client.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** list_client.c for list_client.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Wed May 7 17:52:19 2014 LOEB Thomas 8 | ** Last update Sat Jul 12 15:45:24 2014 abgral_f 9 | */ 10 | 11 | #include "server.h" 12 | 13 | void add_client(t_server *s) 14 | { 15 | t_client *new; 16 | struct sockaddr_in c; 17 | socklen_t size_c; 18 | 19 | size_c = sizeof(struct sockaddr_in); 20 | if ((new = malloc(sizeof(t_client))) == NULL && 21 | my_perror(SYSCALL("malloc"), CONTINUE) == CONTINUE) 22 | return ; 23 | memset(new, '\0', sizeof(t_client)); 24 | if ((new->socket = accept(s->socket, SOCKADDR(&c), &size_c)) == -1 && 25 | my_perror(SYSCALL("accept"), CONTINUE) == CONTINUE) 26 | return ; 27 | strcpy(new->send, WELCOME_CLIENT("\n")); 28 | new->life = STD_LIFE; 29 | new->action_life = action_life(s->delay); 30 | new->level = STD_LEVEL; 31 | new->isAscending = -1; 32 | new->next = s->clients; 33 | if (s->clients != NULL) 34 | { 35 | new->id = s->clients->id + 1; 36 | s->clients->prev = new; 37 | } 38 | s->clients = new; 39 | printf("Client attempting to connect\n"); 40 | } 41 | 42 | void del_client(t_server *s, bool closeClient) 43 | { 44 | t_client *tmp; 45 | 46 | exec_pdi(s); 47 | if (s->tmp_clients->team != NULL) 48 | ++s->tmp_clients->team->nb_remaining; 49 | if (s->tmp_clients->prev != NULL) 50 | s->tmp_clients->prev->next = s->tmp_clients->next; 51 | if (s->tmp_clients->next != NULL) 52 | s->tmp_clients->next->prev = s->tmp_clients->prev; 53 | if (s->tmp_clients->prev == NULL) 54 | { 55 | if (s->tmp_clients == s->graphic) 56 | s->graphic = NULL; 57 | else 58 | s->clients = s->clients->next; 59 | } 60 | tmp = s->tmp_clients; 61 | s->tmp_clients = s->tmp_clients->next; 62 | if (closeClient == TRUE && close(tmp->socket) == -1) 63 | my_perror(SYSCALL("close"), CONTINUE); 64 | free(tmp); 65 | } 66 | 67 | void free_clients(t_server *s) 68 | { 69 | s->tmp_clients = s->clients; 70 | while (s->tmp_clients != NULL) 71 | del_client(s, TRUE); 72 | s->clients = NULL; 73 | } 74 | 75 | void complete_client(t_server *s) 76 | { 77 | --s->tmp_teams->nb_remaining; 78 | s->tmp_clients->x = rand() % s->x; 79 | s->tmp_clients->y = rand() % s->y; 80 | s->tmp_clients->direction = rand() % 4; 81 | exec_pnw(s); 82 | } 83 | -------------------------------------------------------------------------------- /src_client/list_action.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** list_action.c for list_action.c in /home/chauch_a/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by CHAUCHET Alan 5 | ** Login 6 | ** 7 | ** Started on Mon Jun 30 17:43:31 2014 CHAUCHET Alan 8 | ** Last update Fri Jul 11 13:20:00 2014 CHAUCHET Alan 9 | */ 10 | 11 | #include "client.h" 12 | 13 | int add_action(t_client *c, char *cmd, 14 | char *param, int nb_time) 15 | { 16 | t_list_action *new; 17 | t_list_action *prov; 18 | 19 | printf("add action 1 : (%s) (%s) (%d)\n", cmd, param, nb_time); 20 | if ((new = malloc(sizeof(t_list_action))) == NULL) 21 | return (my_perror(SYSCALL("malloc"), FAILURE)); 22 | new->cmd = strdup(cmd); 23 | new->param = (param == NULL) ? NULL : strdup(param); 24 | new->nb_time = nb_time; 25 | new->next = NULL; 26 | if (c->list_action == NULL) 27 | c->list_action = new; 28 | else 29 | { 30 | prov = c->list_action; 31 | while (prov->next != NULL) 32 | prov = prov->next; 33 | prov->next = new; 34 | } 35 | return (SUCCESS); 36 | } 37 | 38 | int add_action_front(t_client *c, char *cmd, 39 | char *param, int nb_time) 40 | { 41 | t_list_action *new; 42 | 43 | printf("add action 2 : (%s) (%s) (%d)\n", cmd, param, nb_time); 44 | if ((new = malloc(sizeof(t_list_action))) == NULL) 45 | return (my_perror(SYSCALL("malloc"), FAILURE)); 46 | new->cmd = strdup(cmd); 47 | new->param = (param == NULL) ? NULL : strdup(param); 48 | new->nb_time = nb_time; 49 | new->next = NULL; 50 | if (c->list_action == NULL) 51 | c->list_action = new; 52 | else 53 | { 54 | new->next = c->list_action; 55 | c->list_action = new; 56 | } 57 | return (SUCCESS); 58 | 59 | } 60 | 61 | void pop_front_action(t_client *c) 62 | { 63 | t_list_action *prov; 64 | 65 | if (c->list_action == NULL) 66 | return ; 67 | prov = c->list_action; 68 | c->list_action = c->list_action->next; 69 | free(prov->cmd); 70 | free(prov->param); 71 | free(prov); 72 | } 73 | 74 | void del_list_action(t_client *c) 75 | { 76 | while (c->list_action) 77 | pop_front_action(c); 78 | } 79 | 80 | int exec_action(t_client *c) 81 | { 82 | int ret; 83 | 84 | if (!c->list_action) 85 | return (SUCCESS); 86 | if ((ret = send_cmd(c, c->list_action->cmd, 87 | c->list_action->param)) == FAILURE) 88 | return (FAILURE); 89 | --c->list_action->nb_time; 90 | if (c->list_action->nb_time <= 0) 91 | pop_front_action(c); 92 | return (ret); 93 | } 94 | -------------------------------------------------------------------------------- /src_server/get_params.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** get_params.c for get_params.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Tue May 6 13:02:15 2014 LOEB Thomas 8 | ** Last update Fri May 16 13:23:13 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | #include "get_params_fct.c" 13 | 14 | static int get_x(t_server *s, char **av, int *i) 15 | { 16 | unsigned int j; 17 | 18 | if (av[++(*i)] == NULL) 19 | return (my_error(BAD_VALUE_OPT, FAILURE)); 20 | j = -1; 21 | while (av[(*i)][++j] != '\0') 22 | if (av[(*i)][j] < '0' || av[(*i)][j] > '9') 23 | return (my_error(BAD_VALUE_OPT, FAILURE)); 24 | if ((s->x = atoi(av[(*i)])) <= 0) 25 | return (my_error(BAD_VALUE_OPT, FAILURE)); 26 | return (SUCCESS); 27 | } 28 | 29 | static int get_y(t_server *s, char **av, int *i) 30 | { 31 | unsigned int j; 32 | 33 | if (av[++(*i)] == NULL) 34 | return (my_error(BAD_VALUE_OPT, FAILURE)); 35 | j = -1; 36 | while (av[(*i)][++j] != '\0') 37 | if (av[(*i)][j] < '0' || av[(*i)][j] > '9') 38 | return (my_error(BAD_VALUE_OPT, FAILURE)); 39 | if ((s->y = atoi(av[(*i)])) <= 0) 40 | return (my_error(BAD_VALUE_OPT, FAILURE)); 41 | return (SUCCESS); 42 | } 43 | 44 | static int get_nb_per_team(t_server *s, char **av, int *i) 45 | { 46 | unsigned int j; 47 | 48 | if (av[++(*i)] == NULL) 49 | return (my_error(BAD_VALUE_OPT, FAILURE)); 50 | j = -1; 51 | while (av[(*i)][++j] != '\0') 52 | if (av[(*i)][j] < '0' || av[(*i)][j] > '9') 53 | return (my_error(BAD_VALUE_OPT, FAILURE)); 54 | s->nb_per_team = atoi(av[(*i)]); 55 | return (SUCCESS); 56 | } 57 | 58 | static int get_delay(t_server *s, char **av, int *i) 59 | { 60 | unsigned int j; 61 | unsigned char comma; 62 | 63 | if (av[++(*i)] == NULL) 64 | return (my_error(BAD_VALUE_OPT, FAILURE)); 65 | j = -1; 66 | comma = 0; 67 | while (av[(*i)][++j] != '\0') 68 | if ((av[(*i)][j] < '0' || av[(*i)][j] > '9') && 69 | (comma == 1 || (comma == 0 && av[(*i)][j] != '.'))) 70 | return (my_error(BAD_VALUE_OPT, FAILURE)); 71 | else if (av[(*i)][j] == '.') 72 | comma = 1; 73 | if ((s->delay = atof(av[(*i)])) <= 0) 74 | return (my_error(BAD_VALUE_OPT, FAILURE)); 75 | return (SUCCESS); 76 | } 77 | 78 | static int (*g_get[SERVER_NB_OPT])(t_server *, char **, int *) = 79 | { 80 | &get_names, 81 | &get_port, 82 | &get_x, 83 | &get_y, 84 | &get_nb_per_team, 85 | &get_delay 86 | }; 87 | 88 | int get_params(t_server *s, char **av, int *i, int pos) 89 | { 90 | return ((*g_get[pos])(s, av, i)); 91 | } 92 | -------------------------------------------------------------------------------- /src_server/server.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** server.c for server.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Mon May 5 15:36:46 2014 LOEB Thomas 8 | ** Last update Sat Jul 12 15:38:15 2014 abgral_f 9 | */ 10 | 11 | #include "server.h" 12 | 13 | static t_opt g_opt[SERVER_NB_OPT + 1] = 14 | { 15 | {"-n", 0, 1}, 16 | {"-p", 0, 1}, 17 | {"-x", 0, 1}, 18 | {"-y", 0, 1}, 19 | {"-c", 0, 1}, 20 | {"-t", 0, 1}, 21 | {"--help", 0, 0} 22 | }; 23 | 24 | int is_in_opts(char *s) 25 | { 26 | unsigned int i; 27 | 28 | i = 0; 29 | while (i < SERVER_NB_OPT + 1 && strcmp(g_opt[i].s, s) != 0) 30 | ++i; 31 | if (i == SERVER_NB_OPT + 1) 32 | return (FAILURE); 33 | return (i); 34 | } 35 | 36 | static int parse_params(t_server *s, char **av, int i) 37 | { 38 | int pos; 39 | 40 | while (av[i] != NULL) 41 | { 42 | if ((pos = is_in_opts(av[i])) == FAILURE) 43 | return (my_error(WRONG_OPT, FAILURE)); 44 | else if (pos == SERVER_NB_OPT) 45 | { 46 | free_teams(s); 47 | printf("%s\n", SERVER_USAGE); 48 | return (FAILURE); 49 | } 50 | else 51 | { 52 | ++g_opt[pos].occurrence; 53 | if (g_opt[pos].occurrence != g_opt[pos].occurrence_max) 54 | my_error(TOO_MANY_OPT, CONTINUE); 55 | if (get_params(s, av, &i, pos) == FAILURE) 56 | return (FAILURE); 57 | } 58 | if (av[i] != NULL) 59 | ++i; 60 | } 61 | return (SUCCESS); 62 | } 63 | 64 | static void display(t_server *s) 65 | { 66 | printf("Server not yet online\n\tName of teams:"); 67 | s->tmp_teams = s->teams; 68 | while (s->tmp_teams != NULL) 69 | { 70 | if (s->tmp_teams->prev == NULL) 71 | printf(" %s", s->tmp_teams->name); 72 | else 73 | printf(" | %s", s->tmp_teams->name); 74 | s->tmp_teams = s->tmp_teams->next; 75 | } 76 | printf(("\n\tPort: %d\n\tWidth: %d\n\tHeight: %d\n" \ 77 | "\tNb per team: %d\n\tDelay: %f\n"), 78 | s->port, s->x, s->y, s->nb_per_team, s->delay); 79 | } 80 | 81 | int main(int ac __attribute__((__unused__)), char **av) 82 | { 83 | t_server s; 84 | 85 | srand(time(NULL)); 86 | memset(&s, '\0', sizeof(t_server)); 87 | s.socket = -1; 88 | s.port = atoi(STD_PORT); 89 | s.x = atoi(STD_X); 90 | s.y = atoi(STD_Y); 91 | s.nb_per_team = atoi(STD_NB); 92 | s.delay = atof(STD_DELAY); 93 | if (parse_params(&s, av + 1, 0) == FAILURE) 94 | return (FAILURE); 95 | init_teams(&s); 96 | my_signal(); 97 | display(&s); 98 | return (open_to_clients(&s)); 99 | } 100 | -------------------------------------------------------------------------------- /src_graphic/check_cmds.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** check_cmds.c for check_cmds.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Tue May 13 12:39:09 2014 LOEB Thomas 8 | ** Last update Thu Jul 10 23:43:35 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | static t_cmds cmp[24] = 14 | { 15 | {"msz", 3, &msz_cmd}, 16 | {"bct", 10, &bct_cmd}, 17 | {"tna", 2, &tna_cmd}, 18 | {"pnw", 7, &pnw_cmd}, 19 | {"ppo", 5, &ppo_cmd}, 20 | {"plv", 3, &plv_cmd}, 21 | {"pin", 11, &pin_cmd}, 22 | {"pex", 2, &pex_cmd}, 23 | {"pbc", 3, &pbc_cmd}, 24 | {"pic", 0, &pic_cmd}, 25 | {"pie", 4, &pie_cmd}, 26 | {"pfk", 2, &pfk_cmd}, 27 | {"pdr", 3, &pdr_cmd}, 28 | {"pgt", 3, &pgt_cmd}, 29 | {"pdi", 2, &pdi_cmd}, 30 | {"enw", 5, &enw_cmd}, 31 | {"eht", 2, &eht_cmd}, 32 | {"ebo", 2, &ebo_cmd}, 33 | {"edi", 2, &edi_cmd}, 34 | {"sgt", 2, &sgt_cmd}, 35 | {"seg", 2, &seg_cmd}, 36 | {"smg", 2, &smg_cmd}, 37 | {"suc", 1, &suc_cmd}, 38 | {"sbp", 1, &sbp_cmd} 39 | }; 40 | 41 | static int check_connection(t_graphic *c) 42 | { 43 | if (strcmp(c->p.line, WELCOME_CLIENT("")) == 0) 44 | { 45 | if (rw(c->socket, GRAPHIC_CLIENT("\n"), 46 | strlen(GRAPHIC_CLIENT("\n")), W) == FAILURE) 47 | return (FAILURE); 48 | c->connected = TRUE; 49 | printf("Graphic connected\n"); 50 | } 51 | return (SUCCESS); 52 | } 53 | 54 | static int compare_cmd(t_graphic *c) 55 | { 56 | int count; 57 | 58 | count = 0; 59 | while (count != 24) 60 | { 61 | if (c->p.cmd[0] != NULL) 62 | { 63 | if (strcmp(c->p.cmd[0], cmp[count].cmd) == 0 64 | && cmp[count].nb_args == c->p.len) 65 | return ((*(cmp[count].ptr_func))(&(c->p.cmd[1]), c)); 66 | else if (strcmp(c->p.cmd[0], cmp[count].cmd) == 0 67 | && cmp[count].nb_args == 0 && c->p.len > 4) 68 | return ((*(cmp[count].ptr_func))(&(c->p.cmd[1]), c)); 69 | else if (strcmp(c->p.cmd[0], cmp[count].cmd) == 0 70 | && cmp[count].nb_args != c->p.len) 71 | return (my_error("Wrong parameter number", FAILURE)); 72 | } 73 | count++; 74 | } 75 | return (my_error("Command undefined", FAILURE)); 76 | } 77 | 78 | int check_cmds(t_graphic *c) 79 | { 80 | int pos; 81 | 82 | if ((pos = pos_cmd(&c->b)) != -1) 83 | { 84 | get_cmd(&c->b, pos); 85 | if (parse_cmd(&c->p, c->b.tmp) == FAILURE) 86 | return (CONTINUE); 87 | printf("(%s)\n", c->p.line); 88 | if (c->connected == FALSE) 89 | return (check_connection(c)); 90 | else 91 | compare_cmd(c); 92 | } 93 | return (SUCCESS); 94 | } 95 | -------------------------------------------------------------------------------- /src_graphic/disp_items.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** disp_items.c for disp_items.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Fri Jul 4 15:11:00 2014 abgral_f 8 | ** Last update Thu Jul 10 19:44:23 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | static t_stones stones[NB_STONE] = 14 | { 15 | {0, 0, 0}, 16 | {1, SPRITE_SIZE, 0}, 17 | {2, SPRITE_SIZE * 2, 0}, 18 | {3, 0, SPRITE_SIZE}, 19 | {4, SPRITE_SIZE, SPRITE_SIZE}, 20 | {5, SPRITE_SIZE * 2, SPRITE_SIZE} 21 | }; 22 | 23 | static int display_stones(t_graphic *c, int count_x, 24 | int count_y, int stone_nb) 25 | { 26 | if (c->map[count_x + count_y * c->x].b.stone[stone_nb] > 0) 27 | { 28 | c->display.sprite.y = stones[stone_nb].pos_y; 29 | c->display.sprite.x = stones[stone_nb].pos_x; 30 | c->display.pos.x = (count_x - c->display.cursor_x) * SPRITE_SIZE 31 | + c->map[count_x + count_y * c->x].b.stone_pos[stone_nb][0]; 32 | c->display.pos.y = (count_y - c->display.cursor_y) * SPRITE_SIZE 33 | + c->map[count_x + count_y * c->x].b.stone_pos[stone_nb][1]; 34 | if (SDL_BlitSurface(c->display.list[ITEMS], &c->display.sprite, 35 | c->display.list[WINDOW], 36 | &c->display.pos) == -1) 37 | return (my_error(SDL_GetError(), FAILURE)); 38 | } 39 | return (SUCCESS); 40 | } 41 | 42 | static int display_food(t_graphic *c, int count_x, int count_y) 43 | { 44 | if (c->map[count_x + count_y * c->x].b.food > 0) 45 | { 46 | c->display.sprite.y = SPRITE_SIZE * 2; 47 | c->display.sprite.x = 0; 48 | c->display.pos.x = (count_x - c->display.cursor_x) * SPRITE_SIZE 49 | + c->map[count_x + count_y * c->x].b.food_pos[0]; 50 | c->display.pos.y = (count_y - c->display.cursor_y) * SPRITE_SIZE 51 | + c->map[count_x + count_y * c->x].b.food_pos[1]; 52 | if (SDL_BlitSurface(c->display.list[ITEMS], 53 | &c->display.sprite, c->display.list[WINDOW], 54 | &c->display.pos) == -1) 55 | return (my_error(SDL_GetError(), FAILURE)); 56 | } 57 | return (SUCCESS); 58 | } 59 | 60 | int display_items(t_graphic *c) 61 | { 62 | unsigned int count_x; 63 | unsigned int count_y; 64 | int stone_nb; 65 | 66 | count_y = c->display.cursor_y - 1; 67 | while (++count_y != c->y && count_y != 68 | c->display.cursor_y + WIN_Y / SPRITE_SIZE) 69 | { 70 | count_x = c->display.cursor_x - 1; 71 | while (++count_x != c->x && count_x != 72 | c->display.cursor_x + MAP_X / SPRITE_SIZE) 73 | { 74 | stone_nb = 0; 75 | while (stone_nb != NB_STONE) 76 | { 77 | if (display_stones(c, count_x, count_y, stone_nb) == FAILURE) 78 | return (FAILURE); 79 | stone_nb++; 80 | } 81 | if (display_food(c, count_x, count_y) == FAILURE) 82 | return (FAILURE); 83 | } 84 | } 85 | return (SUCCESS); 86 | } 87 | -------------------------------------------------------------------------------- /src_graphic/init_sdl.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** init_sdl.c for init_sdl.c in /home/abgral_f/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Mon Jun 30 16:56:48 2014 abgral_f 8 | ** Last update Fri Jul 11 13:46:56 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | void free_surfaces(t_graphic *c) 14 | { 15 | int count; 16 | 17 | count = 0; 18 | while (count != SURFACE_NB) 19 | { 20 | if (c->display.list[count] != NULL) 21 | SDL_FreeSurface(c->display.list[count]); 22 | count++; 23 | } 24 | free(c->display.list); 25 | } 26 | 27 | static int set_transparency(t_graphic *c) 28 | { 29 | int count; 30 | 31 | count = 1; 32 | while (count != SURFACE_NB) 33 | { 34 | if (SDL_SetColorKey(c->display.list[count], SDL_SRCCOLORKEY, 35 | SDL_MapRGB(c->display.list[count]->format, 36 | 0, 0, 170)) == -1) 37 | return (my_error(SDL_GetError(), FAILURE)); 38 | count++; 39 | } 40 | return (SUCCESS); 41 | } 42 | 43 | static void init_display(t_graphic *c) 44 | { 45 | c->display.cursor_x = 0; 46 | c->display.cursor_y = 0; 47 | c->display.coord_x = 0; 48 | c->display.coord_y = 0; 49 | c->display.color.r = 255; 50 | c->display.color.g = 255; 51 | c->display.color.b = 255; 52 | } 53 | 54 | static int init_ttf(t_graphic *c) 55 | { 56 | if (TTF_Init() == -1) 57 | return (my_error(TTF_GetError(), FAILURE)); 58 | if ((c->display.font = TTF_OpenFont("font/BEBAS___.TTF", 24)) == NULL) 59 | return (my_error(TTF_GetError(), FAILURE)); 60 | return (SUCCESS); 61 | } 62 | 63 | int init_sdl(t_graphic *c) 64 | { 65 | if (SDL_Init(SDL_INIT_VIDEO) == -1) 66 | return (my_error(SDL_GetError(), FAILURE)); 67 | if ((c->display.list = malloc(sizeof (*c->display.list) 68 | * SURFACE_NB)) == NULL) 69 | return (my_perror(SYSCALL("malloc"), FAILURE)); 70 | if ((c->display.list[WINDOW] = 71 | SDL_SetVideoMode(WIN_X, WIN_Y, 32, SDL_HWSURFACE)) == NULL) 72 | return (my_error(SDL_GetError(), FAILURE)); 73 | SDL_WM_SetCaption("Zappy", NULL); 74 | if ((c->display.list[MAP] = SDL_LoadBMP("sprites/map.bmp")) == NULL 75 | || (c->display.list[ITEMS] = SDL_LoadBMP("sprites/items.bmp")) == NULL 76 | || (c->display.list[LINK] = SDL_LoadBMP("sprites/link.bmp")) == NULL 77 | || (c->display.list[EGG] = SDL_LoadBMP("sprites/egg.bmp")) == NULL 78 | || (c->display.list[MOVES] = SDL_LoadBMP("sprites/moves.bmp")) == NULL 79 | || (c->display.list[LAY] = SDL_LoadBMP("sprites/lay.bmp")) == NULL 80 | || (c->display.list[KIK] = SDL_LoadBMP("sprites/kik.bmp")) == NULL 81 | || (c->display.list[DROP] = SDL_LoadBMP("sprites/drop.bmp")) == NULL 82 | || (c->display.list[GUI] = SDL_LoadBMP("sprites/gui.bmp")) == NULL 83 | || (c->display.list[INCANT] = SDL_LoadBMP("sprites/incant.bmp")) == NULL) 84 | return (my_error(SDL_GetError(), FAILURE)); 85 | if (set_transparency(c) == FAILURE) 86 | return (FAILURE); 87 | init_display(c); 88 | return (init_ttf(c)); 89 | } 90 | -------------------------------------------------------------------------------- /src_server/check_elevation.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** check_elevation.c for check_elevation.c in /home/loeb_t/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Thu Jun 19 16:07:30 2014 LOEB Thomas 8 | ** Last update Thu Jul 10 14:19:13 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | static int g_ascend[LEVEL_MAX - 1][NB_STONE + 1] = 14 | { 15 | {1, 1, 0, 0, 0, 0, 0}, 16 | {2, 1, 1, 1, 0, 0, 0}, 17 | {2, 2, 0, 1, 0, 2, 0}, 18 | {4, 1, 1, 2, 0, 1, 0}, 19 | {4, 1, 2, 1, 3, 0, 0}, 20 | {6, 1, 2, 3, 0, 1, 0}, 21 | {6, 2, 2, 2, 2, 2, 1} 22 | }; 23 | 24 | static void check_elevation_delete(t_server *s, t_client **c) 25 | { 26 | t_client *tmp; 27 | 28 | tmp = *c; 29 | *c = s->tmp_clients; 30 | s->tmp_clients = tmp; 31 | tmp = tmp->next; 32 | del_client(s, TRUE); 33 | s->tmp_clients = *c; 34 | *c = tmp; 35 | } 36 | 37 | static int check_elevation_fill(t_server *s, t_client *tmp, char *send) 38 | { 39 | tmp->isThereAction = TRUE; 40 | tmp->isAscending = s->tmp_clients->id; 41 | memcpy(&tmp->action, &s->tmp_clients->action, sizeof(t_action)); 42 | if (rw(tmp->socket, send, strlen(send), W) == FAILURE) 43 | return (FAILURE); 44 | return (SUCCESS); 45 | } 46 | 47 | bool check_elevation_send(t_server *s) 48 | { 49 | t_client *tmp; 50 | char send[20]; 51 | 52 | strcpy(send, ELEVATION_LAUNCH("\n")); 53 | tmp = s->clients; 54 | while (tmp != NULL) 55 | if (tmp != s->tmp_clients && tmp->x == s->tmp_clients->x && 56 | tmp->y == s->tmp_clients->y && tmp->level == s->tmp_clients->level) 57 | { 58 | if (check_elevation_fill(s, tmp, send) == FAILURE) 59 | check_elevation_delete(s, &tmp); 60 | else 61 | tmp = tmp->next; 62 | } 63 | else 64 | tmp = tmp->next; 65 | exec_pic(s); 66 | if (check_elevation_fill(s, s->tmp_clients, send) == FAILURE) 67 | del_client(s, TRUE); 68 | else 69 | s->tmp_clients = s->tmp_clients->next; 70 | return (TRUE); 71 | } 72 | 73 | static bool check_elevation_nbr(t_server *s) 74 | { 75 | t_client *tmp; 76 | unsigned int i; 77 | 78 | i = 0; 79 | tmp = s->clients; 80 | while (tmp != NULL) 81 | { 82 | if (tmp->x == s->tmp_clients->x && tmp->y == s->tmp_clients->y && 83 | tmp->level == s->tmp_clients->level) 84 | ++i; 85 | tmp = tmp->next; 86 | } 87 | if ((int)i < g_ascend[s->tmp_clients->level - 1][0]) 88 | return (FALSE); 89 | i = -1; 90 | while (++i < NB_STONE) 91 | if (s->map[s->tmp_clients->x + s->tmp_clients->y * s->x].stone[i] < 92 | g_ascend[s->tmp_clients->level - 1][i + 1]) 93 | return (FALSE); 94 | i = -1; 95 | while (++i < NB_STONE) 96 | s->map[s->tmp_clients->x + s->tmp_clients->y * s->x].stone[i] -= 97 | g_ascend[s->tmp_clients->level - 1][i + 1]; 98 | return (TRUE); 99 | } 100 | 101 | bool check_elevation(t_server *s) 102 | { 103 | if (s->tmp_clients->level == LEVEL_MAX || check_elevation_nbr(s) == FALSE) 104 | return (FALSE); 105 | return (TRUE); 106 | } 107 | -------------------------------------------------------------------------------- /src_server/check_cmds.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** check_cmds.c for check_cmds.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Mon May 12 17:03:05 2014 LOEB Thomas 8 | ** Last update Tue Jun 24 13:40:23 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | static int check_graphic_cmds(t_server *s) 14 | { 15 | int pos; 16 | 17 | if ((pos = pos_cmd(&s->graphic->b)) != -1) 18 | { 19 | get_cmd(&s->graphic->b, pos); 20 | if (parse_cmd(&s->p, s->graphic->b.tmp) == SUCCESS) 21 | action_graphic(s); 22 | } 23 | return (SUCCESS); 24 | } 25 | 26 | static int check_cmd(t_server *s) 27 | { 28 | s->tmp_clients->action = action_create(s); 29 | if (s->tmp_clients->action.cmd != NULL) 30 | { 31 | s->tmp_clients->isThereAction = TRUE; 32 | if (s->tmp_clients->action.id == 9) 33 | check_elevation_send(s); 34 | else 35 | s->tmp_clients = s->tmp_clients->next; 36 | } 37 | else 38 | { 39 | if (s->tmp_clients->action.id == 9 && 40 | rw(s->tmp_clients->socket, KO("\n"), strlen(KO("\n")), W) == FAILURE) 41 | del_client(s, TRUE); 42 | else 43 | s->tmp_clients = s->tmp_clients->next; 44 | } 45 | return (SUCCESS); 46 | } 47 | 48 | static int check_name_team(t_server *s) 49 | { 50 | if (strcmp(s->p.line, GRAPHIC_CLIENT("")) == 0) 51 | return (connect_graphic(s)); 52 | s->tmp_teams = s->teams; 53 | while (s->tmp_teams != NULL && strcmp(s->tmp_teams->name, s->p.line) != 0) 54 | s->tmp_teams = s->tmp_teams->next; 55 | if (s->tmp_teams == NULL || (s->tmp_teams->nb_remaining <= 0 && 56 | s->tmp_teams->nb_egg_remaining <= 0)) 57 | { 58 | rw(s->tmp_clients->socket, "0\n", 2, W); 59 | del_client(s, FALSE); 60 | printf((s->tmp_teams == NULL) ? 61 | "Client disconnected: unknown team name\n" : 62 | "Client disconnected: not enough place in this team\n"); 63 | return (SUCCESS); 64 | } 65 | s->tmp_clients->team = s->tmp_teams; 66 | s->tmp_clients->isConnected = TRUE; 67 | write_nb_and_size(s); 68 | if (s->tmp_teams->nb_egg_remaining != 0) 69 | take_last_egg(s); 70 | else 71 | complete_client(s); 72 | printf("Client connected\n"); 73 | s->tmp_clients = s->tmp_clients->next; 74 | return (SUCCESS); 75 | } 76 | 77 | int check_cmds(t_server *s) 78 | { 79 | int pos; 80 | 81 | s->tmp_clients = s->clients; 82 | while (s->tmp_clients != NULL) 83 | if (s->tmp_clients->isThereAction == FALSE && 84 | s->tmp_clients->isAscending == -1 && 85 | (pos = pos_cmd(&s->tmp_clients->b)) != -1) 86 | { 87 | get_cmd(&s->tmp_clients->b, pos); 88 | if (parse_cmd(&s->p, s->tmp_clients->b.tmp) == SUCCESS) 89 | if (s->tmp_clients->team == NULL) 90 | check_name_team(s); 91 | else 92 | check_cmd(s); 93 | else 94 | s->tmp_clients = s->tmp_clients->next; 95 | } 96 | else 97 | s->tmp_clients = s->tmp_clients->next; 98 | if (s->graphic != NULL) 99 | check_graphic_cmds(s); 100 | return (SUCCESS); 101 | } 102 | -------------------------------------------------------------------------------- /src_server/exec_look.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** exec_look.c for exec_look.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Sun Jun 1 13:46:47 2014 LOEB Thomas 8 | ** Last update Tue Jun 17 12:46:53 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | static char *g_look[NB_STONE + 2][2] = 14 | { 15 | {PLAYER, S_PLAYER}, 16 | {FOOD, S_FOOD}, 17 | {LINEMATE, S_LINEMATE}, 18 | {DERAUMERE, S_DERAUMERE}, 19 | {SIBUR, S_SIBUR}, 20 | {MENDIANE, S_MENDIANE}, 21 | {PHIRAS, S_PHIRAS}, 22 | {THYSTAME, S_THYSTAME} 23 | }; 24 | 25 | static void exec_look_strcpy(t_server *s, char *cpy, char *state) 26 | { 27 | if (*state == 0) 28 | *state = 1; 29 | strcpy(s->tmp_clients->send + strlen(s->tmp_clients->send), cpy); 30 | } 31 | 32 | static void exec_look_write(t_server *s, int x, int y, char state) 33 | { 34 | t_client *tmp; 35 | unsigned int i; 36 | unsigned int j; 37 | 38 | if (state == 2) 39 | state = 1; 40 | tmp = s->clients; 41 | while (tmp != NULL) 42 | { 43 | if (tmp != s->tmp_clients && (int)tmp->x == x && (int)tmp->y == y) 44 | exec_look_strcpy(s, g_look[0][(int)state], &state); 45 | tmp = tmp->next; 46 | } 47 | j = -1; 48 | while (++j < s->map[x + y * s->x].food) 49 | exec_look_strcpy(s, g_look[1][(int)state], &state); 50 | i = -1; 51 | while (++i < NB_STONE) 52 | { 53 | j = -1; 54 | while (++j < s->map[x + y * s->x].stone[i]) 55 | exec_look_strcpy(s, g_look[i + 2][(int)state], &state); 56 | } 57 | } 58 | 59 | static void exec_look_check(t_server *s, int x, int y, char state) 60 | { 61 | if (x < 0) 62 | x = s->x - (x % s->x); 63 | else if (x > s->x) 64 | x %= s->x; 65 | if (y < 0) 66 | y = s->y - (y % s->y); 67 | else if (y > s->y) 68 | y %= s->y; 69 | if (is_empty_box(s, x, y) == FALSE) 70 | exec_look_write(s, x, y, state); 71 | if (state != 2) 72 | s->tmp_clients->send[strlen(s->tmp_clients->send)] = ','; 73 | } 74 | 75 | static int g_x[4] = 76 | { 77 | 0, 78 | 1, 79 | 0, 80 | -1 81 | }; 82 | 83 | static int g_y[4] = 84 | { 85 | -1, 86 | 0, 87 | 1, 88 | 0 89 | }; 90 | 91 | bool exec_look(t_server *s) 92 | { 93 | unsigned int i; 94 | unsigned int k; 95 | char state; 96 | 97 | i = -1; 98 | state = 0; 99 | strcpy(s->tmp_clients->send, "{"); 100 | while (++i != s->tmp_clients->level + 1) 101 | { 102 | k = -1; 103 | while (++k < i * 2 + 1) 104 | { 105 | if (k == i * 2 && i == s->tmp_clients->level) 106 | state = 2; 107 | exec_look_check(s, s->tmp_clients->x + g_x[s->tmp_clients->direction] 108 | * i + (i - k) * g_y[s->tmp_clients->direction], 109 | s->tmp_clients->y + g_y[s->tmp_clients->direction] 110 | * i + (i - k) * g_x[s->tmp_clients->direction], 111 | state); 112 | if (state == 0) 113 | state = 1; 114 | } 115 | } 116 | strcpy(s->tmp_clients->send + strlen(s->tmp_clients->send), "}\n"); 117 | return (FALSE); 118 | } 119 | -------------------------------------------------------------------------------- /src_graphic/anim.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** anim.c for anim.c in /home/abgral_f/backups/zappy5 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Wed Jul 9 18:17:20 2014 abgral_f 8 | ** Last update Wed Jul 9 18:20:25 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | static t_direction direction[NB_DIRECTIONS] = 14 | { 15 | {D_BOTTOM, 0, 0, (SPRITE_SIZE + 4) / 10}, 16 | {D_TOP, SPRITE_SIZE - 1, 0, (SPRITE_SIZE + 4) / 10 * -1}, 17 | {D_LEFT, SPRITE_SIZE * 2 - 2, (SPRITE_SIZE + 7) / 10 * -1, 0}, 18 | {D_RIGHT, SPRITE_SIZE * 3 - 2, (SPRITE_SIZE + 7) / 10, 0} 19 | }; 20 | 21 | int anim_kik(t_graphic *c, t_client *tmp) 22 | { 23 | set_position(c, tmp); 24 | if (SDL_BlitSurface(c->display.list[KIK], 25 | &c->display.sprite, c->display.list[WINDOW], 26 | &c->display.pos) == -1) 27 | return (my_error(SDL_GetError(), FAILURE)); 28 | tmp->count_anim++; 29 | if (tmp->count_anim > 4) 30 | tmp->anim = UNDEFINED; 31 | return (SUCCESS); 32 | } 33 | 34 | int anim_drop(t_graphic *c, t_client *tmp) 35 | { 36 | set_position(c, tmp); 37 | if (SDL_BlitSurface(c->display.list[DROP], 38 | &c->display.sprite, c->display.list[WINDOW], 39 | &c->display.pos) == -1) 40 | return (my_error(SDL_GetError(), FAILURE)); 41 | tmp->count_anim++; 42 | if (tmp->count_anim > 2) 43 | tmp->anim = UNDEFINED; 44 | return (SUCCESS); 45 | } 46 | 47 | int anim_lay(t_graphic *c, t_client *tmp) 48 | { 49 | set_position(c, tmp); 50 | if (SDL_BlitSurface(c->display.list[LAY], 51 | &c->display.sprite, c->display.list[WINDOW], 52 | &c->display.pos) == -1) 53 | return (my_error(SDL_GetError(), FAILURE)); 54 | tmp->count_anim++; 55 | if (tmp->count_anim > 2) 56 | tmp->count_anim = 0; 57 | return (SUCCESS); 58 | } 59 | 60 | int anim_incant(t_graphic *c, t_client *tmp) 61 | { 62 | set_position(c, tmp); 63 | if (SDL_BlitSurface(c->display.list[INCANT], 64 | &c->display.sprite, c->display.list[WINDOW], 65 | &c->display.pos) == -1) 66 | return (my_error(SDL_GetError(), FAILURE)); 67 | tmp->count_anim++; 68 | if (tmp->count_anim > NB_SPRITES_ANIM - 2) 69 | tmp->count_anim = 0; 70 | return (SUCCESS); 71 | } 72 | 73 | int anim_moves(t_graphic *c, t_client *tmp) 74 | { 75 | int count; 76 | 77 | count = 0; 78 | while (count != NB_DIRECTIONS && tmp->direction 79 | != direction[count].direction) 80 | count++; 81 | c->display.sprite.y = direction[count].sprite_pos; 82 | c->display.sprite.x = SPRITE_SIZE * tmp->count_anim; 83 | c->display.pos.x = (tmp->last_coords[0] - c->display.cursor_x) * SPRITE_SIZE 84 | + direction[count].move_x * tmp->count_anim; 85 | c->display.pos.y = (tmp->last_coords[1] - c->display.cursor_y) * SPRITE_SIZE 86 | + direction[count].move_y * tmp->count_anim; 87 | if (SDL_BlitSurface(c->display.list[MOVES], 88 | &c->display.sprite, c->display.list[WINDOW], 89 | &c->display.pos) == -1) 90 | return (my_error(SDL_GetError(), FAILURE)); 91 | tmp->count_anim++; 92 | if (tmp->count_anim > NB_SPRITES_ANIM - 1) 93 | tmp->anim = UNDEFINED; 94 | return (SUCCESS); 95 | } 96 | -------------------------------------------------------------------------------- /src_server/action.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** action.c for action.c in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Fri May 9 17:29:16 2014 LOEB Thomas 8 | ** Last update Thu Jun 26 17:39:54 2014 LOEB Thomas 9 | */ 10 | 11 | #include "server.h" 12 | 13 | t_action action_life(double delay) 14 | { 15 | t_action ret; 16 | 17 | ret.cmd = "life"; 18 | ret.usec = (FOOD_TIME * SEC_TO_USEC) / delay; 19 | ret.id = CLIENT_ACTIONS + 1; 20 | return (ret); 21 | } 22 | 23 | t_action action_egg(double delay) 24 | { 25 | t_action ret; 26 | 27 | ret.cmd = "egg"; 28 | ret.usec = (EGG_TIME * SEC_TO_USEC) / delay; 29 | ret.id = CLIENT_ACTIONS + 2; 30 | return (ret); 31 | } 32 | 33 | static t_action g_actions[CLIENT_ACTIONS] = 34 | { 35 | {FORWARD, "", 7, 0, 1, NULL, &exec_forward}, 36 | {RIGHT, "", 7, 1, 1, NULL, &exec_right}, 37 | {LEFT, "", 7, 2, 1, NULL, &exec_left}, 38 | {LOOK, "", 7, 3, 1, NULL, &exec_look}, 39 | {INVENTORY, "", 1, 4, 1, NULL, &exec_inventory}, 40 | {TAKE, "", 7, 5, 2, &check_take, &exec_take}, 41 | {PUT, "", 7, 6, 2, &check_put, &exec_put}, 42 | {PUSH, "", 7, 7, 1, NULL, &exec_push}, 43 | {BROADCAST, "", 7, 8, 2, NULL, &exec_broadcast}, 44 | {ELEVATION, "", 300, 9, 1, &check_elevation, &exec_elevation}, 45 | {FORK, "", 42, 10, 1, &check_fork, &exec_fork}, 46 | {CONNECT_NBR, "", 0, 11, 1, NULL, &exec_connect_nbr} 47 | }; 48 | 49 | t_action action_create(t_server *s) 50 | { 51 | unsigned int i; 52 | t_action ret; 53 | 54 | ret.cmd = NULL; 55 | ret.id = -1; 56 | if (s->p.cmd[0] == NULL) 57 | return (ret); 58 | i = 0; 59 | while (i < CLIENT_ACTIONS && strcmp(s->p.cmd[0], g_actions[i].cmd) != 0) 60 | ++i; 61 | if (i < CLIENT_ACTIONS && s->p.len == g_actions[i].nb_param && 62 | (g_actions[i].check == NULL || (*g_actions[i].check)(s) == TRUE)) 63 | { 64 | ret.id = i; 65 | ret.cmd = g_actions[i].cmd; 66 | if (s->p.len == 2) 67 | strcpy(ret.param, s->p.cmd[1]); 68 | ret.usec = g_actions[i].usec * SEC_TO_USEC / s->delay; 69 | ret.exec = g_actions[i].exec; 70 | } 71 | return (ret); 72 | } 73 | 74 | static t_action g_graphic[GRAPHIC_ACTIONS] = 75 | { 76 | {MSZ, "", 0, 0, 1, NULL, &exec_msz}, 77 | {BCT, "", 0, 1, 3, &check_bct, &exec_bct_manual}, 78 | {MCT, "", 0, 2, 1, NULL, &exec_mct}, 79 | {TNA, "", 0, 3, 1, NULL, &exec_tna}, 80 | {PPO, "", 0, 4, 2, &check_no_player, &exec_ppo_manual}, 81 | {PLV, "", 0, 5, 2, &check_no_player, &exec_plv_manual}, 82 | {PIN, "", 0, 6, 2, &check_no_player, &exec_pin_manual}, 83 | {SGT, "", 0, 7, 1, NULL, &exec_sgt}, 84 | {SST, "", 0, 8, 2, &check_sst, &exec_sst} 85 | }; 86 | 87 | void action_graphic(t_server *s) 88 | { 89 | unsigned int i; 90 | 91 | if (s->p.cmd[0] == NULL) 92 | exec_suc(s); 93 | else 94 | { 95 | i = 0; 96 | while (i < GRAPHIC_ACTIONS && strcmp(s->p.cmd[0], g_graphic[i].cmd) != 0) 97 | ++i; 98 | if (i == GRAPHIC_ACTIONS) 99 | exec_suc(s); 100 | else if (s->p.len != g_graphic[i].nb_param || 101 | (g_graphic[i].check != NULL && (*g_graphic[i].check)(s) == FALSE)) 102 | exec_sbp(s); 103 | else 104 | { 105 | g_graphic[i].exec(s); 106 | printf("Graphic executed '%s'\n", s->p.cmd[0]); 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /inc/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** common.h for common.h in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Mon May 5 16:06:29 2014 LOEB Thomas 8 | ** Last update Thu Jul 10 17:28:36 2014 CHAUCHET Alan 9 | */ 10 | 11 | #ifndef COMMON_H_ 12 | # define COMMON_H_ 13 | 14 | # include 15 | # include 16 | # include 17 | # include 18 | # include "error.h" 19 | 20 | # include 21 | # include 22 | # include 23 | # include 24 | 25 | # include 26 | # include 27 | 28 | # include 29 | 30 | # define FAILURE -1 31 | # define SUCCESS 0 32 | # define CONTINUE 1 33 | 34 | # define STD_TEAM1 "TEAM_GROS_PORCS" 35 | # define STD_TEAM2 "EUL_TEAM" 36 | # define STD_PORT "6666" 37 | # define STD_IP "127.0.0.1" 38 | 39 | # define STD_LEVEL 1 40 | # define MAX_LEVEL 8 41 | 42 | # define WAITING_LIST 1000000 43 | 44 | # define C_SOCKADDR(x) (const struct sockaddr *)(x) 45 | # define SOCKADDR(x) (struct sockaddr *)(x) 46 | # define IN_ADDR(x) (struct in_addr *)(x) 47 | 48 | # define NB_STONE 6 49 | 50 | typedef struct s_box 51 | { 52 | unsigned char stone[NB_STONE]; 53 | unsigned char food; 54 | int stone_pos[NB_STONE][2]; 55 | int food_pos[2]; 56 | } t_box; 57 | 58 | typedef enum e_direction 59 | { 60 | D_TOP = 0, 61 | D_RIGHT = 1, 62 | D_BOTTOM = 2, 63 | D_LEFT = 3 64 | } e_direction; 65 | 66 | typedef enum e_bool 67 | { 68 | FALSE = 0, 69 | TRUE = 1 70 | } bool; 71 | 72 | typedef struct s_opt 73 | { 74 | char *s; 75 | unsigned char occurrence; 76 | unsigned char occurrence_max; 77 | } t_opt; 78 | 79 | typedef struct s_line 80 | { 81 | char *line; 82 | size_t len; 83 | unsigned int len_line; 84 | FILE *stream; 85 | int retGetline; 86 | } t_line; 87 | 88 | typedef struct s_select 89 | { 90 | unsigned char flag; 91 | int maxfd; 92 | fd_set rdfds; 93 | fd_set wrfds; 94 | int retSelect; 95 | struct timeval tv; 96 | struct timeval save; 97 | } t_select; 98 | 99 | # define BUFF_LEN 4096 100 | 101 | typedef struct s_buffer 102 | { 103 | char circular[BUFF_LEN]; 104 | char tmp[BUFF_LEN]; 105 | unsigned int idx; 106 | } t_buffer; 107 | 108 | # define ARG_LEN 512 109 | 110 | typedef struct s_parse 111 | { 112 | char **cmd; 113 | unsigned int len; 114 | char line[BUFF_LEN]; 115 | } t_parse; 116 | 117 | typedef enum e_mode 118 | { 119 | R = 0, 120 | W = 1, 121 | RW = 2 122 | } e_mode; 123 | 124 | # include "protocol.h" 125 | 126 | int my_select(t_select *, e_mode); 127 | int stop(int); 128 | int my_getline(t_line *); 129 | int rw(int, void *, size_t, e_mode); 130 | void buffer_to_circular(t_buffer *); 131 | int pos_cmd(t_buffer *); 132 | void get_cmd(t_buffer *, int); 133 | int parse_cmd(t_parse *, char *); 134 | void free_words(t_parse *); 135 | int nbrlen(int); 136 | int nbr_to_str(int, char *, char *); 137 | int getnbr(char *); 138 | int nb_space(char *); 139 | char **str_to_wordtab(char *, char *); 140 | void free_wordtab(char **); 141 | unsigned int count_high(unsigned int, unsigned int); 142 | unsigned int pos_up(unsigned int); 143 | unsigned int pos_down(unsigned int); 144 | 145 | #endif /* COMMON_H_ */ 146 | -------------------------------------------------------------------------------- /src_graphic/disp_gui.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** disp_gui.c for disp_gui.c in /home/abgral_f/backups/zappy7/src_graphic 3 | ** 4 | ** Made by abgral_f 5 | ** Login 6 | ** 7 | ** Started on Thu Jul 10 21:32:48 2014 abgral_f 8 | ** Last update Fri Jul 11 13:43:06 2014 abgral_f 9 | */ 10 | 11 | #include "graphic.h" 12 | 13 | static int display_gui_text(t_graphic *c) 14 | { 15 | if ((c->display.text = TTF_RenderText_Blended(c->display.font, 16 | c->display.str, 17 | c->display.color)) == NULL) 18 | return (my_error(TTF_GetError(), FAILURE)); 19 | if (SDL_BlitSurface(c->display.text, NULL, c->display.list[WINDOW], 20 | &c->display.pos) == -1) 21 | return (my_error(SDL_GetError(), FAILURE)); 22 | SDL_FreeSurface(c->display.text); 23 | return (SUCCESS); 24 | } 25 | 26 | static int display_gui_items(t_graphic *c) 27 | { 28 | int count; 29 | 30 | count = 0; 31 | while (count != NB_STONE) 32 | { 33 | c->display.pos.x = MAP_X + MARGE_GUI_ITEMS_X; 34 | c->display.pos.y = MARGE_GUI_ITEMS_Y + MARGE_GUI * count; 35 | sprintf(c->display.str, "%d", 36 | (int)c->map[c->display.coord_x 37 | + c->display.coord_y * c->x].b.stone[count]); 38 | if (display_gui_text(c) == FAILURE) 39 | return (FAILURE); 40 | count++; 41 | } 42 | c->display.pos.y = 150 + 40 * count; 43 | sprintf(c->display.str, "%d", 44 | (int)c->map[c->display.coord_x + c->display.coord_y * c->x].b.food); 45 | if (display_gui_text(c) == FAILURE) 46 | return (FAILURE); 47 | return (SUCCESS); 48 | } 49 | 50 | static int display_gui_coord(t_graphic *c) 51 | { 52 | c->display.pos.x = MAP_X + 70; 53 | c->display.pos.y = 55; 54 | sprintf(c->display.str, "%d", c->display.coord_x); 55 | if (display_gui_text(c) == FAILURE) 56 | return (FAILURE); 57 | c->display.pos.x = MAP_X + 230; 58 | c->display.pos.y = 55; 59 | sprintf(c->display.str, "%d", c->display.coord_y); 60 | if (display_gui_text(c) == FAILURE) 61 | return (FAILURE); 62 | return (SUCCESS); 63 | } 64 | 65 | static int display_gui_teams(t_graphic *c) 66 | { 67 | t_client *tmp; 68 | int count; 69 | 70 | tmp = c->client; 71 | count = 0; 72 | while (tmp != NULL) 73 | { 74 | c->display.pos.x = MAP_X + 20; 75 | if (tmp->x == c->display.coord_x && tmp->y == c->display.coord_y 76 | && count <= GUI_LIST_MAX) 77 | { 78 | c->display.pos.y = 470 + 40 * count; 79 | sprintf(c->display.str, "%s", tmp->team->name); 80 | if (display_gui_text(c) == FAILURE) 81 | return (FAILURE); 82 | c->display.pos.x = MAP_X + 175; 83 | sprintf(c->display.str, "%d", tmp->lvl); 84 | if (display_gui_text(c) == FAILURE) 85 | return (FAILURE); 86 | c->display.pos.x = MAP_X + 275; 87 | sprintf(c->display.str, "%d", (int)tmp->inventory.food); 88 | if (display_gui_text(c) == FAILURE) 89 | return (FAILURE); 90 | count++; 91 | } 92 | tmp = tmp->next; 93 | } 94 | return (SUCCESS); 95 | } 96 | 97 | int display_gui(t_graphic *c) 98 | { 99 | c->display.pos.x = MAP_X; 100 | c->display.pos.y = 0; 101 | if (SDL_BlitSurface(c->display.list[GUI], NULL, c->display.list[WINDOW], 102 | &c->display.pos) == -1) 103 | return (my_error(SDL_GetError(), FAILURE)); 104 | if (display_gui_items(c) == FAILURE 105 | || display_gui_coord(c) == FAILURE 106 | || display_gui_teams(c) == FAILURE) 107 | return (FAILURE); 108 | return (SUCCESS); 109 | } 110 | -------------------------------------------------------------------------------- /inc/protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** protocol.h for protocol.h in /home/loeb_t/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by LOEB Thomas 5 | ** Login 6 | ** 7 | ** Started on Mon May 12 16:59:51 2014 LOEB Thomas 8 | ** Last update Tue Jun 17 11:59:18 2014 LOEB Thomas 9 | */ 10 | 11 | #ifndef PROTOCOL_H_ 12 | # define PROTOCOL_H_ 13 | 14 | # define WELCOME_CLIENT(x) ("BIENVENUE"x) 15 | # define GRAPHIC_CLIENT(x) ("GRAPHIC"x) 16 | # define DEATH(x) ("mort"x) 17 | 18 | # define OK(x) ("ok"x) 19 | # define KO(x) ("ko"x) 20 | 21 | # define LEVEL_MAX 8 22 | 23 | # define ORIENTATION "K" 24 | # define MOVE ("deplacement: "ORIENTATION"\n") 25 | # define MSG ("message "ORIENTATION",") 26 | 27 | # define ELEVATION_LAUNCH(x) ("elevation en cours"x) 28 | # define ELEVATION_DONE ("niveau actuel : "ORIENTATION"\n") 29 | 30 | # define FORWARD "avance" 31 | # define RIGHT "droite" 32 | # define LEFT "gauche" 33 | # define LOOK "voir" 34 | # define INVENTORY "inventaire" 35 | # define TAKE "prend" 36 | # define PUT "pose" 37 | # define PUSH "expulse" 38 | # define BROADCAST "broadcast" 39 | # define ELEVATION "incantation" 40 | # define FORK "fork" 41 | # define CONNECT_NBR "connect_nbr" 42 | 43 | # define S_FORWARD (" "FORWARD) 44 | # define S_RIGHT (" "RIGHT) 45 | # define S_LEFT (" "LEFT) 46 | # define S_LOOK (" "LOOK) 47 | # define S_INVENTORY (" "INVENTORY) 48 | # define S_TAKE (" "TAKE) 49 | # define S_PUT (" "PUT) 50 | # define S_PUSH (" "PUSH) 51 | # define S_BROADCAST (" "BROADCAST) 52 | # define S_ELEVATION (" "ELEVATION) 53 | # define S_FORK (" "FORK) 54 | # define S_CONNECT_NBR (" "CONNECT_NBR) 55 | 56 | # define PLAYER "joueur" 57 | 58 | # define S_PLAYER (" "PLAYER) 59 | 60 | # define LINEMATE "linemate" 61 | # define DERAUMERE "deraumêre" 62 | # define SIBUR "sibur" 63 | # define MENDIANE "mendiane" 64 | # define PHIRAS "phiras" 65 | # define THYSTAME "thystame" 66 | 67 | # define S_LINEMATE (" "LINEMATE) 68 | # define S_DERAUMERE (" "DERAUMERE) 69 | # define S_SIBUR (" "SIBUR) 70 | # define S_MENDIANE (" "MENDIANE) 71 | # define S_PHIRAS (" "PHIRAS) 72 | # define S_THYSTAME (" "THYSTAME) 73 | 74 | # define FOOD "nourriture" 75 | 76 | # define S_FOOD (" "FOOD) 77 | 78 | # define MSZ "msz" 79 | # define BCT "bct" 80 | # define MCT "mct" 81 | # define TNA "tna" 82 | # define PPO "ppo" 83 | # define PLV "plv" 84 | # define PIN "pin" 85 | # define SGT "sgt" 86 | # define SST "sst" 87 | 88 | # define GRAPHIC_CMDS 26 89 | 90 | # define PNW "pnw" 91 | # define PEX "pex" 92 | # define PBC "pbc" 93 | # define PIC "pic" 94 | # define PIE "pie" 95 | # define PFK "pfk" 96 | # define PDR "pdr" 97 | # define PGT "pgt" 98 | # define PDI "pdi" 99 | # define ENW "enw" 100 | # define EHT "eht" 101 | # define EBO "ebo" 102 | # define EDI "edi" 103 | # define SEG "seg" 104 | # define SMG "smg" 105 | # define SUC "suc" 106 | # define SBP "sbp" 107 | 108 | # ifdef SERVER_H_ 109 | 110 | typedef struct s_server t_server; 111 | 112 | typedef struct s_action 113 | { 114 | char *cmd; 115 | char param[ARG_LEN]; 116 | long usec; 117 | unsigned int id; 118 | unsigned int nb_param; 119 | bool (*check)(t_server *); 120 | bool (*exec)(t_server *); 121 | } t_action; 122 | 123 | # endif /* SERVER_H_ */ 124 | 125 | #endif /* PROTOCOL_H_ */ 126 | -------------------------------------------------------------------------------- /inc/client.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** client.h for client.h in /home/chauch_a/rendu/PSU_2013_zappy 3 | ** 4 | ** Made by CHAUCHET Alan 5 | ** Login 6 | ** 7 | ** Started on Fri Jun 27 10:20:32 2014 CHAUCHET Alan 8 | ** Last update Fri Jul 11 19:52:36 2014 Baptiste Acca 9 | */ 10 | 11 | #ifndef CLIENT_H_ 12 | # define CLIENT_H_ 13 | 14 | # include 15 | # include "common.h" 16 | 17 | # define CLIENT_USAGE ("USAGE: ./client " \ 18 | "[-n NAME("STD_TEAM1")] " \ 19 | "[-p PORT("STD_PORT")] " \ 20 | "[-h IP("STD_IP")]") 21 | 22 | # define CLIENT_NB_OPT 3 23 | 24 | # define EXPULSE_MSG "deplacement:" 25 | # define BROADCAST_MSG "message" 26 | 27 | # define WELCOME_MANUAL ("### Welcome to the manual" \ 28 | " version of the Zappy" \ 29 | " client ###") 30 | # define MANUAL_AV_CMDS "Available Commands :" 31 | # define MANUAL_FORWARD_CMD "UP ARROW : Go forward" 32 | # define MANUAL_LEFT_CMD "LEFT ARROW : Turn left" 33 | # define MANUAL_RIGHT_CMD "RIGHT ARROW : Turn right" 34 | # define MANUAL_ENTER_CMD "SPACE BAR : Start elevation" 35 | # define MANUAL_LOOK_CMD "V : Look" 36 | # define M_TAKE "E : Take" 37 | # define M_PUT "R : Drop" 38 | # define M_STONES_LINEMATE "1 : linemate" 39 | # define M_STONES_DERAUMERE "2 : deraumere" 40 | # define M_STONES_SIBUR "3 : sibur" 41 | # define M_STONES_MENDIANE "4 : mendiane" 42 | # define M_STONES_PHIRAS "5 : phiras" 43 | # define M_STONES_THYSTAME "6 : thystame" 44 | # define M_FOOD "7 : food" 45 | # define MANUAL_INVENTORY "I : Inventory" 46 | # define MANUAL_PUSH "P : Push players" 47 | # define MANUAL_BROADCAST "ENTER : Broadcast text" 48 | # define MANUAL_FORK "F : Fork player" 49 | # define MANUAL_CONNECT_NBR "N : Connect_nbr" 50 | # define M_TAKE_LISTITEMS ("1: Linemate - 2: Deraumere -" \ 51 | "3: Sibur - 4: Mendiane - " \ 52 | "5: Phiras - 6: Thystame - " \ 53 | "7: Food") 54 | 55 | # define M_PUT_LISTITEMS ("1: Linemate - 2: Deraumere -" \ 56 | "3: Sibur - 4: Mendiane - " \ 57 | "5: Phiras - 6: Thystame") 58 | 59 | # define NB_TEXT_MANUAL 21 60 | 61 | # define NB_CMD 12 62 | 63 | typedef struct s_list_action 64 | { 65 | char *cmd; 66 | char *param; 67 | int nb_time; 68 | struct s_list_action *next; 69 | } t_list_action; 70 | 71 | typedef struct s_keycodes 72 | { 73 | char *cmd; 74 | char *param; 75 | int keycodes[3]; 76 | } t_keycodes; 77 | 78 | typedef struct s_items 79 | { 80 | char *name; 81 | int keycode; 82 | } t_items; 83 | 84 | typedef struct s_client 85 | { 86 | bool connected; 87 | bool manual; 88 | char *name; 89 | int port; 90 | char *ip; 91 | int socket; 92 | struct sockaddr_in server; 93 | t_line l; 94 | int remaining; 95 | unsigned int x; 96 | unsigned int y; 97 | t_buffer b; 98 | t_parse p; 99 | unsigned int level; 100 | t_list_action *list_action; 101 | struct termios termcaps; 102 | } t_client; 103 | 104 | int get_params(t_client *, char **, int *, int); 105 | int connect_to_server(t_client *); 106 | int close_client(t_client *, int); 107 | int check_fds(t_client *); 108 | void my_signal(void); 109 | int check_cmds(t_client *); 110 | int send_cmd(t_client *, char *, char *); 111 | int exec_action(t_client *); 112 | void del_list_action(t_client *); 113 | void pop_front_action(t_client *); 114 | int add_action(t_client *, char *, char *, int); 115 | int raw_mode_init(t_client *); 116 | int raw_mode_exit(t_client *); 117 | int manual_action(t_client *); 118 | void aff_cmds(void); 119 | 120 | #endif /* CLIENT_H_ */ 121 | --------------------------------------------------------------------------------