/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_irc.hpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/12/01 17:27:37 by apommier #+# #+# */ /* Updated: 2023/02/10 09:59:10 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ #pragma once #include //socket function #include #include //std::string #include //errno #include //std::cout | cerr #include //struct socket #include //epoll ensemble #include //close() #include #include #include "function_tab.hpp" #define MAX_EVENTS 5 #define READ_SIZE 10 #define CMD_NBR 10 /* ************************************************************************** */ /* *********************************STRUCT*********************************** */ /* ************************************************************************** */ struct channelData; struct clientData { bool registered; clientData() { registered = 0; } std::string nickname; std::string password; std::string userName; std::string realName; std::string hostName; std::string serverName; std::string cmdBuffer; //std::string joinedChan[20]; //channelData *joinedChan; //is there a limit? // std::vector joinedChan; std::vector joinedChan; int fd; }; struct channelData { //std::string userList[MAX_EVENTS]; //clientData userList[MAX_EVENTS]; std::string name; std::vector userList; std::vector banList; int op; int nbrUser; }; struct fdList //&allFds in code { struct epoll_event events[MAX_EVENTS]; int epollFd; int serverFd; //int userList[MAX_EVENTS]; //list of userNbr's fd std::vector userList; std::vector channelList; //clientData userData[MAX_EVENTS]; std::vector userData; int nbrUser; functionTab parsingTab; }; /* ************************************************************************** */ /* *******************************CMD UTILS********************************** */ /* ************************************************************************** */ void ft_error(std::string str); void close_fd(int fd); void cmd_error(fdList &allFds, int userNbr, std::string error); void split(std::string const &str, const char delim, std::vector &out); void print_registered_msg(fdList &allFds, int userNbr); /* ************************************************************************** */ /* *******************************CHAN UTILS********************************* */ /* ************************************************************************** */ int find_channel(fdList &allFds, std::string chanName); /* ************************************************************************** */ /* ******************************START SERVER******************************** */ /* ************************************************************************** */ void initialize(char **av); //1st void start_loop(fdList &allFds); //3rd /* ************************************************************************** */ /* *****************************EPOLL UTILITY******************************** */ /* ************************************************************************** */ void epoll_add(int epollFd, int fd); int epoll_start(); //2nd /* ************************************************************************** */ /* *************************CONNECTION AND REQUEST*************************** */ /* ************************************************************************** */ void new_connection(fdList &allFds); bool clientRequest(fdList &allFds, int userNbr); /* ************************************************************************** */ /* ***************************COMMANDS PARSING******************************* */ /* ************************************************************************** */ void parse_commands(std::string buffer, fdList &allFds, int userNbr);