Merge branch 'master' into raph
This commit is contained in:
commit
520814d6bd
9 changed files with 357 additions and 225 deletions
|
|
@ -1,14 +1,14 @@
|
|||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* PollManager.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: omoudni <omoudni@student.42paris.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/19 19:15:13 by omoudni #+# #+# */
|
||||
/* Updated: 2025/05/20 17:22:59 by sben-tay ### ########.fr */
|
||||
/* Updated: 2025/05/22 17:30:00 by omoudni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
|
@ -16,19 +16,18 @@
|
|||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class PollManager {
|
||||
class PollManager
|
||||
{
|
||||
public:
|
||||
PollManager();
|
||||
~PollManager();
|
||||
PollManager();
|
||||
~PollManager();
|
||||
|
||||
void addClient(int fd);
|
||||
void removeClient(int fd);
|
||||
void updateServer(int fd);
|
||||
void pollLoop(int server_fd);
|
||||
void setServerFd(int fd);
|
||||
void addClient(short unsigned fd);
|
||||
void removeClient(short unsigned fd);
|
||||
void updateServer(short unsigned fd);
|
||||
void pollLoop(int server_fd, std::vector<int> &newClients, std::vector<int> &disconnected, std::vector<std::pair<int, std::string> > &readyClients);
|
||||
|
||||
private:
|
||||
|
||||
std::vector<struct pollfd> _fds;
|
||||
std::map<int, std::string> _buffers;
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* core.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: omoudni <omoudni@student.42paris.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/12 14:16:03 by rparodi #+# #+# */
|
||||
/* Updated: 2025/05/20 17:23:41 by sben-tay ### ########.fr */
|
||||
/* Updated: 2025/05/21 21:18:22 by omoudni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
|
@ -28,8 +28,13 @@ enum e_state {
|
|||
CMD,
|
||||
MSG
|
||||
};
|
||||
|
||||
|
||||
|
||||
// INCLUDES (not to repeat)
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "user.hpp"
|
||||
#include "PollManager.hpp"
|
||||
#include "color.hpp"
|
||||
#include "server.hpp"
|
||||
|
|
|
|||
|
|
@ -1,35 +1,36 @@
|
|||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* server.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: omoudni <omoudni@student.42paris.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/20 21:50:32 by rparodi #+# #+# */
|
||||
/* Updated: 2025/05/24 16:48:04 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "PollManager.hpp"
|
||||
#include <list>
|
||||
#include "user.hpp"
|
||||
#include "channel.hpp"
|
||||
#include "core.hpp"
|
||||
|
||||
class Server {
|
||||
private:
|
||||
int _port;
|
||||
int _serverFd;
|
||||
std::string _password;
|
||||
PollManager _pollManager;
|
||||
public:
|
||||
Server(int port, const std::string &password);
|
||||
~Server();
|
||||
void start();
|
||||
std::list<User *> getUsersList() const;
|
||||
std::list<Channel *> getChannelsList() const;
|
||||
unsigned short int getPort() const;
|
||||
void showInfo() const;
|
||||
class User;
|
||||
class Server
|
||||
{
|
||||
private:
|
||||
int _port;
|
||||
int _serverFd;
|
||||
std::string _password;
|
||||
PollManager _pollManager;
|
||||
std::map<int, User *> _users;
|
||||
|
||||
public:
|
||||
Server(int port, const std::string &password);
|
||||
~Server();
|
||||
void start();
|
||||
unsigned short int getPort() const;
|
||||
std::list<User *> getUsersList() const;
|
||||
std::list<Channel *> getChannelsList() const;
|
||||
void showInfo() const;
|
||||
void printUsers() const;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,36 +1,42 @@
|
|||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* user.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: omoudni <omoudni@student.42paris.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/20 21:57:49 by rparodi #+# #+# */
|
||||
/* Updated: 2025/05/20 22:13:41 by rparodi ### ########.fr */
|
||||
/* Updated: 2025/05/21 21:16:56 by omoudni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include "color.hpp"
|
||||
#include "core.hpp"
|
||||
|
||||
class User {
|
||||
private:
|
||||
int _fd;
|
||||
bool _registered;
|
||||
std::string _nickname;
|
||||
std::string _hostname;
|
||||
std::string _read_buffer;
|
||||
std::string _write_buffer;
|
||||
public:
|
||||
int getFd() const;
|
||||
bool isReadyToSend() const;
|
||||
bool isRegistered() const;
|
||||
std::string getName() const;
|
||||
std::string extractFullCommand();
|
||||
void appendToReadBuffer(const std::string &data);
|
||||
void appendToWriteBuffer(const std::string &data);
|
||||
void setNickname(const std::string &nickname);
|
||||
class User
|
||||
{
|
||||
private:
|
||||
short unsigned int _fd;
|
||||
bool _registered;
|
||||
std::string _nickname;
|
||||
std::string _hostname;
|
||||
std::string _read_buffer;
|
||||
std::string _write_buffer;
|
||||
std::string _username;
|
||||
bool _hasNick;
|
||||
bool _hasUser;
|
||||
|
||||
public:
|
||||
User(short unsigned fd);
|
||||
short unsigned int getFd() const;
|
||||
bool isReadyToSend() const;
|
||||
bool isRegistered() const;
|
||||
std::string getName() const;
|
||||
std::string extractFullCommand();
|
||||
void appendToReadBuffer(const std::string &data);
|
||||
void appendToWriteBuffer(const std::string &data);
|
||||
void setNickname(const std::string &nickname);
|
||||
void setUsername(const std::string &username);
|
||||
void checkRegistration();
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue