From 8374c4e8012dfa4623e5f24b65924059b5b5026a Mon Sep 17 00:00:00 2001 From: Samy Ben Tayeb Date: Fri, 20 Jun 2025 19:23:00 +0200 Subject: [PATCH] bug on bufferRead with "cap" fixed. --- include/user.hpp | 31 ++++++++++++++++--------------- sources/commands/cap.cpp | 3 +-- sources/core/Server.cpp | 4 +--- sources/user/user.cpp | 14 +++++++------- 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/include/user.hpp b/include/user.hpp index 4cf642e..2427bfe 100644 --- a/include/user.hpp +++ b/include/user.hpp @@ -6,7 +6,7 @@ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/20 21:57:49 by rparodi #+# #+# */ -/* Updated: 2025/06/19 02:22:55 by sben-tay ### ########.fr */ +/* Updated: 2025/06/20 19:17:53 by sben-tay ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,38 +39,39 @@ class User public: User(short unsigned fd, PollManager& poll); short unsigned int getFd() const; - bool isReadyToSend() const; - bool isRegistered() const; - std::string getName() const; - std::string extractFullCommand(); - void setRegistered(); void appendToReadBuffer(const std::string &data); void appendToWriteBuffer(const std::string &data); + std::string extractFullCommand(); void checkRegistration(); void resolveHostInfo(); // setters and getters + void setRegistered(); void setNickname(const std::string &nickname); void setUsername(const std::string &username); void setRealname(const std::string &realname); - std::string getUsername(void) const; - std::string getRealname(void) const; void setHasNick(bool value); void setHasUser(bool value); void setHasPass(bool value); void setPassReceived(bool value); void setPassIsValid(bool value); - bool getHasPass() const; - std::string getNickname() const; - const std::string& getHostname() const; - const std::string& getIpAddress() const; void setHostname(const std::string &hostname); void setIpAddress(const std::string &ip); - + const std::string getUsername(void) const; + const std::string getRealname(void) const; + const std::string getNickname() const; + const std::string getWriteBuffer() const; + const std::string& getHostname() const; + const std::string& getIpAddress() const; + const std::string getName() const; + const std::string getPrefix() const; + bool hasDataToSend() const; - std::string getWriteBuffer() const; + bool getHasPass() const; + bool isReadyToSend() const; + bool isRegistered() const; + void clearWriteBuffer(); void consumeWriteBuffer(size_t len); - std::string getPrefix() const; }; diff --git a/sources/commands/cap.cpp b/sources/commands/cap.cpp index 3b1510d..82dfcd9 100644 --- a/sources/commands/cap.cpp +++ b/sources/commands/cap.cpp @@ -6,7 +6,7 @@ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/06/08 22:10:24 by sben-tay #+# #+# */ -/* Updated: 2025/06/18 12:54:41 by rparodi ### ########.fr */ +/* Updated: 2025/06/20 19:18:52 by sben-tay ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,6 @@ e_code Cap::checkArgs() { this->_sender->appendToWriteBuffer(msg461); return ERR_NEEDMOREPARAMS; } - _sender->appendToReadBuffer(_command); return (_PARSING_OK); } diff --git a/sources/core/Server.cpp b/sources/core/Server.cpp index 8aee714..39ed601 100644 --- a/sources/core/Server.cpp +++ b/sources/core/Server.cpp @@ -6,7 +6,7 @@ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/13 11:11:07 by rparodi #+# #+# */ -/* Updated: 2025/06/20 15:13:42 by sben-tay ### ########.fr */ +/* Updated: 2025/06/20 19:19:42 by sben-tay ### ########.fr */ /* */ /* ************************************************************************** */ @@ -106,11 +106,9 @@ void Server::start() _users[fd]->appendToReadBuffer(data); std::string rawCmd; - DEBUG_MSG("cmd = " << _users[fd]->extractFullCommand()); while (!(rawCmd = _users[fd]->extractFullCommand()).empty()) { std::vector lines = splitLines(rawCmd); for (size_t i = 0; i < lines.size(); ++i) { - DEBUG_MSG("cmd = " << _users[fd]->extractFullCommand()); std::cout << "Client " << fd << " says: " << lines[i] << std::endl; cmd::dispatch(_users[fd], NULL, this, lines[i]); } diff --git a/sources/user/user.cpp b/sources/user/user.cpp index cf97b7b..8e3301f 100644 --- a/sources/user/user.cpp +++ b/sources/user/user.cpp @@ -6,7 +6,7 @@ /* By: sben-tay +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/05/21 20:37:12 by omoudni #+# #+# */ -/* Updated: 2025/06/20 13:40:14 by sben-tay ### ########.fr */ +/* Updated: 2025/06/20 19:18:27 by sben-tay ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,7 +33,7 @@ short unsigned int User::getFd() const { return this->_fd; } * * @return the actual nickname of the user */ -std::string User::getName() const { +const std::string User::getName() const { return this->_nickname; } @@ -151,17 +151,17 @@ void User::setPassIsValid(bool value) { _passIsValid = value; } bool User::getHasPass() const { return _hasPass; } -std::string User::getNickname() const { return _nickname; } +const std::string User::getNickname() const { return _nickname; } bool User::hasDataToSend() const { return !_write_buffer.empty(); } -std::string User::getWriteBuffer() const { return _write_buffer; } +const std::string User::getWriteBuffer() const { return _write_buffer; } void User::clearWriteBuffer() { _write_buffer.clear(); } -std::string User::getPrefix() const { return _nickname + "!" + _username + "@" + _hostname; } +const std::string User::getPrefix() const { return _nickname + "!" + _username + "@" + _hostname; } -std::string User::getUsername() const { return _username; } +const std::string User::getUsername() const { return _username; } const std::string& User::getHostname() const { return _hostname; } @@ -193,7 +193,7 @@ void User::resolveHostInfo() void User::setRealname(const std::string &realname) { _realname = realname; } -std::string User::getRealname(void) const { return _realname; } +const std::string User::getRealname(void) const { return _realname; } void User::consumeWriteBuffer(size_t len) { if (len >= _write_buffer.size())