I broke something with displaying the clients input plainly
This commit is contained in:
parent
b2c5e0f5d7
commit
bfe88daf3e
10 changed files with 292 additions and 186 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/21 21:34:20 by omoudni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
|
@ -16,19 +16,17 @@
|
|||
#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 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,26 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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/21 13:03:01 by rparodi ### ########.fr */
|
||||
/* Updated: 2025/05/21 21:19:47 by omoudni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
/******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "PollManager.hpp"
|
||||
#include "core.hpp"
|
||||
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -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 getNickname() 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 getNickname() 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