Ejemplo n.º 1
0
int		cmd_fork(t_server *s, t_client *c,
			 char *cmd, e_client_type type)
{
  (void)type;
  (void)cmd;
  static int	id = 0;
  t_egg		*egg;
  t_team	*team;

  if (c->state == CHILD)
    return (ERROR);
  cmd_pfk(c, s->clients);
  team = get_team_by_name(s->teams, c->team_name);
  team->slot_rest++;
  egg = xmalloc(sizeof(t_egg));
  egg->fd = -1;
  egg->fd_father = c->fd;
  egg->id = id;
  egg->pos = xmalloc(sizeof(t_position));
  egg->pos->x = c->pos->x;
  egg->pos->y = c->pos->y;
  egg->team_name = strdup(c->team_name);
  clock_gettime(CLOCK_REALTIME, &egg->eclos);
  get_eclosion(s, egg);
  push_back(s->eggs, egg, EGG);
  cmd_enw(s, c, egg, GUI);
  return (SUCCESS);
}
Ejemplo n.º 2
0
static t_bot	*get_connected_bot(t_env *e, int fd, char *team_name)
{
	t_team		*team;
	t_bot		*bot;

	if ((team = get_team_by_name(e, team_name)) == NULL)
	{
		printf("Client #%d: Invalid request (team doesn't exists)\n", fd);
		return (NULL);
	}
	else if ((bot = connect_bot(e, team)) == NULL)
	{
		printf("Client #%d: Cannot connect to any BOT\n", fd);
		return (NULL);
	}
	return (bot);
}