diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index ee39ead..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "files.associations": { - "iostream": "cpp", - "array": "cpp", - "atomic": "cpp", - "bit": "cpp", - "*.tcc": "cpp", - "cctype": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "compare": "cpp", - "concepts": "cpp", - "csignal": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "map": "cpp", - "string": "cpp", - "unordered_map": "cpp", - "vector": "cpp", - "exception": "cpp", - "algorithm": "cpp", - "functional": "cpp", - "iterator": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "optional": "cpp", - "random": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "initializer_list": "cpp", - "iomanip": "cpp", - "iosfwd": "cpp", - "istream": "cpp", - "limits": "cpp", - "new": "cpp", - "numbers": "cpp", - "ostream": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "cinttypes": "cpp", - "typeinfo": "cpp" - } -} \ No newline at end of file diff --git a/Client.cpp b/Client.cpp index 68ffc86..5080e9c 100644 --- a/Client.cpp +++ b/Client.cpp @@ -16,7 +16,6 @@ std::string Client::getPassowrd() const { return pass; } -// Implementation of getter and setter functions for name std::string Client::getName() const { return name; } @@ -25,7 +24,6 @@ void Client::setName(const std::string& newName) { name = newName; } -// Implementation of getter and setter functions for nick std::string Client::getNick() const { return nick; } @@ -34,7 +32,6 @@ void Client::setNick(const std::string& newNick) { nick = newNick; } -// Implementation of getter and setter functions for user std::string Client::getUser() const { return user; } @@ -50,3 +47,15 @@ int Client::getAuthentication() const { void Client::setAuthentication(int auth) { _authentication = auth; } + +void Client::appendToCommand(std::string toAppend) { + command += toAppend; +} + +const std::string& Client::getCommand() const { + return command; +} + +void Client::clearCommand() { + command.clear(); +} \ No newline at end of file diff --git a/Client.hpp b/Client.hpp index a427fb5..061efe9 100644 --- a/Client.hpp +++ b/Client.hpp @@ -10,6 +10,7 @@ class Client { std::string name; std::string nick; std::string user; + std::string command; int _authentication; public: Client(); @@ -18,22 +19,25 @@ class Client { int getFd() const; std::string getPassowrd() const; - void setPassword(const std::string& password); // Function to set the password - // Getter and setter for name + void setPassword(const std::string& password); + std::string getName() const; void setName(const std::string& newName); - // Getter and setter for nick std::string getNick() const; void setNick(const std::string& newNick); - // Getter and setter for user std::string getUser() const; void setUser(const std::string& newUser); int getAuthentication() const; void setAuthentication(int auth); + + void appendToCommand(std::string toAppend); + const std::string& getCommand() const; + + void clearCommand(); }; #endif \ No newline at end of file diff --git a/Server.cpp b/Server.cpp index 2b1d612..80f47e9 100644 --- a/Server.cpp +++ b/Server.cpp @@ -224,7 +224,7 @@ void Server::createChannel(const std::string& channelName, const std::string& ni } - // Channel already exists, just add the user to it + // Channel already exists, just add the user to it it->second.addClient(nickname, fd); std::string operators = channels[channelName].getOperatorNickname(opperatorfd); std::string operators1 = channels[channelName].getOperatorNickname(abaaba); @@ -518,12 +518,11 @@ int stringToInt(const std::string& str) { void Server::handleClientData(int fd) { - std::string command; char buffer[BUFFER_SIZE]; memset(buffer, 0, sizeof(buffer)); - ssize_t bytesRead; - while ((bytesRead = recv(fd, buffer, BUFFER_SIZE - 1, 0)) > 0) { + ssize_t bytesRead = recv(fd, buffer, BUFFER_SIZE - 1, 0); + if (bytesRead > 0) { bool foundEof = false; for (ssize_t i = 0; i < bytesRead; ++i) { if (buffer[i] == '\n') { @@ -534,9 +533,12 @@ void Server::handleClientData(int fd) if (!foundEof) { buffer[bytesRead] = '\0'; - command += buffer; + getClientByFd(fd).appendToCommand(buffer); + return; } else { - command.append(buffer, bytesRead - 1); + buffer[bytesRead] = '\0'; + getClientByFd(fd).appendToCommand(buffer); + std::string command = getClientByFd(fd).getCommand(); std::cout << "Received data from client " << fd << ": " << command << std::endl; int auth = getClientByFd(fd).getAuthentication(); @@ -1140,10 +1142,9 @@ void Server::handleClientData(int fd) } } } - //**************** STOOOOOOP HERE TOP G ... - break; } + getClientByFd(fd).clearCommand(); } if (bytesRead == 0) { diff --git a/Server.hpp b/Server.hpp index 91e210a..cce92fc 100644 --- a/Server.hpp +++ b/Server.hpp @@ -38,9 +38,9 @@ class Server { std::vector _fds; std::vector _clients; // THAT'S THA DATA OF TOOOP GGG START FROM THERE . - std::map nicknames; // Replace unordered_map with map - std::map usernames; // Replace unordered_map with map - // std::map > channels; //here a chanel name and list of client in every chanel + std::map nicknames; + std::map usernames; + std::map channels;