static t_opt *check(int *val, char **name_team) { t_opt *opt; int i; i = 0; opt = xmalloc(sizeof(t_opt)); opt->port = val[0]; if (check_val(opt->port) == 0) { printf("the port cannot be null\n"); exit(0); } opt->nb_player = xmalloc((strlen_tab(name_team) + 1) * sizeof(int)); while (i < strlen_tab(name_team)) { opt->nb_player[i] = (check_val(val[3]) == 1) ? val[3] : 4; i++; } opt->x_world = (check_val(val[1]) == 1) ? val[1] : 50; opt->y_world = (check_val(val[2]) == 1) ? val[2] : 50; opt->time_world = val[4]; if (check_val(opt->time_world) == 0) opt->time_world = 100; opt->name_team = name_team; return (opt); }
void prend_objet(t_msg *msg, t_client *cl, t_map **map, t_opt *o) { char **tab_cmd; int i; static char tab[7][12] = { "nourriture", "linemate", "deraumere", "sibur", "mendiane", "phiras", "thystame" }; (void)o; map = (void *)map; i = -1; msg->time = get_time_client(cl, 7); tab_cmd = my_str_to_wordtab(msg->comand, ' '); while (strlen_tab(tab_cmd) == 2 && ++i < MAX) if (strcmp(tab[i], tab_cmd[1]) == 0 && cl->map->ress[i] > 0) { cl->map->ress[i] -= 1; cl->ress[i] += (i > 0 ? 1 : 126); sub_food(msg, cl, "ok\n"); take_ress(cl->id, i, cl); giveinvall(cl); givecaseall(cl); repop(map, i); return; } sub_food(msg, cl, "ko\n"); }
int channel_verif(t_msg **msg, char **name, int id, int size) { int pos; if ((pos = find_id_msg(id, msg)) == UNUSED) { fprintf(stderr, "Error: Invalid id.\n"); return (UNUSED); } if (strlen_tab(name) < size) { fprintf(stderr, "Error: transmition failed.\n"); return (UNUSED); } return (pos); }