75 lines
2.1 KiB
C++
75 lines
2.1 KiB
C++
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* Server.hpp :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2026/05/06 17:18:11 by iherman- #+# #+# */
|
|
/* Updated: 2026/05/15 15:29:59 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 <sstream>
|
|
|
|
# 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);
|
|
|
|
|
|
public:
|
|
Server();
|
|
Server(int port, const std::string& password);
|
|
~Server();
|
|
|
|
void run();
|
|
};
|
|
|
|
#endif // SERVER_HPP
|