From ef8a9fd5d8a9fc836994c25b19b670e5c5d01215 Mon Sep 17 00:00:00 2001 From: mochaoui Date: Sat, 27 Apr 2024 14:06:01 +0100 Subject: [PATCH] add some parss --- .vscode/settings.json | 52 ++++++++++++++++++++++++++++++++++++++++++- Server.cpp | 36 +++++++++++++++++++++++++----- 2 files changed, 81 insertions(+), 7 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 0f52d8d..89bff54 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,56 @@ { "files.associations": { "cstring": "cpp", - "iostream": "cpp" + "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", + "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/Server.cpp b/Server.cpp index 74b7b2a..732e95e 100644 --- a/Server.cpp +++ b/Server.cpp @@ -770,7 +770,7 @@ void Server::handleClientData(int fd) std::getline(iss, message); if (iss.fail()) { - std::string errorMessage = "Error: You Just missing an argument\n"; + std::string errorMessage = "Error: You Just missing an argument(5)\n"; send(fd, errorMessage.c_str(), errorMessage.length(), 0); return; } @@ -801,9 +801,16 @@ void Server::handleClientData(int fd) else if (startsWith(command, "KICK ") || startsWith(command, "kick ")) { std::string channelName, userToKick, reason; - std::istringstream iss(command.substr(6)); - iss >> channelName >> userToKick; + std::istringstream iss(command.substr(5)); + iss >> channelName >> userToKick; + if (iss.fail()) + { + std::string errorMessage = "Error: You Just missing an argument(4)\n"; + send(fd, errorMessage.c_str(), errorMessage.length(), 0); + return; + } std::getline(iss, reason); + channelName = channelName.substr(1); channelName = trim(channelName); userToKick = trim(userToKick); reason = trim(reason); @@ -837,9 +844,16 @@ void Server::handleClientData(int fd) else if (startsWith(command, "TOPIC ") || startsWith(command, "topic ")) { std::string channelName, topic; - std::istringstream iss(command.substr(7)); + std::istringstream iss(command.substr(6)); iss >> channelName; std::getline(iss, topic); + if (iss.fail()) + { + std::string errorMessage = "Error: You Just missing an argument(3)\n"; + send(fd, errorMessage.c_str(), errorMessage.length(), 0); + return; + } + channelName = channelName.substr(1); channelName = trim(channelName); topic = trim(topic); topic = topic.substr(1); @@ -865,6 +879,12 @@ void Server::handleClientData(int fd) std::string channelName, nickname; std::istringstream iss(command.substr(7)); iss >> nickname >> channelName; + if (iss.fail()) + { + std::string errorMessage = "Error: You Just missing an argument(2)\n"; + send(fd, errorMessage.c_str(), errorMessage.length(), 0); + return; + } channelName = trim(channelName); nickname = trim(nickname); channelName = channelName.substr(1); @@ -922,8 +942,12 @@ void Server::handleClientData(int fd) { std::string channelName, mode , nick; int limit; - std::istringstream iss(command.substr(6)); + std::istringstream iss(command.substr(5)); iss >> channelName >> mode >> nick; + if (iss.fail()) + return; + // std::getline(iss, nick); + channelName = channelName.substr(1); channelName = trim(channelName); mode = trim(mode); // if (mode == "+l") // what is this ? @@ -1030,7 +1054,7 @@ void Server::handleClientData(int fd) } else if (mode == "-k") { - std::string ChanPass = (mode.substr(2)); + // std::string ChanPass = (mode.substr(2)); if (channels.find(channelName) != channels.end() && channels[channelName].isOperator(fd)) { std::string modeChangeMessage = ":server.host MODE #" + channelName + " -k by " + channels[channelName].getNickname(fd) + "\n";