Files
ft_irc/Server/Server.hpp
2026-05-23 21:38:02 +02:00

81 lines
2.4 KiB
C++

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Server.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: iherman- <iherman-@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/05/06 17:18:11 by iherman- #+# #+# */
/* Updated: 2026/05/23 21:29:13 by iherman- ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SERVER_HPP
# define SERVER_HPP
// C++ lib functions
# include <iostream>
# include <string>
# include <cstring>
# include <vector>
# include <map>
# include <cctype>
# include <sstream>
# include <unistd.h>
# include "../User/User.hpp"
# include "../Channel/Channel.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, Channel> channels_;
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);
void join_cmd(User &client, std::istringstream &ss);
void privmsg_cmd(User &client, std::istringstream &ss);
void quit_cmd(User &client, std::istringstream &ss);
void mode_cmd(User &client, std::istringstream &ss);
void invite_cmd(User &client, std::istringstream &ss);
public:
Server();
Server(int port, const std::string& password);
~Server();
void run();
};
#endif // SERVER_HPP