Пример #1
0
int		is_correct_syntax(const char *str, t_node **list, t_type *type)
{
	char	**split;
	int		ret;

	if ((ret = is_correct_syntax2(str, type)))
		return (ret);
	split = ft_strsplit(str, ' ');
	if (tablen(split) == 3 && !ft_contain(split[0], '-') &&
			!name_exist(*list, split[0]))
	{
		add_cell(list, split, *type);
		freetab(split);
		return (NODE);
	}
	else if (tablen(split) == 1)
		ret = is_correct_syntax3(str, split, list);
	if (ret == EDGE)
		return (ret);
	else
	{
		ft_putstr_fd("Syntax error : ", 2);
		ft_putendl_fd(str, 2);
	}
	freetab(split);
	return (FALSE);
}
Пример #2
0
static void 	add_neighbor(t_room *room, t_room *neighbor)
{
	if (room && neighbor)
	{
		// ICI IL FAUT REMPLIR LES VOISINS DE LA ROOM AVEC NEIGHBOR
		// room->neighbors = neighbor
		printf("ptr = %p\n", room->neighbors);
	}


static int 		check_tubes(char *str, t_infos *infos, t_list **rooms)
{
	int len;
	char **split;
	t_room *left;
	t_room *right;
	(void)infos;

	if (str)
	{
		split = ft_strsplit(str, '-');
		len = tablen(split);
		if (len == 2)
		{
			left = name_to_room(split[0], rooms);
			right = name_to_room(split[1], rooms);
			printf("left = %s right = %s\n", left->name, right->name);
			add_neighbor(left, right);
			add_neighbor(right, left);
			return (1);
		}
		// PENSES A FREE LE **SPLIT
	}
	return (0);
}
Пример #3
0
static char	*check_params_msg(t_fd *self, char **params)
{
  if (tablen(params) == 1)
    {
      if (params[0] && params[0][0] && params[0][0] != ':')
	return (err_serv("412 ", self->nick,
			 ":No text to send", " PRIVMSG\r\n"));
      else
	return (err_serv("411 ", self->nick,
			 ":No recipient given", " PRIVMSG\r\n"));
    }
  if (tablen(params) != 2)
    return (err_serv("461 ", self->nick, "PRIVMSG",
		     " :Not enough parameters\r\n"));
  return ("");
}
Пример #4
0
void			elevation(t_server *serv, t_client *cl, char *cmd,
			     char **command)
{
  int			tb[8];
  int			i;

  i = 0;
  bzero(tb, sizeof(int) * 8);
  if (tablen(command) > 1 || cmd == NULL)
    {
      add_client_response(&cl, "sbp\n");
      return ;
    }
  content_case(FOOD, serv->map[cl->pos_y][cl->pos_x], &tb[0]);
  while (i < 8)
    {
      if (serv->tab_elev[cl->level - 1][i] != tb[i])
	{
	  add_client_response(&cl, "ko\n");
	  return ;
	}
      i++;
    }
  elevation_bis(serv, cl);
}
Пример #5
0
int		error_boss(char *map)
{
  char		*file;
  char		**tab;
  int		width;
  int		height;

  if (check_existence(map) == -1
      || (file = get_file_content(map)) == NULL
      || check_integer(file, "ibwsm.lg\n") == -1
      || (file = put_return(file)) == NULL
      || (tab = my_str_to_wordtab(file, '\n')) == NULL
      || check_largest(tab) == -1
      || is_present("i", file) != 1
      || is_present("b", file) != 1
      || check_tab(tab) == -1)
    return (puterror("One of Boss map isn't correct.\n"));
  width = my_strlen(tab[0]) * 29;
  height = tablen(tab) * 26;
  if (width > 1300 || height > 750)
    return (puterror("Error: Dimension are too big in Boss Map.\n"));
  free(file);
  free_tab(tab);
  return (0);
}
Пример #6
0
int		my_users(t_env *e, char **cmd, int fd)
{
  t_chan	*current_chan;
  t_server	*tmp;

  if (tablen(cmd) != 1)
    {
      dprintf(fd, "user : error arguments.\n");
      return (0);
    }
  if ((current_chan = get_current_chan(e->chan, fd)) != NULL)
    {
      tmp = current_chan->user;
      while (tmp)
	{
	  if (tmp->nickname)
	    dprintf(fd, "%s\n", tmp->nickname);
	  else if (!tmp->nickname && tmp->type == FD_CLIENT)
	    dprintf(fd, "unknown\n");
	  tmp = tmp->next;
	}
    }
  else
    dprintf(fd, "user : error join a chan before.\n");
}
Пример #7
0
Файл: plv.c Проект: GhaisB/Zappy
void			plv(t_server *server, t_client *client,
			    char *cmd, char **av)
{
  int			fd;
  t_client		*cl;

  (void) cmd;
  if (tablen(av) != 2)
    {
      add_client_response(&(client), "sbp\n");
      return ;
    }
  if (!is_num(av[1]))
    {
      add_client_response(&(client), "sbp\n");
      return ;
    }
  fd = atoi(av[1]);
  if (fd <= 0)
    {
      add_client_response(&(client), "sbp\n");
      return ;
    }
  cl = client_by_id(server, fd);
  send_level(client, cl);
}
Пример #8
0
void			pnwa(t_server *server, t_client *client,
			     char *cmd, char **av)
{
  t_client_list		*tmp;
  char			*str;
  t_client		*cl;

  (void) cmd;
  tmp = server->clients;
  if (tablen(av) != 1)
    {
      add_client_response(&(client), "sbp\n");
      return ;
    }
  while (tmp)
    {
      if (tmp->item && tmp->item->is_graphic == 0 && cl->team)
	{
	  cl = tmp->item;
	  str = my_sprintf("pnw %d %d %d %d %d %s\n",
			   cl->fd, cl->pos_x, cl->pos_y,
			   cl->dir, cl->level, cl->team->name);
	  add_client_response(&(client), str);
	  if (str)
	    free(str);
	}
      tmp = tmp->next;
    }
}
Пример #9
0
int	cmd_msz(char **params, t_client *cl)
{
  int i;
  int j;

  if (tablen(params) != 3)
    return (0);
  cl->fx->size_x = atoi(params[1]);
  cl->fx->size_y = atoi(params[2]);
  cl->fx->size = cl->fx->size_y * cl->fx->size_x;
  cl->fx->map = xmalloc(sizeof(t_case) * cl->fx->size_x);
  i = 0;
  while (i <= cl->fx->size_x)
    {
      j = 0;
      cl->fx->map[i] = xmalloc(sizeof(t_case) * cl->fx->size_y);
      while (j <= cl->fx->size_y)
	{
	  cl->fx->map[i][j] = xmalloc(sizeof(t_case));
	  cl->fx->map[i][j]->ress = NULL;
	  cl->fx->map[i][j]->players_id[0] = 0;
	  cl->fx->map[i][j]->status = -1;
	  j++;
	}
      i++;
    }
  printf("WorldX(%d) WorldY(%d)\n", cl->fx->size_x, cl->fx->size_y);
  return (0);
}
Пример #10
0
int		my_msg(t_env *e, char **cmd, int fd)
{
  t_chan	*current_chan;
  t_server	*user;
  t_server	*current_user;

  if (tablen(cmd) < 3)
    dprintf(fd, "msg : error arguments.\n");
  else if ((current_chan = get_current_chan(e->chan, fd)) != NULL)
    {
      user = current_chan->user;
      current_user = (!user) ? NULL : get_current_user(user, fd);
      while (user)
	{
	  if (user->nickname && !strcmp(user->nickname, cmd[1]) && fd != user->fd)
	    {
	      send_msg_to_user(current_user, user, cmd);
	      return (1);
	    }
	  user = user->next;
	}
      dprintf(fd, "msg : error the receiver's nickname doesn't exist.\n");
    }
  else
    dprintf(fd, "msg : error join a chan before.\n");
}
Пример #11
0
void	lcd(char **tab, t_client clt)
{
	if (tablen(tab) == 1)
	{
		chdir(clt.home);
		printf("SUCCES\n");
	}
	else if (tablen(tab) > 2)
		printf("ERROR : Too many arguments for lcd.\n");
	else
	{
		if (chdir(tab[1]) == -1)
			printf("ERROR : Directory cannot be accessed.\n");
		else
			printf("SUCCES\n");
	}
}
Пример #12
0
void	check_quit(char **tab, t_serv clt)
{
	if (tablen(tab) == 1)
	{
		write(clt.cs, "SUCCES\n", 7);
		close_socket(clt);
	}
	else
		write(clt.cs, "ERROR : quit doesn't take any argument.\n", 40);
}
Пример #13
0
int		is_correct_syntax3(const char *str, char **split, t_node **list)
{
	freetab(split);
	split = ft_strsplit(str, '-');
	if (tablen(split) == 2)
	{
		if (add_edge(*list, split[0], split[1]))
		{
			freetab(split);
			return (EDGE);
		}
	}
	return (0);
}
Пример #14
0
int		opt_env2(int *i, char ***env, char **args)
{
	char	**split;

	split = ft_strsplit(args[*i], '=');
	if (tablen(split) > 2)
	{
		ft_putendl("Syntax error : use key=value");
		return (0);
	}
	else
		ft_setenv(env, split[0], split[1], NULL);
	return (1);
}
Пример #15
0
Файл: sgt.c Проект: GhaisB/Zappy
void			sgt(t_server *server, t_client *client,
			    char *cmd, char **av)
{
  char			*str;

  (void) cmd;
  if (tablen(av) != 1)
    {
      add_client_response(&(client), "sbp\n");
      return ;
    }
  str = my_sprintf("sgt %d\n", server->game_infos.time);
  add_client_response(&(client), str);
  if (str)
    free(str);
}
Пример #16
0
int		my_create_chan(t_env *e, char **cmd, int fd)
{
  t_chan	*tmp;

  if (tablen(cmd) != 2)
    {
      dprintf(fd, "create_chan : error arguments.\n");
      return (0);
    }
  tmp = e->chan;
  while (tmp)
    {
      if (!strcmp(tmp->name, cmd[1]))
	{
	  dprintf(fd, "create_chan : this chan already exist.\n");
	  return (0);
	}
      tmp = tmp->next;
    }
  add_elem_chan(&e->chan, cmd[1]);
  dprintf(fd, "The chan %s has been created.\n", cmd[1]);
}
Пример #17
0
int		cmd_pbc(char **params, t_client *cl)
{
    t_player	*temp;
    int		p_id;

    aff_tab(params);
    if (tablen(params) < 3)
        return (0);
    temp = cl->plist;
    p_id = atoi(params[1]);
    while (temp)
    {
        if (temp->id == p_id)
        {
            temp->action = ACT_BRD;
            temp->message = params[2];
        }
        temp = temp->next;
    }
    aff_player(cl, p_id);
    return (0);
}
Пример #18
0
void	pwd_serv(char **tab, t_serv clt)
{
	char	*pwd;
	char	*ret;

	if (tablen(tab) != 1)
	{
		write(clt.cs,
		"ERROR : Only pwd without argument is supported by the serveur.\n", 63);
		return ;
	}
	else
	{
		pwd = getcwd(NULL, 0);
		ret = ft_strjoin(pwd, "\n");
		write(clt.cs, ret, ft_strlen(ret));
		free(pwd);
		pwd = NULL;
		free(ret);
		ret = NULL;
		return ;
	}
}
Пример #19
0
int	cmd_tna(char **params, t_client *cl)
{
  static int i = 0;

  if (tablen(params) != 2)
    return (0);
  if (i == 0)
    {
      cl->team_name1 = params[1];
      printf("team1: %s\n", cl->team_name1);
      i++;
    }
  else
    {
      if (strcmp(cl->team_name1, params[1]) != 0)
	cl->team_name2 = params[1];
      else
	return (-1);
      printf("team2: %s\n", cl->team_name2);
      cl->status = CL_LOAD;
      set_team_as_title(cl->team_name1, cl->team_name2);
    }
  return (0);
}
Пример #20
0
static int tablen(char **tab)
{
	return ((*tab) ? 1 + tablen(tab + 1) : 0);
}