From 52e093f72514aa625cdf6f6f8882cc04a32a69ce Mon Sep 17 00:00:00 2001 From: mochaoui Date: Sat, 20 Apr 2024 11:31:23 -0500 Subject: [PATCH] mode -o done --- Server.cpp | 32 ++++++++++++++++++++++++++++++++ channel.hpp | 13 +++++++++++++ 2 files changed, 45 insertions(+) diff --git a/Server.cpp b/Server.cpp index f16dacb..cac3285 100644 --- a/Server.cpp +++ b/Server.cpp @@ -802,6 +802,38 @@ void Server::handleClientData(int fd) { send(fd, errorMessage.c_str(), errorMessage.size(), 0); } } + else if (startsWith(command, "MODE ")) + { + std::string channelName, mode , nick; + std::istringstream iss(command.substr(6)); + iss >> channelName >> mode >> nick; + channelName = trim(channelName); + mode = trim(mode); + nick = trim(nick); + + + std::cout << "this is the mode : " << mode << std::endl; + if (mode == "+o") + { + if (channels.find(channelName) != channels.end() && channels[channelName].isOperator(fd)) { + channels[channelName].addOperator(nick, channels[channelName].getUserFd(nick)); + std::string modeMessage = ":" + nick + " MODE #" + channelName + " +o " + nick + "\n"; + send(fd, modeMessage.c_str(), modeMessage.length(), 0); + } + } + else if (mode == "-o") + { + if (channels.find(channelName) != channels.end() && channels[channelName].isOperator(fd)) { + channels[channelName].removeOperator(nick); + std::string modeMessage = ":" + nick + " MODE #" + channelName + " -o " + nick + "\n"; + send(fd, modeMessage.c_str(), modeMessage.length(), 0); + } + } + // else if (mode == "-i") + // { + + // } + } //**************** STOOOOOOP HERE TOP G ... break; diff --git a/channel.hpp b/channel.hpp index 67ab2d2..d81b3eb 100644 --- a/channel.hpp +++ b/channel.hpp @@ -142,6 +142,19 @@ std::string getOperatorNickname(int fd) const { return ""; // Return empty string if operator not found } + void removeOperator(const std::string& operatorName ) + { + // Iterate through the map to find the operator + std::map::iterator it; + for (it = operators.begin(); it != operators.end(); ++it) { + if (it->first == operatorName) { + // Erase the operator from the map + operators.erase(it); + return; // Exit the function after removing the operator + } + } + } + // Remove an operator from the channel };