Files
ft_irc/Server/Server.hpp
2026-05-15 14:24:46 +02:00

72 lines
2.0 KiB
C++

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Server.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/05/06 17:18:11 by iherman- #+# #+# */
/* Updated: 2026/05/15 12:47:58 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SERVER_HPP
# define SERVER_HPP
// C++ lib functions
# include <iostream>
# include <string>
# include <cstring>
# include <vector>
# include <map>
# include <cctype>
# include "../User/User.hpp"
# define SERVER_NAME "irc.server"
# define PORT_DEFAULT 9898
class Server
{
private:
static const int kConnectionQueueLimit;
int port_;
int serverSocket_;
std::string password_;
std::vector<struct pollfd> sockets_;
std::map<int, User> clients_;
std::map<std::string, void (Server::*)(User&, std::istringstream&)> commands_;
bool handleClient(User& client);
void addClient();
std::vector<struct pollfd>::iterator removeClient(std::vector<struct pollfd>::iterator& client);
void parseCommand(User& client);
Server(const Server& other);
Server &operator=(const Server& other);
// Commands
void pass_cmd(User &client, std::istringstream &ss);
void nick_cmd(User &client, std::istringstream &ss);
void user_cmd(User &client, std::istringstream &ss);
public:
Server();
Server(int port, const std::string& password);
~Server();
void run();
};
#endif // SERVER_HPP