Example #1
0
char		*obtain_case(t_server *serv, int v, int h, int actual)
{
	t_case	t;
	char	*result;
	int		indic;
	char	*tmp;

	indic = 0;
	t = init_tcase(serv, v, h);
	if (serv->map.map[t.y][t.x].nbr <= 0)
		return (NULL);
	result = ft_trunc("%p", pattern(serv->map.map[t.y][t.x].res[NOURRITURE],
		"nourriture "));
	set_ftcase(serv, t, &result);
	if (result)
	{
		tmp = ft_trunc("%s%p", result,
			pattern(count_player(serv, actual, t.x, t.y), "joueur "));
		free(result);
		result = tmp;
	}
	else
		result = ft_trunc("%p", pattern(count_player(serv, actual, t.x, t.y),
		"joueur "));
	if (result)
		result[ft_strlen(result) - 1] = 0;
	return (result);
}
Example #2
0
void		ft_get(t_info *i)
{
	char			*path;
	struct stat		s;
	char			buff[513];
	int				fd;
	int				count;

	if (!i->argv[1])
		return ;
	if (i->argv[1] && i->argv[1][0] != '/')
		path = ft_trunc("%s/%s", i->pwd, i->argv[1]);
	else
		path = ft_strdup(i->argv[1]);
	if (ft_is_dir(path))
	{
		free(path);
		ft_putendl_fd("ERROR: can't get directory\4", i->sock);
		return ;
	}
	if ((fd = open(path, O_RDONLY)) == -1)
	{
		free(path);
		ft_putendl_fd("ERROR: no such file or permission denied\4", i->sock);
		return ;
	}
	free(path);
	ft_bzero(buff, 512);
	send(i->sock, "ERROR: NULL\n", 12, 0);
	fstat(fd, &s);
	count = 0;
	if (s.st_blocks <= 0)
	{
		close(fd);
		return ;
	}
	path = ft_trunc("SIZE: %d", s.st_blocks * 512);
	ft_putendl_fd(path, i->sock);
	ft_putendl_fd(path, 1);
	free(path);
	while (count < s.st_blocks)
	{
		read(fd, buff, 512);
		send(i->sock, buff, 512, 0);
		ft_bzero(buff, 512);
		count++;
	}
	close(fd);
}
Example #3
0
void		sgt(int csock, time_t *tm)
{
	char	*msg;

	msg = ft_trunc("edi #%d", tm);
	write_client(csock, msg);
	free(msg);
}
Example #4
0
void		edi(int csock, int num_egg)
{
	char	*msg;

	msg = ft_trunc("edi #%d", num_egg);
	write_client(csock, msg);
	free(msg);
}
Example #5
0
void		pfk(int csock, t_client *client)
{
	char	*msg;

	msg = ft_trunc("pfk #%d", client->sock);
	write_client(csock, msg);
	free(msg);
}
Example #6
0
static void	cmd_expulse4(t_server *serv, int actual, int who)
{
	int		ret;
	char	*str;

	ret = expulser_direction(serv, actual, who);
	str = ft_trunc("deplacement %d", ret);
	write_client(serv->clients[who].sock, str);
}
Example #7
0
void		ft_case(t_server *serv, char **result, enum e_res r, t_case t)
{
	char	*tmp;
	int		x;
	int		y;

	x = t.x;
	y = t.y;
	if (*result)
	{
		tmp = ft_trunc("%s%p", *result, pattern(serv->map.map[y][x].res[r],
			g_tab[r]));
		free(*result);
		*result = tmp;
	}
	else
		*result = ft_trunc("%p", pattern(serv->map.map[y][x].res[r],
			g_tab[r]));
}
Example #8
0
void		msz(int csock, t_map *map)
{
	char	*msg;

	msg = ft_trunc("msz %d %d", \
					map->x, \
					map->y);
	write_client(csock, msg);
	free(msg);
}
Example #9
0
void	write_client(int sock, const char *buff)
{
	char	*tmp;

	tmp = ft_trunc("%s\n", buff);
	if (send(sock, tmp, ft_strlen((char *)tmp), 0) < 0)
	{
		free(tmp);
		exit_error("send");
	}
	free(tmp);
}
Example #10
0
void		pic(int csock, int actual, t_server *serv)
{
	char	*msg;
	int		i;

	i = -1;
	msg = ft_trunc("pic %d %d %d #%d", \
					serv->clients[actual].x, \
					serv->clients[actual].y, \
					serv->clients[actual].lvl, \
					serv->clients[actual].sock);
	while (serv->clients[++i].sock)
	{
		if ((actual != i) &&
			(serv->clients[actual].x == serv->clients[i].x) &&
			(serv->clients[actual].y == serv->clients[i].y))
			msg = ft_trunc("%s #%d", msg, serv->clients[actual].sock);
	}
	write_client(csock, msg);
	free(msg);
}