update server.start(), server.poll().polloop() and /JOIN ok

This commit is contained in:
Samy BEN TAYEB 2025-06-18 01:41:23 +02:00
parent 150ada2f4e
commit 3aad000a49
10 changed files with 122 additions and 77 deletions

View file

@ -1,14 +1,14 @@
/******************************************************************************/
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* PollManager.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: omoudni <omoudni@student.42paris.fr> +#+ +:+ +#+ */
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/19 19:15:13 by omoudni #+# #+# */
/* Updated: 2025/05/22 17:30:00 by omoudni ### ########.fr */
/* Updated: 2025/06/18 01:26:38 by sben-tay ### ########.fr */
/* */
/******************************************************************************/
/* ************************************************************************** */
#pragma once
@ -26,7 +26,8 @@ public:
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);
void pollLoop(int server_fd, std::vector<int> &newClients, std::vector<int> &disconnected, std::vector<std::pair<int, std::string> > &readyClients, std::vector<int> &readyToWrite);
void setWritable(short unsigned fd, bool enable);
private:
std::vector<struct pollfd> _fds;

View file

@ -6,13 +6,14 @@
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/20 22:18:17 by rparodi #+# #+# */
/* Updated: 2025/06/18 00:10:56 by sben-tay ### ########.fr */
/* Updated: 2025/06/18 01:18:05 by sben-tay ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#include "user.hpp"
#include "server.hpp"
#include <string>
#include <list>
@ -44,7 +45,7 @@ class Channel {
void removeOperator(User *user);
// utility functions
void sendAllClientInAChannel(const std::string toSend);
void sendAllClientInAChannel(const std::string toSend, User *sender);
private:
std::string _name;

View file

@ -6,7 +6,7 @@
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/20 21:50:32 by rparodi #+# #+# */
/* Updated: 2025/06/17 23:16:58 by sben-tay ### ########.fr */
/* Updated: 2025/06/18 01:09:21 by sben-tay ### ########.fr */
/* */
/* ************************************************************************** */
@ -36,9 +36,10 @@ 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();
std::list<User *> getUsersList() const;
PollManager& getPollManager();
unsigned short int getPort() const;
std::string getPassword() const;
void showInfo() const;
void printUsers() const;

View file

@ -6,13 +6,14 @@
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/20 21:57:49 by rparodi #+# #+# */
/* Updated: 2025/06/17 15:59:19 by sben-tay ### ########.fr */
/* Updated: 2025/06/18 01:19:32 by sben-tay ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#include <string>
#include "PollManager.hpp"
class User
{
@ -26,14 +27,17 @@ class User
std::string _username;
std::string _realname;
std::string _ipAdress;
bool _hasNick;
bool _hasUser;
bool _hasPass;
bool _passReceived;
bool _passIsValid;
PollManager& _poll;
public:
User(short unsigned fd);
User(short unsigned fd, PollManager& poll);
short unsigned int getFd() const;
bool isReadyToSend() const;
bool isRegistered() const;