Esempio n. 1
0
int		ini_map(t_display *d)
{
	if ((d->map = malloc(sizeof(t_map))) == NULL)
		return (-1);
	if ((d->map->map = sgt_map(0)) == NULL)
		return (-1);
	d->map->width = ft_strlen(d->map->map[0]);
	d->map->height = ft_strlistlen(d->map->map);
	return (0);
}
Esempio n. 2
0
void	ft_strlistdel(char **l)
{
	size_t	i;

	i = ft_strlistlen(l);
	while (i > 0)
	{
		free(l[i - 1]);
		i--;
	}
	free(l);
}
Esempio n. 3
0
static int	check_command(char *line, int *sock)
{
	char	**spl;
	int		port;

	spl = ft_strsplit(line, ' ');
	if (ft_strlistlen(spl) > 0 && ft_strcmp(spl[0], "/connect") == '\0')
	{
		if (ft_strlistlen(spl) == 3 && ft_isnumber(spl[2]))
		{
			close(*sock);
			*sock = -1;
			port = ft_atoi(spl[2]);
			if ((*sock = ft_connect(spl[1], port)) != -1)
			{
				ft_strlistdel(spl);
				return (0);
			}
			s_wait_server(&port, sock);
		}
	}
	ft_strlistdel(spl);
	return (1);
}
Esempio n. 4
0
void	ft_del_in_table(char **table, int col)
{
	int		i;

	i = 0;
	while (i <= (int)ft_strlistlen(table))
	{
		if (table[i][col - 1] != '0')
		{
			table[i][col - 1] = '0';
			break ;
		}
		i++;
	}
}
Esempio n. 5
0
void			cmd_who(char *cmd, t_env *e, int cs)
{
	char	*trim;
	char	**spl;
	char	*tmp;

	trim = ft_strtrim(cmd);
	spl = ft_strsplit(trim, ' ');
	ft_strdel(&trim);
	if (ft_strlistlen(spl) == 1)
	{
		s_who(e, cs);
	}
	else
	{
		tmp = ft_strijoin(e->fds[cs].buf_write,
				CLEAR_LINE, "usage: /who\n", 0);
		ft_strcpy(e->fds[cs].buf_write, tmp);
		ft_strdel(&tmp);
	}
	ft_strlistdel(spl);
}
Esempio n. 6
0
void			cmd_msg(char *cmd, t_env *e, int cs)
{
	char	*trim;
	char	**spl;
	char	*tmp;

	trim = ft_strtrim(cmd);
	spl = ft_strsplit(trim, ' ');
	ft_strdel(&trim);
	if (ft_strlistlen(spl) == 3)
	{
		s_msg(e, cs, spl[1], spl[2]);
	}
	else
	{
		tmp = ft_strijoin(e->fds[cs].buf_write,
				CLEAR_LINE, "usage: /msg [name] [message]\n", 0);
		ft_strcpy(e->fds[cs].buf_write, tmp);
		ft_strdel(&tmp);
	}
	ft_strlistdel(spl);
}
Esempio n. 7
0
void		s_wait_server(int *port, int *sock)
{
	char	*line;
	char	**spl;

	line = NULL;
	ft_putstr("Please choose a server [addr] [port] > ");
	while (ft_get_next_line(0, &line) > 0)
	{
		spl = ft_strsplit(line, ' ');
		if (ft_strlistlen(spl) == 2 && ft_isnumber(spl[1]))
		{
			*port = ft_atoi(spl[1]);
			*sock = ft_connect(spl[0], *port);
			if (*sock != -1)
			{
				ft_strlistdel(spl);
				return ;
			}
		}
		ft_putstr("Please choose a server [addr] [port] > ");
		ft_strlistdel(spl);
	}
}