split lines before commands dispatch + irssi recev code 001 + command PING ok-tiers

This commit is contained in:
Samy BEN TAYEB 2025-06-14 23:39:40 +02:00
parent d52b0cc3c2
commit e88d706ae0
4 changed files with 43 additions and 24 deletions

View file

@ -6,7 +6,7 @@
/* By: sben-tay <sben-tay@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/21 20:37:12 by omoudni #+# #+# */
/* Updated: 2025/06/14 22:34:59 by sben-tay ### ########.fr */
/* Updated: 2025/06/14 23:27:43 by sben-tay ### ########.fr */
/* */
/* ************************************************************************** */
@ -83,7 +83,7 @@ void User::appendToWriteBuffer(const std::string &data)
// Check registration
void User::checkRegistration()
{
if (!_registered && _hasNick && _hasUser) // without _hasPass check
if (!_registered && _hasNick && _hasUser && _hasPass)
{
std::cout << "JE SUIS ENREGISTRE" << std::endl;
_registered = true;
@ -102,18 +102,19 @@ bool User::isReadyToSend() const
// Extract full command from read buffer
std::string User::extractFullCommand() {
std::string command;
size_t pos = _read_buffer.find("\r\n");
if (pos == std::string::npos)
pos = _read_buffer.find("\n"); // fallback
if (pos != std::string::npos) {
command = _read_buffer.substr(0, pos);
_read_buffer.erase(0, pos + 1);
if (_read_buffer[pos] == '\r') // clean up stray \r
_read_buffer.erase(0, 1);
std::string command = _read_buffer.substr(0, pos);
if (_read_buffer.substr(pos, 2) == "\r\n")
_read_buffer.erase(0, pos + 2);
else
_read_buffer.erase(0, pos + 1);
return command;
}
return command;
return "";
}
void User::setHasNick(bool value) { _hasNick = value; }